blob: 28f845a9ad028a23a3f1b35965564a1f59c30f47 [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
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000657" Test for getcompletion() with "fuzzy" in 'wildoptions'
658func Test_getcompletion_wildoptions()
659 let save_wildoptions = &wildoptions
660 set wildoptions&
661 let l = getcompletion('space', 'option')
662 call assert_equal([], l)
663 let l = getcompletion('ier', 'command')
664 call assert_equal([], l)
665 set wildoptions=fuzzy
666 let l = getcompletion('space', 'option')
667 call assert_true(index(l, 'backspace') >= 0)
668 let l = getcompletion('ier', 'command')
669 call assert_true(index(l, 'compiler') >= 0)
670 let &wildoptions = save_wildoptions
671endfunc
672
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000673func Test_complete_autoload_error()
674 let save_rtp = &rtp
675 let lines =<< trim END
676 vim9script
677 export def Complete(..._): string
678 return 'match'
679 enddef
680 echo this will cause an error
681 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100682 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000683 call writefile(lines, 'Xdir/autoload/script.vim')
684 exe 'set rtp+=' .. getcwd() .. '/Xdir'
685
686 let lines =<< trim END
687 vim9script
688 import autoload 'script.vim'
689 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
690 &wildcharm = char2nr("\<Tab>")
691 feedkeys(":Cmd \<Tab>", 'xt')
692 END
693 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
694
695 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000696endfunc
697
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100698func Test_fullcommand()
699 let tests = {
700 \ '': '',
701 \ ':': '',
702 \ ':::': '',
703 \ ':::5': '',
704 \ 'not_a_cmd': '',
705 \ 'Check': '',
706 \ 'syntax': 'syntax',
707 \ ':syntax': 'syntax',
708 \ '::::syntax': 'syntax',
709 \ 'sy': 'syntax',
710 \ 'syn': 'syntax',
711 \ 'synt': 'syntax',
712 \ ':sy': 'syntax',
713 \ '::::sy': 'syntax',
714 \ 'match': 'match',
715 \ '2match': 'match',
716 \ '3match': 'match',
717 \ 'aboveleft': 'aboveleft',
718 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100719 \ 'en': 'endif',
720 \ 'end': 'endif',
721 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100722 \ 's': 'substitute',
723 \ '5s': 'substitute',
724 \ ':5s': 'substitute',
725 \ "'<,'>s": 'substitute',
726 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100727 \ 'CheckLin': 'CheckLinux',
728 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100729 \ }
730
731 for [in, want] in items(tests)
732 call assert_equal(want, fullcommand(in))
733 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200734 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100735
736 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200737
738 command -buffer BufferLocalCommand :
739 command GlobalCommand :
740 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
741 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
742 delcommand BufferLocalCommand
743 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100744endfunc
745
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200746func Test_shellcmd_completion()
747 let save_path = $PATH
748
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100749 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200750 call writefile([''], 'Xpathdir/Xfile.exe')
751 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
752
753 " Set PATH to example directory without trailing slash.
754 let $PATH = getcwd() . '/Xpathdir'
755
756 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
757 " dirs in the PATH, even though they won't be executed. We check that only
758 " subdirs of the PWD and executables from the PATH are included in the
759 " suggestions.
760 let actual = getcompletion('X', 'shellcmd')
761 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
762 call insert(expected, 'Xfile.exe')
763 call assert_equal(expected, actual)
764
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200765 let $PATH = save_path
766endfunc
767
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200768func Test_expand_star_star()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100769 call mkdir('a/b', 'pR')
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200770 call writefile(['asdfasdf'], 'a/b/fileXname')
771 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000772 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200773 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200774endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100775
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100776func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100777 let @a = "def"
778 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
779 call assert_equal('"abc def ghi', @:)
780
781 new
782 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
783
784 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
785 call assert_equal('"aaa asdf bbb', @:)
786
787 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
788 call assert_equal('"aaa /tmp/some bbb', @:)
789
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200790 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
791 call assert_equal('"aaa '.getline(1).' bbb', @:)
792
Bram Moolenaar21efc362016-12-03 14:05:49 +0100793 set incsearch
794 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
795 call assert_equal('"aaa verylongword bbb', @:)
796
797 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
798 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100799
800 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
801 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100802 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200803
804 " Error while typing a command used to cause that it was not executed
805 " in the end.
806 new
807 try
808 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
809 catch /^Vim\%((\a\+)\)\=:E32/
810 " ignore error E32
811 endtry
812 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100813
Bram Moolenaar578fe942020-02-27 21:32:51 +0100814 " Try to paste an invalid register using <C-R>
815 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
816 call assert_equal('"onetwo', @:)
817
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100818 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100819 let @a = "xy\<C-H>z"
820 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
821 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100822 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
823 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100824 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
825 call assert_equal("\"xy\<C-H>z", @:)
826
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100827 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
828 let @a = "xy\<C-V>z"
829 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
830 call assert_equal('"xyz', @:)
831 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
832 call assert_equal("\"xy\<C-V>z", @:)
833
Bram Moolenaar578fe942020-02-27 21:32:51 +0100834 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
835
Bram Moolenaar72532d32018-04-07 19:09:09 +0200836 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100837endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100838
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100839func Test_cmdline_remove_char()
840 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100841
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100842 for e in ['utf8', 'latin1']
843 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100844
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100845 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
846 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100847
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100848 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
849 call assert_equal('"abcdef', @:)
850
851 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
852 call assert_equal('"abc ghi', @:, e)
853
854 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
855 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100856
857 " This was going before the start in latin1.
858 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100859 endfor
860
861 let &encoding = encoding_save
862endfunc
863
864func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200865 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100866
867 set keymap=esperanto
868 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
869 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
870 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100871endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100872
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100873func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100874 new
875 2;'(
876 2;')
877 quit
878endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100879
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100880func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100881 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100882 new
883 source Xtest.vim
884 " Trigger calling validate_cursor()
885 diffsp Xtest.vim
886 quit!
887 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100888endfunc
889
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100890func Test_mark_from_line_zero()
891 " this was reading past the end of the first (empty) line
892 new
893 norm oxxxx
894 call assert_fails("0;'(", 'E20:')
895 bwipe!
896endfunc
897
Bram Moolenaarba47b512017-01-24 21:18:19 +0100898func Test_cmdline_complete_wildoptions()
899 help
900 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
901 let a = join(sort(split(@:)),' ')
902 set wildoptions=tagfile
903 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
904 let b = join(sort(split(@:)),' ')
905 call assert_equal(a, b)
906 bw!
907endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100908
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200909func Test_cmdline_complete_user_cmd()
910 command! -complete=color -nargs=1 Foo :
911 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
912 call assert_equal('"Foo blue', @:)
913 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
914 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000915 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
916 call assert_equal('"Foo a blue', @:)
917 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
918 call assert_equal('"Foo b\', @:)
919 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
920 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200921 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100922
923 redraw
924 call assert_equal('~', Screenline(&lines - 1))
925 command! FooOne :
926 command! FooTwo :
927
928 set nowildmenu
929 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
930 call assert_equal('"FooOne', @:)
931 call assert_equal('~', Screenline(&lines - 1))
932
933 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
934 call assert_equal('"FooTwo', @:)
935 call assert_equal('~', Screenline(&lines - 1))
936
937 delcommand FooOne
938 delcommand FooTwo
939 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200940endfunc
941
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100942func Test_complete_user_cmd()
943 command FooBar echo 'global'
944 command -buffer FooBar echo 'local'
945 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
946 call assert_equal('"FooBar', @:)
947
948 delcommand -buffer FooBar
949 delcommand FooBar
950endfunc
951
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100952func s:ScriptLocalFunction()
953 echo 'yes'
954endfunc
955
956func Test_cmdline_complete_user_func()
957 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200958 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100959 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
960 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100961
962 " g: prefix also works
963 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
964 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200965
966 " using g: prefix does not result in just "g:" matches from a lambda
967 let Fx = { a -> a }
968 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
969 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200970
971 " existence of script-local dict function does not break user function name
972 " completion
973 function s:a_dict_func() dict
974 endfunction
975 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
976 call assert_match('"call Test_cmdline_complete_user_', @:)
977 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100978endfunc
979
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200980func Test_cmdline_complete_user_names()
981 if has('unix') && executable('whoami')
982 let whoami = systemlist('whoami')[0]
983 let first_letter = whoami[0]
984 if len(first_letter) > 0
985 " Trying completion of :e ~x where x is the first letter of
986 " the user name should complete to at least the user name.
987 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
988 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
989 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200990 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200991 " Just in case: check that the system has an Administrator account.
992 let names = system('net user')
993 if names =~ 'Administrator'
994 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100995 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200996 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100997 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200998 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200999 else
1000 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001001 endif
1002endfunc
1003
Bram Moolenaar297610b2019-12-27 17:20:55 +01001004func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001005 CheckExecutable whoami
1006 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1007 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001008endfunc
1009
Bram Moolenaar8b633132020-03-20 18:20:51 +01001010func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001011 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1012 call assert_equal(lang, v:lc_time)
1013
1014 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1015 call assert_equal(lang, v:ctype)
1016
1017 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1018 call assert_equal(lang, v:collate)
1019
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001020 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001021 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001022
1023 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001024 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001025
Bram Moolenaarec680282020-06-12 19:35:32 +02001026 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001027
Bram Moolenaarec680282020-06-12 19:35:32 +02001028 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1029 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001030
Bram Moolenaarec680282020-06-12 19:35:32 +02001031 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1032 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001033
Bram Moolenaarec680282020-06-12 19:35:32 +02001034 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1035 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001036
1037 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1038 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001039endfunc
1040
Bram Moolenaar297610b2019-12-27 17:20:55 +01001041func Test_cmdline_complete_env_variable()
1042 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001043 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1044 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001045 unlet $X_VIM_TEST_COMPLETE_ENV
1046endfunc
1047
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001048func Test_cmdline_complete_expression()
1049 let g:SomeVar = 'blah'
1050 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1051 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1052 call assert_match('"' .. cmd .. ' SomeVar', @:)
1053 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1054 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1055 endfor
1056 unlet g:SomeVar
1057endfunc
1058
Bram Moolenaar47016f52021-08-26 16:39:58 +02001059" Unique function name for completion below
1060func s:WeirdFunc()
1061 echo 'weird'
1062endfunc
1063
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001064" Test for various command-line completion
1065func Test_cmdline_complete_various()
1066 " completion for a command starting with a comment
1067 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1068 call assert_equal("\" :|\"\<C-A>", @:)
1069
1070 " completion for a range followed by a comment
1071 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1072 call assert_equal("\"1,2\"\<C-A>", @:)
1073
1074 " completion for :k command
1075 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1076 call assert_equal("\"ka\<C-A>", @:)
1077
1078 " completion for short version of the :s command
1079 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1080 call assert_equal("\"sI \<C-A>", @:)
1081
1082 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001083 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001084 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001085 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001086 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001087 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1088 call assert_equal("\"w >> Xfile1", @:)
1089 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001090
1091 " completion for :w ! and :r ! commands
1092 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1093 call assert_equal("\"w !invalid_xyz_cmd", @:)
1094 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1095 call assert_equal("\"r !invalid_xyz_cmd", @:)
1096
1097 " completion for :>> and :<< commands
1098 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1099 call assert_equal("\">>>\<C-A>", @:)
1100 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1101 call assert_equal("\"<<<\<C-A>", @:)
1102
1103 " completion for command with +cmd argument
1104 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1105 call assert_equal("\"buffer +/pat Xabc", @:)
1106 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1107 call assert_equal("\"buffer +/pat\<C-A>", @:)
1108
1109 " completion for a command with a trailing comment
1110 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1111 call assert_equal("\"ls \" comment\<C-A>", @:)
1112
1113 " completion for a command with a trailing command
1114 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1115 call assert_equal("\"ls | ls", @:)
1116
1117 " completion for a command with an CTRL-V escaped argument
1118 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1119 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1120
1121 " completion for a command that doesn't take additional arguments
1122 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1123 call assert_equal("\"all abc\<C-A>", @:)
1124
zeertzjqd3de1782022-09-01 12:58:52 +01001125 " completion for :wincmd with :horizontal modifier
1126 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1127 call assert_equal("\"horizontal wincmd", @:)
1128
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001129 " completion for a command with a command modifier
1130 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1131 call assert_equal("\"topleft new", @:)
1132
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001133 " completion for vim9 and legacy commands
1134 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1135 call assert_equal("\"vim9 call strlen(", @:)
1136 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1137 call assert_equal("\"legac call strlen(", @:)
1138
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001139 " completion for the :disassemble command
1140 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1141 call assert_equal("\"disas debug", @:)
1142 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1143 call assert_equal("\"disas profile", @:)
1144 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1145 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1146 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1147 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001148 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1149 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001150
Bram Moolenaar47016f52021-08-26 16:39:58 +02001151 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001152 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001153
naohiro onodfe04db2021-09-12 15:45:10 +02001154 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1155 call assert_match('"disas <SNR>\d\+_', @:)
1156 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1157 call assert_match('"disas debug <SNR>\d\+_', @:)
1158
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001159 " completion for the :match command
1160 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1161 call assert_equal("\"match Search /pat/\<C-A>", @:)
1162
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001163 " completion for the :doautocmd command
1164 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1165 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1166
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001167 " completion of autocmd group after comma
1168 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1169 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1170
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001171 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001172 call writefile([], 'Xvarfile1', 'D')
1173 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001174 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1175 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001176
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001177 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001178 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001179 augroup END
1180 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001181 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001182
1183 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001184 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1185 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001186 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1187 call assert_equal("\"au XTest.test", @:)
1188
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001189 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001190
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001191 " autocmd pattern completion
1192 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1193 call assert_equal("\"au BufEnter *.py\t", @:)
1194
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001195 " completion for the :unlet command
1196 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1197 call assert_equal("\"unlet one two", @:)
1198
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001199 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001200 " FIXME: what should happen on MS-Windows?
1201 if !has('win32')
1202 edit \{someFile}
1203 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1204 call assert_equal("\"buf {someFile}", @:)
1205 bwipe {someFile}
1206 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001207
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001208 " completion for the :bdelete command
1209 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1210 call assert_equal("\"bdel a b c", @:)
1211
1212 " completion for the :mapclear command
1213 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1214 call assert_equal("\"mapclear <buffer>", @:)
1215
1216 " completion for user defined commands with menu names
1217 menu Test.foo :ls<CR>
1218 com -nargs=* -complete=menu MyCmd
1219 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1220 call assert_equal('"MyCmd Test.', @:)
1221 delcom MyCmd
1222 unmenu Test
1223
1224 " completion for user defined commands with mappings
1225 mapclear
1226 map <F3> :ls<CR>
1227 com -nargs=* -complete=mapping MyCmd
1228 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001229 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001230 mapclear
1231 delcom MyCmd
1232
1233 " completion for :set path= with multiple backslashes
1234 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1235 call assert_equal('"set path=a\\\ b', @:)
1236
1237 " completion for :set dir= with a backslash
1238 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1239 call assert_equal('"set dir=a\ b', @:)
1240
1241 " completion for the :py3 commands
1242 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1243 call assert_equal('"py3 py3do py3file', @:)
1244
Bram Moolenaardf749a22021-03-28 15:29:43 +02001245 " completion for the :vim9 commands
1246 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1247 call assert_equal('"vim9cmd vim9script', @:)
1248
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001249 " redir @" is not the start of a comment. So complete after that
1250 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1251 call assert_equal('"redir @" | cwindow', @:)
1252
1253 " completion after a backtick
1254 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1255 call assert_equal('"e `a1b2c', @:)
1256
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001257 " completion for :language command with an invalid argument
1258 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1259 call assert_equal("\"language dummy \t", @:)
1260
1261 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001262 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1263 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001264
1265 " completion with ambiguous user defined commands
1266 com TCmd1 echo 'TCmd1'
1267 com TCmd2 echo 'TCmd2'
1268 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1269 call assert_equal('"TCmd ', @:)
1270 delcom TCmd1
1271 delcom TCmd2
1272
1273 " completion after a range followed by a pipe (|) character
1274 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1275 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001276
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001277 " completion after a :global command
1278 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1279 call assert_equal('"g/a/chistory', @:)
1280 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1281 call assert_equal("\"g/a\\/chist\t", @:)
1282
Bram Moolenaar9c929712020-09-07 22:05:28 +02001283 " use <Esc> as the 'wildchar' for completion
1284 set wildchar=<Esc>
1285 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1286 call assert_equal('"g/a\xb/clearjumps', @:)
1287 " pressing <esc> twice should cancel the command
1288 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1289 call assert_equal('"g/a\xb/clearjumps', @:)
1290 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001291
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001292 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001293 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001294 call writefile([], '~Xtest')
1295 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1296 call assert_equal('"e \~Xtest', @:)
1297 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001298
1299 " should be able to complete a file name that has a '*'
1300 call writefile([], 'Xx*Yy')
1301 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1302 call assert_equal('"e Xx\*Yy', @:)
1303 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001304
1305 " use a literal star
1306 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1307 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001308 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001309
1310 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1311 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001312endfunc
1313
1314" Test for 'wildignorecase'
1315func Test_cmdline_wildignorecase()
1316 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001317 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001318 set wildignorecase
1319 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1320 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001321 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001322 let g:Sline = ''
1323 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1324 call assert_equal('"e xt', @:)
1325 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001326 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001327endfunc
1328
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001329func Test_cmdline_write_alternatefile()
1330 new
1331 call setline('.', ['one', 'two'])
1332 f foo.txt
1333 new
1334 f #-A
1335 call assert_equal('foo.txt-A', expand('%'))
1336 f #<-B.txt
1337 call assert_equal('foo-B.txt', expand('%'))
1338 f %<
1339 call assert_equal('foo-B', expand('%'))
1340 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001341 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001342 bw!
1343 f foo-B.txt
1344 f %<-A
1345 call assert_equal('foo-B-A', expand('%'))
1346 bw!
1347 bw!
1348endfunc
1349
Bram Moolenaarf5724372022-09-02 19:45:15 +01001350func Test_cmdline_expand_cur_alt_file()
1351 enew
1352 file http://some.com/file.txt
1353 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1354 call assert_equal('"e http://some.com/file.txt', @:)
1355 edit another
1356 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1357 call assert_equal('"e http://some.com/file.txt', @:)
1358 bwipe
1359 bwipe http://some.com/file.txt
1360endfunc
1361
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001362" using a leading backslash here
1363set cpo+=C
1364
1365func Test_cmdline_search_range()
1366 new
1367 call setline(1, ['a', 'b', 'c', 'd'])
1368 /d
1369 1,\/s/b/B/
1370 call assert_equal('B', getline(2))
1371
1372 /a
1373 $
1374 \?,4s/c/C/
1375 call assert_equal('C', getline(3))
1376
1377 call setline(1, ['a', 'b', 'c', 'd'])
1378 %s/c/c/
1379 1,\&s/b/B/
1380 call assert_equal('B', getline(2))
1381
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001382 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001383 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001384
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001385 bwipe!
1386endfunc
1387
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001388" Test for the tick mark (') in an excmd range
1389func Test_tick_mark_in_range()
1390 " If only the tick is passed as a range and no command is specified, there
1391 " should not be an error
1392 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001393 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001394 call assert_fails("',print", 'E78:')
1395endfunc
1396
1397" Test for using a line number followed by a search pattern as range
1398func Test_lnum_and_pattern_as_range()
1399 new
1400 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1401 let @" = ''
1402 2/foo/yank
1403 call assert_equal("foo 3\n", @")
1404 call assert_equal(1, line('.'))
1405 close!
1406endfunc
1407
Bram Moolenaar65189a12017-02-06 22:22:17 +01001408" Tests for getcmdline(), getcmdpos() and getcmdtype()
1409func Check_cmdline(cmdtype)
1410 call assert_equal('MyCmd a', getcmdline())
1411 call assert_equal(8, getcmdpos())
1412 call assert_equal(a:cmdtype, getcmdtype())
1413 return ''
1414endfunc
1415
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001416set cpo&
1417
Bram Moolenaar65189a12017-02-06 22:22:17 +01001418func Test_getcmdtype()
1419 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1420
1421 let cmdtype = ''
1422 debuggreedy
1423 call feedkeys(":debug echo 'test'\<CR>", "t")
1424 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1425 call feedkeys("cont\<CR>", "xt")
1426 0debuggreedy
1427 call assert_equal('>', cmdtype)
1428
1429 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1430 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1431
1432 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001433 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001434
1435 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1436
1437 cnoremap <expr> <F6> Check_cmdline('=')
1438 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1439 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001440
1441 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001442endfunc
1443
Bram Moolenaar52604f22017-04-07 16:17:39 +02001444func Test_verbosefile()
1445 set verbosefile=Xlog
1446 echomsg 'foo'
1447 echomsg 'bar'
1448 set verbosefile=
1449 let log = readfile('Xlog')
1450 call assert_match("foo\nbar", join(log, "\n"))
1451 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001452
1453 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001454 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001455endfunc
1456
Bram Moolenaar4facea32019-10-12 20:17:40 +02001457func Test_verbose_option()
1458 CheckScreendump
1459
1460 let lines =<< trim [SCRIPT]
1461 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1462 call feedkeys("\r", 't') " for the hit-enter prompt
1463 set verbose=20
1464 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001465 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001466
1467 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001468 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001469 call term_sendkeys(buf, ":DoSomething\<CR>")
1470 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1471
1472 " clean up
1473 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001474endfunc
1475
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001476func Test_setcmdpos()
1477 func InsertTextAtPos(text, pos)
1478 call assert_equal(0, setcmdpos(a:pos))
1479 return a:text
1480 endfunc
1481
1482 " setcmdpos() with position in the middle of the command line.
1483 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1484 call assert_equal('"1ab2', @:)
1485
1486 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1487 call assert_equal('"1b2a', @:)
1488
1489 " setcmdpos() with position beyond the end of the command line.
1490 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1491 call assert_equal('"12ab', @:)
1492
1493 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001494 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001495endfunc
1496
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001497func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001498 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001499 let encoding_save = &encoding
1500
1501 for e in encodings
1502 exe 'set encoding=' . e
1503
1504 " Test overstrike in the middle of the command line.
1505 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001506 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001507
1508 " Test overstrike going beyond end of command line.
1509 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001510 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001511
1512 " Test toggling insert/overstrike a few times.
1513 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001514 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001515 endfor
1516
Bram Moolenaar30276f22019-01-24 17:59:39 +01001517 " Test overstrike with multi-byte characters.
1518 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001519 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001520
1521 let &encoding = encoding_save
1522endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001523
Bram Moolenaar52410572019-10-27 05:12:45 +01001524func Test_buffers_lastused()
1525 " check that buffers are sorted by time when wildmode has lastused
1526 call test_settime(1550020000) " middle
1527 edit bufa
1528 enew
1529 call test_settime(1550030000) " newest
1530 edit bufb
1531 enew
1532 call test_settime(1550010000) " oldest
1533 edit bufc
1534 enew
1535 call test_settime(0)
1536 enew
1537
1538 call assert_equal(['bufa', 'bufb', 'bufc'],
1539 \ getcompletion('', 'buffer'))
1540
1541 let save_wildmode = &wildmode
1542 set wildmode=full:lastused
1543
1544 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1545 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1546 call assert_equal('b bufb', X)
1547 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1548 call assert_equal('b bufa', X)
1549 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1550 call assert_equal('b bufc', X)
1551 enew
1552
1553 edit other
1554 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1555 call assert_equal('b bufb', X)
1556 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1557 call assert_equal('b bufa', X)
1558 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1559 call assert_equal('b bufc', X)
1560 enew
1561
1562 let &wildmode = save_wildmode
1563
1564 bwipeout bufa
1565 bwipeout bufb
1566 bwipeout bufc
1567endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001568
Bram Moolenaar479950f2020-01-19 15:45:17 +01001569func Test_cmdlineclear_tabenter()
1570 CheckScreendump
1571
1572 let lines =<< trim [SCRIPT]
1573 call setline(1, range(30))
1574 [SCRIPT]
1575
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001576 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001577 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001578 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001579 " in one tab make the command line higher with CTRL-W -
1580 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1581 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1582
1583 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001584endfunc
1585
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001586" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001587func Test_cmdline_expand_special()
1588 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001589 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001590 call assert_fails('e <afile>', 'E495:')
1591 call assert_fails('e <abuf>', 'E496:')
1592 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001593
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001594 call writefile([], 'Xfile.cpp', 'D')
1595 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001596 new Xfile.cpp
1597 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1598 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1599 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001600endfunc
1601
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001602" Test for backtick expression in the command line
1603func Test_cmd_backtick()
1604 %argd
1605 argadd `=['a', 'b', 'c']`
1606 call assert_equal(['a', 'b', 'c'], argv())
1607 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001608
1609 argadd `echo abc def`
1610 call assert_equal(['abc def'], argv())
1611 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001612endfunc
1613
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001614" Test for the :! command
1615func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001616 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001617
1618 let lines =<< trim [SCRIPT]
1619 " Test for no previous command
1620 call assert_fails('!!', 'E34:')
1621 set nomore
1622 " Test for cmdline expansion with :!
1623 call setline(1, 'foo!')
1624 silent !echo <cWORD> > Xfile.out
1625 call assert_equal(['foo!'], readfile('Xfile.out'))
1626 " Test for using previous command
1627 silent !echo \! !
1628 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1629 call writefile(v:errors, 'Xresult')
1630 call delete('Xfile.out')
1631 qall!
1632 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001633 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001634 if RunVim([], [], '--clean -S Xscript')
1635 call assert_equal([], readfile('Xresult'))
1636 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001637 call delete('Xresult')
1638endfunc
1639
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001640" Test error: "E135: *Filter* Autocommands must not change current buffer"
1641func Test_cmd_bang_E135()
1642 new
1643 call setline(1, ['a', 'b', 'c', 'd'])
1644 augroup test_cmd_filter_E135
1645 au!
1646 autocmd FilterReadPost * help
1647 augroup END
1648 call assert_fails('2,3!echo "x"', 'E135:')
1649
1650 augroup test_cmd_filter_E135
1651 au!
1652 augroup END
1653 %bwipe!
1654endfunc
1655
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001656func Test_cmd_bang_args()
1657 new
1658 :.!
1659 call assert_equal(0, v:shell_error)
1660
1661 " Note that below there is one space char after the '!'. This caused a
1662 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1663 :.!
1664 call assert_equal(0, v:shell_error)
1665 bwipe!
1666
1667 CheckUnix
1668 :.!pwd
1669 call assert_equal(0, v:shell_error)
1670 :.! pwd
1671 call assert_equal(0, v:shell_error)
1672
1673 " Note there is one space after 'pwd'.
1674 :.! pwd
1675 call assert_equal(0, v:shell_error)
1676
1677 " Note there are two spaces after 'pwd'.
1678 :.! pwd
1679 call assert_equal(0, v:shell_error)
1680 :.!ls ~
1681 call assert_equal(0, v:shell_error)
1682
1683 " Note there is one space char after '~'.
1684 :.!ls ~
1685 call assert_equal(0, v:shell_error)
1686
1687 " Note there are two spaces after '~'.
1688 :.!ls ~
1689 call assert_equal(0, v:shell_error)
1690
1691 :.!echo "foo"
1692 call assert_equal(getline('.'), "foo")
1693 :.!echo "foo "
1694 call assert_equal(getline('.'), "foo ")
1695 :.!echo " foo "
1696 call assert_equal(getline('.'), " foo ")
1697 :.!echo " foo "
1698 call assert_equal(getline('.'), " foo ")
1699
1700 %bwipe!
1701endfunc
1702
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001703" Test for using ~ for home directory in cmdline completion matches
1704func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001705 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001706 call writefile([], 'Xexpdir/Xfile1')
1707 call writefile([], 'Xexpdir/Xfile2')
1708 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001709 let save_HOME = $HOME
1710 let $HOME = getcwd()
1711 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1712 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1713 let $HOME = save_HOME
1714 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001715endfunc
1716
Bram Moolenaar578fe942020-02-27 21:32:51 +01001717" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1718" or insert mode (when 'insertmode' is set)
1719func Test_cmdline_ctrl_g()
1720 new
1721 call setline(1, 'abc')
1722 call cursor(1, 3)
1723 " If command line is entered from insert mode, using C-\ C-G should back to
1724 " insert mode
1725 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1726 call assert_equal('abxyc', getline(1))
1727 call assert_equal(4, col('.'))
1728
1729 " If command line is entered in 'insertmode', using C-\ C-G should back to
1730 " 'insertmode'
1731 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1732 call assert_equal('ab12xyc', getline(1))
1733 close!
1734endfunc
1735
Bram Moolenaar578fe942020-02-27 21:32:51 +01001736" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001737func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001738 func T(a, c, p)
1739 return "oneA\noneB\noneC"
1740 endfunc
1741 command -nargs=1 -complete=custom,T MyCmd
1742
Bram Moolenaar578fe942020-02-27 21:32:51 +01001743 set nowildmenu
1744 set wildmode=full,list
1745 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001746 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001747 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001748 call assert_equal('"MyCmd oneA', @:)
1749
1750 set wildmode=longest,full
1751 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1752 call assert_equal('"MyCmd one', @:)
1753 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1754 call assert_equal('"MyCmd oneC', @:)
1755
1756 set wildmode=longest
1757 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1758 call assert_equal('"MyCmd one', @:)
1759
1760 set wildmode=list:longest
1761 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001762 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001763 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001764 call assert_equal('"MyCmd one', @:)
1765
1766 set wildmode=""
1767 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1768 call assert_equal('"MyCmd oneA', @:)
1769
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001770 " Test for wildmode=longest with 'fileignorecase' set
1771 set wildmode=longest
1772 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001773 argadd AAA AAAA AAAAA
1774 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1775 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001776 set fileignorecase&
1777
1778 " Test for listing files with wildmode=list
1779 set wildmode=list
1780 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001781 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001782 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001783 call assert_equal('"b A', @:)
1784
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001785 " when using longest completion match, matches shorter than the argument
1786 " should be ignored (happens with :help)
1787 set wildmode=longest,full
1788 set wildmenu
1789 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1790 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001791 " non existing file
1792 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1793 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001794 set wildmenu&
1795
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001796 " Test for longest file name completion with 'fileignorecase'
1797 " On MS-Windows, file names are case insensitive.
1798 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001799 call writefile([], 'XTESTfoo', 'D')
1800 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001801 set nofileignorecase
1802 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1803 call assert_equal('"e XTESTfoo', @:)
1804 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1805 call assert_equal('"e Xtestbar', @:)
1806 set fileignorecase
1807 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1808 call assert_equal('"e Xtest', @:)
1809 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1810 call assert_equal('"e Xtest', @:)
1811 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001812 endif
1813
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001814 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001815 delcommand MyCmd
1816 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001817 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001818 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001819endfunc
1820
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001821func Test_wildmode()
1822 " Test with utf-8 encoding
1823 call Wildmode_tests()
1824
1825 " Test with latin1 encoding
1826 let save_encoding = &encoding
1827 set encoding=latin1
1828 call Wildmode_tests()
1829 let &encoding = save_encoding
1830endfunc
1831
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001832func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001833 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001834 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001835 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001836 let lines =<< trim END
1837 func vim8#Complete(a, c, p)
1838 return "oneA\noneB\noneC"
1839 endfunc
1840 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001841 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001842
1843 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1844 set nowildmenu
1845 set wildmode=full,list
1846 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1847 call assert_equal('"MyCmd oneA oneB oneC', @:)
1848
1849 let &rtp = save_rtp
1850 set wildmode& wildmenu&
1851 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001852endfunc
1853
Bram Moolenaar578fe942020-02-27 21:32:51 +01001854" Test for interrupting the command-line completion
1855func Test_interrupt_compl()
1856 func F(lead, cmdl, p)
1857 if a:lead =~ 'tw'
1858 call interrupt()
1859 return
1860 endif
1861 return "one\ntwo\nthree"
1862 endfunc
1863 command -nargs=1 -complete=custom,F Tcmd
1864
1865 set nowildmenu
1866 set wildmode=full
1867 let interrupted = 0
1868 try
1869 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1870 catch /^Vim:Interrupt$/
1871 let interrupted = 1
1872 endtry
1873 call assert_equal(1, interrupted)
1874
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001875 let interrupted = 0
1876 try
1877 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1878 catch /^Vim:Interrupt$/
1879 let interrupted = 1
1880 endtry
1881 call assert_equal(1, interrupted)
1882
Bram Moolenaar578fe942020-02-27 21:32:51 +01001883 delcommand Tcmd
1884 delfunc F
1885 set wildmode&
1886endfunc
1887
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001888" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001889func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001890 let str = ":one two\<C-U>"
1891 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001892 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001893 let str ..= "\<Left>five\<Right>"
1894 let str ..= "\<Home>two "
1895 let str ..= "\<C-Left>one "
1896 let str ..= "\<C-Right> three"
1897 let str ..= "\<End>\<S-Left>four "
1898 let str ..= "\<S-Right> six"
1899 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1900 call feedkeys(str, 'xt')
1901 call assert_equal("\"one two three four five six seven", @:)
1902endfunc
1903
1904" Test for moving the cursor on the / command line in 'rightleft' mode
1905func Test_cmdline_edit_rightleft()
1906 CheckFeature rightleft
1907 set rightleft
1908 set rightleftcmd=search
1909 let str = "/one two\<C-U>"
1910 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001911 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001912 let str ..= "\<Right>five\<Left>"
1913 let str ..= "\<Home>two "
1914 let str ..= "\<C-Right>one "
1915 let str ..= "\<C-Left> three"
1916 let str ..= "\<End>\<S-Right>four "
1917 let str ..= "\<S-Left> six"
1918 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1919 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1920 call assert_equal("\"one two three four five six seven", @/)
1921 set rightleftcmd&
1922 set rightleft&
1923endfunc
1924
1925" Test for using <C-\>e in the command line to evaluate an expression
1926func Test_cmdline_expr()
1927 " Evaluate an expression from the beginning of a command line
1928 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1929 call assert_equal('"hello', @:)
1930
1931 " Use an invalid expression for <C-\>e
1932 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1933
1934 " Insert literal <CTRL-\> in the command line
1935 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1936 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001937endfunc
1938
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001939" This was making the insert position negative
1940func Test_cmdline_expr_register()
1941 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1942endfunc
1943
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001944" Test for 'imcmdline' and 'imsearch'
1945" This test doesn't actually test the input method functionality.
1946func Test_cmdline_inputmethod()
1947 new
1948 call setline(1, ['', 'abc', ''])
1949 set imcmdline
1950
1951 call feedkeys(":\"abc\<CR>", 'xt')
1952 call assert_equal("\"abc", @:)
1953 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1954 call assert_equal("\"abc", @:)
1955 call feedkeys("/abc\<CR>", 'xt')
1956 call assert_equal([2, 1], [line('.'), col('.')])
1957 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1958 call assert_equal([2, 1], [line('.'), col('.')])
1959
1960 set imsearch=2
1961 call cursor(1, 1)
1962 call feedkeys("/abc\<CR>", 'xt')
1963 call assert_equal([2, 1], [line('.'), col('.')])
1964 call cursor(1, 1)
1965 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1966 call assert_equal([2, 1], [line('.'), col('.')])
1967 set imdisable
1968 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1969 call assert_equal([2, 1], [line('.'), col('.')])
1970 set imdisable&
1971 set imsearch&
1972
1973 set imcmdline&
1974 %bwipe!
1975endfunc
1976
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001977" Test for using CTRL-_ in the command line with 'allowrevins'
1978func Test_cmdline_revins()
1979 CheckNotMSWindows
1980 CheckFeature rightleft
1981 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1982 call assert_equal("\"abc\<c-_>", @:)
1983 set allowrevins
1984 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1985 call assert_equal('"abcñèæ', @:)
1986 set allowrevins&
1987endfunc
1988
1989" Test for typing UTF-8 composing characters in the command line
1990func Test_cmdline_composing_chars()
1991 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1992 call assert_equal('"ゔ', @:)
1993endfunc
1994
Bram Moolenaar0e717042020-04-27 19:29:01 +02001995" test that ";" works to find a match at the start of the first line
1996func Test_zero_line_search()
1997 new
1998 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1999 call cursor(1,1)
2000 0;/pattern/d
2001 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2002 q!
2003endfunc
2004
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002005func Test_read_shellcmd()
2006 CheckUnix
2007 if executable('ls')
2008 " There should be ls in the $PATH
2009 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2010 call assert_match('^"r! .*\<ls\>', @:)
2011 endif
2012
2013 if executable('rm')
2014 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2015 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2016 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002017
2018 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2019 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2020 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002021 endif
2022endfunc
2023
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002024" Test for going up and down the directory tree using 'wildmenu'
2025func Test_wildmenu_dirstack()
2026 CheckUnix
2027 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002028 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002029 call writefile([], 'Xwildmenu/file1_1.txt')
2030 call writefile([], 'Xwildmenu/file1_2.txt')
2031 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2032 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2033 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2034 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2035 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2036 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002037 set wildmenu
2038
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002039 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002040 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002041 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002042 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002043 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002044 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002045 call assert_equal('"e ../../dir3/', @:)
2046 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2047 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002048 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002049 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002050 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002051 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002052 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002053 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2054 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002055
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002056 set wildmenu&
2057endfunc
2058
obcat71c6f7a2021-05-13 20:23:10 +02002059" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002060" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2061" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002062func Test_recalling_cmdline()
2063 CheckFeature cmdline_hist
2064
2065 let g:cmdlines = []
2066 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2067
2068 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002069 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2070 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2071 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2072 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002073 "\ TODO: {'name': 'debug', ...}
2074 \]
2075 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002076 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2077 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2078 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2079 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2080 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002081 \]
2082 let prefix = 'vi'
2083 for h in histories
2084 call histadd(h.name, 'vim')
2085 call histadd(h.name, 'virtue')
2086 call histadd(h.name, 'Virgo')
2087 call histadd(h.name, 'vogue')
2088 call histadd(h.name, 'emacs')
2089 for k in keypairs
2090 let g:cmdlines = []
2091 let keyseqs = h.enter
2092 \ .. prefix
2093 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2094 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2095 \ .. h.exit
2096 call feedkeys(keyseqs, 'xt')
2097 call histdel(h.name, -1) " delete the history added by feedkeys above
2098 let expect = k.prefixmatch
2099 \ ? ['virtue', 'vim', 'virtue', prefix]
2100 \ : ['emacs', 'vogue', 'emacs', prefix]
2101 call assert_equal(expect, g:cmdlines)
2102 endfor
2103 endfor
2104
2105 unlet g:cmdlines
2106 cunmap <Plug>(save-cmdline)
2107endfunc
2108
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002109func Test_cmd_map_cmdlineChanged()
2110 let g:log = []
2111 cnoremap <F1> l<Cmd><CR>s
2112 augroup test
2113 autocmd!
2114 autocmd CmdlineChanged : let g:log += [getcmdline()]
2115 augroup END
2116
2117 call feedkeys(":\<F1>\<CR>", 'xt')
2118 call assert_equal(['l', 'ls'], g:log)
2119
Bram Moolenaar796139a2021-05-18 21:38:45 +02002120 let @b = 'b'
2121 cnoremap <F1> a<C-R>b
2122 let g:log = []
2123 call feedkeys(":\<F1>\<CR>", 'xt')
2124 call assert_equal(['a', 'ab'], g:log)
2125
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002126 unlet g:log
2127 cunmap <F1>
2128 augroup test
2129 autocmd!
2130 augroup END
2131endfunc
2132
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002133" Test for the 'suffixes' option
2134func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002135 call writefile([], 'Xsuffile', 'D')
2136 call writefile([], 'Xsuffile.c', 'D')
2137 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002138 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002139 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2140 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2141 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2142 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002143 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002144 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2145 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2146 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2147 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002148 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002149 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2150 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2151 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2152 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002153 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002154 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002155 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2156 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002157endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002158
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002159" Test for using a popup menu for the command line completion matches
2160" (wildoptions=pum)
2161func Test_wildmenu_pum()
2162 CheckRunVimInTerminal
2163
2164 let commands =<< trim [CODE]
2165 set wildmenu
2166 set wildoptions=pum
2167 set shm+=I
2168 set noruler
2169 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002170
2171 func CmdCompl(a, b, c)
2172 return repeat(['aaaa'], 120)
2173 endfunc
2174 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002175
2176 func MyStatusLine() abort
2177 return 'status'
2178 endfunc
2179 func SetupStatusline()
2180 set statusline=%!MyStatusLine()
2181 set laststatus=2
2182 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002183
2184 func MyTabLine()
2185 return 'my tab line'
2186 endfunc
2187 func SetupTabline()
2188 set statusline=
2189 set tabline=%!MyTabLine()
2190 set showtabline=2
2191 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002192
2193 func DoFeedKeys()
2194 let &wildcharm = char2nr("\t")
2195 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2196 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002197 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002198 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002199
2200 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2201
2202 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002203 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2204
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002205 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002206 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002207 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2208
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002209 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002210 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002211 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2212
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002213 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002214 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002215 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2216
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002217 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002218 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002219 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2220
2221 " pressing <C-E> should end completion and go back to the original match
2222 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002223 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2224
2225 " pressing <C-Y> should select the current match and end completion
2226 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002227 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2228
2229 " With 'wildmode' set to 'longest,full', completing a match should display
2230 " the longest match, the wildmenu should not be displayed.
2231 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2232 call TermWait(buf)
2233 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002234 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2235
2236 " pressing <Tab> should display the wildmenu
2237 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002238 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2239
2240 " pressing <Tab> second time should select the next entry in the menu
2241 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002242 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2243
2244 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002245 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002246 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002247 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2248
2249 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002250 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2251
2252 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002253 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2254
2255 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002256 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002257 call writefile([], 'Xnamedir/XfileA')
2258 call writefile([], 'Xnamedir/XdirA/XfileB')
2259 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002260
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002261 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002262 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2263
2264 " Pressing <Right> on a directory name should go into that directory
2265 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002266 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2267
2268 " Pressing <Left> on a directory name should go to the parent directory
2269 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002270 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2271
2272 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002273 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002274 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002275 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2276
2277 " Pressing <C-D> when the popup menu is displayed should remove the popup
2278 " menu
2279 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002280 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2281
2282 " Pressing <S-Tab> should open the popup menu with the last entry selected
2283 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002284 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2285
2286 " Pressing <Esc> should close the popup menu and cancel the cmd line
2287 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002288 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2289
2290 " Typing a character when the popup is open, should close the popup
2291 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002292 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2293
2294 " When the popup is open, entering the cmdline window should close the popup
2295 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002296 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2297 call term_sendkeys(buf, ":q\<CR>")
2298
2299 " After the last popup menu item, <C-N> should show the original string
2300 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002301 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2302
2303 " Use the popup menu for the command name
2304 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002305 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2306
2307 " Pressing the left arrow should remove the popup menu
2308 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002309 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2310
2311 " Pressing <BS> should remove the popup menu and erase the last character
2312 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002313 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2314
2315 " Pressing <C-W> should remove the popup menu and erase the previous word
2316 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002317 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2318
2319 " Pressing <C-U> should remove the popup menu and erase the entire line
2320 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002321 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2322
2323 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2324 " the cmdline from history
2325 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002326 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2327
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002328 " Check "list" still works
2329 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2330 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002331 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2332 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002333 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2334
rbtnn68cc2b82022-02-09 11:55:47 +00002335 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002336 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002337 call writefile([], 'Xnamedir/あいう/abc')
2338 call writefile([], 'Xnamedir/あいう/xyz')
2339 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002340
2341 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002342 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002343 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2344
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002345 " Pressing <C-A> when the popup menu is displayed should list all the
2346 " matches and pressing a key after that should remove the popup menu
2347 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2348 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2349 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2350
2351 " Pressing <C-A> when the popup menu is displayed should list all the
2352 " matches and pressing <Left> after that should move the cursor
2353 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2354 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2355 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2356
2357 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2358 " should be displayed correctly on the screen.
2359 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2360 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2361
2362 " After using <C-A> to expand all the filename matches, pressing <Up>
2363 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002364 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002365 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2366 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2367 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2368
2369 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2370 " crash Vim
2371 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2372 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2373
Bram Moolenaar414acd32022-02-10 21:09:45 +00002374 " After removing the pum the command line is redrawn
2375 call term_sendkeys(buf, ":edit foo\<CR>")
2376 call term_sendkeys(buf, ":edit bar\<CR>")
2377 call term_sendkeys(buf, ":ls\<CR>")
2378 call term_sendkeys(buf, ":com\<Tab> ")
2379 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002380 call term_sendkeys(buf, "\<C-U>\<CR>")
2381
2382 " Esc still works to abort the command when 'statusline' is set
2383 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2384 call term_sendkeys(buf, ":si\<Tab>")
2385 call term_sendkeys(buf, "\<Esc>")
2386 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002387
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002388 " Esc still works to abort the command when 'tabline' is set
2389 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2390 call term_sendkeys(buf, ":si\<Tab>")
2391 call term_sendkeys(buf, "\<Esc>")
2392 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2393
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002394 " popup is cleared also when 'lazyredraw' is set
2395 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2396 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2397 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2398 call term_sendkeys(buf, "\<Esc>")
2399
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002400 " Pressing <PageDown> should scroll the menu downward
2401 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2402 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2403 call term_sendkeys(buf, "\<PageDown>")
2404 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2405 call term_sendkeys(buf, "\<PageDown>")
2406 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2407 call term_sendkeys(buf, "\<PageDown>")
2408 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2409 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2410 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2411
2412 " Pressing <PageUp> should scroll the menu upward
2413 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2414 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2415 call term_sendkeys(buf, "\<PageUp>")
2416 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2417 call term_sendkeys(buf, "\<PageUp>")
2418 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2419 call term_sendkeys(buf, "\<PageUp>")
2420 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2421
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002422 call term_sendkeys(buf, "\<C-U>\<CR>")
2423 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002424endfunc
2425
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002426" Test for wildmenumode() with the cmdline popup menu
2427func Test_wildmenumode_with_pum()
2428 set wildmenu
2429 set wildoptions=pum
2430 cnoremap <expr> <F2> wildmenumode()
2431 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2432 call assert_equal('"sign define10', @:)
2433 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2434 call assert_equal('"sign define jump list place undefine unplace0', @:)
2435 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2436 call assert_equal('"sign 0', @:)
2437 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2438 call assert_equal('"sign define0', @:)
2439 set nowildmenu wildoptions&
2440 cunmap <F2>
2441endfunc
2442
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002443func Test_wildmenu_with_pum_foldexpr()
2444 CheckRunVimInTerminal
2445
2446 let lines =<< trim END
2447 call setline(1, ['folded one', 'folded two', 'some more text'])
2448 func MyFoldText()
2449 return 'foo'
2450 endfunc
2451 set foldtext=MyFoldText() wildoptions=pum
2452 normal ggzfj
2453 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002454 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002455 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2456 call term_sendkeys(buf, ":set\<Tab>")
2457 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2458
2459 call term_sendkeys(buf, "\<Esc>")
2460 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2461
2462 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002463endfunc
2464
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002465" Test for opening the cmdline completion popup menu from the terminal window.
2466" The popup menu should be positioned correctly over the status line of the
2467" bottom-most window.
2468func Test_wildmenu_pum_from_terminal()
2469 CheckRunVimInTerminal
2470 let python = PythonProg()
2471 call CheckPython(python)
2472
2473 %bw!
2474 let cmds = ['set wildmenu wildoptions=pum']
2475 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2476 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002477 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002478 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2479 call term_sendkeys(buf, "\r\r\r")
2480 call term_wait(buf)
2481 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2482 call term_wait(buf)
2483 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2484 call term_wait(buf)
2485 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002486endfunc
2487
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002488func Test_wildmenu_pum_clear_entries()
2489 " This was using freed memory. Run in a terminal to get the pum to update.
2490 let lines =<< trim END
2491 set wildoptions=pum
2492 set wildchar=<C-E>
2493 END
2494 call writefile(lines, 'XwildmenuTest', 'D')
2495 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2496
2497 call term_sendkeys(buf, ":\<C-E>\<C-E>")
2498 call VerifyScreenDump(buf, 'Test_wildmenu_pum_clear_entries_1', {})
2499
2500 set wildoptions& wildchar&
2501endfunc
2502
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002503" Test for completion after a :substitute command followed by a pipe (|)
2504" character
2505func Test_cmdline_complete_substitute()
2506 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2507 call assert_equal("\"s | \t", @:)
2508 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2509 call assert_equal("\"s/ | \t", @:)
2510 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2511 call assert_equal("\"s/one | \t", @:)
2512 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2513 call assert_equal("\"s/one/ | \t", @:)
2514 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2515 call assert_equal("\"s/one/two | \t", @:)
2516 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2517 call assert_equal('"s/one/two/ | chistory', @:)
2518 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2519 call assert_equal("\"s/one/two/g \t", @:)
2520 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2521 call assert_equal("\"s/one/two/g | chistory", @:)
2522 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2523 call assert_equal("\"s/one/t\\/ | \t", @:)
2524 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2525 call assert_equal('"s/one/t"o/ | chistory', @:)
2526 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2527 call assert_equal('"s/one/t|o/ | chistory', @:)
2528 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2529 call assert_equal("\"&\t", @:)
2530endfunc
2531
2532" Test for the :dlist command completion
2533func Test_cmdline_complete_dlist()
2534 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2535 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2536 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2537 call assert_equal("\"dlist 10 /pat/ \t", @:)
2538 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2539 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2540 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2541 call assert_equal("\"dlist 10 /pat\\\t", @:)
2542 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2543 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2544endfunc
2545
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002546" argument list (only for :argdel) fuzzy completion
2547func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002548 argadd change.py count.py charge.py
2549 set wildoptions&
2550 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2551 call assert_equal('"argdel cge', @:)
2552 set wildoptions=fuzzy
2553 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2554 call assert_equal('"argdel change.py charge.py', @:)
2555 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002556 set wildoptions&
2557endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002558
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002559" autocmd group name fuzzy completion
2560func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002561 set wildoptions&
2562 augroup MyFuzzyGroup
2563 augroup END
2564 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2565 call assert_equal('"augroup mfg', @:)
2566 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2567 call assert_equal('"augroup MyFuzzyGroup', @:)
2568 set wildoptions=fuzzy
2569 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2570 call assert_equal('"augroup MyFuzzyGroup', @:)
2571 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2572 call assert_equal('"augroup My*p', @:)
2573 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002574 set wildoptions&
2575endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002576
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002577" buffer name fuzzy completion
2578func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002579 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002580 " Use a long name to reduce the risk of matching a random directory name
2581 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002582 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002583 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2584 call assert_equal('"b SRFWL', @:)
2585 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2586 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002587 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002588 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2589 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2590 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2591 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002592 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002593 set wildoptions&
2594endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002595
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002596" buffer name (full path) fuzzy completion
2597func Test_fuzzy_completion_bufname_fullpath()
2598 CheckUnix
2599 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002600 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002601 edit Xcmd/Xstate/Xfile.js
2602 cd Xcmd/Xstate
2603 enew
2604 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2605 call assert_equal('"b CmdStateFile', @:)
2606 set wildoptions=fuzzy
2607 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2608 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2609 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002610 set wildoptions&
2611endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002612
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002613" :behave suboptions fuzzy completion
2614func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002615 set wildoptions&
2616 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2617 call assert_equal('"behave xm', @:)
2618 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2619 call assert_equal('"behave xterm', @:)
2620 set wildoptions=fuzzy
2621 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2622 call assert_equal('"behave xterm', @:)
2623 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2624 call assert_equal('"behave xt*m', @:)
2625 let g:Sline = ''
2626 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2627 call assert_equal('mswin', g:Sline)
2628 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002629 set wildoptions&
2630endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002631
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002632" " colorscheme name fuzzy completion - NOT supported
2633" func Test_fuzzy_completion_colorscheme()
2634" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002635
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002636" built-in command name fuzzy completion
2637func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002638 set wildoptions&
2639 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2640 call assert_equal('"sbwin', @:)
2641 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2642 call assert_equal('"sbrewind', @:)
2643 set wildoptions=fuzzy
2644 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2645 call assert_equal('"sbrewind', @:)
2646 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2647 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002648 set wildoptions&
2649endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002650
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002651" " compiler name fuzzy completion - NOT supported
2652" func Test_fuzzy_completion_compiler()
2653" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002654
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002655" :cscope suboptions fuzzy completion
2656func Test_fuzzy_completion_cscope()
2657 CheckFeature cscope
2658 set wildoptions&
2659 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2660 call assert_equal('"cscope ret', @:)
2661 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2662 call assert_equal('"cscope reset', @:)
2663 set wildoptions=fuzzy
2664 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2665 call assert_equal('"cscope reset', @:)
2666 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2667 call assert_equal('"cscope re*t', @:)
2668 set wildoptions&
2669endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002670
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002671" :diffget/:diffput buffer name fuzzy completion
2672func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002673 new SomeBuffer
2674 diffthis
2675 new OtherBuffer
2676 diffthis
2677 set wildoptions&
2678 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2679 call assert_equal('"diffget sbuf', @:)
2680 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2681 call assert_equal('"diffput sbuf', @:)
2682 set wildoptions=fuzzy
2683 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2684 call assert_equal('"diffget SomeBuffer', @:)
2685 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2686 call assert_equal('"diffput SomeBuffer', @:)
2687 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002688 set wildoptions&
2689endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002690
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002691" " directory name fuzzy completion - NOT supported
2692" func Test_fuzzy_completion_dirname()
2693" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002694
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002695" environment variable name fuzzy completion
2696func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002697 set wildoptions&
2698 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2699 call assert_equal('"echo $VUT', @:)
2700 set wildoptions=fuzzy
2701 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2702 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002703 set wildoptions&
2704endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002705
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002706" autocmd event fuzzy completion
2707func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002708 set wildoptions&
2709 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2710 call assert_equal('"autocmd BWout', @:)
2711 set wildoptions=fuzzy
2712 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2713 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002714 set wildoptions&
2715endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002716
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002717" vim expression fuzzy completion
2718func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002719 let g:PerPlaceCount = 10
2720 set wildoptions&
2721 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2722 call assert_equal('"let c = ppc', @:)
2723 set wildoptions=fuzzy
2724 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2725 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002726 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002727endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002728
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002729" " file name fuzzy completion - NOT supported
2730" func Test_fuzzy_completion_filename()
2731" endfunc
2732
2733" " files in path fuzzy completion - NOT supported
2734" func Test_fuzzy_completion_filesinpath()
2735" endfunc
2736
2737" " filetype name fuzzy completion - NOT supported
2738" func Test_fuzzy_completion_filetype()
2739" endfunc
2740
2741" user defined function name completion
2742func Test_fuzzy_completion_userdefined_func()
2743 set wildoptions&
2744 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2745 call assert_equal('"call Test_f_u_f', @:)
2746 set wildoptions=fuzzy
2747 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2748 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2749 set wildoptions&
2750endfunc
2751
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002752" <SNR> functions should be sorted to the end
2753func Test_fuzzy_completion_userdefined_snr_func()
2754 func s:Sendmail()
2755 endfunc
2756 func SendSomemail()
2757 endfunc
2758 func S1e2n3dmail()
2759 endfunc
2760 set wildoptions=fuzzy
2761 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002762 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002763 set wildoptions&
2764 delfunc s:Sendmail
2765 delfunc SendSomemail
2766 delfunc S1e2n3dmail
2767endfunc
2768
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002769" user defined command name completion
2770func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002771 set wildoptions&
2772 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2773 call assert_equal('"MsFeat', @:)
2774 set wildoptions=fuzzy
2775 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2776 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002777 set wildoptions&
2778endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002779
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002780" " :help tag fuzzy completion - NOT supported
2781" func Test_fuzzy_completion_helptag()
2782" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002783
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002784" highlight group name fuzzy completion
2785func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002786 set wildoptions&
2787 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2788 call assert_equal('"highlight SKey', @:)
2789 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2790 call assert_equal('"highlight SpecialKey', @:)
2791 set wildoptions=fuzzy
2792 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2793 call assert_equal('"highlight SpecialKey', @:)
2794 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2795 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002796 set wildoptions&
2797endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002798
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002799" :history suboptions fuzzy completion
2800func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002801 set wildoptions&
2802 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2803 call assert_equal('"history dg', @:)
2804 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2805 call assert_equal('"history search', @:)
2806 set wildoptions=fuzzy
2807 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2808 call assert_equal('"history debug', @:)
2809 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2810 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002811 set wildoptions&
2812endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002813
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002814" :language locale name fuzzy completion
2815func Test_fuzzy_completion_lang()
2816 CheckUnix
2817 set wildoptions&
2818 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2819 call assert_equal('"lang psx', @:)
2820 set wildoptions=fuzzy
2821 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2822 call assert_equal('"lang POSIX', @:)
2823 set wildoptions&
2824endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002825
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002826" :mapclear buffer argument fuzzy completion
2827func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002828 set wildoptions&
2829 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2830 call assert_equal('"mapclear buf', @:)
2831 set wildoptions=fuzzy
2832 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2833 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002834 set wildoptions&
2835endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002836
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002837" map name fuzzy completion
2838func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002839 " test regex completion works
2840 set wildoptions=fuzzy
2841 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2842 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002843 nmap <plug>MyLongMap :p<CR>
2844 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2845 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2846 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2847 call assert_equal("\"nmap MLM \t", @:)
2848 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2849 call assert_equal("\"nmap <F2> one two \t", @:)
2850 " duplicate entries should be removed
2851 vmap <plug>MyLongMap :<C-U>#<CR>
2852 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2853 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2854 nunmap <plug>MyLongMap
2855 vunmap <plug>MyLongMap
2856 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2857 call assert_equal("\"nmap ABC\t", @:)
2858 " results should be sorted by best match
2859 nmap <Plug>format :
2860 nmap <Plug>goformat :
2861 nmap <Plug>TestFOrmat :
2862 nmap <Plug>fendoff :
2863 nmap <Plug>state :
2864 nmap <Plug>FendingOff :
2865 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2866 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2867 nunmap <Plug>format
2868 nunmap <Plug>goformat
2869 nunmap <Plug>TestFOrmat
2870 nunmap <Plug>fendoff
2871 nunmap <Plug>state
2872 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002873 set wildoptions&
2874endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002875
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002876" abbreviation fuzzy completion
2877func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002878 set wildoptions=fuzzy
2879 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2880 call assert_equal("\"iabbr <nowait>", @:)
2881 iabbr WaitForCompletion WFC
2882 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2883 call assert_equal("\"iabbr WaitForCompletion", @:)
2884 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2885 call assert_equal("\"iabbr a1z\t", @:)
2886 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002887 set wildoptions&
2888endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002889
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002890" menu name fuzzy completion
2891func Test_fuzzy_completion_menu()
2892 CheckGui
2893 set wildoptions&
2894 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2895 call assert_equal('"menu pup', @:)
2896 set wildoptions=fuzzy
2897 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2898 call assert_equal('"menu PopUp.', @:)
2899 set wildoptions&
2900endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002901
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002902" :messages suboptions fuzzy completion
2903func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002904 set wildoptions&
2905 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2906 call assert_equal('"messages clr', @:)
2907 set wildoptions=fuzzy
2908 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2909 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002910 set wildoptions&
2911endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002912
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002913" :set option name fuzzy completion
2914func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002915 set wildoptions&
2916 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2917 call assert_equal('"set brkopt', @:)
2918 set wildoptions=fuzzy
2919 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2920 call assert_equal('"set breakindentopt', @:)
2921 set wildoptions&
2922 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2923 call assert_equal('"set fixendofline', @:)
2924 set wildoptions=fuzzy
2925 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2926 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002927 set wildoptions&
2928endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002929
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002930" :set <term_option>
2931func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002932 set wildoptions&
2933 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2934 call assert_equal('"set t_EC', @:)
2935 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2936 call assert_equal('"set <t_EC>', @:)
2937 set wildoptions=fuzzy
2938 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2939 call assert_equal('"set t_EC', @:)
2940 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2941 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002942 set wildoptions&
2943endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002944
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002945" " :packadd directory name fuzzy completion - NOT supported
2946" func Test_fuzzy_completion_packadd()
2947" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002948
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002949" " shell command name fuzzy completion - NOT supported
2950" func Test_fuzzy_completion_shellcmd()
2951" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002952
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002953" :sign suboptions fuzzy completion
2954func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002955 set wildoptions&
2956 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2957 call assert_equal('"sign ufe', @:)
2958 set wildoptions=fuzzy
2959 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2960 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002961 set wildoptions&
2962endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002963
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002964" :syntax suboptions fuzzy completion
2965func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002966 set wildoptions&
2967 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2968 call assert_equal('"syntax kwd', @:)
2969 set wildoptions=fuzzy
2970 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2971 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002972 set wildoptions&
2973endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002974
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002975" syntax group name fuzzy completion
2976func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002977 set wildoptions&
2978 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2979 call assert_equal('"syntax list mpar', @:)
2980 set wildoptions=fuzzy
2981 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2982 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002983 set wildoptions&
2984endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002985
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002986" :syntime suboptions fuzzy completion
2987func Test_fuzzy_completion_syntime()
2988 CheckFeature profile
2989 set wildoptions&
2990 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2991 call assert_equal('"syntime clr', @:)
2992 set wildoptions=fuzzy
2993 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2994 call assert_equal('"syntime clear', @:)
2995 set wildoptions&
2996endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002997
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002998" " tag name fuzzy completion - NOT supported
2999" func Test_fuzzy_completion_tagname()
3000" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003001
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003002" " tag name and file fuzzy completion - NOT supported
3003" func Test_fuzzy_completion_tagfile()
3004" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003005
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003006" " user names fuzzy completion - how to test this functionality?
3007" func Test_fuzzy_completion_username()
3008" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003009
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003010" user defined variable name fuzzy completion
3011func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003012 let g:SomeVariable=10
3013 set wildoptions&
3014 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3015 call assert_equal('"let SVar', @:)
3016 set wildoptions=fuzzy
3017 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3018 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003019 set wildoptions&
3020endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003021
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003022" Test for sorting the results by the best match
3023func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003024 %bw!
3025 command T123format :
3026 command T123goformat :
3027 command T123TestFOrmat :
3028 command T123fendoff :
3029 command T123state :
3030 command T123FendingOff :
3031 set wildoptions=fuzzy
3032 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3033 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3034 delcommand T123format
3035 delcommand T123goformat
3036 delcommand T123TestFOrmat
3037 delcommand T123fendoff
3038 delcommand T123state
3039 delcommand T123FendingOff
3040 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003041 set wildoptions&
3042endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003043
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003044" Test for fuzzy completion of a command with lower case letters and a number
3045func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003046 command Foo2Bar :
3047 set wildoptions=fuzzy
3048 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3049 call assert_equal('"Foo2Bar', @:)
3050 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3051 call assert_equal('"Foo2Bar', @:)
3052 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3053 call assert_equal('"Foo2Bar', @:)
3054 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003055 set wildoptions&
3056endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003057
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003058" Test for command completion for a command starting with 'k'
3059func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003060 command KillKillKill :
3061 set wildoptions&
3062 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3063 call assert_equal("\"killkill\<Tab>", @:)
3064 set wildoptions=fuzzy
3065 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3066 call assert_equal('"KillKillKill', @:)
3067 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003068 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003069endfunc
3070
3071" Test for fuzzy completion for user defined custom completion function
3072func Test_fuzzy_completion_custom_func()
3073 func Tcompl(a, c, p)
3074 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3075 endfunc
3076 command -nargs=* -complete=custom,Tcompl Fuzzy :
3077 set wildoptions&
3078 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3079 call assert_equal("\"Fuzzy format", @:)
3080 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3081 call assert_equal("\"Fuzzy xy", @:)
3082 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3083 call assert_equal("\"Fuzzy ttt", @:)
3084 set wildoptions=fuzzy
3085 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3086 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3087 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3088 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3089 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3090 call assert_equal("\"Fuzzy xy", @:)
3091 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3092 call assert_equal("\"Fuzzy TestFOrmat", @:)
3093 delcom Fuzzy
3094 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003095endfunc
3096
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003097" Test for :breakadd argument completion
3098func Test_cmdline_complete_breakadd()
3099 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3100 call assert_equal("\"breakadd expr file func here", @:)
3101 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3102 call assert_equal("\"breakadd expr", @:)
3103 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3104 call assert_equal("\"breakadd expr", @:)
3105 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3106 call assert_equal("\"breakadd here", @:)
3107 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3108 call assert_equal("\"breakadd here", @:)
3109 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3110 call assert_equal("\"breakadd abc", @:)
3111 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3112 let l = getcompletion('not', 'breakpoint')
3113 call assert_equal([], l)
3114
3115 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003116 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003117 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3118 call assert_equal("\"breakadd file Xscript", @:)
3119 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3120 call assert_equal("\"breakadd file Xscript", @:)
3121 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3122 call assert_equal("\"breakadd file 20 Xscript", @:)
3123 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3124 call assert_equal("\"breakadd file 20 Xscript", @:)
3125 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3126 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3127 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3128 call assert_equal("\"breakadd file 20\t", @:)
3129 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3130 call assert_equal("\"breakadd file 20x\t", @:)
3131 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3132 call assert_equal("\"breakadd file Xscript ", @:)
3133 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3134 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003135
3136 " Test for :breakadd func [lnum] <function>
3137 func Xbreak_func()
3138 endfunc
3139 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal("\"breakadd func Xbreak_func", @:)
3141 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal("\"breakadd func Xbreak_func", @:)
3143 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3144 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3145 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3146 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3147 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3148 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3149 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3150 call assert_equal("\"breakadd func 20\t", @:)
3151 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal("\"breakadd func 20x\t", @:)
3153 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3154 call assert_equal("\"breakadd func Xbreak_func ", @:)
3155 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3156 call assert_equal("\"breakadd func X1B2C3", @:)
3157 delfunc Xbreak_func
3158
3159 " Test for :breakadd expr <expression>
3160 let g:Xtest_var = 10
3161 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3162 call assert_equal("\"breakadd expr Xtest_var", @:)
3163 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3164 call assert_equal("\"breakadd expr Xtest_var", @:)
3165 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3166 call assert_equal("\"breakadd expr Xtest_var ", @:)
3167 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3168 call assert_equal("\"breakadd expr X1B2C3", @:)
3169 unlet g:Xtest_var
3170
3171 " Test for :breakadd here
3172 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3173 call assert_equal("\"breakadd here Xtest", @:)
3174 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3175 call assert_equal("\"breakadd here Xtest", @:)
3176 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3177 call assert_equal("\"breakadd here ", @:)
3178endfunc
3179
3180" Test for :breakdel argument completion
3181func Test_cmdline_complete_breakdel()
3182 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3183 call assert_equal("\"breakdel file func here", @:)
3184 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3185 call assert_equal("\"breakdel file", @:)
3186 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3187 call assert_equal("\"breakdel file", @:)
3188 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3189 call assert_equal("\"breakdel here", @:)
3190 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3191 call assert_equal("\"breakdel here", @:)
3192 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3193 call assert_equal("\"breakdel abc", @:)
3194
3195 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003196 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003197 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3198 call assert_equal("\"breakdel file Xscript", @:)
3199 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3200 call assert_equal("\"breakdel file Xscript", @:)
3201 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3202 call assert_equal("\"breakdel file 20 Xscript", @:)
3203 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3204 call assert_equal("\"breakdel file 20 Xscript", @:)
3205 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3206 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3207 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3208 call assert_equal("\"breakdel file 20\t", @:)
3209 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3210 call assert_equal("\"breakdel file 20x\t", @:)
3211 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3212 call assert_equal("\"breakdel file Xscript ", @:)
3213 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3214 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003215
3216 " Test for :breakdel func [lnum] <function>
3217 func Xbreak_func()
3218 endfunc
3219 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3220 call assert_equal("\"breakdel func Xbreak_func", @:)
3221 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal("\"breakdel func Xbreak_func", @:)
3223 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3225 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3227 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3229 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3230 call assert_equal("\"breakdel func 20\t", @:)
3231 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3232 call assert_equal("\"breakdel func 20x\t", @:)
3233 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3234 call assert_equal("\"breakdel func Xbreak_func ", @:)
3235 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3236 call assert_equal("\"breakdel func X1B2C3", @:)
3237 delfunc Xbreak_func
3238
3239 " Test for :breakdel here
3240 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3241 call assert_equal("\"breakdel here Xtest", @:)
3242 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3243 call assert_equal("\"breakdel here Xtest", @:)
3244 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3245 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003246endfunc
3247
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003248" Test for :scriptnames argument completion
3249func Test_cmdline_complete_scriptnames()
3250 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003251 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003252 source Xa1b2c3.vim
3253 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3254 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3255 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3256 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3257 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3258 call assert_equal("\"script b2c3", @:)
3259 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3260 call assert_match("\"script 2\<Tab>$", @:)
3261 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3262 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3263 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal("\"script ", @:)
3265 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3266 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3267 new
3268 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3269 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3270 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003271 set wildmenu&
3272endfunc
3273
Bram Moolenaard8893442022-05-06 20:38:47 +01003274" this was going over the end of IObuff
3275func Test_report_error_with_composing()
3276 let caught = 'no'
3277 try
3278 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3279 catch /E492:/
3280 let caught = 'yes'
3281 endtry
3282 call assert_equal('yes', caught)
3283endfunc
3284
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003285" Test for expanding 2-letter and 3-letter :substitute command arguments.
3286" These commands don't accept an argument.
3287func Test_cmdline_complete_substitute_short()
3288 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3289 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3290 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3291 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3292 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3293 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3294 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3295 endfor
3296endfunc
3297
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003298" Test for :! shell command argument completion
3299func Test_cmdline_complete_bang_cmd_argument()
3300 set wildoptions=fuzzy
3301 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3302 call assert_equal('"!vim test_cmdline.vim', @:)
3303 set wildoptions&
3304 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3305 call assert_equal('"!vim test_cmdline.vim', @:)
3306endfunc
3307
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003308func Check_completion()
3309 call assert_equal('let a', getcmdline())
3310 call assert_equal(6, getcmdpos())
3311 call assert_equal(7, getcmdscreenpos())
3312 call assert_equal('var', getcmdcompltype())
3313 return ''
3314endfunc
3315
3316func Test_screenpos_and_completion()
3317 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3318endfunc
3319
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003320func Test_recursive_register()
3321 let @= = ''
3322 silent! ?e/
3323 let caught = 'no'
3324 try
3325 normal //
3326 catch /E169:/
3327 let caught = 'yes'
3328 endtry
3329 call assert_equal('yes', caught)
3330endfunc
3331
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003332func Test_long_error_message()
3333 " the error should be truncated, not overrun IObuff
3334 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3335endfunc
3336
zeertzjq6791adc2022-07-26 20:42:25 +01003337func Test_cmdline_redraw_tabline()
3338 CheckRunVimInTerminal
3339
3340 let lines =<< trim END
3341 set showtabline=2
3342 autocmd CmdlineEnter * set tabline=foo
3343 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003344 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003345 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3346 call term_sendkeys(buf, ':')
3347 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3348
3349 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003350endfunc
3351
zeertzjqb82a2ab2022-08-21 14:33:57 +01003352func Test_wildmenu_pum_disable_while_shown()
3353 set wildoptions=pum
3354 set wildmenu
3355 cnoremap <F2> <Cmd>set nowildmenu<CR>
3356 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3357 call assert_equal(0, pumvisible())
3358 cunmap <F2>
3359 set wildoptions& wildmenu&
3360endfunc
3361
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003362func Test_setcmdline()
3363 func SetText(text, pos)
zeertzjq54acb902022-08-29 16:21:25 +01003364 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003365 call assert_equal(0, setcmdline(a:text))
3366 call assert_equal(a:text, getcmdline())
3367 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003368 call assert_equal(getcmdtype(), g:cmdtype)
3369 unlet g:cmdtype
3370 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003371
3372 call assert_equal(0, setcmdline(a:text, a:pos))
3373 call assert_equal(a:text, getcmdline())
3374 call assert_equal(a:pos, getcmdpos())
3375
3376 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003377 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3378 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003379
3380 return ''
3381 endfunc
3382
3383 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3384 call assert_equal('set rtp?', @:)
3385
zeertzjq54acb902022-08-29 16:21:25 +01003386 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3387 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3388 call assert_equal('foo', g:str)
3389 unlet g:str
3390
3391 delfunc SetText
3392
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003393 " setcmdline() returns 1 when not editing the command line.
3394 call assert_equal(1, 'foo'->setcmdline())
3395
3396 " Called in custom function
3397 func CustomComplete(A, L, P)
3398 call assert_equal(0, setcmdline("DoCmd "))
3399 return "January\nFebruary\nMars\n"
3400 endfunc
3401
3402 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3403 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3404 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003405 delcom DoCmd
3406 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003407
3408 " Called in <expr>
3409 cnoremap <expr>a setcmdline('let foo=')
3410 call feedkeys(":a\<CR>", 'tx')
3411 call assert_equal('let foo=0', @:)
3412 cunmap a
3413endfunc
3414
Bram Moolenaar309976e2019-12-05 18:16:33 +01003415" vim: shiftwidth=2 sts=2 expandtab