blob: 9406a7eac4a6634f6d4220b8c3234ce4e43e606b [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Bram Moolenaar4facea32019-10-12 20:17:40 +02003source check.vim
4source screendump.vim
Bram Moolenaar24ebd832020-03-16 21:25:24 +01005source view_util.vim
Bram Moolenaarc82dd862020-06-07 17:30:33 +02006source shared.vim
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00007import './vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02008
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00009func SetUp()
10 func SaveLastScreenLine()
11 let g:Sline = Screenline(&lines - 1)
12 return ''
13 endfunc
14 cnoremap <expr> <F4> SaveLastScreenLine()
15endfunc
16
17func TearDown()
18 delfunc SaveLastScreenLine
19 cunmap <F4>
20endfunc
21
Bram Moolenaarae3150e2016-06-11 23:22:36 +020022func Test_complete_tab()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010023 call writefile(['testfile'], 'Xtestfile', 'D')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020024 call feedkeys(":e Xtest\t\r", "tx")
25 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020026
27 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
28 call feedkeys(":e %\t\r", "tx")
29 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020030endfunc
31
32func Test_complete_list()
33 " We can't see the output, but at least we check the code runs properly.
34 call feedkeys(":e test\<C-D>\r", "tx")
35 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010036
37 " If a command doesn't support completion, then CTRL-D should be literally
38 " used.
39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000041
42 " Test for displaying the tail of the completion matches
43 set wildmode=longest,full
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010044 call mkdir('Xtest', 'R')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000045 call writefile([], 'Xtest/a.c')
46 call writefile([], 'Xtest/a.h')
47 let g:Sline = ''
48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49 call assert_equal('a.c a.h', g:Sline)
50 call assert_equal('"e Xtest/', @:)
51 if has('win32')
52 " Test for 'completeslash'
53 set completeslash=backslash
54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000056 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000058 set completeslash=slash
59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000061 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000063 set completeslash&
64 endif
65
66 " Test for displaying the tail with wildcards
67 let g:Sline = ''
68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
70 call assert_equal('"e Xtes?/', @:)
71 let g:Sline = ''
72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
74 call assert_equal('"e Xtes*/', @:)
75 let g:Sline = ''
76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77 call assert_equal(':e Xtes[/', g:Sline)
78 call assert_equal('"e Xtes[/', @:)
79
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000080 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020081endfunc
82
83func Test_complete_wildmenu()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010084 call mkdir('Xwilddir1/Xdir2', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010085 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
86 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
87 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
88 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020089 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010090
91 " Pressing <Tab> completes, and moves to next files when pressing again.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010092 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010093 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010094 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020095 call assert_equal('testfile2', getline(1))
96
Bram Moolenaar37db6422019-03-28 21:26:23 +010097 " <S-Tab> is like <Tab> but begin with the last match and then go to
98 " previous.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010099 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100100 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100101 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100102 call assert_equal('testfile1', getline(1))
103
104 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100105 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100106 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100107 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100108 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100109 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100110 call assert_equal('testfile1', getline(1))
111
112 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100113 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100114 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100115 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100116 call assert_equal('testfile1', getline(1))
117
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100118 " this fails in some Unix GUIs, not sure why
119 if !has('unix') || !has('gui_running')
120 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
121 " different than 'wildchar'.
122 set wildcharm=<C-Z>
123 cnoremap <C-J> <Down><C-Z>
124 cnoremap <C-K> <Up><C-Z>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100125 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100126 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100127 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100128 call assert_equal('testfile1', getline(1))
129 set wildcharm=0
130 cunmap <C-J>
131 cunmap <C-K>
132 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100133
Bram Moolenaar578fe942020-02-27 21:32:51 +0100134 " Test for canceling the wild menu by adding a character
135 redrawstatus
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100136 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
137 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100138
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100139 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100140 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
142 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
143 cd -
144
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000145 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100146 cnoremap <expr> <F2> wildmenumode()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100147 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
148 call assert_equal('"cd Xwilddir1/0', @:)
149 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
150 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100151 cunmap <F2>
152
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000153 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
154 " After this pressing <Left> or <Right> should not change the selection.
155 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
156 call assert_equal('"sign define', @:)
157 call histadd('cmd', 'TestWildMenu')
158 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
159 call assert_equal('"TestWildMenu', @:)
160
Bram Moolenaar37db6422019-03-28 21:26:23 +0100161 " cleanup
162 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200163 set nowildmenu
164endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100165
Bram Moolenaara60053b2020-09-03 16:50:13 +0200166func Test_wildmenu_screendump()
167 CheckScreendump
168
169 let lines =<< trim [SCRIPT]
170 set wildmenu hlsearch
171 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100172 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173
174 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
175 call term_sendkeys(buf, ":vim\<Tab>")
176 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
177
178 call term_sendkeys(buf, "\<Tab>")
179 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
180
181 call term_sendkeys(buf, "\<Tab>")
182 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
183
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100184 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200185 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
186 call term_sendkeys(buf, "\<Esc>")
187
188 " clean up
189 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200190endfunc
191
Bram Moolenaara653e532022-04-19 11:38:24 +0100192func Test_redraw_in_autocmd()
193 CheckScreendump
194
195 let lines =<< trim END
196 set cmdheight=2
197 autocmd CmdlineChanged * redraw
198 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100199 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100200
201 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
202 call term_sendkeys(buf, ":for i in range(3)\<CR>")
203 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
204
205 call term_sendkeys(buf, "let i =")
206 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
207
208 " clean up
209 call term_sendkeys(buf, "\<CR>")
210 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100211endfunc
212
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100213func Test_redrawstatus_in_autocmd()
214 CheckScreendump
215
216 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100217 set laststatus=2
218 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100219 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100220 END
221 call writefile(lines, 'XTest_redrawstatus', 'D')
222
223 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100224 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100225 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
226 call term_sendkeys(buf, ":foobar")
227 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100228 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100229 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100230 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100231 " with cmdheight=1 messages have scrolled when typing :endfor
232 call term_sendkeys(buf, "\<CR>:endfor")
233 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
234 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
235 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
236 call term_sendkeys(buf, ":for in in range(3)")
237 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
238 call term_sendkeys(buf, "\<CR>:endfor")
239 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100240
241 " clean up
242 call term_sendkeys(buf, "\<CR>")
243 call StopVimInTerminal(buf)
244endfunc
245
Bram Moolenaarf797e302022-08-11 13:17:30 +0100246func Test_changing_cmdheight()
247 CheckScreendump
248
249 let lines =<< trim END
250 set cmdheight=1 laststatus=2
Bram Moolenaar0816f472022-10-05 15:42:32 +0100251 func EchoTwo()
252 set laststatus=2
253 set cmdheight=5
254 echo 'foo'
255 echo 'bar'
256 set cmdheight=1
257 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100258 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100259 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100260
261 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
262 call term_sendkeys(buf, ":resize -3\<CR>")
263 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
264
265 " using the space available doesn't change the status line
266 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
267 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
268
269 " using more space moves the status line up
270 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
271 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
272
273 " reducing cmdheight moves status line down
274 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
275 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
276
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100277 " reducing window size and then setting cmdheight
278 call term_sendkeys(buf, ":resize -1\<CR>")
279 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
280 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
281
Bram Moolenaar0816f472022-10-05 15:42:32 +0100282 " setting 'cmdheight' works after outputting two messages
283 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
284 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
285
Bram Moolenaarf797e302022-08-11 13:17:30 +0100286 " clean up
287 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100288endfunc
289
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100290func Test_cmdheight_tabline()
291 CheckScreendump
292
293 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
294 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
295
296 " clean up
297 call StopVimInTerminal(buf)
298endfunc
299
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100300func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100301 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
302 call assert_equal('"map <unique> <silent>', getreg(':'))
303 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
304 call assert_equal('"map <script> <unique>', getreg(':'))
305 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
306 call assert_equal('"map <expr> <script>', getreg(':'))
307 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
308 call assert_equal('"map <buffer> <expr>', getreg(':'))
309 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
310 call assert_equal('"map <nowait> <buffer>', getreg(':'))
311 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
312 call assert_equal('"map <special> <nowait>', getreg(':'))
313 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
314 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200315
Bram Moolenaar1776a282019-05-03 16:05:41 +0200316 map <Middle>x middle
317
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200318 map ,f commaf
319 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200320 map <Left> left
321 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200322 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
323 call assert_equal('"map ,f', getreg(':'))
324 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
325 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200326 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
327 call assert_equal('"map <Left>', getreg(':'))
328 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200329 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200330 unmap ,f
331 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200332 unmap <Left>
333 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200334
335 set cpo-=< cpo-=B cpo-=k
336 map <Left> left
337 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
338 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200339 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200340 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200341 unmap <Left>
342
343 set cpo+=<
344 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200345 exe "set t_k6=\<Esc>[17~"
346 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200347 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
348 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200349 if !has('gui_running')
350 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
351 call assert_equal("\"map <F6>x", getreg(':'))
352 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200353 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200354 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200355 set cpo-=<
356
357 set cpo+=B
358 map <Left> left
359 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
360 call assert_equal('"map <Left>', getreg(':'))
361 unmap <Left>
362 set cpo-=B
363
364 set cpo+=k
365 map <Left> left
366 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
367 call assert_equal('"map <Left>', getreg(':'))
368 unmap <Left>
369 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200370
Bram Moolenaar531be472020-09-23 22:38:05 +0200371 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
372
Bram Moolenaar1776a282019-05-03 16:05:41 +0200373 unmap <Middle>x
374 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100375endfunc
376
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100377func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100378 hi Aardig ctermfg=green
379 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000380 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100381 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000382 call assert_equal('"match none', @:)
383 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
384 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100385endfunc
386
387func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100388 hi Aardig ctermfg=green
389 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
390 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200391 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
392 call assert_equal('"hi default Aardig', getreg(':'))
393 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
394 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100395 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
396 call assert_equal('"hi link', getreg(':'))
397 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
398 call assert_equal('"hi default', getreg(':'))
399 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
400 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200401 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
402 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
403 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
404 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200405
406 " A cleared group does not show up in completions.
407 hi Anders ctermfg=green
408 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
409 hi clear Aardig
410 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
411 hi clear Anders
412 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100413endfunc
414
Bram Moolenaar75e15672020-06-28 13:10:22 +0200415" Test for command-line expansion of "hi Ni " (easter egg)
416func Test_highlight_easter_egg()
417 call test_override('ui_delay', 1)
418 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
419 call assert_equal("\"hi Ni \<Tab>", @:)
420 call test_override('ALL', 0)
421endfunc
422
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200423func Test_getcompletion()
424 let groupcount = len(getcompletion('', 'event'))
425 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200426 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200427 call assert_true(matchcount > 0)
428 call assert_true(groupcount > matchcount)
429
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200430 if has('menu')
431 source $VIMRUNTIME/menu.vim
432 let matchcount = len(getcompletion('', 'menu'))
433 call assert_true(matchcount > 0)
434 call assert_equal(['File.'], getcompletion('File', 'menu'))
435 call assert_true(matchcount > 0)
436 let matchcount = len(getcompletion('File.', 'menu'))
437 call assert_true(matchcount > 0)
438 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200439
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200440 let l = getcompletion('v:n', 'var')
441 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200442 let l = getcompletion('v:notexists', 'var')
443 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200444
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200445 args a.c b.c
446 let l = getcompletion('', 'arglist')
447 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000448 let l = getcompletion('a.', 'buffer')
449 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200450 %argdelete
451
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200452 let l = getcompletion('', 'augroup')
453 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200454 let l = getcompletion('blahblah', 'augroup')
455 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200456
457 let l = getcompletion('', 'behave')
458 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200459 let l = getcompletion('not', 'behave')
460 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200461
462 let l = getcompletion('', 'color')
463 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200464 let l = getcompletion('dirty', 'color')
465 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200466
467 let l = getcompletion('', 'command')
468 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200469 let l = getcompletion('awake', 'command')
470 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200471
472 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200473 call assert_true(index(l, 'samples/') >= 0)
474 let l = getcompletion('NoMatch', 'dir')
475 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200476
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100477 if glob('~/*') !=# ''
478 let l = getcompletion('~/', 'dir')
479 call assert_true(l[0][0] ==# '~')
480 endif
481
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200482 let l = getcompletion('exe', 'expression')
483 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200484 let l = getcompletion('kill', 'expression')
485 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200486
487 let l = getcompletion('tag', 'function')
488 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200489 let l = getcompletion('paint', 'function')
490 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200491
Kota Kato90c23532023-01-18 15:27:38 +0000492 if !has('ruby')
493 " global_functions[] has an entry but it doesn't have an implemention
494 let l = getcompletion('ruby', 'function')
495 call assert_equal([], l)
496 endif
497
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200498 let Flambda = {-> 'hello'}
499 let l = getcompletion('', 'function')
500 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200501 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200502
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200503 let l = getcompletion('run', 'file')
504 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200505 let l = getcompletion('walk', 'file')
506 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200507 set wildignore=*.vim
508 let l = getcompletion('run', 'file', 1)
509 call assert_true(index(l, 'runtest.vim') < 0)
510 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000511 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100512 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000513 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
514 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200515
516 let l = getcompletion('ha', 'filetype')
517 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200518 let l = getcompletion('horse', 'filetype')
519 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200520
521 let l = getcompletion('z', 'syntax')
522 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200523 let l = getcompletion('emacs', 'syntax')
524 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200525
526 let l = getcompletion('jikes', 'compiler')
527 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200528 let l = getcompletion('break', 'compiler')
529 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200530
531 let l = getcompletion('last', 'help')
532 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200533 let l = getcompletion('giveup', 'help')
534 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200535
536 let l = getcompletion('time', 'option')
537 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200538 let l = getcompletion('space', 'option')
539 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200540
541 let l = getcompletion('er', 'highlight')
542 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200543 let l = getcompletion('dark', 'highlight')
544 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200545
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200546 let l = getcompletion('', 'messages')
547 call assert_true(index(l, 'clear') >= 0)
548 let l = getcompletion('not', 'messages')
549 call assert_equal([], l)
550
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200551 let l = getcompletion('', 'mapclear')
552 call assert_true(index(l, '<buffer>') >= 0)
553 let l = getcompletion('not', 'mapclear')
554 call assert_equal([], l)
roota6759382023-01-21 21:56:06 +0000555
556 let l = getcompletion('', 'runtime')
557 call assert_true(index(l, 'defaults.vim') >= 0)
558 let l = getcompletion('synt', 'runtime')
559 call assert_true(index(l, 'syntax') >= 0)
560 let l = getcompletion('syntax/vi', 'runtime')
561 call assert_true(index(l, 'syntax/vim.vim') >= 0)
562 let l = getcompletion('notexitsts', 'runtime')
563 call assert_equal([], l)
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200564
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200565 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200566 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200567 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
568 let root = has('win32') ? 'C:\\' : '/'
569 let l = getcompletion(root, 'shellcmd')
570 let expected = map(filter(glob(root . '*', 0, 1),
571 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
572 call assert_equal(expected, l)
573
Bram Moolenaarb650b982016-08-05 20:35:13 +0200574 if has('cscope')
575 let l = getcompletion('', 'cscope')
576 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
577 call assert_equal(cmds, l)
578 " using cmdline completion must not change the result
579 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
580 let l = getcompletion('', 'cscope')
581 call assert_equal(cmds, l)
582 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
583 let l = getcompletion('find ', 'cscope')
584 call assert_equal(keys, l)
585 endif
586
Bram Moolenaar7522f692016-08-06 14:12:50 +0200587 if has('signs')
588 sign define Testing linehl=Comment
589 let l = getcompletion('', 'sign')
590 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
591 call assert_equal(cmds, l)
592 " using cmdline completion must not change the result
593 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
594 let l = getcompletion('', 'sign')
595 call assert_equal(cmds, l)
596 let l = getcompletion('list ', 'sign')
597 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000598 let l = getcompletion('de*', 'sign')
599 call assert_equal(['define'], l)
600 let l = getcompletion('p?', 'sign')
601 call assert_equal(['place'], l)
602 let l = getcompletion('j.', 'sign')
603 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200604 endif
605
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200606 " Command line completion tests
607 let l = getcompletion('cd ', 'cmdline')
608 call assert_true(index(l, 'samples/') >= 0)
609 let l = getcompletion('cd NoMatch', 'cmdline')
610 call assert_equal([], l)
611 let l = getcompletion('let v:n', 'cmdline')
612 call assert_true(index(l, 'v:null') >= 0)
613 let l = getcompletion('let v:notexists', 'cmdline')
614 call assert_equal([], l)
615 let l = getcompletion('call tag', 'cmdline')
616 call assert_true(index(l, 'taglist(') >= 0)
617 let l = getcompletion('call paint', 'cmdline')
618 call assert_equal([], l)
619
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100620 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000621 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100622 return "oneA\noneB\noneC"
623 endfunc
624 command -nargs=1 -complete=custom,T MyCmd
625 let l = getcompletion('MyCmd ', 'cmdline')
626 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000627 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100628
629 delcommand MyCmd
630 delfunc T
ii144785fe02021-11-21 12:13:56 +0000631 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100632
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200633 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200634 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200635 if has('cmdline_hist')
636 call add(names, 'history')
637 endif
638 if has('gettext')
639 call add(names, 'locale')
640 endif
641 if has('profile')
642 call add(names, 'syntime')
643 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200644
645 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100646 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200647
648 for name in names
649 let matchcount = len(getcompletion('', name))
650 call assert_true(matchcount >= 0, 'No matches for ' . name)
651 endfor
652
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200653 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200654
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000655 edit a~b
656 enew
657 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
658 bw a~b
659
660 if has('unix')
661 edit Xtest\
662 enew
663 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
664 bw Xtest\
665 endif
666
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200667 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200668 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100669 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200670endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200671
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000672func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000673 " Get a dialog in the GUI
674 CheckNotGui
675
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000676 " This was using uninitialized memory.
677 let lines =<< trim END
678 set verbose=6
679 norm @=ٷ
680 qall!
681 END
682 call writefile(lines, 'XmultiScript', 'D')
683 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
684endfunc
685
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000686" Test for getcompletion() with "fuzzy" in 'wildoptions'
687func Test_getcompletion_wildoptions()
688 let save_wildoptions = &wildoptions
689 set wildoptions&
690 let l = getcompletion('space', 'option')
691 call assert_equal([], l)
692 let l = getcompletion('ier', 'command')
693 call assert_equal([], l)
694 set wildoptions=fuzzy
695 let l = getcompletion('space', 'option')
696 call assert_true(index(l, 'backspace') >= 0)
697 let l = getcompletion('ier', 'command')
698 call assert_true(index(l, 'compiler') >= 0)
699 let &wildoptions = save_wildoptions
700endfunc
701
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000702func Test_complete_autoload_error()
703 let save_rtp = &rtp
704 let lines =<< trim END
705 vim9script
706 export def Complete(..._): string
707 return 'match'
708 enddef
709 echo this will cause an error
710 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100711 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000712 call writefile(lines, 'Xdir/autoload/script.vim')
713 exe 'set rtp+=' .. getcwd() .. '/Xdir'
714
715 let lines =<< trim END
716 vim9script
717 import autoload 'script.vim'
718 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
719 &wildcharm = char2nr("\<Tab>")
720 feedkeys(":Cmd \<Tab>", 'xt')
721 END
722 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
723
724 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000725endfunc
726
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100727func Test_fullcommand()
728 let tests = {
729 \ '': '',
730 \ ':': '',
731 \ ':::': '',
732 \ ':::5': '',
733 \ 'not_a_cmd': '',
734 \ 'Check': '',
735 \ 'syntax': 'syntax',
736 \ ':syntax': 'syntax',
737 \ '::::syntax': 'syntax',
738 \ 'sy': 'syntax',
739 \ 'syn': 'syntax',
740 \ 'synt': 'syntax',
741 \ ':sy': 'syntax',
742 \ '::::sy': 'syntax',
743 \ 'match': 'match',
744 \ '2match': 'match',
745 \ '3match': 'match',
746 \ 'aboveleft': 'aboveleft',
747 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100748 \ 'en': 'endif',
749 \ 'end': 'endif',
750 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100751 \ 's': 'substitute',
752 \ '5s': 'substitute',
753 \ ':5s': 'substitute',
754 \ "'<,'>s": 'substitute',
755 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100756 \ 'CheckLin': 'CheckLinux',
757 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100758 \ }
759
760 for [in, want] in items(tests)
761 call assert_equal(want, fullcommand(in))
762 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200763 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100764
765 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200766
767 command -buffer BufferLocalCommand :
768 command GlobalCommand :
769 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
770 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
771 delcommand BufferLocalCommand
772 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100773endfunc
774
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200775func Test_shellcmd_completion()
776 let save_path = $PATH
777
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100778 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200779 call writefile([''], 'Xpathdir/Xfile.exe')
780 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
781
782 " Set PATH to example directory without trailing slash.
783 let $PATH = getcwd() . '/Xpathdir'
784
785 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
786 " dirs in the PATH, even though they won't be executed. We check that only
787 " subdirs of the PWD and executables from the PATH are included in the
788 " suggestions.
789 let actual = getcompletion('X', 'shellcmd')
790 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
791 call insert(expected, 'Xfile.exe')
792 call assert_equal(expected, actual)
793
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200794 let $PATH = save_path
795endfunc
796
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200797func Test_expand_star_star()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100798 call mkdir('a/b', 'pR')
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200799 call writefile(['asdfasdf'], 'a/b/fileXname')
800 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000801 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200802 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200803endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100804
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100805func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100806 let @a = "def"
807 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
808 call assert_equal('"abc def ghi', @:)
809
810 new
811 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
812
813 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
814 call assert_equal('"aaa asdf bbb', @:)
815
816 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
817 call assert_equal('"aaa /tmp/some bbb', @:)
818
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200819 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
820 call assert_equal('"aaa '.getline(1).' bbb', @:)
821
Bram Moolenaar21efc362016-12-03 14:05:49 +0100822 set incsearch
823 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
824 call assert_equal('"aaa verylongword bbb', @:)
825
826 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
827 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100828
829 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
830 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100831 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200832
833 " Error while typing a command used to cause that it was not executed
834 " in the end.
835 new
836 try
837 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
838 catch /^Vim\%((\a\+)\)\=:E32/
839 " ignore error E32
840 endtry
841 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100842
Bram Moolenaar578fe942020-02-27 21:32:51 +0100843 " Try to paste an invalid register using <C-R>
844 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
845 call assert_equal('"onetwo', @:)
846
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100847 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100848 let @a = "xy\<C-H>z"
849 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
850 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100851 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
852 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100853 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
854 call assert_equal("\"xy\<C-H>z", @:)
855
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100856 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
857 let @a = "xy\<C-V>z"
858 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
859 call assert_equal('"xyz', @:)
860 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
861 call assert_equal("\"xy\<C-V>z", @:)
862
Bram Moolenaar578fe942020-02-27 21:32:51 +0100863 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
864
Bram Moolenaar72532d32018-04-07 19:09:09 +0200865 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100866endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100867
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100868func Test_cmdline_remove_char()
869 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100870
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100871 for e in ['utf8', 'latin1']
872 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100873
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100874 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
875 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100876
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100877 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
878 call assert_equal('"abcdef', @:)
879
880 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
881 call assert_equal('"abc ghi', @:, e)
882
883 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
884 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100885
886 " This was going before the start in latin1.
887 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100888 endfor
889
890 let &encoding = encoding_save
891endfunc
892
893func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200894 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100895
896 set keymap=esperanto
897 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
898 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
899 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100900endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100901
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100902func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100903 new
904 2;'(
905 2;')
906 quit
907endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100908
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100909func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100910 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100911 new
912 source Xtest.vim
913 " Trigger calling validate_cursor()
914 diffsp Xtest.vim
915 quit!
916 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100917endfunc
918
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100919func Test_mark_from_line_zero()
920 " this was reading past the end of the first (empty) line
921 new
922 norm oxxxx
923 call assert_fails("0;'(", 'E20:')
924 bwipe!
925endfunc
926
Bram Moolenaarba47b512017-01-24 21:18:19 +0100927func Test_cmdline_complete_wildoptions()
928 help
929 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
930 let a = join(sort(split(@:)),' ')
931 set wildoptions=tagfile
932 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
933 let b = join(sort(split(@:)),' ')
934 call assert_equal(a, b)
935 bw!
936endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100937
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200938func Test_cmdline_complete_user_cmd()
939 command! -complete=color -nargs=1 Foo :
940 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
941 call assert_equal('"Foo blue', @:)
942 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
943 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000944 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
945 call assert_equal('"Foo a blue', @:)
946 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
947 call assert_equal('"Foo b\', @:)
948 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
949 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200950 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100951
952 redraw
953 call assert_equal('~', Screenline(&lines - 1))
954 command! FooOne :
955 command! FooTwo :
956
957 set nowildmenu
958 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
959 call assert_equal('"FooOne', @:)
960 call assert_equal('~', Screenline(&lines - 1))
961
962 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
963 call assert_equal('"FooTwo', @:)
964 call assert_equal('~', Screenline(&lines - 1))
965
966 delcommand FooOne
967 delcommand FooTwo
968 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200969endfunc
970
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100971func Test_complete_user_cmd()
972 command FooBar echo 'global'
973 command -buffer FooBar echo 'local'
974 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
975 call assert_equal('"FooBar', @:)
976
977 delcommand -buffer FooBar
978 delcommand FooBar
979endfunc
980
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100981func s:ScriptLocalFunction()
982 echo 'yes'
983endfunc
984
985func Test_cmdline_complete_user_func()
986 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200987 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100988 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
989 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100990
991 " g: prefix also works
992 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
993 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200994
995 " using g: prefix does not result in just "g:" matches from a lambda
996 let Fx = { a -> a }
997 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
998 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200999
1000 " existence of script-local dict function does not break user function name
1001 " completion
1002 function s:a_dict_func() dict
1003 endfunction
1004 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1005 call assert_match('"call Test_cmdline_complete_user_', @:)
1006 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001007endfunc
1008
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001009func Test_cmdline_complete_user_names()
1010 if has('unix') && executable('whoami')
1011 let whoami = systemlist('whoami')[0]
1012 let first_letter = whoami[0]
1013 if len(first_letter) > 0
1014 " Trying completion of :e ~x where x is the first letter of
1015 " the user name should complete to at least the user name.
1016 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1017 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1018 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001019 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001020 " Just in case: check that the system has an Administrator account.
1021 let names = system('net user')
1022 if names =~ 'Administrator'
1023 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001024 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001025 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001026 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001027 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001028 else
1029 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001030 endif
1031endfunc
1032
Bram Moolenaar297610b2019-12-27 17:20:55 +01001033func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001034 CheckExecutable whoami
1035 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1036 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001037endfunc
1038
Bram Moolenaar8b633132020-03-20 18:20:51 +01001039func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001040 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1041 call assert_equal(lang, v:lc_time)
1042
1043 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1044 call assert_equal(lang, v:ctype)
1045
1046 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1047 call assert_equal(lang, v:collate)
1048
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001049 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001050 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001051
1052 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001053 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001054
Bram Moolenaarec680282020-06-12 19:35:32 +02001055 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001056
Bram Moolenaarec680282020-06-12 19:35:32 +02001057 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1058 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001059
Bram Moolenaarec680282020-06-12 19:35:32 +02001060 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1061 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001062
Bram Moolenaarec680282020-06-12 19:35:32 +02001063 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1064 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001065
1066 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1067 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001068endfunc
1069
Bram Moolenaar297610b2019-12-27 17:20:55 +01001070func Test_cmdline_complete_env_variable()
1071 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001072 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1073 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001074 unlet $X_VIM_TEST_COMPLETE_ENV
1075endfunc
1076
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001077func Test_cmdline_complete_expression()
1078 let g:SomeVar = 'blah'
1079 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1080 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1081 call assert_match('"' .. cmd .. ' SomeVar', @:)
1082 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1083 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1084 endfor
1085 unlet g:SomeVar
1086endfunc
1087
Bram Moolenaar47016f52021-08-26 16:39:58 +02001088" Unique function name for completion below
1089func s:WeirdFunc()
1090 echo 'weird'
1091endfunc
1092
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001093" Test for various command-line completion
1094func Test_cmdline_complete_various()
1095 " completion for a command starting with a comment
1096 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1097 call assert_equal("\" :|\"\<C-A>", @:)
1098
1099 " completion for a range followed by a comment
1100 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1101 call assert_equal("\"1,2\"\<C-A>", @:)
1102
1103 " completion for :k command
1104 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1105 call assert_equal("\"ka\<C-A>", @:)
1106
1107 " completion for short version of the :s command
1108 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1109 call assert_equal("\"sI \<C-A>", @:)
1110
1111 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001112 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001113 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001114 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001115 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001116 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1117 call assert_equal("\"w >> Xfile1", @:)
1118 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001119
1120 " completion for :w ! and :r ! commands
1121 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1122 call assert_equal("\"w !invalid_xyz_cmd", @:)
1123 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1124 call assert_equal("\"r !invalid_xyz_cmd", @:)
1125
1126 " completion for :>> and :<< commands
1127 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1128 call assert_equal("\">>>\<C-A>", @:)
1129 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1130 call assert_equal("\"<<<\<C-A>", @:)
1131
1132 " completion for command with +cmd argument
1133 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1134 call assert_equal("\"buffer +/pat Xabc", @:)
1135 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1136 call assert_equal("\"buffer +/pat\<C-A>", @:)
1137
1138 " completion for a command with a trailing comment
1139 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1140 call assert_equal("\"ls \" comment\<C-A>", @:)
1141
1142 " completion for a command with a trailing command
1143 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1144 call assert_equal("\"ls | ls", @:)
1145
1146 " completion for a command with an CTRL-V escaped argument
1147 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1148 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1149
1150 " completion for a command that doesn't take additional arguments
1151 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1152 call assert_equal("\"all abc\<C-A>", @:)
1153
zeertzjqd3de1782022-09-01 12:58:52 +01001154 " completion for :wincmd with :horizontal modifier
1155 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1156 call assert_equal("\"horizontal wincmd", @:)
1157
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001158 " completion for a command with a command modifier
1159 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1160 call assert_equal("\"topleft new", @:)
1161
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001162 " completion for vim9 and legacy commands
1163 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1164 call assert_equal("\"vim9 call strlen(", @:)
1165 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1166 call assert_equal("\"legac call strlen(", @:)
1167
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001168 " completion for the :disassemble command
1169 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1170 call assert_equal("\"disas debug", @:)
1171 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1172 call assert_equal("\"disas profile", @:)
1173 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1174 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1175 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1176 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001177 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1178 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001179
Bram Moolenaar47016f52021-08-26 16:39:58 +02001180 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001181 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001182
naohiro onodfe04db2021-09-12 15:45:10 +02001183 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1184 call assert_match('"disas <SNR>\d\+_', @:)
1185 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1186 call assert_match('"disas debug <SNR>\d\+_', @:)
1187
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001188 " completion for the :match command
1189 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1190 call assert_equal("\"match Search /pat/\<C-A>", @:)
1191
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001192 " completion for the :doautocmd command
1193 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1194 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1195
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001196 " completion of autocmd group after comma
1197 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1198 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1199
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001200 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001201 call writefile([], 'Xvarfile1', 'D')
1202 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001203 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1204 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001205
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001206 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001207 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001208 augroup END
1209 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001210 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001211
1212 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001213 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1214 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001215 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1216 call assert_equal("\"au XTest.test", @:)
1217
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001218 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001219
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001220 " autocmd pattern completion
1221 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1222 call assert_equal("\"au BufEnter *.py\t", @:)
1223
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001224 " completion for the :unlet command
1225 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1226 call assert_equal("\"unlet one two", @:)
1227
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001228 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001229 " FIXME: what should happen on MS-Windows?
1230 if !has('win32')
1231 edit \{someFile}
1232 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1233 call assert_equal("\"buf {someFile}", @:)
1234 bwipe {someFile}
1235 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001236
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001237 " completion for the :bdelete command
1238 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1239 call assert_equal("\"bdel a b c", @:)
1240
1241 " completion for the :mapclear command
1242 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1243 call assert_equal("\"mapclear <buffer>", @:)
1244
1245 " completion for user defined commands with menu names
1246 menu Test.foo :ls<CR>
1247 com -nargs=* -complete=menu MyCmd
1248 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1249 call assert_equal('"MyCmd Test.', @:)
1250 delcom MyCmd
1251 unmenu Test
1252
1253 " completion for user defined commands with mappings
1254 mapclear
1255 map <F3> :ls<CR>
1256 com -nargs=* -complete=mapping MyCmd
1257 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001258 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001259 mapclear
1260 delcom MyCmd
1261
1262 " completion for :set path= with multiple backslashes
1263 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1264 call assert_equal('"set path=a\\\ b', @:)
1265
1266 " completion for :set dir= with a backslash
1267 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1268 call assert_equal('"set dir=a\ b', @:)
1269
1270 " completion for the :py3 commands
1271 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1272 call assert_equal('"py3 py3do py3file', @:)
1273
Bram Moolenaardf749a22021-03-28 15:29:43 +02001274 " completion for the :vim9 commands
1275 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1276 call assert_equal('"vim9cmd vim9script', @:)
1277
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001278 " redir @" is not the start of a comment. So complete after that
1279 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1280 call assert_equal('"redir @" | cwindow', @:)
1281
1282 " completion after a backtick
1283 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1284 call assert_equal('"e `a1b2c', @:)
1285
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001286 " completion for :language command with an invalid argument
1287 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1288 call assert_equal("\"language dummy \t", @:)
1289
1290 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001291 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1292 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001293
1294 " completion with ambiguous user defined commands
1295 com TCmd1 echo 'TCmd1'
1296 com TCmd2 echo 'TCmd2'
1297 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1298 call assert_equal('"TCmd ', @:)
1299 delcom TCmd1
1300 delcom TCmd2
1301
1302 " completion after a range followed by a pipe (|) character
1303 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1304 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001305
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001306 " completion after a :global command
1307 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1308 call assert_equal('"g/a/chistory', @:)
1309 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1310 call assert_equal("\"g/a\\/chist\t", @:)
1311
Bram Moolenaar9c929712020-09-07 22:05:28 +02001312 " use <Esc> as the 'wildchar' for completion
1313 set wildchar=<Esc>
1314 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1315 call assert_equal('"g/a\xb/clearjumps', @:)
1316 " pressing <esc> twice should cancel the command
1317 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1318 call assert_equal('"g/a\xb/clearjumps', @:)
1319 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001320
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001321 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001322 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001323 call writefile([], '~Xtest')
1324 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1325 call assert_equal('"e \~Xtest', @:)
1326 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001327
1328 " should be able to complete a file name that has a '*'
1329 call writefile([], 'Xx*Yy')
1330 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1331 call assert_equal('"e Xx\*Yy', @:)
1332 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001333
1334 " use a literal star
1335 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1336 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001337 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001338
1339 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1340 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001341endfunc
1342
1343" Test for 'wildignorecase'
1344func Test_cmdline_wildignorecase()
1345 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001346 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001347 set wildignorecase
1348 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1349 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001350 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001351 let g:Sline = ''
1352 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1353 call assert_equal('"e xt', @:)
1354 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001355 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001356endfunc
1357
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001358func Test_cmdline_write_alternatefile()
1359 new
1360 call setline('.', ['one', 'two'])
1361 f foo.txt
1362 new
1363 f #-A
1364 call assert_equal('foo.txt-A', expand('%'))
1365 f #<-B.txt
1366 call assert_equal('foo-B.txt', expand('%'))
1367 f %<
1368 call assert_equal('foo-B', expand('%'))
1369 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001370 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001371 bw!
1372 f foo-B.txt
1373 f %<-A
1374 call assert_equal('foo-B-A', expand('%'))
1375 bw!
1376 bw!
1377endfunc
1378
Bram Moolenaarf5724372022-09-02 19:45:15 +01001379func Test_cmdline_expand_cur_alt_file()
1380 enew
1381 file http://some.com/file.txt
1382 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1383 call assert_equal('"e http://some.com/file.txt', @:)
1384 edit another
1385 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1386 call assert_equal('"e http://some.com/file.txt', @:)
1387 bwipe
1388 bwipe http://some.com/file.txt
1389endfunc
1390
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001391" using a leading backslash here
1392set cpo+=C
1393
1394func Test_cmdline_search_range()
1395 new
1396 call setline(1, ['a', 'b', 'c', 'd'])
1397 /d
1398 1,\/s/b/B/
1399 call assert_equal('B', getline(2))
1400
1401 /a
1402 $
1403 \?,4s/c/C/
1404 call assert_equal('C', getline(3))
1405
1406 call setline(1, ['a', 'b', 'c', 'd'])
1407 %s/c/c/
1408 1,\&s/b/B/
1409 call assert_equal('B', getline(2))
1410
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001411 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001412 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001413
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001414 bwipe!
1415endfunc
1416
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001417" Test for the tick mark (') in an excmd range
1418func Test_tick_mark_in_range()
1419 " If only the tick is passed as a range and no command is specified, there
1420 " should not be an error
1421 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001422 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001423 call assert_fails("',print", 'E78:')
1424endfunc
1425
1426" Test for using a line number followed by a search pattern as range
1427func Test_lnum_and_pattern_as_range()
1428 new
1429 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1430 let @" = ''
1431 2/foo/yank
1432 call assert_equal("foo 3\n", @")
1433 call assert_equal(1, line('.'))
1434 close!
1435endfunc
1436
Bram Moolenaar65189a12017-02-06 22:22:17 +01001437" Tests for getcmdline(), getcmdpos() and getcmdtype()
1438func Check_cmdline(cmdtype)
1439 call assert_equal('MyCmd a', getcmdline())
1440 call assert_equal(8, getcmdpos())
1441 call assert_equal(a:cmdtype, getcmdtype())
1442 return ''
1443endfunc
1444
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001445set cpo&
1446
Bram Moolenaar65189a12017-02-06 22:22:17 +01001447func Test_getcmdtype()
1448 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1449
1450 let cmdtype = ''
1451 debuggreedy
1452 call feedkeys(":debug echo 'test'\<CR>", "t")
1453 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1454 call feedkeys("cont\<CR>", "xt")
1455 0debuggreedy
1456 call assert_equal('>', cmdtype)
1457
1458 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1459 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1460
1461 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001462 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001463
1464 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1465
1466 cnoremap <expr> <F6> Check_cmdline('=')
1467 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1468 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001469
1470 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001471endfunc
1472
Bram Moolenaar52604f22017-04-07 16:17:39 +02001473func Test_verbosefile()
1474 set verbosefile=Xlog
1475 echomsg 'foo'
1476 echomsg 'bar'
1477 set verbosefile=
1478 let log = readfile('Xlog')
1479 call assert_match("foo\nbar", join(log, "\n"))
1480 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001481
1482 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001483 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001484endfunc
1485
Bram Moolenaar4facea32019-10-12 20:17:40 +02001486func Test_verbose_option()
1487 CheckScreendump
1488
1489 let lines =<< trim [SCRIPT]
1490 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1491 call feedkeys("\r", 't') " for the hit-enter prompt
1492 set verbose=20
1493 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001494 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001495
1496 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001497 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001498 call term_sendkeys(buf, ":DoSomething\<CR>")
1499 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1500
1501 " clean up
1502 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001503endfunc
1504
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001505func Test_setcmdpos()
1506 func InsertTextAtPos(text, pos)
1507 call assert_equal(0, setcmdpos(a:pos))
1508 return a:text
1509 endfunc
1510
1511 " setcmdpos() with position in the middle of the command line.
1512 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1513 call assert_equal('"1ab2', @:)
1514
1515 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1516 call assert_equal('"1b2a', @:)
1517
1518 " setcmdpos() with position beyond the end of the command line.
1519 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1520 call assert_equal('"12ab', @:)
1521
1522 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001523 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001524endfunc
1525
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001526func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001527 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001528 let encoding_save = &encoding
1529
1530 for e in encodings
1531 exe 'set encoding=' . e
1532
1533 " Test overstrike in the middle of the command line.
1534 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001535 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001536
1537 " Test overstrike going beyond end of command line.
1538 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001539 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001540
1541 " Test toggling insert/overstrike a few times.
1542 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001543 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001544 endfor
1545
Bram Moolenaar30276f22019-01-24 17:59:39 +01001546 " Test overstrike with multi-byte characters.
1547 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001548 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001549
1550 let &encoding = encoding_save
1551endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001552
Bram Moolenaar52410572019-10-27 05:12:45 +01001553func Test_buffers_lastused()
1554 " check that buffers are sorted by time when wildmode has lastused
1555 call test_settime(1550020000) " middle
1556 edit bufa
1557 enew
1558 call test_settime(1550030000) " newest
1559 edit bufb
1560 enew
1561 call test_settime(1550010000) " oldest
1562 edit bufc
1563 enew
1564 call test_settime(0)
1565 enew
1566
1567 call assert_equal(['bufa', 'bufb', 'bufc'],
1568 \ getcompletion('', 'buffer'))
1569
1570 let save_wildmode = &wildmode
1571 set wildmode=full:lastused
1572
1573 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1574 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1575 call assert_equal('b bufb', X)
1576 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1577 call assert_equal('b bufa', X)
1578 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1579 call assert_equal('b bufc', X)
1580 enew
1581
1582 edit other
1583 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1584 call assert_equal('b bufb', X)
1585 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1586 call assert_equal('b bufa', X)
1587 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1588 call assert_equal('b bufc', X)
1589 enew
1590
1591 let &wildmode = save_wildmode
1592
1593 bwipeout bufa
1594 bwipeout bufb
1595 bwipeout bufc
1596endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001597
Bram Moolenaar479950f2020-01-19 15:45:17 +01001598func Test_cmdlineclear_tabenter()
1599 CheckScreendump
1600
1601 let lines =<< trim [SCRIPT]
1602 call setline(1, range(30))
1603 [SCRIPT]
1604
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001605 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001606 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001607 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001608 " in one tab make the command line higher with CTRL-W -
1609 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1610 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1611
1612 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001613endfunc
1614
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001615" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001616func Test_cmdline_expand_special()
1617 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001618 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001619 call assert_fails('e <afile>', 'E495:')
1620 call assert_fails('e <abuf>', 'E496:')
1621 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001622
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001623 call writefile([], 'Xfile.cpp', 'D')
1624 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001625 new Xfile.cpp
1626 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1627 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1628 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001629endfunc
1630
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001631" Test for backtick expression in the command line
1632func Test_cmd_backtick()
1633 %argd
1634 argadd `=['a', 'b', 'c']`
1635 call assert_equal(['a', 'b', 'c'], argv())
1636 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001637
1638 argadd `echo abc def`
1639 call assert_equal(['abc def'], argv())
1640 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001641endfunc
1642
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001643" Test for the :! command
1644func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001645 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001646
1647 let lines =<< trim [SCRIPT]
1648 " Test for no previous command
1649 call assert_fails('!!', 'E34:')
1650 set nomore
1651 " Test for cmdline expansion with :!
1652 call setline(1, 'foo!')
1653 silent !echo <cWORD> > Xfile.out
1654 call assert_equal(['foo!'], readfile('Xfile.out'))
1655 " Test for using previous command
1656 silent !echo \! !
1657 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1658 call writefile(v:errors, 'Xresult')
1659 call delete('Xfile.out')
1660 qall!
1661 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001662 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001663 if RunVim([], [], '--clean -S Xscript')
1664 call assert_equal([], readfile('Xresult'))
1665 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001666 call delete('Xresult')
1667endfunc
1668
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001669" Test error: "E135: *Filter* Autocommands must not change current buffer"
1670func Test_cmd_bang_E135()
1671 new
1672 call setline(1, ['a', 'b', 'c', 'd'])
1673 augroup test_cmd_filter_E135
1674 au!
1675 autocmd FilterReadPost * help
1676 augroup END
1677 call assert_fails('2,3!echo "x"', 'E135:')
1678
1679 augroup test_cmd_filter_E135
1680 au!
1681 augroup END
1682 %bwipe!
1683endfunc
1684
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001685func Test_cmd_bang_args()
1686 new
1687 :.!
1688 call assert_equal(0, v:shell_error)
1689
1690 " Note that below there is one space char after the '!'. This caused a
1691 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1692 :.!
1693 call assert_equal(0, v:shell_error)
1694 bwipe!
1695
1696 CheckUnix
1697 :.!pwd
1698 call assert_equal(0, v:shell_error)
1699 :.! pwd
1700 call assert_equal(0, v:shell_error)
1701
1702 " Note there is one space after 'pwd'.
1703 :.! pwd
1704 call assert_equal(0, v:shell_error)
1705
1706 " Note there are two spaces after 'pwd'.
1707 :.! pwd
1708 call assert_equal(0, v:shell_error)
1709 :.!ls ~
1710 call assert_equal(0, v:shell_error)
1711
1712 " Note there is one space char after '~'.
1713 :.!ls ~
1714 call assert_equal(0, v:shell_error)
1715
1716 " Note there are two spaces after '~'.
1717 :.!ls ~
1718 call assert_equal(0, v:shell_error)
1719
1720 :.!echo "foo"
1721 call assert_equal(getline('.'), "foo")
1722 :.!echo "foo "
1723 call assert_equal(getline('.'), "foo ")
1724 :.!echo " foo "
1725 call assert_equal(getline('.'), " foo ")
1726 :.!echo " foo "
1727 call assert_equal(getline('.'), " foo ")
1728
1729 %bwipe!
1730endfunc
1731
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001732" Test for using ~ for home directory in cmdline completion matches
1733func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001734 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001735 call writefile([], 'Xexpdir/Xfile1')
1736 call writefile([], 'Xexpdir/Xfile2')
1737 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001738 let save_HOME = $HOME
1739 let $HOME = getcwd()
1740 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1741 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1742 let $HOME = save_HOME
1743 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001744endfunc
1745
Bram Moolenaar578fe942020-02-27 21:32:51 +01001746" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1747" or insert mode (when 'insertmode' is set)
1748func Test_cmdline_ctrl_g()
1749 new
1750 call setline(1, 'abc')
1751 call cursor(1, 3)
1752 " If command line is entered from insert mode, using C-\ C-G should back to
1753 " insert mode
1754 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1755 call assert_equal('abxyc', getline(1))
1756 call assert_equal(4, col('.'))
1757
1758 " If command line is entered in 'insertmode', using C-\ C-G should back to
1759 " 'insertmode'
1760 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1761 call assert_equal('ab12xyc', getline(1))
1762 close!
1763endfunc
1764
Bram Moolenaar578fe942020-02-27 21:32:51 +01001765" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001766func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001767 func T(a, c, p)
1768 return "oneA\noneB\noneC"
1769 endfunc
1770 command -nargs=1 -complete=custom,T MyCmd
1771
Bram Moolenaar578fe942020-02-27 21:32:51 +01001772 set nowildmenu
1773 set wildmode=full,list
1774 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001775 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001776 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001777 call assert_equal('"MyCmd oneA', @:)
1778
1779 set wildmode=longest,full
1780 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1781 call assert_equal('"MyCmd one', @:)
1782 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1783 call assert_equal('"MyCmd oneC', @:)
1784
1785 set wildmode=longest
1786 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1787 call assert_equal('"MyCmd one', @:)
1788
1789 set wildmode=list:longest
1790 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001791 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001792 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001793 call assert_equal('"MyCmd one', @:)
1794
1795 set wildmode=""
1796 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1797 call assert_equal('"MyCmd oneA', @:)
1798
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001799 " Test for wildmode=longest with 'fileignorecase' set
1800 set wildmode=longest
1801 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001802 argadd AAA AAAA AAAAA
1803 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1804 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001805 set fileignorecase&
1806
1807 " Test for listing files with wildmode=list
1808 set wildmode=list
1809 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001810 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001811 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001812 call assert_equal('"b A', @:)
1813
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001814 " when using longest completion match, matches shorter than the argument
1815 " should be ignored (happens with :help)
1816 set wildmode=longest,full
1817 set wildmenu
1818 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1819 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001820 " non existing file
1821 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1822 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001823 set wildmenu&
1824
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001825 " Test for longest file name completion with 'fileignorecase'
1826 " On MS-Windows, file names are case insensitive.
1827 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001828 call writefile([], 'XTESTfoo', 'D')
1829 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001830 set nofileignorecase
1831 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1832 call assert_equal('"e XTESTfoo', @:)
1833 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1834 call assert_equal('"e Xtestbar', @:)
1835 set fileignorecase
1836 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1837 call assert_equal('"e Xtest', @:)
1838 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1839 call assert_equal('"e Xtest', @:)
1840 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001841 endif
1842
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001843 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001844 delcommand MyCmd
1845 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001846 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001847 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001848endfunc
1849
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001850func Test_wildmode()
1851 " Test with utf-8 encoding
1852 call Wildmode_tests()
1853
1854 " Test with latin1 encoding
1855 let save_encoding = &encoding
1856 set encoding=latin1
1857 call Wildmode_tests()
1858 let &encoding = save_encoding
1859endfunc
1860
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001861func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001862 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001863 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001864 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001865 let lines =<< trim END
1866 func vim8#Complete(a, c, p)
1867 return "oneA\noneB\noneC"
1868 endfunc
1869 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001870 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001871
1872 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1873 set nowildmenu
1874 set wildmode=full,list
1875 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1876 call assert_equal('"MyCmd oneA oneB oneC', @:)
1877
1878 let &rtp = save_rtp
1879 set wildmode& wildmenu&
1880 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001881endfunc
1882
Bram Moolenaar578fe942020-02-27 21:32:51 +01001883" Test for interrupting the command-line completion
1884func Test_interrupt_compl()
1885 func F(lead, cmdl, p)
1886 if a:lead =~ 'tw'
1887 call interrupt()
1888 return
1889 endif
1890 return "one\ntwo\nthree"
1891 endfunc
1892 command -nargs=1 -complete=custom,F Tcmd
1893
1894 set nowildmenu
1895 set wildmode=full
1896 let interrupted = 0
1897 try
1898 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1899 catch /^Vim:Interrupt$/
1900 let interrupted = 1
1901 endtry
1902 call assert_equal(1, interrupted)
1903
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001904 let interrupted = 0
1905 try
1906 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1907 catch /^Vim:Interrupt$/
1908 let interrupted = 1
1909 endtry
1910 call assert_equal(1, interrupted)
1911
Bram Moolenaar578fe942020-02-27 21:32:51 +01001912 delcommand Tcmd
1913 delfunc F
1914 set wildmode&
1915endfunc
1916
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001917" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001918func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001919 let str = ":one two\<C-U>"
1920 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001921 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001922 let str ..= "\<Left>five\<Right>"
1923 let str ..= "\<Home>two "
1924 let str ..= "\<C-Left>one "
1925 let str ..= "\<C-Right> three"
1926 let str ..= "\<End>\<S-Left>four "
1927 let str ..= "\<S-Right> six"
1928 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1929 call feedkeys(str, 'xt')
1930 call assert_equal("\"one two three four five six seven", @:)
1931endfunc
1932
1933" Test for moving the cursor on the / command line in 'rightleft' mode
1934func Test_cmdline_edit_rightleft()
1935 CheckFeature rightleft
1936 set rightleft
1937 set rightleftcmd=search
1938 let str = "/one two\<C-U>"
1939 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001940 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001941 let str ..= "\<Right>five\<Left>"
1942 let str ..= "\<Home>two "
1943 let str ..= "\<C-Right>one "
1944 let str ..= "\<C-Left> three"
1945 let str ..= "\<End>\<S-Right>four "
1946 let str ..= "\<S-Left> six"
1947 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1948 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1949 call assert_equal("\"one two three four five six seven", @/)
1950 set rightleftcmd&
1951 set rightleft&
1952endfunc
1953
1954" Test for using <C-\>e in the command line to evaluate an expression
1955func Test_cmdline_expr()
1956 " Evaluate an expression from the beginning of a command line
1957 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1958 call assert_equal('"hello', @:)
1959
1960 " Use an invalid expression for <C-\>e
1961 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1962
1963 " Insert literal <CTRL-\> in the command line
1964 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1965 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001966endfunc
1967
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001968" This was making the insert position negative
1969func Test_cmdline_expr_register()
1970 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1971endfunc
1972
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001973" Test for 'imcmdline' and 'imsearch'
1974" This test doesn't actually test the input method functionality.
1975func Test_cmdline_inputmethod()
1976 new
1977 call setline(1, ['', 'abc', ''])
1978 set imcmdline
1979
1980 call feedkeys(":\"abc\<CR>", 'xt')
1981 call assert_equal("\"abc", @:)
1982 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1983 call assert_equal("\"abc", @:)
1984 call feedkeys("/abc\<CR>", 'xt')
1985 call assert_equal([2, 1], [line('.'), col('.')])
1986 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1987 call assert_equal([2, 1], [line('.'), col('.')])
1988
1989 set imsearch=2
1990 call cursor(1, 1)
1991 call feedkeys("/abc\<CR>", 'xt')
1992 call assert_equal([2, 1], [line('.'), col('.')])
1993 call cursor(1, 1)
1994 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1995 call assert_equal([2, 1], [line('.'), col('.')])
1996 set imdisable
1997 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1998 call assert_equal([2, 1], [line('.'), col('.')])
1999 set imdisable&
2000 set imsearch&
2001
2002 set imcmdline&
2003 %bwipe!
2004endfunc
2005
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002006" Test for using CTRL-_ in the command line with 'allowrevins'
2007func Test_cmdline_revins()
2008 CheckNotMSWindows
2009 CheckFeature rightleft
2010 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2011 call assert_equal("\"abc\<c-_>", @:)
2012 set allowrevins
2013 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2014 call assert_equal('"abcñèæ', @:)
2015 set allowrevins&
2016endfunc
2017
2018" Test for typing UTF-8 composing characters in the command line
2019func Test_cmdline_composing_chars()
2020 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2021 call assert_equal('"ゔ', @:)
2022endfunc
2023
Bram Moolenaar0e717042020-04-27 19:29:01 +02002024" test that ";" works to find a match at the start of the first line
2025func Test_zero_line_search()
2026 new
2027 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2028 call cursor(1,1)
2029 0;/pattern/d
2030 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2031 q!
2032endfunc
2033
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002034func Test_read_shellcmd()
2035 CheckUnix
2036 if executable('ls')
2037 " There should be ls in the $PATH
2038 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2039 call assert_match('^"r! .*\<ls\>', @:)
2040 endif
2041
2042 if executable('rm')
2043 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2044 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2045 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002046
2047 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2048 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2049 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002050 endif
2051endfunc
2052
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002053" Test for going up and down the directory tree using 'wildmenu'
2054func Test_wildmenu_dirstack()
2055 CheckUnix
2056 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002057 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002058 call writefile([], 'Xwildmenu/file1_1.txt')
2059 call writefile([], 'Xwildmenu/file1_2.txt')
2060 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2061 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2062 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2063 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2064 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2065 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002066 set wildmenu
2067
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002068 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002069 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002070 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002071 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002072 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002073 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002074 call assert_equal('"e ../../dir3/', @:)
2075 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2076 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002077 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002078 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002079 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002080 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002081 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002082 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2083 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002084
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002085 set wildmenu&
2086endfunc
2087
obcat71c6f7a2021-05-13 20:23:10 +02002088" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002089" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2090" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002091func Test_recalling_cmdline()
2092 CheckFeature cmdline_hist
2093
2094 let g:cmdlines = []
2095 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2096
2097 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002098 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2099 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2100 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2101 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002102 "\ TODO: {'name': 'debug', ...}
2103 \]
2104 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002105 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2106 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2107 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2108 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2109 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002110 \]
2111 let prefix = 'vi'
2112 for h in histories
2113 call histadd(h.name, 'vim')
2114 call histadd(h.name, 'virtue')
2115 call histadd(h.name, 'Virgo')
2116 call histadd(h.name, 'vogue')
2117 call histadd(h.name, 'emacs')
2118 for k in keypairs
2119 let g:cmdlines = []
2120 let keyseqs = h.enter
2121 \ .. prefix
2122 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2123 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2124 \ .. h.exit
2125 call feedkeys(keyseqs, 'xt')
2126 call histdel(h.name, -1) " delete the history added by feedkeys above
2127 let expect = k.prefixmatch
2128 \ ? ['virtue', 'vim', 'virtue', prefix]
2129 \ : ['emacs', 'vogue', 'emacs', prefix]
2130 call assert_equal(expect, g:cmdlines)
2131 endfor
2132 endfor
2133
2134 unlet g:cmdlines
2135 cunmap <Plug>(save-cmdline)
2136endfunc
2137
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002138func Test_cmd_map_cmdlineChanged()
2139 let g:log = []
2140 cnoremap <F1> l<Cmd><CR>s
2141 augroup test
2142 autocmd!
2143 autocmd CmdlineChanged : let g:log += [getcmdline()]
2144 augroup END
2145
2146 call feedkeys(":\<F1>\<CR>", 'xt')
2147 call assert_equal(['l', 'ls'], g:log)
2148
Bram Moolenaar796139a2021-05-18 21:38:45 +02002149 let @b = 'b'
2150 cnoremap <F1> a<C-R>b
2151 let g:log = []
2152 call feedkeys(":\<F1>\<CR>", 'xt')
2153 call assert_equal(['a', 'ab'], g:log)
2154
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002155 unlet g:log
2156 cunmap <F1>
2157 augroup test
2158 autocmd!
2159 augroup END
2160endfunc
2161
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002162" Test for the 'suffixes' option
2163func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002164 call writefile([], 'Xsuffile', 'D')
2165 call writefile([], 'Xsuffile.c', 'D')
2166 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002167 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002168 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2169 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2170 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2171 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002172 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002173 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2174 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2175 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2176 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002177 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002178 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2179 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2180 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2181 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002182 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002183 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002184 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2185 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002186endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002187
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002188" Test for using a popup menu for the command line completion matches
2189" (wildoptions=pum)
2190func Test_wildmenu_pum()
2191 CheckRunVimInTerminal
2192
2193 let commands =<< trim [CODE]
2194 set wildmenu
2195 set wildoptions=pum
2196 set shm+=I
2197 set noruler
2198 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002199
2200 func CmdCompl(a, b, c)
2201 return repeat(['aaaa'], 120)
2202 endfunc
2203 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002204
2205 func MyStatusLine() abort
2206 return 'status'
2207 endfunc
2208 func SetupStatusline()
2209 set statusline=%!MyStatusLine()
2210 set laststatus=2
2211 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002212
2213 func MyTabLine()
2214 return 'my tab line'
2215 endfunc
2216 func SetupTabline()
2217 set statusline=
2218 set tabline=%!MyTabLine()
2219 set showtabline=2
2220 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002221
2222 func DoFeedKeys()
2223 let &wildcharm = char2nr("\t")
2224 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2225 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002226 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002227 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002228
2229 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2230
2231 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002232 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2233
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002234 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002235 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002236 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2237
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002238 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002239 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002240 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2241
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002242 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002243 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002244 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2245
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002246 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002247 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002248 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2249
2250 " pressing <C-E> should end completion and go back to the original match
2251 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002252 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2253
2254 " pressing <C-Y> should select the current match and end completion
2255 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002256 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2257
2258 " With 'wildmode' set to 'longest,full', completing a match should display
2259 " the longest match, the wildmenu should not be displayed.
2260 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2261 call TermWait(buf)
2262 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002263 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2264
2265 " pressing <Tab> should display the wildmenu
2266 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002267 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2268
2269 " pressing <Tab> second time should select the next entry in the menu
2270 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002271 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2272
2273 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002274 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002275 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002276 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2277
2278 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002279 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2280
2281 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002282 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2283
2284 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002285 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002286 call writefile([], 'Xnamedir/XfileA')
2287 call writefile([], 'Xnamedir/XdirA/XfileB')
2288 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002289
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002290 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002291 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2292
2293 " Pressing <Right> on a directory name should go into that directory
2294 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002295 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2296
2297 " Pressing <Left> on a directory name should go to the parent directory
2298 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002299 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2300
2301 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002302 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002303 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002304 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2305
2306 " Pressing <C-D> when the popup menu is displayed should remove the popup
2307 " menu
2308 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002309 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2310
2311 " Pressing <S-Tab> should open the popup menu with the last entry selected
2312 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002313 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2314
2315 " Pressing <Esc> should close the popup menu and cancel the cmd line
2316 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002317 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2318
2319 " Typing a character when the popup is open, should close the popup
2320 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002321 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2322
2323 " When the popup is open, entering the cmdline window should close the popup
2324 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002325 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2326 call term_sendkeys(buf, ":q\<CR>")
2327
2328 " After the last popup menu item, <C-N> should show the original string
2329 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002330 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2331
2332 " Use the popup menu for the command name
2333 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002334 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2335
2336 " Pressing the left arrow should remove the popup menu
2337 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002338 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2339
2340 " Pressing <BS> should remove the popup menu and erase the last character
2341 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002342 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2343
2344 " Pressing <C-W> should remove the popup menu and erase the previous word
2345 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002346 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2347
2348 " Pressing <C-U> should remove the popup menu and erase the entire line
2349 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002350 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2351
2352 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2353 " the cmdline from history
2354 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002355 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2356
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002357 " Check "list" still works
2358 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2359 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002360 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2361 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002362 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2363
rbtnn68cc2b82022-02-09 11:55:47 +00002364 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002365 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002366 call writefile([], 'Xnamedir/あいう/abc')
2367 call writefile([], 'Xnamedir/あいう/xyz')
2368 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002369
2370 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002371 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002372 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2373
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002374 " Pressing <C-A> when the popup menu is displayed should list all the
2375 " matches and pressing a key after that should remove the popup menu
2376 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2377 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2378 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2379
2380 " Pressing <C-A> when the popup menu is displayed should list all the
2381 " matches and pressing <Left> after that should move the cursor
2382 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2383 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2384 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2385
2386 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2387 " should be displayed correctly on the screen.
2388 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2389 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2390
2391 " After using <C-A> to expand all the filename matches, pressing <Up>
2392 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002393 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002394 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2395 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2396 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2397
2398 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2399 " crash Vim
2400 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2401 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2402
Bram Moolenaar414acd32022-02-10 21:09:45 +00002403 " After removing the pum the command line is redrawn
2404 call term_sendkeys(buf, ":edit foo\<CR>")
2405 call term_sendkeys(buf, ":edit bar\<CR>")
2406 call term_sendkeys(buf, ":ls\<CR>")
2407 call term_sendkeys(buf, ":com\<Tab> ")
2408 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002409 call term_sendkeys(buf, "\<C-U>\<CR>")
2410
2411 " Esc still works to abort the command when 'statusline' is set
2412 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2413 call term_sendkeys(buf, ":si\<Tab>")
2414 call term_sendkeys(buf, "\<Esc>")
2415 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002416
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002417 " Esc still works to abort the command when 'tabline' is set
2418 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2419 call term_sendkeys(buf, ":si\<Tab>")
2420 call term_sendkeys(buf, "\<Esc>")
2421 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2422
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002423 " popup is cleared also when 'lazyredraw' is set
2424 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2425 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2426 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2427 call term_sendkeys(buf, "\<Esc>")
2428
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002429 " Pressing <PageDown> should scroll the menu downward
2430 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2431 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2432 call term_sendkeys(buf, "\<PageDown>")
2433 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2434 call term_sendkeys(buf, "\<PageDown>")
2435 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2436 call term_sendkeys(buf, "\<PageDown>")
2437 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2438 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2439 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2440
2441 " Pressing <PageUp> should scroll the menu upward
2442 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2443 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2444 call term_sendkeys(buf, "\<PageUp>")
2445 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2446 call term_sendkeys(buf, "\<PageUp>")
2447 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2448 call term_sendkeys(buf, "\<PageUp>")
2449 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2450
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002451 call term_sendkeys(buf, "\<C-U>\<CR>")
2452 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002453endfunc
2454
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002455" Test for wildmenumode() with the cmdline popup menu
2456func Test_wildmenumode_with_pum()
2457 set wildmenu
2458 set wildoptions=pum
2459 cnoremap <expr> <F2> wildmenumode()
2460 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2461 call assert_equal('"sign define10', @:)
2462 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2463 call assert_equal('"sign define jump list place undefine unplace0', @:)
2464 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2465 call assert_equal('"sign 0', @:)
2466 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2467 call assert_equal('"sign define0', @:)
2468 set nowildmenu wildoptions&
2469 cunmap <F2>
2470endfunc
2471
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002472func Test_wildmenu_with_pum_foldexpr()
2473 CheckRunVimInTerminal
2474
2475 let lines =<< trim END
2476 call setline(1, ['folded one', 'folded two', 'some more text'])
2477 func MyFoldText()
2478 return 'foo'
2479 endfunc
2480 set foldtext=MyFoldText() wildoptions=pum
2481 normal ggzfj
2482 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002483 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002484 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2485 call term_sendkeys(buf, ":set\<Tab>")
2486 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2487
2488 call term_sendkeys(buf, "\<Esc>")
2489 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2490
2491 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002492endfunc
2493
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002494" Test for opening the cmdline completion popup menu from the terminal window.
2495" The popup menu should be positioned correctly over the status line of the
2496" bottom-most window.
2497func Test_wildmenu_pum_from_terminal()
2498 CheckRunVimInTerminal
2499 let python = PythonProg()
2500 call CheckPython(python)
2501
2502 %bw!
2503 let cmds = ['set wildmenu wildoptions=pum']
2504 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2505 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002506 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002507 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2508 call term_sendkeys(buf, "\r\r\r")
2509 call term_wait(buf)
2510 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2511 call term_wait(buf)
2512 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2513 call term_wait(buf)
2514 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002515endfunc
2516
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002517func Test_wildmenu_pum_clear_entries()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002518 CheckRunVimInTerminal
2519
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002520 " This was using freed memory. Run in a terminal to get the pum to update.
2521 let lines =<< trim END
2522 set wildoptions=pum
2523 set wildchar=<C-E>
2524 END
2525 call writefile(lines, 'XwildmenuTest', 'D')
2526 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2527
2528 call term_sendkeys(buf, ":\<C-E>\<C-E>")
2529 call VerifyScreenDump(buf, 'Test_wildmenu_pum_clear_entries_1', {})
2530
2531 set wildoptions& wildchar&
2532endfunc
2533
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002534" Test for completion after a :substitute command followed by a pipe (|)
2535" character
2536func Test_cmdline_complete_substitute()
2537 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2538 call assert_equal("\"s | \t", @:)
2539 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2540 call assert_equal("\"s/ | \t", @:)
2541 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2542 call assert_equal("\"s/one | \t", @:)
2543 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2544 call assert_equal("\"s/one/ | \t", @:)
2545 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2546 call assert_equal("\"s/one/two | \t", @:)
2547 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2548 call assert_equal('"s/one/two/ | chistory', @:)
2549 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2550 call assert_equal("\"s/one/two/g \t", @:)
2551 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2552 call assert_equal("\"s/one/two/g | chistory", @:)
2553 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2554 call assert_equal("\"s/one/t\\/ | \t", @:)
2555 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2556 call assert_equal('"s/one/t"o/ | chistory', @:)
2557 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2558 call assert_equal('"s/one/t|o/ | chistory', @:)
2559 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2560 call assert_equal("\"&\t", @:)
2561endfunc
2562
2563" Test for the :dlist command completion
2564func Test_cmdline_complete_dlist()
2565 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2566 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2567 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2568 call assert_equal("\"dlist 10 /pat/ \t", @:)
2569 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2570 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2571 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2572 call assert_equal("\"dlist 10 /pat\\\t", @:)
2573 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2574 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2575endfunc
2576
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002577" argument list (only for :argdel) fuzzy completion
2578func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002579 argadd change.py count.py charge.py
2580 set wildoptions&
2581 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2582 call assert_equal('"argdel cge', @:)
2583 set wildoptions=fuzzy
2584 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2585 call assert_equal('"argdel change.py charge.py', @:)
2586 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002587 set wildoptions&
2588endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002589
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002590" autocmd group name fuzzy completion
2591func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002592 set wildoptions&
2593 augroup MyFuzzyGroup
2594 augroup END
2595 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2596 call assert_equal('"augroup mfg', @:)
2597 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2598 call assert_equal('"augroup MyFuzzyGroup', @:)
2599 set wildoptions=fuzzy
2600 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2601 call assert_equal('"augroup MyFuzzyGroup', @:)
2602 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2603 call assert_equal('"augroup My*p', @:)
2604 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002605 set wildoptions&
2606endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002607
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002608" buffer name fuzzy completion
2609func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002610 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002611 " Use a long name to reduce the risk of matching a random directory name
2612 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002613 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002614 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2615 call assert_equal('"b SRFWL', @:)
2616 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2617 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002618 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002619 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2620 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2621 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2622 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002623 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002624 set wildoptions&
2625endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002626
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002627" buffer name (full path) fuzzy completion
2628func Test_fuzzy_completion_bufname_fullpath()
2629 CheckUnix
2630 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002631 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002632 edit Xcmd/Xstate/Xfile.js
2633 cd Xcmd/Xstate
2634 enew
2635 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2636 call assert_equal('"b CmdStateFile', @:)
2637 set wildoptions=fuzzy
2638 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2639 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2640 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002641 set wildoptions&
2642endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002643
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002644" :behave suboptions fuzzy completion
2645func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002646 set wildoptions&
2647 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2648 call assert_equal('"behave xm', @:)
2649 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2650 call assert_equal('"behave xterm', @:)
2651 set wildoptions=fuzzy
2652 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2653 call assert_equal('"behave xterm', @:)
2654 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2655 call assert_equal('"behave xt*m', @:)
2656 let g:Sline = ''
2657 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2658 call assert_equal('mswin', g:Sline)
2659 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002660 set wildoptions&
2661endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002662
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002663" " colorscheme name fuzzy completion - NOT supported
2664" func Test_fuzzy_completion_colorscheme()
2665" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002666
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002667" built-in command name fuzzy completion
2668func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002669 set wildoptions&
2670 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2671 call assert_equal('"sbwin', @:)
2672 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2673 call assert_equal('"sbrewind', @:)
2674 set wildoptions=fuzzy
2675 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2676 call assert_equal('"sbrewind', @:)
2677 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2678 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002679 set wildoptions&
2680endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002681
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002682" " compiler name fuzzy completion - NOT supported
2683" func Test_fuzzy_completion_compiler()
2684" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002685
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002686" :cscope suboptions fuzzy completion
2687func Test_fuzzy_completion_cscope()
2688 CheckFeature cscope
2689 set wildoptions&
2690 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2691 call assert_equal('"cscope ret', @:)
2692 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2693 call assert_equal('"cscope reset', @:)
2694 set wildoptions=fuzzy
2695 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2696 call assert_equal('"cscope reset', @:)
2697 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2698 call assert_equal('"cscope re*t', @:)
2699 set wildoptions&
2700endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002701
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002702" :diffget/:diffput buffer name fuzzy completion
2703func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002704 new SomeBuffer
2705 diffthis
2706 new OtherBuffer
2707 diffthis
2708 set wildoptions&
2709 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2710 call assert_equal('"diffget sbuf', @:)
2711 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2712 call assert_equal('"diffput sbuf', @:)
2713 set wildoptions=fuzzy
2714 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2715 call assert_equal('"diffget SomeBuffer', @:)
2716 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2717 call assert_equal('"diffput SomeBuffer', @:)
2718 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002719 set wildoptions&
2720endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002721
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002722" " directory name fuzzy completion - NOT supported
2723" func Test_fuzzy_completion_dirname()
2724" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002725
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002726" environment variable name fuzzy completion
2727func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002728 set wildoptions&
2729 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2730 call assert_equal('"echo $VUT', @:)
2731 set wildoptions=fuzzy
2732 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2733 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002734 set wildoptions&
2735endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002736
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002737" autocmd event fuzzy completion
2738func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002739 set wildoptions&
2740 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2741 call assert_equal('"autocmd BWout', @:)
2742 set wildoptions=fuzzy
2743 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2744 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002745 set wildoptions&
2746endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002747
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002748" vim expression fuzzy completion
2749func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002750 let g:PerPlaceCount = 10
2751 set wildoptions&
2752 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2753 call assert_equal('"let c = ppc', @:)
2754 set wildoptions=fuzzy
2755 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2756 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002757 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002758endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002759
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002760" " file name fuzzy completion - NOT supported
2761" func Test_fuzzy_completion_filename()
2762" endfunc
2763
2764" " files in path fuzzy completion - NOT supported
2765" func Test_fuzzy_completion_filesinpath()
2766" endfunc
2767
2768" " filetype name fuzzy completion - NOT supported
2769" func Test_fuzzy_completion_filetype()
2770" endfunc
2771
2772" user defined function name completion
2773func Test_fuzzy_completion_userdefined_func()
2774 set wildoptions&
2775 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2776 call assert_equal('"call Test_f_u_f', @:)
2777 set wildoptions=fuzzy
2778 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2779 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2780 set wildoptions&
2781endfunc
2782
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002783" <SNR> functions should be sorted to the end
2784func Test_fuzzy_completion_userdefined_snr_func()
2785 func s:Sendmail()
2786 endfunc
2787 func SendSomemail()
2788 endfunc
2789 func S1e2n3dmail()
2790 endfunc
2791 set wildoptions=fuzzy
2792 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002793 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002794 set wildoptions&
2795 delfunc s:Sendmail
2796 delfunc SendSomemail
2797 delfunc S1e2n3dmail
2798endfunc
2799
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002800" user defined command name completion
2801func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002802 set wildoptions&
2803 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2804 call assert_equal('"MsFeat', @:)
2805 set wildoptions=fuzzy
2806 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2807 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002808 set wildoptions&
2809endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002810
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002811" " :help tag fuzzy completion - NOT supported
2812" func Test_fuzzy_completion_helptag()
2813" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002814
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002815" highlight group name fuzzy completion
2816func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002817 set wildoptions&
2818 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2819 call assert_equal('"highlight SKey', @:)
2820 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2821 call assert_equal('"highlight SpecialKey', @:)
2822 set wildoptions=fuzzy
2823 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2824 call assert_equal('"highlight SpecialKey', @:)
2825 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2826 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002827 set wildoptions&
2828endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002829
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002830" :history suboptions fuzzy completion
2831func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002832 set wildoptions&
2833 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2834 call assert_equal('"history dg', @:)
2835 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2836 call assert_equal('"history search', @:)
2837 set wildoptions=fuzzy
2838 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2839 call assert_equal('"history debug', @:)
2840 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2841 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002842 set wildoptions&
2843endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002844
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002845" :language locale name fuzzy completion
2846func Test_fuzzy_completion_lang()
2847 CheckUnix
2848 set wildoptions&
2849 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2850 call assert_equal('"lang psx', @:)
2851 set wildoptions=fuzzy
2852 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2853 call assert_equal('"lang POSIX', @:)
2854 set wildoptions&
2855endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002856
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002857" :mapclear buffer argument fuzzy completion
2858func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002859 set wildoptions&
2860 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2861 call assert_equal('"mapclear buf', @:)
2862 set wildoptions=fuzzy
2863 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2864 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002865 set wildoptions&
2866endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002867
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002868" map name fuzzy completion
2869func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002870 " test regex completion works
2871 set wildoptions=fuzzy
2872 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2873 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002874 nmap <plug>MyLongMap :p<CR>
2875 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2876 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2877 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2878 call assert_equal("\"nmap MLM \t", @:)
2879 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2880 call assert_equal("\"nmap <F2> one two \t", @:)
2881 " duplicate entries should be removed
2882 vmap <plug>MyLongMap :<C-U>#<CR>
2883 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2884 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2885 nunmap <plug>MyLongMap
2886 vunmap <plug>MyLongMap
2887 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2888 call assert_equal("\"nmap ABC\t", @:)
2889 " results should be sorted by best match
2890 nmap <Plug>format :
2891 nmap <Plug>goformat :
2892 nmap <Plug>TestFOrmat :
2893 nmap <Plug>fendoff :
2894 nmap <Plug>state :
2895 nmap <Plug>FendingOff :
2896 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2897 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2898 nunmap <Plug>format
2899 nunmap <Plug>goformat
2900 nunmap <Plug>TestFOrmat
2901 nunmap <Plug>fendoff
2902 nunmap <Plug>state
2903 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002904 set wildoptions&
2905endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002906
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002907" abbreviation fuzzy completion
2908func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002909 set wildoptions=fuzzy
2910 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2911 call assert_equal("\"iabbr <nowait>", @:)
2912 iabbr WaitForCompletion WFC
2913 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2914 call assert_equal("\"iabbr WaitForCompletion", @:)
2915 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2916 call assert_equal("\"iabbr a1z\t", @:)
2917 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002918 set wildoptions&
2919endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002920
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002921" menu name fuzzy completion
2922func Test_fuzzy_completion_menu()
2923 CheckGui
2924 set wildoptions&
2925 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2926 call assert_equal('"menu pup', @:)
2927 set wildoptions=fuzzy
2928 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2929 call assert_equal('"menu PopUp.', @:)
2930 set wildoptions&
2931endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002932
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002933" :messages suboptions fuzzy completion
2934func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002935 set wildoptions&
2936 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2937 call assert_equal('"messages clr', @:)
2938 set wildoptions=fuzzy
2939 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2940 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002941 set wildoptions&
2942endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002943
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002944" :set option name fuzzy completion
2945func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002946 set wildoptions&
2947 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2948 call assert_equal('"set brkopt', @:)
2949 set wildoptions=fuzzy
2950 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2951 call assert_equal('"set breakindentopt', @:)
2952 set wildoptions&
2953 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2954 call assert_equal('"set fixendofline', @:)
2955 set wildoptions=fuzzy
2956 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2957 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002958 set wildoptions&
2959endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002960
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002961" :set <term_option>
2962func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002963 set wildoptions&
2964 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2965 call assert_equal('"set t_EC', @:)
2966 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2967 call assert_equal('"set <t_EC>', @:)
2968 set wildoptions=fuzzy
2969 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2970 call assert_equal('"set t_EC', @:)
2971 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2972 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002973 set wildoptions&
2974endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002975
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002976" " :packadd directory name fuzzy completion - NOT supported
2977" func Test_fuzzy_completion_packadd()
2978" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002979
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002980" " shell command name fuzzy completion - NOT supported
2981" func Test_fuzzy_completion_shellcmd()
2982" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002983
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002984" :sign suboptions fuzzy completion
2985func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002986 set wildoptions&
2987 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2988 call assert_equal('"sign ufe', @:)
2989 set wildoptions=fuzzy
2990 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2991 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002992 set wildoptions&
2993endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002994
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002995" :syntax suboptions fuzzy completion
2996func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002997 set wildoptions&
2998 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2999 call assert_equal('"syntax kwd', @:)
3000 set wildoptions=fuzzy
3001 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3002 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003003 set wildoptions&
3004endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003005
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003006" syntax group name fuzzy completion
3007func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003008 set wildoptions&
3009 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3010 call assert_equal('"syntax list mpar', @:)
3011 set wildoptions=fuzzy
3012 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3013 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003014 set wildoptions&
3015endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003016
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003017" :syntime suboptions fuzzy completion
3018func Test_fuzzy_completion_syntime()
3019 CheckFeature profile
3020 set wildoptions&
3021 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3022 call assert_equal('"syntime clr', @:)
3023 set wildoptions=fuzzy
3024 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3025 call assert_equal('"syntime clear', @:)
3026 set wildoptions&
3027endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003028
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003029" " tag name fuzzy completion - NOT supported
3030" func Test_fuzzy_completion_tagname()
3031" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003032
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003033" " tag name and file fuzzy completion - NOT supported
3034" func Test_fuzzy_completion_tagfile()
3035" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003036
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003037" " user names fuzzy completion - how to test this functionality?
3038" func Test_fuzzy_completion_username()
3039" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003040
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003041" user defined variable name fuzzy completion
3042func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003043 let g:SomeVariable=10
3044 set wildoptions&
3045 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3046 call assert_equal('"let SVar', @:)
3047 set wildoptions=fuzzy
3048 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3049 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003050 set wildoptions&
3051endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003052
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003053" Test for sorting the results by the best match
3054func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003055 %bw!
3056 command T123format :
3057 command T123goformat :
3058 command T123TestFOrmat :
3059 command T123fendoff :
3060 command T123state :
3061 command T123FendingOff :
3062 set wildoptions=fuzzy
3063 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3064 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3065 delcommand T123format
3066 delcommand T123goformat
3067 delcommand T123TestFOrmat
3068 delcommand T123fendoff
3069 delcommand T123state
3070 delcommand T123FendingOff
3071 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003072 set wildoptions&
3073endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003074
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003075" Test for fuzzy completion of a command with lower case letters and a number
3076func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003077 command Foo2Bar :
3078 set wildoptions=fuzzy
3079 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3080 call assert_equal('"Foo2Bar', @:)
3081 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3082 call assert_equal('"Foo2Bar', @:)
3083 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3084 call assert_equal('"Foo2Bar', @:)
3085 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003086 set wildoptions&
3087endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003088
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003089" Test for command completion for a command starting with 'k'
3090func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003091 command KillKillKill :
3092 set wildoptions&
3093 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3094 call assert_equal("\"killkill\<Tab>", @:)
3095 set wildoptions=fuzzy
3096 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3097 call assert_equal('"KillKillKill', @:)
3098 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003099 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003100endfunc
3101
3102" Test for fuzzy completion for user defined custom completion function
3103func Test_fuzzy_completion_custom_func()
3104 func Tcompl(a, c, p)
3105 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3106 endfunc
3107 command -nargs=* -complete=custom,Tcompl Fuzzy :
3108 set wildoptions&
3109 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3110 call assert_equal("\"Fuzzy format", @:)
3111 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3112 call assert_equal("\"Fuzzy xy", @:)
3113 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3114 call assert_equal("\"Fuzzy ttt", @:)
3115 set wildoptions=fuzzy
3116 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3117 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3118 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3119 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3120 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal("\"Fuzzy xy", @:)
3122 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3123 call assert_equal("\"Fuzzy TestFOrmat", @:)
3124 delcom Fuzzy
3125 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003126endfunc
3127
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003128" Test for :breakadd argument completion
3129func Test_cmdline_complete_breakadd()
3130 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3131 call assert_equal("\"breakadd expr file func here", @:)
3132 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3133 call assert_equal("\"breakadd expr", @:)
3134 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3135 call assert_equal("\"breakadd expr", @:)
3136 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3137 call assert_equal("\"breakadd here", @:)
3138 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3139 call assert_equal("\"breakadd here", @:)
3140 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3141 call assert_equal("\"breakadd abc", @:)
3142 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3143 let l = getcompletion('not', 'breakpoint')
3144 call assert_equal([], l)
3145
3146 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003147 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003148 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3149 call assert_equal("\"breakadd file Xscript", @:)
3150 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3151 call assert_equal("\"breakadd file Xscript", @:)
3152 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3153 call assert_equal("\"breakadd file 20 Xscript", @:)
3154 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3155 call assert_equal("\"breakadd file 20 Xscript", @:)
3156 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3157 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3158 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3159 call assert_equal("\"breakadd file 20\t", @:)
3160 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3161 call assert_equal("\"breakadd file 20x\t", @:)
3162 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3163 call assert_equal("\"breakadd file Xscript ", @:)
3164 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3165 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003166
3167 " Test for :breakadd func [lnum] <function>
3168 func Xbreak_func()
3169 endfunc
3170 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3171 call assert_equal("\"breakadd func Xbreak_func", @:)
3172 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3173 call assert_equal("\"breakadd func Xbreak_func", @:)
3174 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3175 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3176 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3177 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3178 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3179 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3180 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3181 call assert_equal("\"breakadd func 20\t", @:)
3182 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3183 call assert_equal("\"breakadd func 20x\t", @:)
3184 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3185 call assert_equal("\"breakadd func Xbreak_func ", @:)
3186 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3187 call assert_equal("\"breakadd func X1B2C3", @:)
3188 delfunc Xbreak_func
3189
3190 " Test for :breakadd expr <expression>
3191 let g:Xtest_var = 10
3192 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3193 call assert_equal("\"breakadd expr Xtest_var", @:)
3194 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3195 call assert_equal("\"breakadd expr Xtest_var", @:)
3196 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3197 call assert_equal("\"breakadd expr Xtest_var ", @:)
3198 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3199 call assert_equal("\"breakadd expr X1B2C3", @:)
3200 unlet g:Xtest_var
3201
3202 " Test for :breakadd here
3203 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3204 call assert_equal("\"breakadd here Xtest", @:)
3205 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3206 call assert_equal("\"breakadd here Xtest", @:)
3207 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3208 call assert_equal("\"breakadd here ", @:)
3209endfunc
3210
3211" Test for :breakdel argument completion
3212func Test_cmdline_complete_breakdel()
3213 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3214 call assert_equal("\"breakdel file func here", @:)
3215 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3216 call assert_equal("\"breakdel file", @:)
3217 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3218 call assert_equal("\"breakdel file", @:)
3219 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3220 call assert_equal("\"breakdel here", @:)
3221 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal("\"breakdel here", @:)
3223 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal("\"breakdel abc", @:)
3225
3226 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003227 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003228 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3229 call assert_equal("\"breakdel file Xscript", @:)
3230 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3231 call assert_equal("\"breakdel file Xscript", @:)
3232 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3233 call assert_equal("\"breakdel file 20 Xscript", @:)
3234 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3235 call assert_equal("\"breakdel file 20 Xscript", @:)
3236 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3237 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3238 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3239 call assert_equal("\"breakdel file 20\t", @:)
3240 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3241 call assert_equal("\"breakdel file 20x\t", @:)
3242 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3243 call assert_equal("\"breakdel file Xscript ", @:)
3244 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3245 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003246
3247 " Test for :breakdel func [lnum] <function>
3248 func Xbreak_func()
3249 endfunc
3250 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3251 call assert_equal("\"breakdel func Xbreak_func", @:)
3252 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3253 call assert_equal("\"breakdel func Xbreak_func", @:)
3254 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3255 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3256 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3257 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3258 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3259 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3260 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3261 call assert_equal("\"breakdel func 20\t", @:)
3262 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3263 call assert_equal("\"breakdel func 20x\t", @:)
3264 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3265 call assert_equal("\"breakdel func Xbreak_func ", @:)
3266 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3267 call assert_equal("\"breakdel func X1B2C3", @:)
3268 delfunc Xbreak_func
3269
3270 " Test for :breakdel here
3271 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3272 call assert_equal("\"breakdel here Xtest", @:)
3273 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3274 call assert_equal("\"breakdel here Xtest", @:)
3275 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3276 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003277endfunc
3278
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003279" Test for :scriptnames argument completion
3280func Test_cmdline_complete_scriptnames()
3281 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003282 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003283 source Xa1b2c3.vim
3284 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3285 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3286 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3287 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3288 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3289 call assert_equal("\"script b2c3", @:)
3290 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3291 call assert_match("\"script 2\<Tab>$", @:)
3292 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3293 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3294 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3295 call assert_equal("\"script ", @:)
3296 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3297 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3298 new
3299 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3300 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3301 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003302 set wildmenu&
3303endfunc
3304
Bram Moolenaard8893442022-05-06 20:38:47 +01003305" this was going over the end of IObuff
3306func Test_report_error_with_composing()
3307 let caught = 'no'
3308 try
3309 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3310 catch /E492:/
3311 let caught = 'yes'
3312 endtry
3313 call assert_equal('yes', caught)
3314endfunc
3315
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003316" Test for expanding 2-letter and 3-letter :substitute command arguments.
3317" These commands don't accept an argument.
3318func Test_cmdline_complete_substitute_short()
3319 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3320 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3321 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3322 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3323 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3324 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3325 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3326 endfor
3327endfunc
3328
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003329" Test for :! shell command argument completion
3330func Test_cmdline_complete_bang_cmd_argument()
3331 set wildoptions=fuzzy
3332 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3333 call assert_equal('"!vim test_cmdline.vim', @:)
3334 set wildoptions&
3335 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3336 call assert_equal('"!vim test_cmdline.vim', @:)
3337endfunc
3338
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003339func Check_completion()
3340 call assert_equal('let a', getcmdline())
3341 call assert_equal(6, getcmdpos())
3342 call assert_equal(7, getcmdscreenpos())
3343 call assert_equal('var', getcmdcompltype())
3344 return ''
3345endfunc
3346
3347func Test_screenpos_and_completion()
3348 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3349endfunc
3350
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003351func Test_recursive_register()
3352 let @= = ''
3353 silent! ?e/
3354 let caught = 'no'
3355 try
3356 normal //
3357 catch /E169:/
3358 let caught = 'yes'
3359 endtry
3360 call assert_equal('yes', caught)
3361endfunc
3362
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003363func Test_long_error_message()
3364 " the error should be truncated, not overrun IObuff
3365 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3366endfunc
3367
zeertzjq6791adc2022-07-26 20:42:25 +01003368func Test_cmdline_redraw_tabline()
3369 CheckRunVimInTerminal
3370
3371 let lines =<< trim END
3372 set showtabline=2
3373 autocmd CmdlineEnter * set tabline=foo
3374 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003375 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003376 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3377 call term_sendkeys(buf, ':')
3378 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3379
3380 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003381endfunc
3382
zeertzjqb82a2ab2022-08-21 14:33:57 +01003383func Test_wildmenu_pum_disable_while_shown()
3384 set wildoptions=pum
3385 set wildmenu
3386 cnoremap <F2> <Cmd>set nowildmenu<CR>
3387 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3388 call assert_equal(0, pumvisible())
3389 cunmap <F2>
3390 set wildoptions& wildmenu&
3391endfunc
3392
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003393func Test_setcmdline()
3394 func SetText(text, pos)
zeertzjq54acb902022-08-29 16:21:25 +01003395 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003396 call assert_equal(0, setcmdline(a:text))
3397 call assert_equal(a:text, getcmdline())
3398 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003399 call assert_equal(getcmdtype(), g:cmdtype)
3400 unlet g:cmdtype
3401 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003402
3403 call assert_equal(0, setcmdline(a:text, a:pos))
3404 call assert_equal(a:text, getcmdline())
3405 call assert_equal(a:pos, getcmdpos())
3406
3407 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003408 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3409 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003410
3411 return ''
3412 endfunc
3413
3414 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3415 call assert_equal('set rtp?', @:)
3416
zeertzjq54acb902022-08-29 16:21:25 +01003417 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3418 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3419 call assert_equal('foo', g:str)
3420 unlet g:str
3421
3422 delfunc SetText
3423
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003424 " setcmdline() returns 1 when not editing the command line.
3425 call assert_equal(1, 'foo'->setcmdline())
3426
3427 " Called in custom function
3428 func CustomComplete(A, L, P)
3429 call assert_equal(0, setcmdline("DoCmd "))
3430 return "January\nFebruary\nMars\n"
3431 endfunc
3432
3433 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3434 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3435 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003436 delcom DoCmd
3437 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003438
3439 " Called in <expr>
3440 cnoremap <expr>a setcmdline('let foo=')
3441 call feedkeys(":a\<CR>", 'tx')
3442 call assert_equal('let foo=0', @:)
3443 cunmap a
3444endfunc
3445
Bram Moolenaar309976e2019-12-05 18:16:33 +01003446" vim: shiftwidth=2 sts=2 expandtab