blob: a8323062084170f37ca2a0e98b5c773723e6f697 [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Bram Moolenaar4facea32019-10-12 20:17:40 +02003source check.vim
4source screendump.vim
Bram Moolenaar24ebd832020-03-16 21:25:24 +01005source view_util.vim
Bram Moolenaarc82dd862020-06-07 17:30:33 +02006source shared.vim
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00007import './vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02008
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00009func SetUp()
10 func SaveLastScreenLine()
11 let g:Sline = Screenline(&lines - 1)
12 return ''
13 endfunc
14 cnoremap <expr> <F4> SaveLastScreenLine()
15endfunc
16
17func TearDown()
18 delfunc SaveLastScreenLine
19 cunmap <F4>
20endfunc
21
Bram Moolenaarae3150e2016-06-11 23:22:36 +020022func Test_complete_tab()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010023 call writefile(['testfile'], 'Xtestfile', 'D')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020024 call feedkeys(":e Xtest\t\r", "tx")
25 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020026
27 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
28 call feedkeys(":e %\t\r", "tx")
29 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020030endfunc
31
32func Test_complete_list()
33 " We can't see the output, but at least we check the code runs properly.
34 call feedkeys(":e test\<C-D>\r", "tx")
35 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010036
37 " If a command doesn't support completion, then CTRL-D should be literally
38 " used.
39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000041
42 " Test for displaying the tail of the completion matches
43 set wildmode=longest,full
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010044 call mkdir('Xtest', 'R')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000045 call writefile([], 'Xtest/a.c')
46 call writefile([], 'Xtest/a.h')
47 let g:Sline = ''
48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49 call assert_equal('a.c a.h', g:Sline)
50 call assert_equal('"e Xtest/', @:)
51 if has('win32')
52 " Test for 'completeslash'
53 set completeslash=backslash
54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000056 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000058 set completeslash=slash
59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000061 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000063 set completeslash&
64 endif
65
66 " Test for displaying the tail with wildcards
67 let g:Sline = ''
68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
70 call assert_equal('"e Xtes?/', @:)
71 let g:Sline = ''
72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
74 call assert_equal('"e Xtes*/', @:)
75 let g:Sline = ''
76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77 call assert_equal(':e Xtes[/', g:Sline)
78 call assert_equal('"e Xtes[/', @:)
79
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000080 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020081endfunc
82
83func Test_complete_wildmenu()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010084 call mkdir('Xwilddir1/Xdir2', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010085 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
86 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
87 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
88 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020089 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010090
91 " Pressing <Tab> completes, and moves to next files when pressing again.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010092 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010093 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010094 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020095 call assert_equal('testfile2', getline(1))
96
Bram Moolenaar37db6422019-03-28 21:26:23 +010097 " <S-Tab> is like <Tab> but begin with the last match and then go to
98 " previous.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010099 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100100 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100101 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100102 call assert_equal('testfile1', getline(1))
103
104 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100105 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100106 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100107 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100108 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100109 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100110 call assert_equal('testfile1', getline(1))
111
112 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100113 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100114 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100115 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100116 call assert_equal('testfile1', getline(1))
117
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100118 " this fails in some Unix GUIs, not sure why
119 if !has('unix') || !has('gui_running')
120 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
121 " different than 'wildchar'.
122 set wildcharm=<C-Z>
123 cnoremap <C-J> <Down><C-Z>
124 cnoremap <C-K> <Up><C-Z>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100125 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100126 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100127 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100128 call assert_equal('testfile1', getline(1))
129 set wildcharm=0
130 cunmap <C-J>
131 cunmap <C-K>
132 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100133
Bram Moolenaar578fe942020-02-27 21:32:51 +0100134 " Test for canceling the wild menu by adding a character
135 redrawstatus
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100136 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
137 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100138
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100139 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100140 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
142 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
143 cd -
144
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000145 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100146 cnoremap <expr> <F2> wildmenumode()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100147 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
148 call assert_equal('"cd Xwilddir1/0', @:)
149 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
150 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100151 cunmap <F2>
152
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000153 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
154 " After this pressing <Left> or <Right> should not change the selection.
155 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
156 call assert_equal('"sign define', @:)
157 call histadd('cmd', 'TestWildMenu')
158 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
159 call assert_equal('"TestWildMenu', @:)
160
Bram Moolenaar37db6422019-03-28 21:26:23 +0100161 " cleanup
162 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200163 set nowildmenu
164endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100165
Bram Moolenaara60053b2020-09-03 16:50:13 +0200166func Test_wildmenu_screendump()
167 CheckScreendump
168
169 let lines =<< trim [SCRIPT]
170 set wildmenu hlsearch
171 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100172 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173
174 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
175 call term_sendkeys(buf, ":vim\<Tab>")
176 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
177
178 call term_sendkeys(buf, "\<Tab>")
179 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
180
181 call term_sendkeys(buf, "\<Tab>")
182 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
183
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100184 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200185 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
186 call term_sendkeys(buf, "\<Esc>")
187
188 " clean up
189 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200190endfunc
191
Bram Moolenaara653e532022-04-19 11:38:24 +0100192func Test_redraw_in_autocmd()
193 CheckScreendump
194
195 let lines =<< trim END
196 set cmdheight=2
197 autocmd CmdlineChanged * redraw
198 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100199 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100200
201 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
202 call term_sendkeys(buf, ":for i in range(3)\<CR>")
203 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
204
205 call term_sendkeys(buf, "let i =")
206 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
207
208 " clean up
209 call term_sendkeys(buf, "\<CR>")
210 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100211endfunc
212
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100213func Test_redrawstatus_in_autocmd()
214 CheckScreendump
215
216 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100217 set laststatus=2
218 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100219 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100220 END
221 call writefile(lines, 'XTest_redrawstatus', 'D')
222
223 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100224 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100225 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
226 call term_sendkeys(buf, ":foobar")
227 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100228 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100229 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100230 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100231 " with cmdheight=1 messages have scrolled when typing :endfor
232 call term_sendkeys(buf, "\<CR>:endfor")
233 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
234 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
235 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
236 call term_sendkeys(buf, ":for in in range(3)")
237 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
238 call term_sendkeys(buf, "\<CR>:endfor")
239 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100240
241 " clean up
242 call term_sendkeys(buf, "\<CR>")
243 call StopVimInTerminal(buf)
244endfunc
245
Bram Moolenaarf797e302022-08-11 13:17:30 +0100246func Test_changing_cmdheight()
247 CheckScreendump
248
249 let lines =<< trim END
250 set cmdheight=1 laststatus=2
Bram Moolenaar0816f472022-10-05 15:42:32 +0100251 func EchoTwo()
252 set laststatus=2
253 set cmdheight=5
254 echo 'foo'
255 echo 'bar'
256 set cmdheight=1
257 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100258 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100259 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100260
261 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
262 call term_sendkeys(buf, ":resize -3\<CR>")
263 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
264
265 " using the space available doesn't change the status line
266 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
267 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
268
269 " using more space moves the status line up
270 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
271 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
272
273 " reducing cmdheight moves status line down
274 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
275 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
276
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100277 " reducing window size and then setting cmdheight
278 call term_sendkeys(buf, ":resize -1\<CR>")
279 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
280 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
281
Bram Moolenaar0816f472022-10-05 15:42:32 +0100282 " setting 'cmdheight' works after outputting two messages
283 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
284 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
285
Bram Moolenaarf797e302022-08-11 13:17:30 +0100286 " clean up
287 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100288endfunc
289
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100290func Test_cmdheight_tabline()
291 CheckScreendump
292
293 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
294 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
295
296 " clean up
297 call StopVimInTerminal(buf)
298endfunc
299
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100300func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100301 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
302 call assert_equal('"map <unique> <silent>', getreg(':'))
303 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
304 call assert_equal('"map <script> <unique>', getreg(':'))
305 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
306 call assert_equal('"map <expr> <script>', getreg(':'))
307 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
308 call assert_equal('"map <buffer> <expr>', getreg(':'))
309 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
310 call assert_equal('"map <nowait> <buffer>', getreg(':'))
311 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
312 call assert_equal('"map <special> <nowait>', getreg(':'))
313 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
314 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200315
Bram Moolenaar1776a282019-05-03 16:05:41 +0200316 map <Middle>x middle
317
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200318 map ,f commaf
319 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200320 map <Left> left
321 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200322 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
323 call assert_equal('"map ,f', getreg(':'))
324 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
325 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200326 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
327 call assert_equal('"map <Left>', getreg(':'))
328 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200329 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200330 unmap ,f
331 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200332 unmap <Left>
333 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200334
335 set cpo-=< cpo-=B cpo-=k
336 map <Left> left
337 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
338 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200339 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200340 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200341 unmap <Left>
342
343 set cpo+=<
344 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200345 exe "set t_k6=\<Esc>[17~"
346 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200347 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
348 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200349 if !has('gui_running')
350 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
351 call assert_equal("\"map <F6>x", getreg(':'))
352 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200353 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200354 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200355 set cpo-=<
356
357 set cpo+=B
358 map <Left> left
359 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
360 call assert_equal('"map <Left>', getreg(':'))
361 unmap <Left>
362 set cpo-=B
363
364 set cpo+=k
365 map <Left> left
366 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
367 call assert_equal('"map <Left>', getreg(':'))
368 unmap <Left>
369 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200370
Bram Moolenaar531be472020-09-23 22:38:05 +0200371 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
372
Bram Moolenaar1776a282019-05-03 16:05:41 +0200373 unmap <Middle>x
374 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100375endfunc
376
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100377func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100378 hi Aardig ctermfg=green
379 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000380 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100381 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000382 call assert_equal('"match none', @:)
383 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
384 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100385endfunc
386
387func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100388 hi Aardig ctermfg=green
389 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
390 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200391 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
392 call assert_equal('"hi default Aardig', getreg(':'))
393 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
394 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100395 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
396 call assert_equal('"hi link', getreg(':'))
397 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
398 call assert_equal('"hi default', getreg(':'))
399 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
400 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200401 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
402 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
403 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
404 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200405
406 " A cleared group does not show up in completions.
407 hi Anders ctermfg=green
408 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
409 hi clear Aardig
410 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
411 hi clear Anders
412 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100413endfunc
414
Bram Moolenaar75e15672020-06-28 13:10:22 +0200415" Test for command-line expansion of "hi Ni " (easter egg)
416func Test_highlight_easter_egg()
417 call test_override('ui_delay', 1)
418 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
419 call assert_equal("\"hi Ni \<Tab>", @:)
420 call test_override('ALL', 0)
421endfunc
422
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200423func Test_getcompletion()
424 let groupcount = len(getcompletion('', 'event'))
425 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200426 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200427 call assert_true(matchcount > 0)
428 call assert_true(groupcount > matchcount)
429
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200430 if has('menu')
431 source $VIMRUNTIME/menu.vim
432 let matchcount = len(getcompletion('', 'menu'))
433 call assert_true(matchcount > 0)
434 call assert_equal(['File.'], getcompletion('File', 'menu'))
435 call assert_true(matchcount > 0)
436 let matchcount = len(getcompletion('File.', 'menu'))
437 call assert_true(matchcount > 0)
438 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200439
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200440 let l = getcompletion('v:n', 'var')
441 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200442 let l = getcompletion('v:notexists', 'var')
443 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200444
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200445 args a.c b.c
446 let l = getcompletion('', 'arglist')
447 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000448 let l = getcompletion('a.', 'buffer')
449 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200450 %argdelete
451
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200452 let l = getcompletion('', 'augroup')
453 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200454 let l = getcompletion('blahblah', 'augroup')
455 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200456
457 let l = getcompletion('', 'behave')
458 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200459 let l = getcompletion('not', 'behave')
460 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200461
462 let l = getcompletion('', 'color')
463 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200464 let l = getcompletion('dirty', 'color')
465 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200466
467 let l = getcompletion('', 'command')
468 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200469 let l = getcompletion('awake', 'command')
470 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200471
472 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200473 call assert_true(index(l, 'samples/') >= 0)
474 let l = getcompletion('NoMatch', 'dir')
475 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200476
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100477 if glob('~/*') !=# ''
478 let l = getcompletion('~/', 'dir')
479 call assert_true(l[0][0] ==# '~')
480 endif
481
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200482 let l = getcompletion('exe', 'expression')
483 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200484 let l = getcompletion('kill', 'expression')
485 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200486
487 let l = getcompletion('tag', 'function')
488 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200489 let l = getcompletion('paint', 'function')
490 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200491
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200492 let Flambda = {-> 'hello'}
493 let l = getcompletion('', 'function')
494 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200495 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200496
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200497 let l = getcompletion('run', 'file')
498 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200499 let l = getcompletion('walk', 'file')
500 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200501 set wildignore=*.vim
502 let l = getcompletion('run', 'file', 1)
503 call assert_true(index(l, 'runtest.vim') < 0)
504 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000505 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100506 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000507 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
508 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200509
510 let l = getcompletion('ha', 'filetype')
511 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200512 let l = getcompletion('horse', 'filetype')
513 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200514
515 let l = getcompletion('z', 'syntax')
516 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200517 let l = getcompletion('emacs', 'syntax')
518 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200519
520 let l = getcompletion('jikes', 'compiler')
521 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200522 let l = getcompletion('break', 'compiler')
523 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200524
525 let l = getcompletion('last', 'help')
526 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200527 let l = getcompletion('giveup', 'help')
528 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200529
530 let l = getcompletion('time', 'option')
531 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200532 let l = getcompletion('space', 'option')
533 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200534
535 let l = getcompletion('er', 'highlight')
536 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200537 let l = getcompletion('dark', 'highlight')
538 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200539
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200540 let l = getcompletion('', 'messages')
541 call assert_true(index(l, 'clear') >= 0)
542 let l = getcompletion('not', 'messages')
543 call assert_equal([], l)
544
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200545 let l = getcompletion('', 'mapclear')
546 call assert_true(index(l, '<buffer>') >= 0)
547 let l = getcompletion('not', 'mapclear')
548 call assert_equal([], l)
549
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200550 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200551 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200552 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
553 let root = has('win32') ? 'C:\\' : '/'
554 let l = getcompletion(root, 'shellcmd')
555 let expected = map(filter(glob(root . '*', 0, 1),
556 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
557 call assert_equal(expected, l)
558
Bram Moolenaarb650b982016-08-05 20:35:13 +0200559 if has('cscope')
560 let l = getcompletion('', 'cscope')
561 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
562 call assert_equal(cmds, l)
563 " using cmdline completion must not change the result
564 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
565 let l = getcompletion('', 'cscope')
566 call assert_equal(cmds, l)
567 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
568 let l = getcompletion('find ', 'cscope')
569 call assert_equal(keys, l)
570 endif
571
Bram Moolenaar7522f692016-08-06 14:12:50 +0200572 if has('signs')
573 sign define Testing linehl=Comment
574 let l = getcompletion('', 'sign')
575 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
576 call assert_equal(cmds, l)
577 " using cmdline completion must not change the result
578 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
579 let l = getcompletion('', 'sign')
580 call assert_equal(cmds, l)
581 let l = getcompletion('list ', 'sign')
582 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000583 let l = getcompletion('de*', 'sign')
584 call assert_equal(['define'], l)
585 let l = getcompletion('p?', 'sign')
586 call assert_equal(['place'], l)
587 let l = getcompletion('j.', 'sign')
588 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200589 endif
590
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200591 " Command line completion tests
592 let l = getcompletion('cd ', 'cmdline')
593 call assert_true(index(l, 'samples/') >= 0)
594 let l = getcompletion('cd NoMatch', 'cmdline')
595 call assert_equal([], l)
596 let l = getcompletion('let v:n', 'cmdline')
597 call assert_true(index(l, 'v:null') >= 0)
598 let l = getcompletion('let v:notexists', 'cmdline')
599 call assert_equal([], l)
600 let l = getcompletion('call tag', 'cmdline')
601 call assert_true(index(l, 'taglist(') >= 0)
602 let l = getcompletion('call paint', 'cmdline')
603 call assert_equal([], l)
604
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100605 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000606 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100607 return "oneA\noneB\noneC"
608 endfunc
609 command -nargs=1 -complete=custom,T MyCmd
610 let l = getcompletion('MyCmd ', 'cmdline')
611 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000612 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100613
614 delcommand MyCmd
615 delfunc T
ii144785fe02021-11-21 12:13:56 +0000616 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100617
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200618 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200619 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200620 if has('cmdline_hist')
621 call add(names, 'history')
622 endif
623 if has('gettext')
624 call add(names, 'locale')
625 endif
626 if has('profile')
627 call add(names, 'syntime')
628 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200629
630 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100631 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200632
633 for name in names
634 let matchcount = len(getcompletion('', name))
635 call assert_true(matchcount >= 0, 'No matches for ' . name)
636 endfor
637
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200638 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200639
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000640 edit a~b
641 enew
642 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
643 bw a~b
644
645 if has('unix')
646 edit Xtest\
647 enew
648 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
649 bw Xtest\
650 endif
651
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200652 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200653 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100654 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200655endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200656
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000657func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000658 " Get a dialog in the GUI
659 CheckNotGui
660
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000661 " This was using uninitialized memory.
662 let lines =<< trim END
663 set verbose=6
664 norm @=ٷ
665 qall!
666 END
667 call writefile(lines, 'XmultiScript', 'D')
668 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
669endfunc
670
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000671" Test for getcompletion() with "fuzzy" in 'wildoptions'
672func Test_getcompletion_wildoptions()
673 let save_wildoptions = &wildoptions
674 set wildoptions&
675 let l = getcompletion('space', 'option')
676 call assert_equal([], l)
677 let l = getcompletion('ier', 'command')
678 call assert_equal([], l)
679 set wildoptions=fuzzy
680 let l = getcompletion('space', 'option')
681 call assert_true(index(l, 'backspace') >= 0)
682 let l = getcompletion('ier', 'command')
683 call assert_true(index(l, 'compiler') >= 0)
684 let &wildoptions = save_wildoptions
685endfunc
686
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000687func Test_complete_autoload_error()
688 let save_rtp = &rtp
689 let lines =<< trim END
690 vim9script
691 export def Complete(..._): string
692 return 'match'
693 enddef
694 echo this will cause an error
695 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100696 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000697 call writefile(lines, 'Xdir/autoload/script.vim')
698 exe 'set rtp+=' .. getcwd() .. '/Xdir'
699
700 let lines =<< trim END
701 vim9script
702 import autoload 'script.vim'
703 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
704 &wildcharm = char2nr("\<Tab>")
705 feedkeys(":Cmd \<Tab>", 'xt')
706 END
707 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
708
709 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000710endfunc
711
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100712func Test_fullcommand()
713 let tests = {
714 \ '': '',
715 \ ':': '',
716 \ ':::': '',
717 \ ':::5': '',
718 \ 'not_a_cmd': '',
719 \ 'Check': '',
720 \ 'syntax': 'syntax',
721 \ ':syntax': 'syntax',
722 \ '::::syntax': 'syntax',
723 \ 'sy': 'syntax',
724 \ 'syn': 'syntax',
725 \ 'synt': 'syntax',
726 \ ':sy': 'syntax',
727 \ '::::sy': 'syntax',
728 \ 'match': 'match',
729 \ '2match': 'match',
730 \ '3match': 'match',
731 \ 'aboveleft': 'aboveleft',
732 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100733 \ 'en': 'endif',
734 \ 'end': 'endif',
735 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100736 \ 's': 'substitute',
737 \ '5s': 'substitute',
738 \ ':5s': 'substitute',
739 \ "'<,'>s": 'substitute',
740 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100741 \ 'CheckLin': 'CheckLinux',
742 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100743 \ }
744
745 for [in, want] in items(tests)
746 call assert_equal(want, fullcommand(in))
747 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200748 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100749
750 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200751
752 command -buffer BufferLocalCommand :
753 command GlobalCommand :
754 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
755 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
756 delcommand BufferLocalCommand
757 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100758endfunc
759
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200760func Test_shellcmd_completion()
761 let save_path = $PATH
762
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100763 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200764 call writefile([''], 'Xpathdir/Xfile.exe')
765 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
766
767 " Set PATH to example directory without trailing slash.
768 let $PATH = getcwd() . '/Xpathdir'
769
770 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
771 " dirs in the PATH, even though they won't be executed. We check that only
772 " subdirs of the PWD and executables from the PATH are included in the
773 " suggestions.
774 let actual = getcompletion('X', 'shellcmd')
775 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
776 call insert(expected, 'Xfile.exe')
777 call assert_equal(expected, actual)
778
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200779 let $PATH = save_path
780endfunc
781
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200782func Test_expand_star_star()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100783 call mkdir('a/b', 'pR')
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200784 call writefile(['asdfasdf'], 'a/b/fileXname')
785 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000786 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200787 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200788endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100789
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100790func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100791 let @a = "def"
792 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
793 call assert_equal('"abc def ghi', @:)
794
795 new
796 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
797
798 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
799 call assert_equal('"aaa asdf bbb', @:)
800
801 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
802 call assert_equal('"aaa /tmp/some bbb', @:)
803
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200804 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
805 call assert_equal('"aaa '.getline(1).' bbb', @:)
806
Bram Moolenaar21efc362016-12-03 14:05:49 +0100807 set incsearch
808 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
809 call assert_equal('"aaa verylongword bbb', @:)
810
811 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
812 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100813
814 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
815 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100816 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200817
818 " Error while typing a command used to cause that it was not executed
819 " in the end.
820 new
821 try
822 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
823 catch /^Vim\%((\a\+)\)\=:E32/
824 " ignore error E32
825 endtry
826 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100827
Bram Moolenaar578fe942020-02-27 21:32:51 +0100828 " Try to paste an invalid register using <C-R>
829 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
830 call assert_equal('"onetwo', @:)
831
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100832 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100833 let @a = "xy\<C-H>z"
834 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
835 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100836 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
837 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100838 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
839 call assert_equal("\"xy\<C-H>z", @:)
840
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100841 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
842 let @a = "xy\<C-V>z"
843 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
844 call assert_equal('"xyz', @:)
845 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
846 call assert_equal("\"xy\<C-V>z", @:)
847
Bram Moolenaar578fe942020-02-27 21:32:51 +0100848 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
849
Bram Moolenaar72532d32018-04-07 19:09:09 +0200850 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100851endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100852
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100853func Test_cmdline_remove_char()
854 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100855
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100856 for e in ['utf8', 'latin1']
857 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100858
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100859 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
860 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100861
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100862 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
863 call assert_equal('"abcdef', @:)
864
865 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
866 call assert_equal('"abc ghi', @:, e)
867
868 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
869 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100870
871 " This was going before the start in latin1.
872 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100873 endfor
874
875 let &encoding = encoding_save
876endfunc
877
878func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200879 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100880
881 set keymap=esperanto
882 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
883 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
884 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100885endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100886
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100887func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100888 new
889 2;'(
890 2;')
891 quit
892endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100893
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100894func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100895 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100896 new
897 source Xtest.vim
898 " Trigger calling validate_cursor()
899 diffsp Xtest.vim
900 quit!
901 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100902endfunc
903
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100904func Test_mark_from_line_zero()
905 " this was reading past the end of the first (empty) line
906 new
907 norm oxxxx
908 call assert_fails("0;'(", 'E20:')
909 bwipe!
910endfunc
911
Bram Moolenaarba47b512017-01-24 21:18:19 +0100912func Test_cmdline_complete_wildoptions()
913 help
914 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
915 let a = join(sort(split(@:)),' ')
916 set wildoptions=tagfile
917 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
918 let b = join(sort(split(@:)),' ')
919 call assert_equal(a, b)
920 bw!
921endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100922
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200923func Test_cmdline_complete_user_cmd()
924 command! -complete=color -nargs=1 Foo :
925 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
926 call assert_equal('"Foo blue', @:)
927 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
928 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000929 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
930 call assert_equal('"Foo a blue', @:)
931 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
932 call assert_equal('"Foo b\', @:)
933 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
934 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200935 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100936
937 redraw
938 call assert_equal('~', Screenline(&lines - 1))
939 command! FooOne :
940 command! FooTwo :
941
942 set nowildmenu
943 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
944 call assert_equal('"FooOne', @:)
945 call assert_equal('~', Screenline(&lines - 1))
946
947 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
948 call assert_equal('"FooTwo', @:)
949 call assert_equal('~', Screenline(&lines - 1))
950
951 delcommand FooOne
952 delcommand FooTwo
953 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200954endfunc
955
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100956func Test_complete_user_cmd()
957 command FooBar echo 'global'
958 command -buffer FooBar echo 'local'
959 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
960 call assert_equal('"FooBar', @:)
961
962 delcommand -buffer FooBar
963 delcommand FooBar
964endfunc
965
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100966func s:ScriptLocalFunction()
967 echo 'yes'
968endfunc
969
970func Test_cmdline_complete_user_func()
971 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200972 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100973 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
974 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100975
976 " g: prefix also works
977 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
978 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200979
980 " using g: prefix does not result in just "g:" matches from a lambda
981 let Fx = { a -> a }
982 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
983 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200984
985 " existence of script-local dict function does not break user function name
986 " completion
987 function s:a_dict_func() dict
988 endfunction
989 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
990 call assert_match('"call Test_cmdline_complete_user_', @:)
991 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100992endfunc
993
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200994func Test_cmdline_complete_user_names()
995 if has('unix') && executable('whoami')
996 let whoami = systemlist('whoami')[0]
997 let first_letter = whoami[0]
998 if len(first_letter) > 0
999 " Trying completion of :e ~x where x is the first letter of
1000 " the user name should complete to at least the user name.
1001 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1002 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1003 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001004 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001005 " Just in case: check that the system has an Administrator account.
1006 let names = system('net user')
1007 if names =~ 'Administrator'
1008 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001009 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001010 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001011 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001012 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001013 else
1014 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001015 endif
1016endfunc
1017
Bram Moolenaar297610b2019-12-27 17:20:55 +01001018func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001019 CheckExecutable whoami
1020 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1021 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001022endfunc
1023
Bram Moolenaar8b633132020-03-20 18:20:51 +01001024func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001025 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1026 call assert_equal(lang, v:lc_time)
1027
1028 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1029 call assert_equal(lang, v:ctype)
1030
1031 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1032 call assert_equal(lang, v:collate)
1033
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001034 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001035 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001036
1037 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001038 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001039
Bram Moolenaarec680282020-06-12 19:35:32 +02001040 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001041
Bram Moolenaarec680282020-06-12 19:35:32 +02001042 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1043 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001044
Bram Moolenaarec680282020-06-12 19:35:32 +02001045 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1046 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001047
Bram Moolenaarec680282020-06-12 19:35:32 +02001048 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1049 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001050
1051 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1052 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001053endfunc
1054
Bram Moolenaar297610b2019-12-27 17:20:55 +01001055func Test_cmdline_complete_env_variable()
1056 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001057 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1058 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001059 unlet $X_VIM_TEST_COMPLETE_ENV
1060endfunc
1061
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001062func Test_cmdline_complete_expression()
1063 let g:SomeVar = 'blah'
1064 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1065 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1066 call assert_match('"' .. cmd .. ' SomeVar', @:)
1067 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1068 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1069 endfor
1070 unlet g:SomeVar
1071endfunc
1072
Bram Moolenaar47016f52021-08-26 16:39:58 +02001073" Unique function name for completion below
1074func s:WeirdFunc()
1075 echo 'weird'
1076endfunc
1077
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001078" Test for various command-line completion
1079func Test_cmdline_complete_various()
1080 " completion for a command starting with a comment
1081 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1082 call assert_equal("\" :|\"\<C-A>", @:)
1083
1084 " completion for a range followed by a comment
1085 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1086 call assert_equal("\"1,2\"\<C-A>", @:)
1087
1088 " completion for :k command
1089 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1090 call assert_equal("\"ka\<C-A>", @:)
1091
1092 " completion for short version of the :s command
1093 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1094 call assert_equal("\"sI \<C-A>", @:)
1095
1096 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001097 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001098 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001099 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001100 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001101 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1102 call assert_equal("\"w >> Xfile1", @:)
1103 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001104
1105 " completion for :w ! and :r ! commands
1106 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1107 call assert_equal("\"w !invalid_xyz_cmd", @:)
1108 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1109 call assert_equal("\"r !invalid_xyz_cmd", @:)
1110
1111 " completion for :>> and :<< commands
1112 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1113 call assert_equal("\">>>\<C-A>", @:)
1114 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1115 call assert_equal("\"<<<\<C-A>", @:)
1116
1117 " completion for command with +cmd argument
1118 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1119 call assert_equal("\"buffer +/pat Xabc", @:)
1120 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1121 call assert_equal("\"buffer +/pat\<C-A>", @:)
1122
1123 " completion for a command with a trailing comment
1124 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1125 call assert_equal("\"ls \" comment\<C-A>", @:)
1126
1127 " completion for a command with a trailing command
1128 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1129 call assert_equal("\"ls | ls", @:)
1130
1131 " completion for a command with an CTRL-V escaped argument
1132 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1133 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1134
1135 " completion for a command that doesn't take additional arguments
1136 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1137 call assert_equal("\"all abc\<C-A>", @:)
1138
zeertzjqd3de1782022-09-01 12:58:52 +01001139 " completion for :wincmd with :horizontal modifier
1140 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1141 call assert_equal("\"horizontal wincmd", @:)
1142
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001143 " completion for a command with a command modifier
1144 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1145 call assert_equal("\"topleft new", @:)
1146
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001147 " completion for vim9 and legacy commands
1148 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1149 call assert_equal("\"vim9 call strlen(", @:)
1150 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1151 call assert_equal("\"legac call strlen(", @:)
1152
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001153 " completion for the :disassemble command
1154 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1155 call assert_equal("\"disas debug", @:)
1156 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1157 call assert_equal("\"disas profile", @:)
1158 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1159 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1160 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1161 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001162 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1163 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001164
Bram Moolenaar47016f52021-08-26 16:39:58 +02001165 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001166 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001167
naohiro onodfe04db2021-09-12 15:45:10 +02001168 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1169 call assert_match('"disas <SNR>\d\+_', @:)
1170 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1171 call assert_match('"disas debug <SNR>\d\+_', @:)
1172
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001173 " completion for the :match command
1174 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1175 call assert_equal("\"match Search /pat/\<C-A>", @:)
1176
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001177 " completion for the :doautocmd command
1178 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1179 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1180
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001181 " completion of autocmd group after comma
1182 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1183 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1184
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001185 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001186 call writefile([], 'Xvarfile1', 'D')
1187 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001188 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1189 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001190
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001191 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001192 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001193 augroup END
1194 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001195 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001196
1197 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001198 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1199 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001200 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1201 call assert_equal("\"au XTest.test", @:)
1202
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001203 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001204
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001205 " autocmd pattern completion
1206 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1207 call assert_equal("\"au BufEnter *.py\t", @:)
1208
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001209 " completion for the :unlet command
1210 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1211 call assert_equal("\"unlet one two", @:)
1212
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001213 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001214 " FIXME: what should happen on MS-Windows?
1215 if !has('win32')
1216 edit \{someFile}
1217 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1218 call assert_equal("\"buf {someFile}", @:)
1219 bwipe {someFile}
1220 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001221
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001222 " completion for the :bdelete command
1223 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1224 call assert_equal("\"bdel a b c", @:)
1225
1226 " completion for the :mapclear command
1227 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1228 call assert_equal("\"mapclear <buffer>", @:)
1229
1230 " completion for user defined commands with menu names
1231 menu Test.foo :ls<CR>
1232 com -nargs=* -complete=menu MyCmd
1233 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1234 call assert_equal('"MyCmd Test.', @:)
1235 delcom MyCmd
1236 unmenu Test
1237
1238 " completion for user defined commands with mappings
1239 mapclear
1240 map <F3> :ls<CR>
1241 com -nargs=* -complete=mapping MyCmd
1242 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001243 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001244 mapclear
1245 delcom MyCmd
1246
1247 " completion for :set path= with multiple backslashes
1248 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1249 call assert_equal('"set path=a\\\ b', @:)
1250
1251 " completion for :set dir= with a backslash
1252 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1253 call assert_equal('"set dir=a\ b', @:)
1254
1255 " completion for the :py3 commands
1256 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1257 call assert_equal('"py3 py3do py3file', @:)
1258
Bram Moolenaardf749a22021-03-28 15:29:43 +02001259 " completion for the :vim9 commands
1260 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1261 call assert_equal('"vim9cmd vim9script', @:)
1262
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001263 " redir @" is not the start of a comment. So complete after that
1264 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1265 call assert_equal('"redir @" | cwindow', @:)
1266
1267 " completion after a backtick
1268 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1269 call assert_equal('"e `a1b2c', @:)
1270
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001271 " completion for :language command with an invalid argument
1272 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1273 call assert_equal("\"language dummy \t", @:)
1274
1275 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001276 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1277 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001278
1279 " completion with ambiguous user defined commands
1280 com TCmd1 echo 'TCmd1'
1281 com TCmd2 echo 'TCmd2'
1282 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1283 call assert_equal('"TCmd ', @:)
1284 delcom TCmd1
1285 delcom TCmd2
1286
1287 " completion after a range followed by a pipe (|) character
1288 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1289 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001290
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001291 " completion after a :global command
1292 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1293 call assert_equal('"g/a/chistory', @:)
1294 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1295 call assert_equal("\"g/a\\/chist\t", @:)
1296
Bram Moolenaar9c929712020-09-07 22:05:28 +02001297 " use <Esc> as the 'wildchar' for completion
1298 set wildchar=<Esc>
1299 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1300 call assert_equal('"g/a\xb/clearjumps', @:)
1301 " pressing <esc> twice should cancel the command
1302 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1303 call assert_equal('"g/a\xb/clearjumps', @:)
1304 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001305
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001306 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001307 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001308 call writefile([], '~Xtest')
1309 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1310 call assert_equal('"e \~Xtest', @:)
1311 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001312
1313 " should be able to complete a file name that has a '*'
1314 call writefile([], 'Xx*Yy')
1315 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1316 call assert_equal('"e Xx\*Yy', @:)
1317 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001318
1319 " use a literal star
1320 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1321 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001322 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001323
1324 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1325 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001326endfunc
1327
1328" Test for 'wildignorecase'
1329func Test_cmdline_wildignorecase()
1330 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001331 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001332 set wildignorecase
1333 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1334 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001335 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001336 let g:Sline = ''
1337 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1338 call assert_equal('"e xt', @:)
1339 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001340 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001341endfunc
1342
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001343func Test_cmdline_write_alternatefile()
1344 new
1345 call setline('.', ['one', 'two'])
1346 f foo.txt
1347 new
1348 f #-A
1349 call assert_equal('foo.txt-A', expand('%'))
1350 f #<-B.txt
1351 call assert_equal('foo-B.txt', expand('%'))
1352 f %<
1353 call assert_equal('foo-B', expand('%'))
1354 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001355 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001356 bw!
1357 f foo-B.txt
1358 f %<-A
1359 call assert_equal('foo-B-A', expand('%'))
1360 bw!
1361 bw!
1362endfunc
1363
Bram Moolenaarf5724372022-09-02 19:45:15 +01001364func Test_cmdline_expand_cur_alt_file()
1365 enew
1366 file http://some.com/file.txt
1367 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1368 call assert_equal('"e http://some.com/file.txt', @:)
1369 edit another
1370 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1371 call assert_equal('"e http://some.com/file.txt', @:)
1372 bwipe
1373 bwipe http://some.com/file.txt
1374endfunc
1375
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001376" using a leading backslash here
1377set cpo+=C
1378
1379func Test_cmdline_search_range()
1380 new
1381 call setline(1, ['a', 'b', 'c', 'd'])
1382 /d
1383 1,\/s/b/B/
1384 call assert_equal('B', getline(2))
1385
1386 /a
1387 $
1388 \?,4s/c/C/
1389 call assert_equal('C', getline(3))
1390
1391 call setline(1, ['a', 'b', 'c', 'd'])
1392 %s/c/c/
1393 1,\&s/b/B/
1394 call assert_equal('B', getline(2))
1395
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001396 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001397 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001398
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001399 bwipe!
1400endfunc
1401
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001402" Test for the tick mark (') in an excmd range
1403func Test_tick_mark_in_range()
1404 " If only the tick is passed as a range and no command is specified, there
1405 " should not be an error
1406 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001407 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001408 call assert_fails("',print", 'E78:')
1409endfunc
1410
1411" Test for using a line number followed by a search pattern as range
1412func Test_lnum_and_pattern_as_range()
1413 new
1414 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1415 let @" = ''
1416 2/foo/yank
1417 call assert_equal("foo 3\n", @")
1418 call assert_equal(1, line('.'))
1419 close!
1420endfunc
1421
Bram Moolenaar65189a12017-02-06 22:22:17 +01001422" Tests for getcmdline(), getcmdpos() and getcmdtype()
1423func Check_cmdline(cmdtype)
1424 call assert_equal('MyCmd a', getcmdline())
1425 call assert_equal(8, getcmdpos())
1426 call assert_equal(a:cmdtype, getcmdtype())
1427 return ''
1428endfunc
1429
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001430set cpo&
1431
Bram Moolenaar65189a12017-02-06 22:22:17 +01001432func Test_getcmdtype()
1433 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1434
1435 let cmdtype = ''
1436 debuggreedy
1437 call feedkeys(":debug echo 'test'\<CR>", "t")
1438 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1439 call feedkeys("cont\<CR>", "xt")
1440 0debuggreedy
1441 call assert_equal('>', cmdtype)
1442
1443 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1444 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1445
1446 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001447 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001448
1449 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1450
1451 cnoremap <expr> <F6> Check_cmdline('=')
1452 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1453 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001454
1455 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001456endfunc
1457
Bram Moolenaar52604f22017-04-07 16:17:39 +02001458func Test_verbosefile()
1459 set verbosefile=Xlog
1460 echomsg 'foo'
1461 echomsg 'bar'
1462 set verbosefile=
1463 let log = readfile('Xlog')
1464 call assert_match("foo\nbar", join(log, "\n"))
1465 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001466
1467 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001468 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001469endfunc
1470
Bram Moolenaar4facea32019-10-12 20:17:40 +02001471func Test_verbose_option()
1472 CheckScreendump
1473
1474 let lines =<< trim [SCRIPT]
1475 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1476 call feedkeys("\r", 't') " for the hit-enter prompt
1477 set verbose=20
1478 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001479 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001480
1481 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001482 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001483 call term_sendkeys(buf, ":DoSomething\<CR>")
1484 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1485
1486 " clean up
1487 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001488endfunc
1489
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001490func Test_setcmdpos()
1491 func InsertTextAtPos(text, pos)
1492 call assert_equal(0, setcmdpos(a:pos))
1493 return a:text
1494 endfunc
1495
1496 " setcmdpos() with position in the middle of the command line.
1497 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1498 call assert_equal('"1ab2', @:)
1499
1500 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1501 call assert_equal('"1b2a', @:)
1502
1503 " setcmdpos() with position beyond the end of the command line.
1504 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1505 call assert_equal('"12ab', @:)
1506
1507 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001508 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001509endfunc
1510
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001511func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001512 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001513 let encoding_save = &encoding
1514
1515 for e in encodings
1516 exe 'set encoding=' . e
1517
1518 " Test overstrike in the middle of the command line.
1519 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001520 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001521
1522 " Test overstrike going beyond end of command line.
1523 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001524 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001525
1526 " Test toggling insert/overstrike a few times.
1527 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001528 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001529 endfor
1530
Bram Moolenaar30276f22019-01-24 17:59:39 +01001531 " Test overstrike with multi-byte characters.
1532 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001533 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001534
1535 let &encoding = encoding_save
1536endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001537
Bram Moolenaar52410572019-10-27 05:12:45 +01001538func Test_buffers_lastused()
1539 " check that buffers are sorted by time when wildmode has lastused
1540 call test_settime(1550020000) " middle
1541 edit bufa
1542 enew
1543 call test_settime(1550030000) " newest
1544 edit bufb
1545 enew
1546 call test_settime(1550010000) " oldest
1547 edit bufc
1548 enew
1549 call test_settime(0)
1550 enew
1551
1552 call assert_equal(['bufa', 'bufb', 'bufc'],
1553 \ getcompletion('', 'buffer'))
1554
1555 let save_wildmode = &wildmode
1556 set wildmode=full:lastused
1557
1558 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1559 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1560 call assert_equal('b bufb', X)
1561 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1562 call assert_equal('b bufa', X)
1563 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1564 call assert_equal('b bufc', X)
1565 enew
1566
1567 edit other
1568 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1569 call assert_equal('b bufb', X)
1570 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1571 call assert_equal('b bufa', X)
1572 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1573 call assert_equal('b bufc', X)
1574 enew
1575
1576 let &wildmode = save_wildmode
1577
1578 bwipeout bufa
1579 bwipeout bufb
1580 bwipeout bufc
1581endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001582
Bram Moolenaar479950f2020-01-19 15:45:17 +01001583func Test_cmdlineclear_tabenter()
1584 CheckScreendump
1585
1586 let lines =<< trim [SCRIPT]
1587 call setline(1, range(30))
1588 [SCRIPT]
1589
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001590 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001591 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001592 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001593 " in one tab make the command line higher with CTRL-W -
1594 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1595 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1596
1597 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001598endfunc
1599
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001600" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001601func Test_cmdline_expand_special()
1602 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001603 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001604 call assert_fails('e <afile>', 'E495:')
1605 call assert_fails('e <abuf>', 'E496:')
1606 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001607
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001608 call writefile([], 'Xfile.cpp', 'D')
1609 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001610 new Xfile.cpp
1611 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1612 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1613 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001614endfunc
1615
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001616" Test for backtick expression in the command line
1617func Test_cmd_backtick()
1618 %argd
1619 argadd `=['a', 'b', 'c']`
1620 call assert_equal(['a', 'b', 'c'], argv())
1621 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001622
1623 argadd `echo abc def`
1624 call assert_equal(['abc def'], argv())
1625 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001626endfunc
1627
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001628" Test for the :! command
1629func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001630 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001631
1632 let lines =<< trim [SCRIPT]
1633 " Test for no previous command
1634 call assert_fails('!!', 'E34:')
1635 set nomore
1636 " Test for cmdline expansion with :!
1637 call setline(1, 'foo!')
1638 silent !echo <cWORD> > Xfile.out
1639 call assert_equal(['foo!'], readfile('Xfile.out'))
1640 " Test for using previous command
1641 silent !echo \! !
1642 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1643 call writefile(v:errors, 'Xresult')
1644 call delete('Xfile.out')
1645 qall!
1646 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001647 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001648 if RunVim([], [], '--clean -S Xscript')
1649 call assert_equal([], readfile('Xresult'))
1650 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001651 call delete('Xresult')
1652endfunc
1653
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001654" Test error: "E135: *Filter* Autocommands must not change current buffer"
1655func Test_cmd_bang_E135()
1656 new
1657 call setline(1, ['a', 'b', 'c', 'd'])
1658 augroup test_cmd_filter_E135
1659 au!
1660 autocmd FilterReadPost * help
1661 augroup END
1662 call assert_fails('2,3!echo "x"', 'E135:')
1663
1664 augroup test_cmd_filter_E135
1665 au!
1666 augroup END
1667 %bwipe!
1668endfunc
1669
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001670func Test_cmd_bang_args()
1671 new
1672 :.!
1673 call assert_equal(0, v:shell_error)
1674
1675 " Note that below there is one space char after the '!'. This caused a
1676 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1677 :.!
1678 call assert_equal(0, v:shell_error)
1679 bwipe!
1680
1681 CheckUnix
1682 :.!pwd
1683 call assert_equal(0, v:shell_error)
1684 :.! pwd
1685 call assert_equal(0, v:shell_error)
1686
1687 " Note there is one space after 'pwd'.
1688 :.! pwd
1689 call assert_equal(0, v:shell_error)
1690
1691 " Note there are two spaces after 'pwd'.
1692 :.! pwd
1693 call assert_equal(0, v:shell_error)
1694 :.!ls ~
1695 call assert_equal(0, v:shell_error)
1696
1697 " Note there is one space char after '~'.
1698 :.!ls ~
1699 call assert_equal(0, v:shell_error)
1700
1701 " Note there are two spaces after '~'.
1702 :.!ls ~
1703 call assert_equal(0, v:shell_error)
1704
1705 :.!echo "foo"
1706 call assert_equal(getline('.'), "foo")
1707 :.!echo "foo "
1708 call assert_equal(getline('.'), "foo ")
1709 :.!echo " foo "
1710 call assert_equal(getline('.'), " foo ")
1711 :.!echo " foo "
1712 call assert_equal(getline('.'), " foo ")
1713
1714 %bwipe!
1715endfunc
1716
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001717" Test for using ~ for home directory in cmdline completion matches
1718func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001719 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001720 call writefile([], 'Xexpdir/Xfile1')
1721 call writefile([], 'Xexpdir/Xfile2')
1722 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001723 let save_HOME = $HOME
1724 let $HOME = getcwd()
1725 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1726 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1727 let $HOME = save_HOME
1728 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001729endfunc
1730
Bram Moolenaar578fe942020-02-27 21:32:51 +01001731" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1732" or insert mode (when 'insertmode' is set)
1733func Test_cmdline_ctrl_g()
1734 new
1735 call setline(1, 'abc')
1736 call cursor(1, 3)
1737 " If command line is entered from insert mode, using C-\ C-G should back to
1738 " insert mode
1739 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1740 call assert_equal('abxyc', getline(1))
1741 call assert_equal(4, col('.'))
1742
1743 " If command line is entered in 'insertmode', using C-\ C-G should back to
1744 " 'insertmode'
1745 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1746 call assert_equal('ab12xyc', getline(1))
1747 close!
1748endfunc
1749
Bram Moolenaar578fe942020-02-27 21:32:51 +01001750" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001751func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001752 func T(a, c, p)
1753 return "oneA\noneB\noneC"
1754 endfunc
1755 command -nargs=1 -complete=custom,T MyCmd
1756
Bram Moolenaar578fe942020-02-27 21:32:51 +01001757 set nowildmenu
1758 set wildmode=full,list
1759 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001760 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001761 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001762 call assert_equal('"MyCmd oneA', @:)
1763
1764 set wildmode=longest,full
1765 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1766 call assert_equal('"MyCmd one', @:)
1767 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1768 call assert_equal('"MyCmd oneC', @:)
1769
1770 set wildmode=longest
1771 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1772 call assert_equal('"MyCmd one', @:)
1773
1774 set wildmode=list:longest
1775 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001776 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001777 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001778 call assert_equal('"MyCmd one', @:)
1779
1780 set wildmode=""
1781 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1782 call assert_equal('"MyCmd oneA', @:)
1783
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001784 " Test for wildmode=longest with 'fileignorecase' set
1785 set wildmode=longest
1786 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001787 argadd AAA AAAA AAAAA
1788 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1789 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001790 set fileignorecase&
1791
1792 " Test for listing files with wildmode=list
1793 set wildmode=list
1794 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001795 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001796 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001797 call assert_equal('"b A', @:)
1798
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001799 " when using longest completion match, matches shorter than the argument
1800 " should be ignored (happens with :help)
1801 set wildmode=longest,full
1802 set wildmenu
1803 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1804 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001805 " non existing file
1806 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1807 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001808 set wildmenu&
1809
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001810 " Test for longest file name completion with 'fileignorecase'
1811 " On MS-Windows, file names are case insensitive.
1812 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001813 call writefile([], 'XTESTfoo', 'D')
1814 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001815 set nofileignorecase
1816 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1817 call assert_equal('"e XTESTfoo', @:)
1818 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1819 call assert_equal('"e Xtestbar', @:)
1820 set fileignorecase
1821 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1822 call assert_equal('"e Xtest', @:)
1823 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1824 call assert_equal('"e Xtest', @:)
1825 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001826 endif
1827
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001828 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001829 delcommand MyCmd
1830 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001831 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001832 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001833endfunc
1834
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001835func Test_wildmode()
1836 " Test with utf-8 encoding
1837 call Wildmode_tests()
1838
1839 " Test with latin1 encoding
1840 let save_encoding = &encoding
1841 set encoding=latin1
1842 call Wildmode_tests()
1843 let &encoding = save_encoding
1844endfunc
1845
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001846func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001847 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001848 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001849 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001850 let lines =<< trim END
1851 func vim8#Complete(a, c, p)
1852 return "oneA\noneB\noneC"
1853 endfunc
1854 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001855 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001856
1857 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1858 set nowildmenu
1859 set wildmode=full,list
1860 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1861 call assert_equal('"MyCmd oneA oneB oneC', @:)
1862
1863 let &rtp = save_rtp
1864 set wildmode& wildmenu&
1865 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001866endfunc
1867
Bram Moolenaar578fe942020-02-27 21:32:51 +01001868" Test for interrupting the command-line completion
1869func Test_interrupt_compl()
1870 func F(lead, cmdl, p)
1871 if a:lead =~ 'tw'
1872 call interrupt()
1873 return
1874 endif
1875 return "one\ntwo\nthree"
1876 endfunc
1877 command -nargs=1 -complete=custom,F Tcmd
1878
1879 set nowildmenu
1880 set wildmode=full
1881 let interrupted = 0
1882 try
1883 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1884 catch /^Vim:Interrupt$/
1885 let interrupted = 1
1886 endtry
1887 call assert_equal(1, interrupted)
1888
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001889 let interrupted = 0
1890 try
1891 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1892 catch /^Vim:Interrupt$/
1893 let interrupted = 1
1894 endtry
1895 call assert_equal(1, interrupted)
1896
Bram Moolenaar578fe942020-02-27 21:32:51 +01001897 delcommand Tcmd
1898 delfunc F
1899 set wildmode&
1900endfunc
1901
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001902" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001903func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001904 let str = ":one two\<C-U>"
1905 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001906 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001907 let str ..= "\<Left>five\<Right>"
1908 let str ..= "\<Home>two "
1909 let str ..= "\<C-Left>one "
1910 let str ..= "\<C-Right> three"
1911 let str ..= "\<End>\<S-Left>four "
1912 let str ..= "\<S-Right> six"
1913 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1914 call feedkeys(str, 'xt')
1915 call assert_equal("\"one two three four five six seven", @:)
1916endfunc
1917
1918" Test for moving the cursor on the / command line in 'rightleft' mode
1919func Test_cmdline_edit_rightleft()
1920 CheckFeature rightleft
1921 set rightleft
1922 set rightleftcmd=search
1923 let str = "/one two\<C-U>"
1924 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001925 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001926 let str ..= "\<Right>five\<Left>"
1927 let str ..= "\<Home>two "
1928 let str ..= "\<C-Right>one "
1929 let str ..= "\<C-Left> three"
1930 let str ..= "\<End>\<S-Right>four "
1931 let str ..= "\<S-Left> six"
1932 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1933 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1934 call assert_equal("\"one two three four five six seven", @/)
1935 set rightleftcmd&
1936 set rightleft&
1937endfunc
1938
1939" Test for using <C-\>e in the command line to evaluate an expression
1940func Test_cmdline_expr()
1941 " Evaluate an expression from the beginning of a command line
1942 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1943 call assert_equal('"hello', @:)
1944
1945 " Use an invalid expression for <C-\>e
1946 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1947
1948 " Insert literal <CTRL-\> in the command line
1949 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1950 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001951endfunc
1952
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001953" This was making the insert position negative
1954func Test_cmdline_expr_register()
1955 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1956endfunc
1957
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001958" Test for 'imcmdline' and 'imsearch'
1959" This test doesn't actually test the input method functionality.
1960func Test_cmdline_inputmethod()
1961 new
1962 call setline(1, ['', 'abc', ''])
1963 set imcmdline
1964
1965 call feedkeys(":\"abc\<CR>", 'xt')
1966 call assert_equal("\"abc", @:)
1967 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1968 call assert_equal("\"abc", @:)
1969 call feedkeys("/abc\<CR>", 'xt')
1970 call assert_equal([2, 1], [line('.'), col('.')])
1971 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1972 call assert_equal([2, 1], [line('.'), col('.')])
1973
1974 set imsearch=2
1975 call cursor(1, 1)
1976 call feedkeys("/abc\<CR>", 'xt')
1977 call assert_equal([2, 1], [line('.'), col('.')])
1978 call cursor(1, 1)
1979 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1980 call assert_equal([2, 1], [line('.'), col('.')])
1981 set imdisable
1982 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1983 call assert_equal([2, 1], [line('.'), col('.')])
1984 set imdisable&
1985 set imsearch&
1986
1987 set imcmdline&
1988 %bwipe!
1989endfunc
1990
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001991" Test for using CTRL-_ in the command line with 'allowrevins'
1992func Test_cmdline_revins()
1993 CheckNotMSWindows
1994 CheckFeature rightleft
1995 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1996 call assert_equal("\"abc\<c-_>", @:)
1997 set allowrevins
1998 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1999 call assert_equal('"abcñèæ', @:)
2000 set allowrevins&
2001endfunc
2002
2003" Test for typing UTF-8 composing characters in the command line
2004func Test_cmdline_composing_chars()
2005 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2006 call assert_equal('"ゔ', @:)
2007endfunc
2008
Bram Moolenaar0e717042020-04-27 19:29:01 +02002009" test that ";" works to find a match at the start of the first line
2010func Test_zero_line_search()
2011 new
2012 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2013 call cursor(1,1)
2014 0;/pattern/d
2015 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2016 q!
2017endfunc
2018
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002019func Test_read_shellcmd()
2020 CheckUnix
2021 if executable('ls')
2022 " There should be ls in the $PATH
2023 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2024 call assert_match('^"r! .*\<ls\>', @:)
2025 endif
2026
2027 if executable('rm')
2028 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2029 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2030 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002031
2032 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2033 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2034 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002035 endif
2036endfunc
2037
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002038" Test for going up and down the directory tree using 'wildmenu'
2039func Test_wildmenu_dirstack()
2040 CheckUnix
2041 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002042 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002043 call writefile([], 'Xwildmenu/file1_1.txt')
2044 call writefile([], 'Xwildmenu/file1_2.txt')
2045 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2046 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2047 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2048 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2049 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2050 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002051 set wildmenu
2052
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002053 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002054 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002055 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002056 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002057 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002058 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002059 call assert_equal('"e ../../dir3/', @:)
2060 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2061 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002062 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002063 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002064 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002065 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002066 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002067 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2068 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002069
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002070 set wildmenu&
2071endfunc
2072
obcat71c6f7a2021-05-13 20:23:10 +02002073" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002074" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2075" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002076func Test_recalling_cmdline()
2077 CheckFeature cmdline_hist
2078
2079 let g:cmdlines = []
2080 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2081
2082 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002083 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2084 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2085 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2086 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002087 "\ TODO: {'name': 'debug', ...}
2088 \]
2089 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002090 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2091 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2092 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2093 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2094 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002095 \]
2096 let prefix = 'vi'
2097 for h in histories
2098 call histadd(h.name, 'vim')
2099 call histadd(h.name, 'virtue')
2100 call histadd(h.name, 'Virgo')
2101 call histadd(h.name, 'vogue')
2102 call histadd(h.name, 'emacs')
2103 for k in keypairs
2104 let g:cmdlines = []
2105 let keyseqs = h.enter
2106 \ .. prefix
2107 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2108 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2109 \ .. h.exit
2110 call feedkeys(keyseqs, 'xt')
2111 call histdel(h.name, -1) " delete the history added by feedkeys above
2112 let expect = k.prefixmatch
2113 \ ? ['virtue', 'vim', 'virtue', prefix]
2114 \ : ['emacs', 'vogue', 'emacs', prefix]
2115 call assert_equal(expect, g:cmdlines)
2116 endfor
2117 endfor
2118
2119 unlet g:cmdlines
2120 cunmap <Plug>(save-cmdline)
2121endfunc
2122
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002123func Test_cmd_map_cmdlineChanged()
2124 let g:log = []
2125 cnoremap <F1> l<Cmd><CR>s
2126 augroup test
2127 autocmd!
2128 autocmd CmdlineChanged : let g:log += [getcmdline()]
2129 augroup END
2130
2131 call feedkeys(":\<F1>\<CR>", 'xt')
2132 call assert_equal(['l', 'ls'], g:log)
2133
Bram Moolenaar796139a2021-05-18 21:38:45 +02002134 let @b = 'b'
2135 cnoremap <F1> a<C-R>b
2136 let g:log = []
2137 call feedkeys(":\<F1>\<CR>", 'xt')
2138 call assert_equal(['a', 'ab'], g:log)
2139
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002140 unlet g:log
2141 cunmap <F1>
2142 augroup test
2143 autocmd!
2144 augroup END
2145endfunc
2146
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002147" Test for the 'suffixes' option
2148func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002149 call writefile([], 'Xsuffile', 'D')
2150 call writefile([], 'Xsuffile.c', 'D')
2151 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002152 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002153 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2154 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2155 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2156 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002157 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002158 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2159 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2160 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2161 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002162 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002163 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2164 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2165 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2166 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002167 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002168 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002169 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2170 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002171endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002172
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002173" Test for using a popup menu for the command line completion matches
2174" (wildoptions=pum)
2175func Test_wildmenu_pum()
2176 CheckRunVimInTerminal
2177
2178 let commands =<< trim [CODE]
2179 set wildmenu
2180 set wildoptions=pum
2181 set shm+=I
2182 set noruler
2183 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002184
2185 func CmdCompl(a, b, c)
2186 return repeat(['aaaa'], 120)
2187 endfunc
2188 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002189
2190 func MyStatusLine() abort
2191 return 'status'
2192 endfunc
2193 func SetupStatusline()
2194 set statusline=%!MyStatusLine()
2195 set laststatus=2
2196 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002197
2198 func MyTabLine()
2199 return 'my tab line'
2200 endfunc
2201 func SetupTabline()
2202 set statusline=
2203 set tabline=%!MyTabLine()
2204 set showtabline=2
2205 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002206
2207 func DoFeedKeys()
2208 let &wildcharm = char2nr("\t")
2209 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2210 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002211 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002212 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002213
2214 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2215
2216 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002217 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2218
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002219 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002220 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002221 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2222
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002223 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002224 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002225 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2226
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002227 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002228 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002229 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2230
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002231 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002232 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002233 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2234
2235 " pressing <C-E> should end completion and go back to the original match
2236 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002237 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2238
2239 " pressing <C-Y> should select the current match and end completion
2240 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002241 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2242
2243 " With 'wildmode' set to 'longest,full', completing a match should display
2244 " the longest match, the wildmenu should not be displayed.
2245 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2246 call TermWait(buf)
2247 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002248 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2249
2250 " pressing <Tab> should display the wildmenu
2251 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002252 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2253
2254 " pressing <Tab> second time should select the next entry in the menu
2255 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002256 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2257
2258 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002259 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002260 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002261 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2262
2263 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002264 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2265
2266 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002267 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2268
2269 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002270 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002271 call writefile([], 'Xnamedir/XfileA')
2272 call writefile([], 'Xnamedir/XdirA/XfileB')
2273 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002274
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002275 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002276 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2277
2278 " Pressing <Right> on a directory name should go into that directory
2279 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002280 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2281
2282 " Pressing <Left> on a directory name should go to the parent directory
2283 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002284 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2285
2286 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002287 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002288 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002289 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2290
2291 " Pressing <C-D> when the popup menu is displayed should remove the popup
2292 " menu
2293 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002294 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2295
2296 " Pressing <S-Tab> should open the popup menu with the last entry selected
2297 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002298 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2299
2300 " Pressing <Esc> should close the popup menu and cancel the cmd line
2301 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002302 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2303
2304 " Typing a character when the popup is open, should close the popup
2305 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002306 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2307
2308 " When the popup is open, entering the cmdline window should close the popup
2309 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002310 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2311 call term_sendkeys(buf, ":q\<CR>")
2312
2313 " After the last popup menu item, <C-N> should show the original string
2314 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002315 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2316
2317 " Use the popup menu for the command name
2318 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002319 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2320
2321 " Pressing the left arrow should remove the popup menu
2322 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002323 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2324
2325 " Pressing <BS> should remove the popup menu and erase the last character
2326 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002327 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2328
2329 " Pressing <C-W> should remove the popup menu and erase the previous word
2330 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002331 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2332
2333 " Pressing <C-U> should remove the popup menu and erase the entire line
2334 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002335 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2336
2337 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2338 " the cmdline from history
2339 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002340 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2341
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002342 " Check "list" still works
2343 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2344 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002345 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2346 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002347 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2348
rbtnn68cc2b82022-02-09 11:55:47 +00002349 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002350 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002351 call writefile([], 'Xnamedir/あいう/abc')
2352 call writefile([], 'Xnamedir/あいう/xyz')
2353 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002354
2355 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002356 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002357 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2358
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002359 " Pressing <C-A> when the popup menu is displayed should list all the
2360 " matches and pressing a key after that should remove the popup menu
2361 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2362 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2363 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2364
2365 " Pressing <C-A> when the popup menu is displayed should list all the
2366 " matches and pressing <Left> after that should move the cursor
2367 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2368 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2369 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2370
2371 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2372 " should be displayed correctly on the screen.
2373 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2374 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2375
2376 " After using <C-A> to expand all the filename matches, pressing <Up>
2377 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002378 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002379 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2380 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2381 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2382
2383 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2384 " crash Vim
2385 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2386 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2387
Bram Moolenaar414acd32022-02-10 21:09:45 +00002388 " After removing the pum the command line is redrawn
2389 call term_sendkeys(buf, ":edit foo\<CR>")
2390 call term_sendkeys(buf, ":edit bar\<CR>")
2391 call term_sendkeys(buf, ":ls\<CR>")
2392 call term_sendkeys(buf, ":com\<Tab> ")
2393 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002394 call term_sendkeys(buf, "\<C-U>\<CR>")
2395
2396 " Esc still works to abort the command when 'statusline' is set
2397 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2398 call term_sendkeys(buf, ":si\<Tab>")
2399 call term_sendkeys(buf, "\<Esc>")
2400 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002401
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002402 " Esc still works to abort the command when 'tabline' is set
2403 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2404 call term_sendkeys(buf, ":si\<Tab>")
2405 call term_sendkeys(buf, "\<Esc>")
2406 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2407
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002408 " popup is cleared also when 'lazyredraw' is set
2409 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2410 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2411 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2412 call term_sendkeys(buf, "\<Esc>")
2413
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002414 " Pressing <PageDown> should scroll the menu downward
2415 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2416 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2417 call term_sendkeys(buf, "\<PageDown>")
2418 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2419 call term_sendkeys(buf, "\<PageDown>")
2420 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2421 call term_sendkeys(buf, "\<PageDown>")
2422 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2423 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2424 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2425
2426 " Pressing <PageUp> should scroll the menu upward
2427 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2428 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2429 call term_sendkeys(buf, "\<PageUp>")
2430 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2431 call term_sendkeys(buf, "\<PageUp>")
2432 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2433 call term_sendkeys(buf, "\<PageUp>")
2434 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2435
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002436 call term_sendkeys(buf, "\<C-U>\<CR>")
2437 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002438endfunc
2439
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002440" Test for wildmenumode() with the cmdline popup menu
2441func Test_wildmenumode_with_pum()
2442 set wildmenu
2443 set wildoptions=pum
2444 cnoremap <expr> <F2> wildmenumode()
2445 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2446 call assert_equal('"sign define10', @:)
2447 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2448 call assert_equal('"sign define jump list place undefine unplace0', @:)
2449 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2450 call assert_equal('"sign 0', @:)
2451 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2452 call assert_equal('"sign define0', @:)
2453 set nowildmenu wildoptions&
2454 cunmap <F2>
2455endfunc
2456
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002457func Test_wildmenu_with_pum_foldexpr()
2458 CheckRunVimInTerminal
2459
2460 let lines =<< trim END
2461 call setline(1, ['folded one', 'folded two', 'some more text'])
2462 func MyFoldText()
2463 return 'foo'
2464 endfunc
2465 set foldtext=MyFoldText() wildoptions=pum
2466 normal ggzfj
2467 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002468 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002469 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2470 call term_sendkeys(buf, ":set\<Tab>")
2471 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2472
2473 call term_sendkeys(buf, "\<Esc>")
2474 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2475
2476 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002477endfunc
2478
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002479" Test for opening the cmdline completion popup menu from the terminal window.
2480" The popup menu should be positioned correctly over the status line of the
2481" bottom-most window.
2482func Test_wildmenu_pum_from_terminal()
2483 CheckRunVimInTerminal
2484 let python = PythonProg()
2485 call CheckPython(python)
2486
2487 %bw!
2488 let cmds = ['set wildmenu wildoptions=pum']
2489 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2490 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002491 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002492 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2493 call term_sendkeys(buf, "\r\r\r")
2494 call term_wait(buf)
2495 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2496 call term_wait(buf)
2497 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2498 call term_wait(buf)
2499 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002500endfunc
2501
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002502func Test_wildmenu_pum_clear_entries()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002503 CheckRunVimInTerminal
2504
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002505 " This was using freed memory. Run in a terminal to get the pum to update.
2506 let lines =<< trim END
2507 set wildoptions=pum
2508 set wildchar=<C-E>
2509 END
2510 call writefile(lines, 'XwildmenuTest', 'D')
2511 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2512
2513 call term_sendkeys(buf, ":\<C-E>\<C-E>")
2514 call VerifyScreenDump(buf, 'Test_wildmenu_pum_clear_entries_1', {})
2515
2516 set wildoptions& wildchar&
2517endfunc
2518
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002519" Test for completion after a :substitute command followed by a pipe (|)
2520" character
2521func Test_cmdline_complete_substitute()
2522 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2523 call assert_equal("\"s | \t", @:)
2524 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2525 call assert_equal("\"s/ | \t", @:)
2526 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2527 call assert_equal("\"s/one | \t", @:)
2528 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2529 call assert_equal("\"s/one/ | \t", @:)
2530 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2531 call assert_equal("\"s/one/two | \t", @:)
2532 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2533 call assert_equal('"s/one/two/ | chistory', @:)
2534 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2535 call assert_equal("\"s/one/two/g \t", @:)
2536 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2537 call assert_equal("\"s/one/two/g | chistory", @:)
2538 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2539 call assert_equal("\"s/one/t\\/ | \t", @:)
2540 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2541 call assert_equal('"s/one/t"o/ | chistory', @:)
2542 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2543 call assert_equal('"s/one/t|o/ | chistory', @:)
2544 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2545 call assert_equal("\"&\t", @:)
2546endfunc
2547
2548" Test for the :dlist command completion
2549func Test_cmdline_complete_dlist()
2550 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2551 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2552 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2553 call assert_equal("\"dlist 10 /pat/ \t", @:)
2554 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2555 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2556 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2557 call assert_equal("\"dlist 10 /pat\\\t", @:)
2558 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2559 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2560endfunc
2561
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002562" argument list (only for :argdel) fuzzy completion
2563func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002564 argadd change.py count.py charge.py
2565 set wildoptions&
2566 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2567 call assert_equal('"argdel cge', @:)
2568 set wildoptions=fuzzy
2569 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2570 call assert_equal('"argdel change.py charge.py', @:)
2571 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002572 set wildoptions&
2573endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002574
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002575" autocmd group name fuzzy completion
2576func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002577 set wildoptions&
2578 augroup MyFuzzyGroup
2579 augroup END
2580 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2581 call assert_equal('"augroup mfg', @:)
2582 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2583 call assert_equal('"augroup MyFuzzyGroup', @:)
2584 set wildoptions=fuzzy
2585 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2586 call assert_equal('"augroup MyFuzzyGroup', @:)
2587 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2588 call assert_equal('"augroup My*p', @:)
2589 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002590 set wildoptions&
2591endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002592
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002593" buffer name fuzzy completion
2594func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002595 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002596 " Use a long name to reduce the risk of matching a random directory name
2597 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002598 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002599 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2600 call assert_equal('"b SRFWL', @:)
2601 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2602 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002603 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002604 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2605 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2606 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2607 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002608 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002609 set wildoptions&
2610endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002611
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002612" buffer name (full path) fuzzy completion
2613func Test_fuzzy_completion_bufname_fullpath()
2614 CheckUnix
2615 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002616 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002617 edit Xcmd/Xstate/Xfile.js
2618 cd Xcmd/Xstate
2619 enew
2620 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2621 call assert_equal('"b CmdStateFile', @:)
2622 set wildoptions=fuzzy
2623 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2624 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2625 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002626 set wildoptions&
2627endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002628
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002629" :behave suboptions fuzzy completion
2630func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002631 set wildoptions&
2632 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2633 call assert_equal('"behave xm', @:)
2634 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2635 call assert_equal('"behave xterm', @:)
2636 set wildoptions=fuzzy
2637 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2638 call assert_equal('"behave xterm', @:)
2639 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2640 call assert_equal('"behave xt*m', @:)
2641 let g:Sline = ''
2642 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2643 call assert_equal('mswin', g:Sline)
2644 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002645 set wildoptions&
2646endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002647
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002648" " colorscheme name fuzzy completion - NOT supported
2649" func Test_fuzzy_completion_colorscheme()
2650" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002651
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002652" built-in command name fuzzy completion
2653func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002654 set wildoptions&
2655 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2656 call assert_equal('"sbwin', @:)
2657 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2658 call assert_equal('"sbrewind', @:)
2659 set wildoptions=fuzzy
2660 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2661 call assert_equal('"sbrewind', @:)
2662 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2663 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002664 set wildoptions&
2665endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002666
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002667" " compiler name fuzzy completion - NOT supported
2668" func Test_fuzzy_completion_compiler()
2669" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002670
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002671" :cscope suboptions fuzzy completion
2672func Test_fuzzy_completion_cscope()
2673 CheckFeature cscope
2674 set wildoptions&
2675 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2676 call assert_equal('"cscope ret', @:)
2677 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2678 call assert_equal('"cscope reset', @:)
2679 set wildoptions=fuzzy
2680 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2681 call assert_equal('"cscope reset', @:)
2682 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2683 call assert_equal('"cscope re*t', @:)
2684 set wildoptions&
2685endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002686
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002687" :diffget/:diffput buffer name fuzzy completion
2688func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002689 new SomeBuffer
2690 diffthis
2691 new OtherBuffer
2692 diffthis
2693 set wildoptions&
2694 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2695 call assert_equal('"diffget sbuf', @:)
2696 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2697 call assert_equal('"diffput sbuf', @:)
2698 set wildoptions=fuzzy
2699 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2700 call assert_equal('"diffget SomeBuffer', @:)
2701 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2702 call assert_equal('"diffput SomeBuffer', @:)
2703 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002704 set wildoptions&
2705endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002706
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002707" " directory name fuzzy completion - NOT supported
2708" func Test_fuzzy_completion_dirname()
2709" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002710
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002711" environment variable name fuzzy completion
2712func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002713 set wildoptions&
2714 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2715 call assert_equal('"echo $VUT', @:)
2716 set wildoptions=fuzzy
2717 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2718 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002719 set wildoptions&
2720endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002721
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002722" autocmd event fuzzy completion
2723func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002724 set wildoptions&
2725 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2726 call assert_equal('"autocmd BWout', @:)
2727 set wildoptions=fuzzy
2728 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2729 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002730 set wildoptions&
2731endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002732
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002733" vim expression fuzzy completion
2734func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002735 let g:PerPlaceCount = 10
2736 set wildoptions&
2737 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2738 call assert_equal('"let c = ppc', @:)
2739 set wildoptions=fuzzy
2740 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2741 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002742 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002743endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002744
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002745" " file name fuzzy completion - NOT supported
2746" func Test_fuzzy_completion_filename()
2747" endfunc
2748
2749" " files in path fuzzy completion - NOT supported
2750" func Test_fuzzy_completion_filesinpath()
2751" endfunc
2752
2753" " filetype name fuzzy completion - NOT supported
2754" func Test_fuzzy_completion_filetype()
2755" endfunc
2756
2757" user defined function name completion
2758func Test_fuzzy_completion_userdefined_func()
2759 set wildoptions&
2760 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2761 call assert_equal('"call Test_f_u_f', @:)
2762 set wildoptions=fuzzy
2763 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2764 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2765 set wildoptions&
2766endfunc
2767
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002768" <SNR> functions should be sorted to the end
2769func Test_fuzzy_completion_userdefined_snr_func()
2770 func s:Sendmail()
2771 endfunc
2772 func SendSomemail()
2773 endfunc
2774 func S1e2n3dmail()
2775 endfunc
2776 set wildoptions=fuzzy
2777 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002778 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002779 set wildoptions&
2780 delfunc s:Sendmail
2781 delfunc SendSomemail
2782 delfunc S1e2n3dmail
2783endfunc
2784
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002785" user defined command name completion
2786func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002787 set wildoptions&
2788 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2789 call assert_equal('"MsFeat', @:)
2790 set wildoptions=fuzzy
2791 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2792 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002793 set wildoptions&
2794endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002795
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002796" " :help tag fuzzy completion - NOT supported
2797" func Test_fuzzy_completion_helptag()
2798" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002799
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002800" highlight group name fuzzy completion
2801func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002802 set wildoptions&
2803 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2804 call assert_equal('"highlight SKey', @:)
2805 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2806 call assert_equal('"highlight SpecialKey', @:)
2807 set wildoptions=fuzzy
2808 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2809 call assert_equal('"highlight SpecialKey', @:)
2810 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2811 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002812 set wildoptions&
2813endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002814
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002815" :history suboptions fuzzy completion
2816func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002817 set wildoptions&
2818 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2819 call assert_equal('"history dg', @:)
2820 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2821 call assert_equal('"history search', @:)
2822 set wildoptions=fuzzy
2823 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2824 call assert_equal('"history debug', @:)
2825 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2826 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002827 set wildoptions&
2828endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002829
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002830" :language locale name fuzzy completion
2831func Test_fuzzy_completion_lang()
2832 CheckUnix
2833 set wildoptions&
2834 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2835 call assert_equal('"lang psx', @:)
2836 set wildoptions=fuzzy
2837 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2838 call assert_equal('"lang POSIX', @:)
2839 set wildoptions&
2840endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002841
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002842" :mapclear buffer argument fuzzy completion
2843func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002844 set wildoptions&
2845 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2846 call assert_equal('"mapclear buf', @:)
2847 set wildoptions=fuzzy
2848 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2849 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002850 set wildoptions&
2851endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002852
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002853" map name fuzzy completion
2854func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002855 " test regex completion works
2856 set wildoptions=fuzzy
2857 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2858 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002859 nmap <plug>MyLongMap :p<CR>
2860 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2861 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2862 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2863 call assert_equal("\"nmap MLM \t", @:)
2864 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2865 call assert_equal("\"nmap <F2> one two \t", @:)
2866 " duplicate entries should be removed
2867 vmap <plug>MyLongMap :<C-U>#<CR>
2868 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2869 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2870 nunmap <plug>MyLongMap
2871 vunmap <plug>MyLongMap
2872 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2873 call assert_equal("\"nmap ABC\t", @:)
2874 " results should be sorted by best match
2875 nmap <Plug>format :
2876 nmap <Plug>goformat :
2877 nmap <Plug>TestFOrmat :
2878 nmap <Plug>fendoff :
2879 nmap <Plug>state :
2880 nmap <Plug>FendingOff :
2881 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2882 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2883 nunmap <Plug>format
2884 nunmap <Plug>goformat
2885 nunmap <Plug>TestFOrmat
2886 nunmap <Plug>fendoff
2887 nunmap <Plug>state
2888 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002889 set wildoptions&
2890endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002891
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002892" abbreviation fuzzy completion
2893func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002894 set wildoptions=fuzzy
2895 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2896 call assert_equal("\"iabbr <nowait>", @:)
2897 iabbr WaitForCompletion WFC
2898 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2899 call assert_equal("\"iabbr WaitForCompletion", @:)
2900 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2901 call assert_equal("\"iabbr a1z\t", @:)
2902 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002903 set wildoptions&
2904endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002905
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002906" menu name fuzzy completion
2907func Test_fuzzy_completion_menu()
2908 CheckGui
2909 set wildoptions&
2910 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2911 call assert_equal('"menu pup', @:)
2912 set wildoptions=fuzzy
2913 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2914 call assert_equal('"menu PopUp.', @:)
2915 set wildoptions&
2916endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002917
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002918" :messages suboptions fuzzy completion
2919func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002920 set wildoptions&
2921 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2922 call assert_equal('"messages clr', @:)
2923 set wildoptions=fuzzy
2924 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2925 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002926 set wildoptions&
2927endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002928
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002929" :set option name fuzzy completion
2930func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002931 set wildoptions&
2932 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2933 call assert_equal('"set brkopt', @:)
2934 set wildoptions=fuzzy
2935 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2936 call assert_equal('"set breakindentopt', @:)
2937 set wildoptions&
2938 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2939 call assert_equal('"set fixendofline', @:)
2940 set wildoptions=fuzzy
2941 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2942 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002943 set wildoptions&
2944endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002945
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002946" :set <term_option>
2947func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002948 set wildoptions&
2949 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2950 call assert_equal('"set t_EC', @:)
2951 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2952 call assert_equal('"set <t_EC>', @:)
2953 set wildoptions=fuzzy
2954 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2955 call assert_equal('"set t_EC', @:)
2956 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2957 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002958 set wildoptions&
2959endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002960
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002961" " :packadd directory name fuzzy completion - NOT supported
2962" func Test_fuzzy_completion_packadd()
2963" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002964
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002965" " shell command name fuzzy completion - NOT supported
2966" func Test_fuzzy_completion_shellcmd()
2967" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002968
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002969" :sign suboptions fuzzy completion
2970func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002971 set wildoptions&
2972 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2973 call assert_equal('"sign ufe', @:)
2974 set wildoptions=fuzzy
2975 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2976 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002977 set wildoptions&
2978endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002979
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002980" :syntax suboptions fuzzy completion
2981func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002982 set wildoptions&
2983 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2984 call assert_equal('"syntax kwd', @:)
2985 set wildoptions=fuzzy
2986 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2987 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002988 set wildoptions&
2989endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002990
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002991" syntax group name fuzzy completion
2992func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002993 set wildoptions&
2994 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2995 call assert_equal('"syntax list mpar', @:)
2996 set wildoptions=fuzzy
2997 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2998 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002999 set wildoptions&
3000endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003001
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003002" :syntime suboptions fuzzy completion
3003func Test_fuzzy_completion_syntime()
3004 CheckFeature profile
3005 set wildoptions&
3006 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3007 call assert_equal('"syntime clr', @:)
3008 set wildoptions=fuzzy
3009 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3010 call assert_equal('"syntime clear', @:)
3011 set wildoptions&
3012endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003013
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003014" " tag name fuzzy completion - NOT supported
3015" func Test_fuzzy_completion_tagname()
3016" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003017
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003018" " tag name and file fuzzy completion - NOT supported
3019" func Test_fuzzy_completion_tagfile()
3020" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003021
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003022" " user names fuzzy completion - how to test this functionality?
3023" func Test_fuzzy_completion_username()
3024" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003025
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003026" user defined variable name fuzzy completion
3027func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003028 let g:SomeVariable=10
3029 set wildoptions&
3030 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3031 call assert_equal('"let SVar', @:)
3032 set wildoptions=fuzzy
3033 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3034 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003035 set wildoptions&
3036endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003037
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003038" Test for sorting the results by the best match
3039func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003040 %bw!
3041 command T123format :
3042 command T123goformat :
3043 command T123TestFOrmat :
3044 command T123fendoff :
3045 command T123state :
3046 command T123FendingOff :
3047 set wildoptions=fuzzy
3048 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3049 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3050 delcommand T123format
3051 delcommand T123goformat
3052 delcommand T123TestFOrmat
3053 delcommand T123fendoff
3054 delcommand T123state
3055 delcommand T123FendingOff
3056 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003057 set wildoptions&
3058endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003059
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003060" Test for fuzzy completion of a command with lower case letters and a number
3061func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003062 command Foo2Bar :
3063 set wildoptions=fuzzy
3064 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3065 call assert_equal('"Foo2Bar', @:)
3066 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3067 call assert_equal('"Foo2Bar', @:)
3068 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3069 call assert_equal('"Foo2Bar', @:)
3070 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003071 set wildoptions&
3072endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003073
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003074" Test for command completion for a command starting with 'k'
3075func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003076 command KillKillKill :
3077 set wildoptions&
3078 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3079 call assert_equal("\"killkill\<Tab>", @:)
3080 set wildoptions=fuzzy
3081 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3082 call assert_equal('"KillKillKill', @:)
3083 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003084 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003085endfunc
3086
3087" Test for fuzzy completion for user defined custom completion function
3088func Test_fuzzy_completion_custom_func()
3089 func Tcompl(a, c, p)
3090 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3091 endfunc
3092 command -nargs=* -complete=custom,Tcompl Fuzzy :
3093 set wildoptions&
3094 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3095 call assert_equal("\"Fuzzy format", @:)
3096 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3097 call assert_equal("\"Fuzzy xy", @:)
3098 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3099 call assert_equal("\"Fuzzy ttt", @:)
3100 set wildoptions=fuzzy
3101 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3102 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3103 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3104 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3105 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3106 call assert_equal("\"Fuzzy xy", @:)
3107 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3108 call assert_equal("\"Fuzzy TestFOrmat", @:)
3109 delcom Fuzzy
3110 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003111endfunc
3112
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003113" Test for :breakadd argument completion
3114func Test_cmdline_complete_breakadd()
3115 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3116 call assert_equal("\"breakadd expr file func here", @:)
3117 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3118 call assert_equal("\"breakadd expr", @:)
3119 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3120 call assert_equal("\"breakadd expr", @:)
3121 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3122 call assert_equal("\"breakadd here", @:)
3123 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3124 call assert_equal("\"breakadd here", @:)
3125 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3126 call assert_equal("\"breakadd abc", @:)
3127 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3128 let l = getcompletion('not', 'breakpoint')
3129 call assert_equal([], l)
3130
3131 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003132 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003133 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3134 call assert_equal("\"breakadd file Xscript", @:)
3135 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3136 call assert_equal("\"breakadd file Xscript", @:)
3137 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal("\"breakadd file 20 Xscript", @:)
3139 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal("\"breakadd file 20 Xscript", @:)
3141 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3143 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3144 call assert_equal("\"breakadd file 20\t", @:)
3145 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3146 call assert_equal("\"breakadd file 20x\t", @:)
3147 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3148 call assert_equal("\"breakadd file Xscript ", @:)
3149 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3150 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003151
3152 " Test for :breakadd func [lnum] <function>
3153 func Xbreak_func()
3154 endfunc
3155 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3156 call assert_equal("\"breakadd func Xbreak_func", @:)
3157 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal("\"breakadd func Xbreak_func", @:)
3159 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3160 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3161 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3162 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3163 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3164 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3165 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3166 call assert_equal("\"breakadd func 20\t", @:)
3167 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3168 call assert_equal("\"breakadd func 20x\t", @:)
3169 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3170 call assert_equal("\"breakadd func Xbreak_func ", @:)
3171 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3172 call assert_equal("\"breakadd func X1B2C3", @:)
3173 delfunc Xbreak_func
3174
3175 " Test for :breakadd expr <expression>
3176 let g:Xtest_var = 10
3177 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal("\"breakadd expr Xtest_var", @:)
3179 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3180 call assert_equal("\"breakadd expr Xtest_var", @:)
3181 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3182 call assert_equal("\"breakadd expr Xtest_var ", @:)
3183 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3184 call assert_equal("\"breakadd expr X1B2C3", @:)
3185 unlet g:Xtest_var
3186
3187 " Test for :breakadd here
3188 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3189 call assert_equal("\"breakadd here Xtest", @:)
3190 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3191 call assert_equal("\"breakadd here Xtest", @:)
3192 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3193 call assert_equal("\"breakadd here ", @:)
3194endfunc
3195
3196" Test for :breakdel argument completion
3197func Test_cmdline_complete_breakdel()
3198 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3199 call assert_equal("\"breakdel file func here", @:)
3200 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3201 call assert_equal("\"breakdel file", @:)
3202 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3203 call assert_equal("\"breakdel file", @:)
3204 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3205 call assert_equal("\"breakdel here", @:)
3206 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3207 call assert_equal("\"breakdel here", @:)
3208 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3209 call assert_equal("\"breakdel abc", @:)
3210
3211 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003212 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003213 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3214 call assert_equal("\"breakdel file Xscript", @:)
3215 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3216 call assert_equal("\"breakdel file Xscript", @:)
3217 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3218 call assert_equal("\"breakdel file 20 Xscript", @:)
3219 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3220 call assert_equal("\"breakdel file 20 Xscript", @:)
3221 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3223 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal("\"breakdel file 20\t", @:)
3225 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal("\"breakdel file 20x\t", @:)
3227 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal("\"breakdel file Xscript ", @:)
3229 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3230 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003231
3232 " Test for :breakdel func [lnum] <function>
3233 func Xbreak_func()
3234 endfunc
3235 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3236 call assert_equal("\"breakdel func Xbreak_func", @:)
3237 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3238 call assert_equal("\"breakdel func Xbreak_func", @:)
3239 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3240 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3241 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3242 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3243 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3244 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3245 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3246 call assert_equal("\"breakdel func 20\t", @:)
3247 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3248 call assert_equal("\"breakdel func 20x\t", @:)
3249 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3250 call assert_equal("\"breakdel func Xbreak_func ", @:)
3251 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3252 call assert_equal("\"breakdel func X1B2C3", @:)
3253 delfunc Xbreak_func
3254
3255 " Test for :breakdel here
3256 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3257 call assert_equal("\"breakdel here Xtest", @:)
3258 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3259 call assert_equal("\"breakdel here Xtest", @:)
3260 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3261 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003262endfunc
3263
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003264" Test for :scriptnames argument completion
3265func Test_cmdline_complete_scriptnames()
3266 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003267 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003268 source Xa1b2c3.vim
3269 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3270 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3271 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3272 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3273 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3274 call assert_equal("\"script b2c3", @:)
3275 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3276 call assert_match("\"script 2\<Tab>$", @:)
3277 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3278 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3279 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3280 call assert_equal("\"script ", @:)
3281 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3282 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3283 new
3284 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3285 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3286 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003287 set wildmenu&
3288endfunc
3289
Bram Moolenaard8893442022-05-06 20:38:47 +01003290" this was going over the end of IObuff
3291func Test_report_error_with_composing()
3292 let caught = 'no'
3293 try
3294 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3295 catch /E492:/
3296 let caught = 'yes'
3297 endtry
3298 call assert_equal('yes', caught)
3299endfunc
3300
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003301" Test for expanding 2-letter and 3-letter :substitute command arguments.
3302" These commands don't accept an argument.
3303func Test_cmdline_complete_substitute_short()
3304 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3305 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3306 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3307 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3308 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3309 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3310 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3311 endfor
3312endfunc
3313
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003314" Test for :! shell command argument completion
3315func Test_cmdline_complete_bang_cmd_argument()
3316 set wildoptions=fuzzy
3317 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3318 call assert_equal('"!vim test_cmdline.vim', @:)
3319 set wildoptions&
3320 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3321 call assert_equal('"!vim test_cmdline.vim', @:)
3322endfunc
3323
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003324func Check_completion()
3325 call assert_equal('let a', getcmdline())
3326 call assert_equal(6, getcmdpos())
3327 call assert_equal(7, getcmdscreenpos())
3328 call assert_equal('var', getcmdcompltype())
3329 return ''
3330endfunc
3331
3332func Test_screenpos_and_completion()
3333 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3334endfunc
3335
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003336func Test_recursive_register()
3337 let @= = ''
3338 silent! ?e/
3339 let caught = 'no'
3340 try
3341 normal //
3342 catch /E169:/
3343 let caught = 'yes'
3344 endtry
3345 call assert_equal('yes', caught)
3346endfunc
3347
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003348func Test_long_error_message()
3349 " the error should be truncated, not overrun IObuff
3350 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3351endfunc
3352
zeertzjq6791adc2022-07-26 20:42:25 +01003353func Test_cmdline_redraw_tabline()
3354 CheckRunVimInTerminal
3355
3356 let lines =<< trim END
3357 set showtabline=2
3358 autocmd CmdlineEnter * set tabline=foo
3359 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003360 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003361 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3362 call term_sendkeys(buf, ':')
3363 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3364
3365 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003366endfunc
3367
zeertzjqb82a2ab2022-08-21 14:33:57 +01003368func Test_wildmenu_pum_disable_while_shown()
3369 set wildoptions=pum
3370 set wildmenu
3371 cnoremap <F2> <Cmd>set nowildmenu<CR>
3372 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3373 call assert_equal(0, pumvisible())
3374 cunmap <F2>
3375 set wildoptions& wildmenu&
3376endfunc
3377
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003378func Test_setcmdline()
3379 func SetText(text, pos)
zeertzjq54acb902022-08-29 16:21:25 +01003380 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003381 call assert_equal(0, setcmdline(a:text))
3382 call assert_equal(a:text, getcmdline())
3383 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003384 call assert_equal(getcmdtype(), g:cmdtype)
3385 unlet g:cmdtype
3386 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003387
3388 call assert_equal(0, setcmdline(a:text, a:pos))
3389 call assert_equal(a:text, getcmdline())
3390 call assert_equal(a:pos, getcmdpos())
3391
3392 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003393 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3394 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003395
3396 return ''
3397 endfunc
3398
3399 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3400 call assert_equal('set rtp?', @:)
3401
zeertzjq54acb902022-08-29 16:21:25 +01003402 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3403 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3404 call assert_equal('foo', g:str)
3405 unlet g:str
3406
3407 delfunc SetText
3408
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003409 " setcmdline() returns 1 when not editing the command line.
3410 call assert_equal(1, 'foo'->setcmdline())
3411
3412 " Called in custom function
3413 func CustomComplete(A, L, P)
3414 call assert_equal(0, setcmdline("DoCmd "))
3415 return "January\nFebruary\nMars\n"
3416 endfunc
3417
3418 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3419 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3420 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003421 delcom DoCmd
3422 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003423
3424 " Called in <expr>
3425 cnoremap <expr>a setcmdline('let foo=')
3426 call feedkeys(":a\<CR>", 'tx')
3427 call assert_equal('let foo=0', @:)
3428 cunmap a
3429endfunc
3430
Bram Moolenaar309976e2019-12-05 18:16:33 +01003431" vim: shiftwidth=2 sts=2 expandtab