blob: 166c9da87fb1f79be2d3c081d937568aca260bd2 [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
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200161 " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match
162 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx')
163 call assert_equal('"sign un yy zz', @:)
164
165 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx')
166 call assert_equal('"sign unplace yy zz', @:)
167
Bram Moolenaar37db6422019-03-28 21:26:23 +0100168 " cleanup
169 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200170 set nowildmenu
171endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100172
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173func Test_wildmenu_screendump()
174 CheckScreendump
175
176 let lines =<< trim [SCRIPT]
177 set wildmenu hlsearch
178 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100179 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200180
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200181 " Test simple wildmenu
Bram Moolenaara60053b2020-09-03 16:50:13 +0200182 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
183 call term_sendkeys(buf, ":vim\<Tab>")
184 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
185
186 call term_sendkeys(buf, "\<Tab>")
187 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
188
189 call term_sendkeys(buf, "\<Tab>")
190 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
191
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200192 " Looped back to the original value
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100193 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200194 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200195
196 " Test that the wild menu is cleared properly
197 call term_sendkeys(buf, " ")
198 call VerifyScreenDump(buf, 'Test_wildmenu_5', {})
199
200 " Test that a different wildchar still works
201 call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>")
202 call term_sendkeys(buf, ":vim\<Esc>")
203 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
204
205 " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
206 " sure clean up is properly done in edge case like this.
Bram Moolenaara60053b2020-09-03 16:50:13 +0200207 call term_sendkeys(buf, "\<Esc>")
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200208 call VerifyScreenDump(buf, 'Test_wildmenu_6', {})
Bram Moolenaara60053b2020-09-03 16:50:13 +0200209
210 " clean up
211 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200212endfunc
213
Bram Moolenaara653e532022-04-19 11:38:24 +0100214func Test_redraw_in_autocmd()
215 CheckScreendump
216
217 let lines =<< trim END
218 set cmdheight=2
219 autocmd CmdlineChanged * redraw
220 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100221 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100222
223 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
224 call term_sendkeys(buf, ":for i in range(3)\<CR>")
225 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
226
227 call term_sendkeys(buf, "let i =")
228 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
229
230 " clean up
231 call term_sendkeys(buf, "\<CR>")
232 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100233endfunc
234
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100235func Test_redrawstatus_in_autocmd()
236 CheckScreendump
237
238 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100239 set laststatus=2
240 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100241 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100242 END
243 call writefile(lines, 'XTest_redrawstatus', 'D')
244
245 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100246 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100247 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
248 call term_sendkeys(buf, ":foobar")
249 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100250 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100251 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100252 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100253 " with cmdheight=1 messages have scrolled when typing :endfor
254 call term_sendkeys(buf, "\<CR>:endfor")
255 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
256 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
257 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
258 call term_sendkeys(buf, ":for in in range(3)")
259 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
260 call term_sendkeys(buf, "\<CR>:endfor")
261 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100262
263 " clean up
264 call term_sendkeys(buf, "\<CR>")
265 call StopVimInTerminal(buf)
266endfunc
267
Bram Moolenaarf797e302022-08-11 13:17:30 +0100268func Test_changing_cmdheight()
269 CheckScreendump
270
271 let lines =<< trim END
272 set cmdheight=1 laststatus=2
nwounkn2e485672024-11-11 21:48:30 +0100273 func EchoOne()
274 set laststatus=2 cmdheight=1
275 echo 'foo'
276 echo 'bar'
277 set cmdheight=2
278 endfunc
Bram Moolenaar0816f472022-10-05 15:42:32 +0100279 func EchoTwo()
280 set laststatus=2
281 set cmdheight=5
282 echo 'foo'
283 echo 'bar'
284 set cmdheight=1
285 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100286 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100287 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100288
289 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
290 call term_sendkeys(buf, ":resize -3\<CR>")
291 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
292
Luuk van Baale15cbc12025-01-04 17:18:08 +0100293 " :resize now also changes 'cmdheight' accordingly
294 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100295 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
296
297 " using more space moves the status line up
298 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
299 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
300
301 " reducing cmdheight moves status line down
Luuk van Baalc97e8692025-01-06 18:58:21 +0100302 call term_sendkeys(buf, ":set cmdheight-=3\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100303 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
304
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000305 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100306 call term_sendkeys(buf, ":resize -1\<CR>")
307 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
308 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
309
Bram Moolenaar0816f472022-10-05 15:42:32 +0100310 " setting 'cmdheight' works after outputting two messages
311 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
312 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
313
Luuk van Baalc97e8692025-01-06 18:58:21 +0100314 " increasing 'cmdheight' doesn't clear the messages that need hit-enter
nwounkn2e485672024-11-11 21:48:30 +0100315 call term_sendkeys(buf, ":call EchoOne()\<CR>")
316 call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})
317
Luuk van Baalc97e8692025-01-06 18:58:21 +0100318 " window commands do not reduce 'cmdheight' to value lower than :set by user
319 call term_sendkeys(buf, "\<CR>:wincmd _\<CR>")
320 call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {})
321
Bram Moolenaarf797e302022-08-11 13:17:30 +0100322 " clean up
323 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100324endfunc
325
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100326func Test_cmdheight_tabline()
327 CheckScreendump
328
329 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
330 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
331
332 " clean up
333 call StopVimInTerminal(buf)
334endfunc
335
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100336func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100337 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
338 call assert_equal('"map <unique> <silent>', getreg(':'))
339 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
340 call assert_equal('"map <script> <unique>', getreg(':'))
341 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
342 call assert_equal('"map <expr> <script>', getreg(':'))
343 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
344 call assert_equal('"map <buffer> <expr>', getreg(':'))
345 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
346 call assert_equal('"map <nowait> <buffer>', getreg(':'))
347 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
348 call assert_equal('"map <special> <nowait>', getreg(':'))
349 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
350 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200351
Bram Moolenaar1776a282019-05-03 16:05:41 +0200352 map <Middle>x middle
353
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200354 map ,f commaf
355 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200356 map <Left> left
357 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200358 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
359 call assert_equal('"map ,f', getreg(':'))
360 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
361 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200362 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
363 call assert_equal('"map <Left>', getreg(':'))
364 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200365 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000366 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
367 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200368 unmap ,f
369 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200370 unmap <Left>
371 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200372
zeertzjqc3a26c62023-02-17 16:40:20 +0000373 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200374 map <Left> left
375 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
376 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200377 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200378 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000379 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
380 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200381 unmap <Left>
382
383 set cpo+=<
384 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200385 exe "set t_k6=\<Esc>[17~"
386 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200387 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
388 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200389 if !has('gui_running')
390 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
391 call assert_equal("\"map <F6>x", getreg(':'))
392 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200393 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200394 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200395 set cpo-=<
396
397 set cpo+=B
398 map <Left> left
399 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
400 call assert_equal('"map <Left>', getreg(':'))
401 unmap <Left>
402 set cpo-=B
403
404 set cpo+=k
405 map <Left> left
406 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
407 call assert_equal('"map <Left>', getreg(':'))
408 unmap <Left>
409 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200410
Bram Moolenaar531be472020-09-23 22:38:05 +0200411 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
412
Bram Moolenaar1776a282019-05-03 16:05:41 +0200413 unmap <Middle>x
414 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100415endfunc
416
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100417func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100418 hi Aardig ctermfg=green
419 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000420 call assert_equal('"match Aardig', @:)
Yee Cheng China7b81202025-02-23 09:32:47 +0100421 call feedkeys(":match NON\<Tab>\<Home>\"\<CR>", 'xt')
422 call assert_equal('"match NONE', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000423 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
424 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100425endfunc
426
427func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100428 hi Aardig ctermfg=green
429 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
430 call assert_equal('"hi Aardig', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100431
432 " hi default
Bram Moolenaarea588152017-04-10 22:45:30 +0200433 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
434 call assert_equal('"hi default Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100435 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
436 call assert_equal('"hi default', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100437 call feedkeys(":hi default link Aa\<Tab>\<Home>\"\<CR>", 'xt')
438 call assert_equal('"hi default link Aardig', getreg(':'))
439
440 " hi clear only accepts one parameter
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100441 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
442 call assert_equal('"hi clear', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100443 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
444 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200445 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
Yee Cheng China7b81202025-02-23 09:32:47 +0100446 call assert_equal("\"hi clear Aardig Aard\<Tab>", getreg(':'))
447 " hi link accepts up to two parameters
448 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
449 call assert_equal('"hi link', getreg(':'))
450 call assert_equal('"hi link', getreg(':'))
451 call feedkeys(":hi link Aa\<Tab>\<Home>\"\<CR>", 'xt')
452 call assert_equal('"hi link Aardig', getreg(':'))
453 call feedkeys(":hi link Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
454 call assert_equal("\"hi link Aardig Aardig", getreg(':'))
455 call feedkeys(":hi link Aardig Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
456 call assert_equal("\"hi link Aardig Aardig Aard\<Tab>", getreg(':'))
457 " hi link will complete to "NONE" for second parameter
458 call feedkeys(":hi link NON\<Tab>\<Home>\"\<CR>", 'xt')
459 call assert_equal("\"hi link NonText", getreg(':'))
460 call feedkeys(":hi link Aardig NON\<Tab>\<Home>\"\<CR>", 'xt')
461 call assert_equal("\"hi link Aardig NONE", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200462
463 " A cleared group does not show up in completions.
464 hi Anders ctermfg=green
465 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
466 hi clear Aardig
467 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
468 hi clear Anders
469 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100470endfunc
471
Bram Moolenaar75e15672020-06-28 13:10:22 +0200472" Test for command-line expansion of "hi Ni " (easter egg)
473func Test_highlight_easter_egg()
474 call test_override('ui_delay', 1)
475 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
476 call assert_equal("\"hi Ni \<Tab>", @:)
477 call test_override('ALL', 0)
478endfunc
479
Yee Cheng China7b81202025-02-23 09:32:47 +0100480func Test_highlight_group_completion()
481 " Test completing keys
482 call assert_equal('term=', getcompletion('hi Foo ', 'cmdline')[0])
483 call assert_equal('ctermfg=', getcompletion('hi Foo c*fg', 'cmdline')[0])
484 call assert_equal('NONE', getcompletion('hi Foo NON', 'cmdline')[0])
485 set wildoptions+=fuzzy
486 call assert_equal('ctermbg=', getcompletion('hi Foo cmbg', 'cmdline')[0])
487 set wildoptions-=fuzzy
488
489 " Test completing the current value
490 hi FooBar term=bold,underline cterm=undercurl ctermfg=lightgray ctermbg=12 ctermul=34
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100491 hi AlmostEmpty term=bold
Yee Cheng China7b81202025-02-23 09:32:47 +0100492 call assert_equal('bold,underline', getcompletion('hi FooBar term=', 'cmdline')[0])
493 call assert_equal('undercurl', getcompletion('hi FooBar cterm=', 'cmdline')[0])
494 call assert_equal('7', getcompletion('hi FooBar ctermfg=', 'cmdline')[0])
495 call assert_equal('12', getcompletion('hi FooBar ctermbg=', 'cmdline')[0])
496 call assert_equal('34', getcompletion('hi FooBar ctermul=', 'cmdline')[0])
497
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100498 " highlight group exists, but no value was set. Should not complete to
499 " existing value
500 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermfg=', 'cmdline')[0])
501 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermbg=', 'cmdline')[0])
502 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermul=', 'cmdline')[0])
503 call assert_equal('bold', getcompletion('hi AlmostEmpty cterm=', 'cmdline')[0])
504
505 " "bold,underline" is unique and creates an extra item. "undercurl" isn't
506 " and should be de-duplicated.
Yee Cheng China7b81202025-02-23 09:32:47 +0100507 call assert_equal(len(getcompletion('hi FooBar term=', 'cmdline')),
508 \ 1 + len(getcompletion('hi FooBar cterm=', 'cmdline')))
509
510 " don't complete original value if we have user input already, similar to
511 " behavior in :set <option>=<pattern>
512 call assert_equal(['bold'], getcompletion('hi FooBar term=bol', 'cmdline'))
513 call assert_equal([], getcompletion('hi FooBar ctermfg=1', 'cmdline'))
514
515 " start/stop do not fill their current value now as they are more
516 " complicated
517 hi FooBar start=123 stop=234
518 call assert_equal([], getcompletion('hi FooBar start=', 'cmdline'))
519 call assert_equal([], getcompletion('hi FooBar stop=', 'cmdline'))
520
521 if has("gui") || has("termguicolors")
522 hi FooBar gui=italic guifg=#112233 guibg=brown1 guisp=green
523 call assert_equal('italic', getcompletion('hi FooBar gui=', 'cmdline')[0])
524 call assert_equal('#112233', getcompletion('hi FooBar guifg=', 'cmdline')[0])
525 call assert_equal('brown1', getcompletion('hi FooBar guibg=', 'cmdline')[0])
526 call assert_equal('green', getcompletion('hi FooBar guisp=', 'cmdline')[0])
527
528 " Check that existing value is de-duplicated and doesn't show up later
529 call assert_equal(1, count(getcompletion('hi FooBar guibg=', 'cmdline'), 'brown1'))
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100530
531 " highlight group exists, but no value was set. Should not complete to
532 " existing value
533 call assert_equal('fg', getcompletion('hi AlmostEmpty guifg=', 'cmdline')[0])
534 call assert_equal('fg', getcompletion('hi AlmostEmpty guibg=', 'cmdline')[0])
535 call assert_equal('fg', getcompletion('hi AlmostEmpty guisp=', 'cmdline')[0])
536 call assert_equal('bold', getcompletion('hi AlmostEmpty gui=', 'cmdline')[0])
Yee Cheng China7b81202025-02-23 09:32:47 +0100537 endif
538
539 " Test completing attributes
540 call assert_equal(['underdouble', 'underdotted'], getcompletion('hi DoesNotExist term=un*erdo*', 'cmdline'))
541 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=NON', 'cmdline')[0])
542 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=', 'cmdline')[-1]) " NONE should be at the end and not sorted
543 call assert_equal('bold', getcompletion('hi DoesNotExist cterm=underline,bo', 'cmdline')[0]) " complete after comma
544 if has("gui") || has("termguicolors")
545 set wildoptions+=fuzzy
546 call assert_equal('italic', getcompletion('hi DoesNotExist gui=itic', 'cmdline')[0])
547 set wildoptions-=fuzzy
548 endif
549
550 " Test completing cterm colors
551 call assert_equal('fg', getcompletion('hi FooBar ctermbg=f*g', 'cmdline')[0])
552 call assert_equal('fg', getcompletion('hi DoesNotExist ctermbg=f*g', 'cmdline')[0])
553 call assert_equal('NONE', getcompletion('hi FooBar ctermfg=NON', 'cmdline')[0])
554 call assert_equal('NONE', getcompletion('hi DoesNotExist ctermfg=NON', 'cmdline')[0])
555 set wildoptions+=fuzzy
556 call assert_equal('Black', getcompletion('hi FooBar ctermul=blck', 'cmdline')[0])
557 call assert_equal('Black', getcompletion('hi DoesNotExist ctermul=blck', 'cmdline')[0])
558 set wildoptions-=fuzzy
559
560 " Test completing gui colors
561 if has("gui") || has("termguicolors")
562 call assert_equal('fg', getcompletion('hi FooBar guibg=f*g', 'cmdline')[0])
563 call assert_equal('fg', getcompletion('hi DoesNotExist guibg=f*g', 'cmdline')[0])
564 call assert_equal('NONE', getcompletion('hi FooBar guifg=NON', 'cmdline')[0])
565 call assert_equal('NONE', getcompletion('hi DoesNotExist guifg=NON', 'cmdline')[0])
566 set wildoptions=fuzzy
567 call assert_equal('limegreen', getcompletion('hi FooBar guisp=limgrn', 'cmdline')[0])
568 call assert_equal('limegreen', getcompletion('hi DoesNotExist guisp=limgrn', 'cmdline')[0])
569 set wildoptions-=fuzzy
570
571 " Test pruning bad color names with space. Vim doesn't support them.
572 let v:colornames['foobar with space'] = '#123456'
573 let v:colornames['foobarwithoutspace'] = '#234567'
574 call assert_equal(['foobarwithoutspace'], getcompletion('hi FooBar guibg=foobarw', 'cmdline'))
575
576 " Test specialized sorting. First few items are special values that
577 " go first, after that it's a sorted list of color names.
578 call assert_equal(['fg','bg','NONE'], getcompletion('hi DoesNotExist guifg=', 'cmdline')[0:2])
579 let completed_colors=getcompletion('hi DoesNotExist guifg=', 'cmdline')[3:]
580 let gui_colors_no_space=filter(copy(v:colornames), {key,val -> match(key, ' ')==-1})
581 call assert_equal(len(gui_colors_no_space), len(completed_colors))
582 call assert_equal(sort(copy(completed_colors)), completed_colors)
583
584 " Test that the specialized sorting still works if we have some pattern matches
585 let completed_colors=getcompletion('hi DoesNotExist guifg=*blue*', 'cmdline')
586 call assert_equal(sort(copy(completed_colors)), completed_colors)
587 call assert_equal('aliceblue', completed_colors[0])
588 endif
589endfunc
590
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200591func Test_getcompletion()
592 let groupcount = len(getcompletion('', 'event'))
593 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200594 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200595 call assert_true(matchcount > 0)
596 call assert_true(groupcount > matchcount)
597
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200598 if has('menu')
599 source $VIMRUNTIME/menu.vim
600 let matchcount = len(getcompletion('', 'menu'))
601 call assert_true(matchcount > 0)
602 call assert_equal(['File.'], getcompletion('File', 'menu'))
603 call assert_true(matchcount > 0)
604 let matchcount = len(getcompletion('File.', 'menu'))
605 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000606 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200607 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200608
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200609 let l = getcompletion('v:n', 'var')
610 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200611 let l = getcompletion('v:notexists', 'var')
612 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200613
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200614 args a.c b.c
615 let l = getcompletion('', 'arglist')
616 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000617 let l = getcompletion('a.', 'buffer')
618 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200619 %argdelete
620
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200621 let l = getcompletion('', 'augroup')
622 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200623 let l = getcompletion('blahblah', 'augroup')
624 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200625
626 let l = getcompletion('', 'behave')
627 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200628 let l = getcompletion('not', 'behave')
629 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200630
631 let l = getcompletion('', 'color')
632 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200633 let l = getcompletion('dirty', 'color')
634 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200635
636 let l = getcompletion('', 'command')
637 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200638 let l = getcompletion('awake', 'command')
639 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200640
641 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200642 call assert_true(index(l, 'samples/') >= 0)
643 let l = getcompletion('NoMatch', 'dir')
644 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200645
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100646 if glob('~/*') !=# ''
647 let l = getcompletion('~/', 'dir')
648 call assert_true(l[0][0] ==# '~')
649 endif
650
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200651 let l = getcompletion('exe', 'expression')
652 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200653 let l = getcompletion('kill', 'expression')
654 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200655
656 let l = getcompletion('tag', 'function')
657 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200658 let l = getcompletion('paint', 'function')
659 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200660
Kota Kato90c23532023-01-18 15:27:38 +0000661 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000662 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000663 let l = getcompletion('ruby', 'function')
664 call assert_equal([], l)
665 endif
666
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200667 let Flambda = {-> 'hello'}
668 let l = getcompletion('', 'function')
669 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200670 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200671
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200672 let l = getcompletion('run', 'file')
673 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200674 let l = getcompletion('walk', 'file')
675 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200676 set wildignore=*.vim
677 let l = getcompletion('run', 'file', 1)
678 call assert_true(index(l, 'runtest.vim') < 0)
679 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000680 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100681 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000682 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
683 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200684
685 let l = getcompletion('ha', 'filetype')
686 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200687 let l = getcompletion('horse', 'filetype')
688 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200689
Doug Kearns81642d92024-01-04 22:37:44 +0100690 if has('keymap')
691 let l = getcompletion('acc', 'keymap')
692 call assert_true(index(l, 'accents') >= 0)
693 let l = getcompletion('nullkeymap', 'keymap')
694 call assert_equal([], l)
695 endif
696
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200697 let l = getcompletion('z', 'syntax')
698 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200699 let l = getcompletion('emacs', 'syntax')
700 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200701
702 let l = getcompletion('jikes', 'compiler')
703 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200704 let l = getcompletion('break', 'compiler')
705 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200706
707 let l = getcompletion('last', 'help')
708 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200709 let l = getcompletion('giveup', 'help')
710 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200711
712 let l = getcompletion('time', 'option')
713 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200714 let l = getcompletion('space', 'option')
715 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200716
717 let l = getcompletion('er', 'highlight')
718 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200719 let l = getcompletion('dark', 'highlight')
720 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200721
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200722 let l = getcompletion('', 'messages')
723 call assert_true(index(l, 'clear') >= 0)
724 let l = getcompletion('not', 'messages')
725 call assert_equal([], l)
726
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200727 let l = getcompletion('', 'mapclear')
728 call assert_true(index(l, '<buffer>') >= 0)
729 let l = getcompletion('not', 'mapclear')
730 call assert_equal([], l)
731
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200732 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200733 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200734 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
735 let root = has('win32') ? 'C:\\' : '/'
736 let l = getcompletion(root, 'shellcmd')
737 let expected = map(filter(glob(root . '*', 0, 1),
738 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
739 call assert_equal(expected, l)
740
Bram Moolenaarb650b982016-08-05 20:35:13 +0200741 if has('cscope')
742 let l = getcompletion('', 'cscope')
743 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
744 call assert_equal(cmds, l)
745 " using cmdline completion must not change the result
746 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
747 let l = getcompletion('', 'cscope')
748 call assert_equal(cmds, l)
749 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
750 let l = getcompletion('find ', 'cscope')
751 call assert_equal(keys, l)
752 endif
753
Bram Moolenaar7522f692016-08-06 14:12:50 +0200754 if has('signs')
755 sign define Testing linehl=Comment
756 let l = getcompletion('', 'sign')
757 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
758 call assert_equal(cmds, l)
759 " using cmdline completion must not change the result
760 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
761 let l = getcompletion('', 'sign')
762 call assert_equal(cmds, l)
763 let l = getcompletion('list ', 'sign')
764 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000765 let l = getcompletion('de*', 'sign')
766 call assert_equal(['define'], l)
767 let l = getcompletion('p?', 'sign')
768 call assert_equal(['place'], l)
769 let l = getcompletion('j.', 'sign')
770 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200771 endif
772
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200773 " Command line completion tests
774 let l = getcompletion('cd ', 'cmdline')
775 call assert_true(index(l, 'samples/') >= 0)
776 let l = getcompletion('cd NoMatch', 'cmdline')
777 call assert_equal([], l)
778 let l = getcompletion('let v:n', 'cmdline')
779 call assert_true(index(l, 'v:null') >= 0)
780 let l = getcompletion('let v:notexists', 'cmdline')
781 call assert_equal([], l)
782 let l = getcompletion('call tag', 'cmdline')
783 call assert_true(index(l, 'taglist(') >= 0)
784 let l = getcompletion('call paint', 'cmdline')
785 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200786 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
787 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200788
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100789 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000790 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100791 return "oneA\noneB\noneC"
792 endfunc
793 command -nargs=1 -complete=custom,T MyCmd
794 let l = getcompletion('MyCmd ', 'cmdline')
795 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000796 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100797
798 delcommand MyCmd
799 delfunc T
ii144785fe02021-11-21 12:13:56 +0000800 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100801
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200802 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200803 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
804 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200805 if has('cmdline_hist')
806 call add(names, 'history')
807 endif
808 if has('gettext')
809 call add(names, 'locale')
810 endif
811 if has('profile')
812 call add(names, 'syntime')
813 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200814
815 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100816 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200817
818 for name in names
819 let matchcount = len(getcompletion('', name))
820 call assert_true(matchcount >= 0, 'No matches for ' . name)
821 endfor
822
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200823 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200824
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000825 edit a~b
826 enew
827 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
828 bw a~b
829
830 if has('unix')
831 edit Xtest\
832 enew
833 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
834 bw Xtest\
835 endif
836
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100837 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200838 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100839 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200840endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200841
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000842func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000843 " Get a dialog in the GUI
844 CheckNotGui
845
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000846 " This was using uninitialized memory.
847 let lines =<< trim END
848 set verbose=6
849 norm @=ٷ
850 qall!
851 END
852 call writefile(lines, 'XmultiScript', 'D')
853 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
854endfunc
855
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000856" Test for getcompletion() with "fuzzy" in 'wildoptions'
857func Test_getcompletion_wildoptions()
858 let save_wildoptions = &wildoptions
859 set wildoptions&
860 let l = getcompletion('space', 'option')
861 call assert_equal([], l)
862 let l = getcompletion('ier', 'command')
863 call assert_equal([], l)
864 set wildoptions=fuzzy
865 let l = getcompletion('space', 'option')
866 call assert_true(index(l, 'backspace') >= 0)
867 let l = getcompletion('ier', 'command')
868 call assert_true(index(l, 'compiler') >= 0)
869 let &wildoptions = save_wildoptions
870endfunc
871
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000872func Test_complete_autoload_error()
873 let save_rtp = &rtp
874 let lines =<< trim END
875 vim9script
876 export def Complete(..._): string
877 return 'match'
878 enddef
879 echo this will cause an error
880 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100881 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000882 call writefile(lines, 'Xdir/autoload/script.vim')
883 exe 'set rtp+=' .. getcwd() .. '/Xdir'
884
885 let lines =<< trim END
886 vim9script
887 import autoload 'script.vim'
888 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
889 &wildcharm = char2nr("\<Tab>")
890 feedkeys(":Cmd \<Tab>", 'xt')
891 END
892 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
893
894 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000895endfunc
896
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100897func Test_fullcommand()
898 let tests = {
899 \ '': '',
900 \ ':': '',
901 \ ':::': '',
902 \ ':::5': '',
903 \ 'not_a_cmd': '',
904 \ 'Check': '',
905 \ 'syntax': 'syntax',
906 \ ':syntax': 'syntax',
907 \ '::::syntax': 'syntax',
908 \ 'sy': 'syntax',
909 \ 'syn': 'syntax',
910 \ 'synt': 'syntax',
911 \ ':sy': 'syntax',
912 \ '::::sy': 'syntax',
913 \ 'match': 'match',
914 \ '2match': 'match',
915 \ '3match': 'match',
916 \ 'aboveleft': 'aboveleft',
917 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100918 \ 'en': 'endif',
919 \ 'end': 'endif',
920 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100921 \ 's': 'substitute',
922 \ '5s': 'substitute',
923 \ ':5s': 'substitute',
924 \ "'<,'>s": 'substitute',
925 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100926 \ 'CheckLin': 'CheckLinux',
927 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100928 \ }
929
930 for [in, want] in items(tests)
931 call assert_equal(want, fullcommand(in))
932 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200933 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100934
935 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200936
937 command -buffer BufferLocalCommand :
938 command GlobalCommand :
939 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
940 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
941 delcommand BufferLocalCommand
942 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100943endfunc
944
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200945func Test_shellcmd_completion()
946 let save_path = $PATH
947
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100948 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200949 call writefile([''], 'Xpathdir/Xfile.exe')
950 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
951
952 " Set PATH to example directory without trailing slash.
953 let $PATH = getcwd() . '/Xpathdir'
954
955 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
956 " dirs in the PATH, even though they won't be executed. We check that only
957 " subdirs of the PWD and executables from the PATH are included in the
958 " suggestions.
959 let actual = getcompletion('X', 'shellcmd')
960 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
961 call insert(expected, 'Xfile.exe')
962 call assert_equal(expected, actual)
963
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200964 let $PATH = save_path
965endfunc
966
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200967func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100968 call mkdir('a/b/c', 'pR')
969 call writefile(['asdfasdf'], 'a/b/c/fileXname')
970 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
971 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200972 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200973endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100974
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100975func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100976 let @a = "def"
977 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
978 call assert_equal('"abc def ghi', @:)
979
980 new
981 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
982
983 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
984 call assert_equal('"aaa asdf bbb', @:)
985
986 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
987 call assert_equal('"aaa /tmp/some bbb', @:)
988
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200989 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
990 call assert_equal('"aaa '.getline(1).' bbb', @:)
991
Bram Moolenaar21efc362016-12-03 14:05:49 +0100992 set incsearch
993 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
994 call assert_equal('"aaa verylongword bbb', @:)
995
996 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
997 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100998
999 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
1000 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +01001001 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +02001002
1003 " Error while typing a command used to cause that it was not executed
1004 " in the end.
1005 new
1006 try
1007 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
1008 catch /^Vim\%((\a\+)\)\=:E32/
1009 " ignore error E32
1010 endtry
1011 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001012
Bram Moolenaar578fe942020-02-27 21:32:51 +01001013 " Try to paste an invalid register using <C-R>
1014 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
1015 call assert_equal('"onetwo', @:)
1016
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001017 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +01001018 let @a = "xy\<C-H>z"
1019 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
1020 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001021 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
1022 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001023 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
1024 call assert_equal("\"xy\<C-H>z", @:)
1025
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001026 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
1027 let @a = "xy\<C-V>z"
1028 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
1029 call assert_equal('"xyz', @:)
1030 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
1031 call assert_equal("\"xy\<C-V>z", @:)
1032
Bram Moolenaar578fe942020-02-27 21:32:51 +01001033 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
1034
Bram Moolenaar72532d32018-04-07 19:09:09 +02001035 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +01001036endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001037
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001038func Test_cmdline_remove_char()
1039 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001040
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001041 for e in ['utf8', 'latin1']
1042 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001043
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001044 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
1045 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001046
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001047 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
1048 call assert_equal('"abcdef', @:)
1049
1050 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
1051 call assert_equal('"abc ghi', @:, e)
1052
1053 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
1054 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +01001055
1056 " This was going before the start in latin1.
1057 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001058 endfor
1059
1060 let &encoding = encoding_save
1061endfunc
1062
zeertzjqff2b79d2024-02-26 20:38:36 +01001063func Test_cmdline_del_utf8()
1064 let @s = ''
1065 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1066 call assert_equal('",,', @:)
1067
1068 let @s = 'a̳'
1069 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1070 call assert_equal('",,', @:)
1071
1072 let @s = 'β̳'
1073 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1074 call assert_equal('",,', @:)
1075
1076 if has('arabic')
1077 let @s = 'لا'
1078 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1079 call assert_equal('",,', @:)
1080 endif
1081endfunc
1082
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001083func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001084 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001085
1086 set keymap=esperanto
1087 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
1088 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
1089 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001090endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001091
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001092func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001093 new
1094 2;'(
1095 2;')
1096 quit
1097endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +01001098
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001099func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001100 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001101 new
1102 source Xtest.vim
1103 " Trigger calling validate_cursor()
1104 diffsp Xtest.vim
1105 quit!
1106 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001107endfunc
1108
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +01001109func Test_mark_from_line_zero()
1110 " this was reading past the end of the first (empty) line
1111 new
1112 norm oxxxx
1113 call assert_fails("0;'(", 'E20:')
1114 bwipe!
1115endfunc
1116
Bram Moolenaarba47b512017-01-24 21:18:19 +01001117func Test_cmdline_complete_wildoptions()
1118 help
1119 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1120 let a = join(sort(split(@:)),' ')
1121 set wildoptions=tagfile
1122 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1123 let b = join(sort(split(@:)),' ')
1124 call assert_equal(a, b)
1125 bw!
1126endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001127
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001128func Test_cmdline_complete_user_cmd()
1129 command! -complete=color -nargs=1 Foo :
1130 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1131 call assert_equal('"Foo blue', @:)
1132 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1133 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001134 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1135 call assert_equal('"Foo a blue', @:)
1136 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1137 call assert_equal('"Foo b\', @:)
1138 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1139 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001140 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001141
1142 redraw
1143 call assert_equal('~', Screenline(&lines - 1))
1144 command! FooOne :
1145 command! FooTwo :
1146
1147 set nowildmenu
1148 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1149 call assert_equal('"FooOne', @:)
1150 call assert_equal('~', Screenline(&lines - 1))
1151
1152 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1153 call assert_equal('"FooTwo', @:)
1154 call assert_equal('~', Screenline(&lines - 1))
1155
1156 delcommand FooOne
1157 delcommand FooTwo
1158 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001159endfunc
1160
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001161func Test_complete_user_cmd()
1162 command FooBar echo 'global'
1163 command -buffer FooBar echo 'local'
1164 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1165 call assert_equal('"FooBar', @:)
1166
1167 delcommand -buffer FooBar
1168 delcommand FooBar
1169endfunc
1170
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001171func s:ScriptLocalFunction()
1172 echo 'yes'
1173endfunc
1174
1175func Test_cmdline_complete_user_func()
1176 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001177 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001178 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1179 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001180
1181 " g: prefix also works
1182 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1183 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001184
1185 " using g: prefix does not result in just "g:" matches from a lambda
1186 let Fx = { a -> a }
1187 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1188 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001189
1190 " existence of script-local dict function does not break user function name
1191 " completion
1192 function s:a_dict_func() dict
1193 endfunction
1194 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1195 call assert_match('"call Test_cmdline_complete_user_', @:)
1196 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001197endfunc
1198
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001199func Test_cmdline_complete_user_names()
1200 if has('unix') && executable('whoami')
1201 let whoami = systemlist('whoami')[0]
1202 let first_letter = whoami[0]
1203 if len(first_letter) > 0
1204 " Trying completion of :e ~x where x is the first letter of
1205 " the user name should complete to at least the user name.
1206 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1207 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1208 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001209 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001210 " Just in case: check that the system has an Administrator account.
1211 let names = system('net user')
1212 if names =~ 'Administrator'
1213 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001214 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001215 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001216 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001217 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001218 else
1219 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001220 endif
1221endfunc
1222
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001223func Test_cmdline_complete_shellcmdline()
1224 CheckExecutable whoami
1225 command -nargs=1 -complete=shellcmdline MyCmd
1226
1227 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1228 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001229 let l = getcompletion('whoam', 'shellcmdline')
1230 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001231
1232 delcommand MyCmd
1233endfunc
1234
Bram Moolenaar297610b2019-12-27 17:20:55 +01001235func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001236 CheckExecutable whoami
1237 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1238 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001239endfunc
1240
Bram Moolenaar8b633132020-03-20 18:20:51 +01001241func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001242 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1243 call assert_equal(lang, v:lc_time)
1244
1245 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1246 call assert_equal(lang, v:ctype)
1247
1248 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1249 call assert_equal(lang, v:collate)
1250
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001251 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001252 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001253
1254 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001255 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001256
Bram Moolenaarec680282020-06-12 19:35:32 +02001257 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001258
Bram Moolenaarec680282020-06-12 19:35:32 +02001259 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1260 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001261
Bram Moolenaarec680282020-06-12 19:35:32 +02001262 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1263 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001264
Bram Moolenaarec680282020-06-12 19:35:32 +02001265 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1266 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001267
1268 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1269 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001270endfunc
1271
Bram Moolenaar297610b2019-12-27 17:20:55 +01001272func Test_cmdline_complete_env_variable()
1273 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001274 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1275 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001276 unlet $X_VIM_TEST_COMPLETE_ENV
1277endfunc
1278
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001279func Test_cmdline_complete_expression()
1280 let g:SomeVar = 'blah'
1281 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1282 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1283 call assert_match('"' .. cmd .. ' SomeVar', @:)
1284 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1285 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1286 endfor
1287 unlet g:SomeVar
1288endfunc
1289
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001290func Test_cmdline_complete_argopt()
1291 " completion for ++opt=arg for file commands
1292 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1293 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1294 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1295
1296 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001297 " Test ++ff in the middle of the cmdline
1298 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1299 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001300
1301 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1302 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1303 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1304 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1305 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1306
1307 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1308
1309 " completion should skip the ++opt and continue
1310 call writefile([], 'Xaaaaa.txt', 'D')
1311 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1312 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1313
1314 if has('terminal')
1315 " completion for terminal's [options]
1316 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1317 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1318 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1319
1320 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1321
1322 " :terminal completion should skip the ++opt when considering what is the
1323 " first option, which is a list of shell commands, unlike second option
1324 " onwards.
1325 let first_param = getcompletion('terminal ', 'cmdline')
1326 let second_param = getcompletion('terminal foo ', 'cmdline')
1327 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1328 call assert_equal(first_param, skipped_opt_param)
1329 call assert_notequal(first_param, second_param)
1330 endif
1331endfunc
1332
Bram Moolenaar47016f52021-08-26 16:39:58 +02001333" Unique function name for completion below
1334func s:WeirdFunc()
1335 echo 'weird'
1336endfunc
1337
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001338" Test for various command-line completion
1339func Test_cmdline_complete_various()
1340 " completion for a command starting with a comment
1341 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1342 call assert_equal("\" :|\"\<C-A>", @:)
1343
1344 " completion for a range followed by a comment
1345 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1346 call assert_equal("\"1,2\"\<C-A>", @:)
1347
1348 " completion for :k command
1349 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1350 call assert_equal("\"ka\<C-A>", @:)
1351
Doug Kearnsea842022024-09-29 17:17:41 +02001352 " completion for :keepmarks command
1353 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1354 call assert_equal("\"kee edit", @:)
1355
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001356 " completion for short version of the :s command
1357 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1358 call assert_equal("\"sI \<C-A>", @:)
1359
1360 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001361 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001362 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001363 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001364 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001365 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1366 call assert_equal("\"w >> Xfile1", @:)
1367 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001368
1369 " completion for :w ! and :r ! commands
1370 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1371 call assert_equal("\"w !invalid_xyz_cmd", @:)
1372 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1373 call assert_equal("\"r !invalid_xyz_cmd", @:)
1374
1375 " completion for :>> and :<< commands
1376 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1377 call assert_equal("\">>>\<C-A>", @:)
1378 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1379 call assert_equal("\"<<<\<C-A>", @:)
1380
1381 " completion for command with +cmd argument
1382 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1383 call assert_equal("\"buffer +/pat Xabc", @:)
1384 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1385 call assert_equal("\"buffer +/pat\<C-A>", @:)
1386
1387 " completion for a command with a trailing comment
1388 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1389 call assert_equal("\"ls \" comment\<C-A>", @:)
1390
1391 " completion for a command with a trailing command
1392 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1393 call assert_equal("\"ls | ls", @:)
1394
1395 " completion for a command with an CTRL-V escaped argument
1396 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1397 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1398
1399 " completion for a command that doesn't take additional arguments
1400 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1401 call assert_equal("\"all abc\<C-A>", @:)
1402
zeertzjqd3de1782022-09-01 12:58:52 +01001403 " completion for :wincmd with :horizontal modifier
1404 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1405 call assert_equal("\"horizontal wincmd", @:)
1406
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001407 " completion for a command with a command modifier
1408 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1409 call assert_equal("\"topleft new", @:)
1410
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001411 " completion for vim9 and legacy commands
1412 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1413 call assert_equal("\"vim9 call strlen(", @:)
1414 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1415 call assert_equal("\"legac call strlen(", @:)
1416
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001417 " completion for the :disassemble command
1418 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1419 call assert_equal("\"disas debug", @:)
1420 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1421 call assert_equal("\"disas profile", @:)
1422 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1423 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1424 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1425 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001426 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1427 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001428
Bram Moolenaar47016f52021-08-26 16:39:58 +02001429 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001430 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001431
naohiro onodfe04db2021-09-12 15:45:10 +02001432 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1433 call assert_match('"disas <SNR>\d\+_', @:)
1434 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1435 call assert_match('"disas debug <SNR>\d\+_', @:)
1436
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001437 " completion for the :match command
1438 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1439 call assert_equal("\"match Search /pat/\<C-A>", @:)
1440
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001441 " completion for the :doautocmd command
1442 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1443 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1444
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001445 " completion of autocmd group after comma
1446 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1447 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1448
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001449 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001450 call writefile([], 'Xvarfile1', 'D')
1451 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001452 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1453 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001454
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001455 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001456 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001457 augroup END
1458 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001459 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001460
1461 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001462 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1463 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001464 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1465 call assert_equal("\"au XTest.test", @:)
1466
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001467 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001468
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001469 " autocmd pattern completion
1470 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1471 call assert_equal("\"au BufEnter *.py\t", @:)
1472
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001473 " completion for the :unlet command
1474 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1475 call assert_equal("\"unlet one two", @:)
1476
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001477 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001478 " FIXME: what should happen on MS-Windows?
1479 if !has('win32')
1480 edit \{someFile}
1481 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1482 call assert_equal("\"buf {someFile}", @:)
1483 bwipe {someFile}
1484 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001485
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001486 " completion for the :bdelete command
1487 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1488 call assert_equal("\"bdel a b c", @:)
1489
1490 " completion for the :mapclear command
1491 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1492 call assert_equal("\"mapclear <buffer>", @:)
1493
1494 " completion for user defined commands with menu names
1495 menu Test.foo :ls<CR>
1496 com -nargs=* -complete=menu MyCmd
1497 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1498 call assert_equal('"MyCmd Test.', @:)
1499 delcom MyCmd
1500 unmenu Test
1501
1502 " completion for user defined commands with mappings
1503 mapclear
1504 map <F3> :ls<CR>
1505 com -nargs=* -complete=mapping MyCmd
1506 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001507 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001508 mapclear
1509 delcom MyCmd
1510
Yee Cheng Chin54844852023-10-09 18:12:31 +02001511 " Prepare for path completion
1512 call mkdir('Xa b c', 'D')
1513 defer delete('Xcomma,foobar.txt')
1514 call writefile([], 'Xcomma,foobar.txt')
1515
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001516 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001517 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1518 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1519 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001520
1521 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001522 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1523 call assert_equal('"set dir=Xa\ b\ c/', @:)
1524 set dir&
1525
1526 " completion for :set tags= / set dictionary= with escaped commas
1527 if has('win32')
1528 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1529 " '\,'
1530 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1531 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1532
1533 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1534 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1535
1536 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1537 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1538
1539 " completion for :set dictionary= with escaped commas (same behavior, but
1540 " different internal code path from 'set tags=' for escaping the output)
1541 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1542 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1543 else
1544 " In other platforms, backslashes are rounded down (since '\,' itself will
1545 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1546 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1547 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1548
1549 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1550 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1551
1552 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1553 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1554
1555 " completion for :set dictionary= with escaped commas (same behavior, but
1556 " different internal code path from 'set tags=' for escaping the output)
1557 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1558 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1559 endif
1560 set tags&
1561 set dictionary&
1562
1563 " completion for :set makeprg= with no escaped commas
1564 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1565 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1566
1567 if !has('win32')
1568 " Cannot create file with backslash in file name in Windows, so only test
1569 " this elsewhere.
1570 defer delete('Xcomma\,fooslash.txt')
1571 call writefile([], 'Xcomma\,fooslash.txt')
1572 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1573 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1574 endif
1575 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001576
1577 " completion for the :py3 commands
1578 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1579 call assert_equal('"py3 py3do py3file', @:)
1580
Bram Moolenaardf749a22021-03-28 15:29:43 +02001581 " completion for the :vim9 commands
1582 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1583 call assert_equal('"vim9cmd vim9script', @:)
1584
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001585 " redir @" is not the start of a comment. So complete after that
1586 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1587 call assert_equal('"redir @" | cwindow', @:)
1588
1589 " completion after a backtick
1590 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1591 call assert_equal('"e `a1b2c', @:)
1592
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001593 " completion for :language command with an invalid argument
1594 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1595 call assert_equal("\"language dummy \t", @:)
1596
1597 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001598 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1599 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001600
1601 " completion with ambiguous user defined commands
1602 com TCmd1 echo 'TCmd1'
1603 com TCmd2 echo 'TCmd2'
1604 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1605 call assert_equal('"TCmd ', @:)
1606 delcom TCmd1
1607 delcom TCmd2
1608
1609 " completion after a range followed by a pipe (|) character
1610 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1611 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001612
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001613 " completion after a :global command
1614 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1615 call assert_equal('"g/a/chistory', @:)
1616 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1617 call assert_equal("\"g/a\\/chist\t", @:)
1618
Bram Moolenaar9c929712020-09-07 22:05:28 +02001619 " use <Esc> as the 'wildchar' for completion
1620 set wildchar=<Esc>
1621 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1622 call assert_equal('"g/a\xb/clearjumps', @:)
1623 " pressing <esc> twice should cancel the command
1624 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1625 call assert_equal('"g/a\xb/clearjumps', @:)
1626 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001627
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001628 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001629 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001630 call writefile([], '~Xtest')
1631 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1632 call assert_equal('"e \~Xtest', @:)
1633 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001634
1635 " should be able to complete a file name that has a '*'
1636 call writefile([], 'Xx*Yy')
1637 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1638 call assert_equal('"e Xx\*Yy', @:)
1639 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001640
1641 " use a literal star
1642 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1643 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001644 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001645
1646 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1647 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001648endfunc
1649
zeertzjq094dd152023-06-15 22:51:57 +01001650" Test that expanding a pattern doesn't interfere with cmdline completion.
1651func Test_expand_during_cmdline_completion()
1652 func ExpandStuff()
1653 badd <script>:p:h/README.*
1654 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1655 $bwipe
1656 call assert_equal('README.txt', expand('README.*'))
1657 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1658 endfunc
1659 augroup test_CmdlineChanged
1660 autocmd!
1661 autocmd CmdlineChanged * call ExpandStuff()
1662 augroup END
1663
1664 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1665 call assert_equal('"sign place', @:)
1666
1667 augroup test_CmdlineChanged
1668 au!
1669 augroup END
1670 augroup! test_CmdlineChanged
1671 delfunc ExpandStuff
1672endfunc
1673
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001674" Test for 'wildignorecase'
1675func Test_cmdline_wildignorecase()
1676 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001677 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001678 set wildignorecase
1679 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1680 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001681 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001682 let g:Sline = ''
1683 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1684 call assert_equal('"e xt', @:)
1685 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001686 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001687endfunc
1688
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001689func Test_cmdline_write_alternatefile()
1690 new
1691 call setline('.', ['one', 'two'])
1692 f foo.txt
1693 new
1694 f #-A
1695 call assert_equal('foo.txt-A', expand('%'))
1696 f #<-B.txt
1697 call assert_equal('foo-B.txt', expand('%'))
1698 f %<
1699 call assert_equal('foo-B', expand('%'))
1700 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001701 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001702 bw!
1703 f foo-B.txt
1704 f %<-A
1705 call assert_equal('foo-B-A', expand('%'))
1706 bw!
1707 bw!
1708endfunc
1709
Bram Moolenaarf5724372022-09-02 19:45:15 +01001710func Test_cmdline_expand_cur_alt_file()
1711 enew
1712 file http://some.com/file.txt
1713 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1714 call assert_equal('"e http://some.com/file.txt', @:)
1715 edit another
1716 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1717 call assert_equal('"e http://some.com/file.txt', @:)
1718 bwipe
1719 bwipe http://some.com/file.txt
1720endfunc
1721
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001722" using a leading backslash here
1723set cpo+=C
1724
1725func Test_cmdline_search_range()
1726 new
1727 call setline(1, ['a', 'b', 'c', 'd'])
1728 /d
1729 1,\/s/b/B/
1730 call assert_equal('B', getline(2))
1731
1732 /a
1733 $
1734 \?,4s/c/C/
1735 call assert_equal('C', getline(3))
1736
1737 call setline(1, ['a', 'b', 'c', 'd'])
1738 %s/c/c/
1739 1,\&s/b/B/
1740 call assert_equal('B', getline(2))
1741
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001742 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001743 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001744
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001745 bwipe!
1746endfunc
1747
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001748" Test for the tick mark (') in an excmd range
1749func Test_tick_mark_in_range()
1750 " If only the tick is passed as a range and no command is specified, there
1751 " should not be an error
1752 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001753 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001754 call assert_fails("',print", 'E78:')
1755endfunc
1756
1757" Test for using a line number followed by a search pattern as range
1758func Test_lnum_and_pattern_as_range()
1759 new
1760 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1761 let @" = ''
1762 2/foo/yank
1763 call assert_equal("foo 3\n", @")
1764 call assert_equal(1, line('.'))
1765 close!
1766endfunc
1767
Bram Moolenaar65189a12017-02-06 22:22:17 +01001768" Tests for getcmdline(), getcmdpos() and getcmdtype()
1769func Check_cmdline(cmdtype)
1770 call assert_equal('MyCmd a', getcmdline())
1771 call assert_equal(8, getcmdpos())
1772 call assert_equal(a:cmdtype, getcmdtype())
1773 return ''
1774endfunc
1775
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001776set cpo&
1777
Shougo Matsushita69084282024-09-23 20:34:47 +02001778func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001779 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1780
1781 let cmdtype = ''
1782 debuggreedy
1783 call feedkeys(":debug echo 'test'\<CR>", "t")
1784 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1785 call feedkeys("cont\<CR>", "xt")
1786 0debuggreedy
1787 call assert_equal('>', cmdtype)
1788
1789 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1790 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1791
1792 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001793 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001794
1795 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1796
1797 cnoremap <expr> <F6> Check_cmdline('=')
1798 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1799 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001800
1801 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001802
1803 call assert_equal('', getcmdprompt())
1804 augroup test_CmdlineEnter
1805 autocmd!
1806 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1807 augroup END
1808 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1809 call assert_equal('Answer?', g:cmdprompt)
1810 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001811 call feedkeys(":\<CR>\<ESC>", "xt")
1812 call assert_equal('', g:cmdprompt)
1813 call assert_equal('', getcmdprompt())
1814
1815 let str = "C" .. repeat("c", 1023) .. "xyz"
1816 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1817 call assert_equal(str, g:cmdprompt)
1818
1819 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1820 call assert_equal('Ans?', g:cmdprompt)
1821 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001822
1823 augroup test_CmdlineEnter
1824 au!
1825 augroup END
1826 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001827endfunc
1828
Bram Moolenaar52604f22017-04-07 16:17:39 +02001829func Test_verbosefile()
1830 set verbosefile=Xlog
1831 echomsg 'foo'
1832 echomsg 'bar'
1833 set verbosefile=
1834 let log = readfile('Xlog')
1835 call assert_match("foo\nbar", join(log, "\n"))
1836 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001837
1838 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001839 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001840endfunc
1841
Bram Moolenaar4facea32019-10-12 20:17:40 +02001842func Test_verbose_option()
1843 CheckScreendump
1844
1845 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001846 " clear the TermResponse autocommand from defaults.vim
1847 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001848 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1849 call feedkeys("\r", 't') " for the hit-enter prompt
1850 set verbose=20
1851 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001852 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001853
1854 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001855 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001856 call term_sendkeys(buf, ":DoSomething\<CR>")
1857 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1858
1859 " clean up
1860 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001861endfunc
1862
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001863func Test_setcmdpos()
1864 func InsertTextAtPos(text, pos)
1865 call assert_equal(0, setcmdpos(a:pos))
1866 return a:text
1867 endfunc
1868
1869 " setcmdpos() with position in the middle of the command line.
1870 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1871 call assert_equal('"1ab2', @:)
1872
1873 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1874 call assert_equal('"1b2a', @:)
1875
1876 " setcmdpos() with position beyond the end of the command line.
1877 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1878 call assert_equal('"12ab', @:)
1879
1880 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001881 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001882endfunc
1883
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001884func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001885 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001886 let encoding_save = &encoding
1887
1888 for e in encodings
1889 exe 'set encoding=' . e
1890
1891 " Test overstrike in the middle of the command line.
1892 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001893 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001894
1895 " Test overstrike going beyond end of command line.
1896 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001897 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001898
1899 " Test toggling insert/overstrike a few times.
1900 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001901 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001902 endfor
1903
Bram Moolenaar30276f22019-01-24 17:59:39 +01001904 " Test overstrike with multi-byte characters.
1905 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001906 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001907
1908 let &encoding = encoding_save
1909endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001910
Bram Moolenaar52410572019-10-27 05:12:45 +01001911func Test_buffers_lastused()
1912 " check that buffers are sorted by time when wildmode has lastused
1913 call test_settime(1550020000) " middle
1914 edit bufa
1915 enew
1916 call test_settime(1550030000) " newest
1917 edit bufb
1918 enew
1919 call test_settime(1550010000) " oldest
1920 edit bufc
1921 enew
1922 call test_settime(0)
1923 enew
1924
1925 call assert_equal(['bufa', 'bufb', 'bufc'],
1926 \ getcompletion('', 'buffer'))
1927
1928 let save_wildmode = &wildmode
1929 set wildmode=full:lastused
1930
1931 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1932 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1933 call assert_equal('b bufb', X)
1934 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1935 call assert_equal('b bufa', X)
1936 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1937 call assert_equal('b bufc', X)
1938 enew
1939
1940 edit other
1941 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1942 call assert_equal('b bufb', X)
1943 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1944 call assert_equal('b bufa', X)
1945 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1946 call assert_equal('b bufc', X)
1947 enew
1948
1949 let &wildmode = save_wildmode
1950
1951 bwipeout bufa
1952 bwipeout bufb
1953 bwipeout bufc
1954endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001955
Bram Moolenaar479950f2020-01-19 15:45:17 +01001956func Test_cmdlineclear_tabenter()
1957 CheckScreendump
1958
1959 let lines =<< trim [SCRIPT]
1960 call setline(1, range(30))
1961 [SCRIPT]
1962
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001963 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001964 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001965 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001966 " in one tab make the command line higher with CTRL-W -
1967 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1968 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1969
1970 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001971endfunc
1972
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001973" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001974func Test_cmdline_expand_special()
1975 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001976 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001977 call assert_fails('e <afile>', 'E495:')
1978 call assert_fails('e <abuf>', 'E496:')
1979 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001980
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001981 call writefile([], 'Xfile.cpp', 'D')
1982 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001983 new Xfile.cpp
1984 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1985 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1986 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001987endfunc
1988
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001989" Test for backtick expression in the command line
1990func Test_cmd_backtick()
1991 %argd
1992 argadd `=['a', 'b', 'c']`
1993 call assert_equal(['a', 'b', 'c'], argv())
1994 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001995
1996 argadd `echo abc def`
1997 call assert_equal(['abc def'], argv())
1998 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001999endfunc
2000
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002001" Test for the :! command
2002func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002003 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002004
2005 let lines =<< trim [SCRIPT]
2006 " Test for no previous command
2007 call assert_fails('!!', 'E34:')
2008 set nomore
2009 " Test for cmdline expansion with :!
2010 call setline(1, 'foo!')
2011 silent !echo <cWORD> > Xfile.out
2012 call assert_equal(['foo!'], readfile('Xfile.out'))
2013 " Test for using previous command
2014 silent !echo \! !
2015 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
2016 call writefile(v:errors, 'Xresult')
2017 call delete('Xfile.out')
2018 qall!
2019 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002020 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002021 if RunVim([], [], '--clean -S Xscript')
2022 call assert_equal([], readfile('Xresult'))
2023 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002024 call delete('Xresult')
2025endfunc
2026
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002027" Test error: "E135: *Filter* Autocommands must not change current buffer"
2028func Test_cmd_bang_E135()
2029 new
2030 call setline(1, ['a', 'b', 'c', 'd'])
2031 augroup test_cmd_filter_E135
2032 au!
2033 autocmd FilterReadPost * help
2034 augroup END
2035 call assert_fails('2,3!echo "x"', 'E135:')
2036
2037 augroup test_cmd_filter_E135
2038 au!
2039 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002040 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002041 %bwipe!
2042endfunc
2043
shane.xb.qian4e7590e2022-11-08 21:40:04 +00002044func Test_cmd_bang_args()
2045 new
2046 :.!
2047 call assert_equal(0, v:shell_error)
2048
2049 " Note that below there is one space char after the '!'. This caused a
2050 " shell error in the past, see https://github.com/vim/vim/issues/11495.
2051 :.!
2052 call assert_equal(0, v:shell_error)
2053 bwipe!
2054
2055 CheckUnix
2056 :.!pwd
2057 call assert_equal(0, v:shell_error)
2058 :.! pwd
2059 call assert_equal(0, v:shell_error)
2060
2061 " Note there is one space after 'pwd'.
2062 :.! pwd
2063 call assert_equal(0, v:shell_error)
2064
2065 " Note there are two spaces after 'pwd'.
2066 :.! pwd
2067 call assert_equal(0, v:shell_error)
2068 :.!ls ~
2069 call assert_equal(0, v:shell_error)
2070
2071 " Note there is one space char after '~'.
2072 :.!ls ~
2073 call assert_equal(0, v:shell_error)
2074
2075 " Note there are two spaces after '~'.
2076 :.!ls ~
2077 call assert_equal(0, v:shell_error)
2078
2079 :.!echo "foo"
2080 call assert_equal(getline('.'), "foo")
2081 :.!echo "foo "
2082 call assert_equal(getline('.'), "foo ")
2083 :.!echo " foo "
2084 call assert_equal(getline('.'), " foo ")
2085 :.!echo " foo "
2086 call assert_equal(getline('.'), " foo ")
2087
2088 %bwipe!
2089endfunc
2090
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002091" Test for using ~ for home directory in cmdline completion matches
2092func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002093 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002094 call writefile([], 'Xexpdir/Xfile1')
2095 call writefile([], 'Xexpdir/Xfile2')
2096 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002097 let save_HOME = $HOME
2098 let $HOME = getcwd()
2099 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
2100 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
2101 let $HOME = save_HOME
2102 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002103endfunc
2104
Bram Moolenaar578fe942020-02-27 21:32:51 +01002105" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
2106" or insert mode (when 'insertmode' is set)
2107func Test_cmdline_ctrl_g()
2108 new
2109 call setline(1, 'abc')
2110 call cursor(1, 3)
2111 " If command line is entered from insert mode, using C-\ C-G should back to
2112 " insert mode
2113 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
2114 call assert_equal('abxyc', getline(1))
2115 call assert_equal(4, col('.'))
2116
2117 " If command line is entered in 'insertmode', using C-\ C-G should back to
2118 " 'insertmode'
2119 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
2120 call assert_equal('ab12xyc', getline(1))
2121 close!
2122endfunc
2123
Bram Moolenaar578fe942020-02-27 21:32:51 +01002124" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002125func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01002126 func T(a, c, p)
2127 return "oneA\noneB\noneC"
2128 endfunc
2129 command -nargs=1 -complete=custom,T MyCmd
2130
Bram Moolenaar578fe942020-02-27 21:32:51 +01002131 set nowildmenu
2132 set wildmode=full,list
2133 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002134 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002135 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002136 call assert_equal('"MyCmd oneA', @:)
2137
2138 set wildmode=longest,full
2139 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2140 call assert_equal('"MyCmd one', @:)
2141 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2142 call assert_equal('"MyCmd oneC', @:)
2143
2144 set wildmode=longest
2145 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2146 call assert_equal('"MyCmd one', @:)
2147
2148 set wildmode=list:longest
2149 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002150 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002151 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002152 call assert_equal('"MyCmd one', @:)
2153
2154 set wildmode=""
2155 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2156 call assert_equal('"MyCmd oneA', @:)
2157
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002158 " Test for wildmode=longest with 'fileignorecase' set
2159 set wildmode=longest
2160 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002161 argadd AAA AAAA AAAAA
2162 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2163 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002164 set fileignorecase&
2165
2166 " Test for listing files with wildmode=list
2167 set wildmode=list
2168 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002169 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002170 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002171 call assert_equal('"b A', @:)
2172
Girish Palya2bacc3e2025-03-02 22:55:57 +01002173 " When 'wildmenu' is not set, 'noselect' completes first item
2174 set wildmode=noselect
2175 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2176 call assert_equal('"MyCmd oneA', @:)
2177
2178 " When 'noselect' is present, do not complete first <tab>.
2179 set wildmenu
2180 set wildmode=noselect
2181 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2182 call assert_equal('"MyCmd o', @:)
2183 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2184 call assert_equal('"MyCmd o', @:)
2185 call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2186 call assert_equal('"MyCmd o', @:)
2187
2188 " When 'full' is present, complete after first <tab>.
2189 set wildmode=noselect,full
2190 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2191 call assert_equal('"MyCmd o', @:)
2192 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2193 call assert_equal('"MyCmd oneA', @:)
2194 call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt')
2195 call assert_equal('"MyCmd oneB', @:)
2196 call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2197 call assert_equal('"MyCmd oneB', @:)
2198
2199 " 'noselect' has no effect when 'longest' is present.
2200 set wildmode=noselect:longest
2201 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2202 call assert_equal('"MyCmd one', @:)
2203
2204 " Complete 'noselect' value in 'wildmode' option
2205 set wildmode&
2206 call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt')
2207 call assert_equal('"set wildmode=noselect', @:)
2208 call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt')
2209 call assert_equal('"set wildmode=noselect', @:)
2210
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002211 " when using longest completion match, matches shorter than the argument
2212 " should be ignored (happens with :help)
2213 set wildmode=longest,full
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002214 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2215 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002216 " non existing file
2217 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2218 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002219
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002220 " Test for longest file name completion with 'fileignorecase'
2221 " On MS-Windows, file names are case insensitive.
2222 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002223 call writefile([], 'XTESTfoo', 'D')
2224 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002225 set nofileignorecase
2226 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2227 call assert_equal('"e XTESTfoo', @:)
2228 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2229 call assert_equal('"e Xtestbar', @:)
2230 set fileignorecase
2231 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2232 call assert_equal('"e Xtest', @:)
2233 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2234 call assert_equal('"e Xtest', @:)
2235 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002236 endif
2237
Girish Palya2bacc3e2025-03-02 22:55:57 +01002238 " If 'noselect' is present, single item menu should not insert item
2239 func! T(a, c, p)
2240 return "oneA"
2241 endfunc
2242 command! -nargs=1 -complete=custom,T MyCmd
2243 set wildmode=noselect,full
2244 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2245 call assert_equal('"MyCmd o', @:)
2246 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2247 call assert_equal('"MyCmd oneA', @:)
2248 " 'nowildmenu' should make 'noselect' ineffective
2249 set nowildmenu
2250 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2251 call assert_equal('"MyCmd oneA', @:)
2252
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002253 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002254 delcommand MyCmd
2255 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002256 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002257 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002258endfunc
2259
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002260func Test_wildmode()
2261 " Test with utf-8 encoding
2262 call Wildmode_tests()
2263
2264 " Test with latin1 encoding
2265 let save_encoding = &encoding
2266 set encoding=latin1
2267 call Wildmode_tests()
2268 let &encoding = save_encoding
2269endfunc
2270
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002271func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002272 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002273 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002274 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002275 let lines =<< trim END
2276 func vim8#Complete(a, c, p)
2277 return "oneA\noneB\noneC"
2278 endfunc
2279 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002280 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002281
2282 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2283 set nowildmenu
2284 set wildmode=full,list
2285 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2286 call assert_equal('"MyCmd oneA oneB oneC', @:)
2287
2288 let &rtp = save_rtp
2289 set wildmode& wildmenu&
2290 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002291endfunc
2292
Bram Moolenaar578fe942020-02-27 21:32:51 +01002293" Test for interrupting the command-line completion
2294func Test_interrupt_compl()
2295 func F(lead, cmdl, p)
2296 if a:lead =~ 'tw'
2297 call interrupt()
2298 return
2299 endif
2300 return "one\ntwo\nthree"
2301 endfunc
2302 command -nargs=1 -complete=custom,F Tcmd
2303
2304 set nowildmenu
2305 set wildmode=full
2306 let interrupted = 0
2307 try
2308 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2309 catch /^Vim:Interrupt$/
2310 let interrupted = 1
2311 endtry
2312 call assert_equal(1, interrupted)
2313
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002314 let interrupted = 0
2315 try
2316 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2317 catch /^Vim:Interrupt$/
2318 let interrupted = 1
2319 endtry
2320 call assert_equal(1, interrupted)
2321
Bram Moolenaar578fe942020-02-27 21:32:51 +01002322 delcommand Tcmd
2323 delfunc F
2324 set wildmode&
2325endfunc
2326
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002327" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002328func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002329 let str = ":one two\<C-U>"
2330 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002331 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002332 let str ..= "\<Left>five\<Right>"
2333 let str ..= "\<Home>two "
2334 let str ..= "\<C-Left>one "
2335 let str ..= "\<C-Right> three"
2336 let str ..= "\<End>\<S-Left>four "
2337 let str ..= "\<S-Right> six"
2338 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2339 call feedkeys(str, 'xt')
2340 call assert_equal("\"one two three four five six seven", @:)
2341endfunc
2342
2343" Test for moving the cursor on the / command line in 'rightleft' mode
2344func Test_cmdline_edit_rightleft()
2345 CheckFeature rightleft
2346 set rightleft
2347 set rightleftcmd=search
2348 let str = "/one two\<C-U>"
2349 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002350 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002351 let str ..= "\<Right>five\<Left>"
2352 let str ..= "\<Home>two "
2353 let str ..= "\<C-Right>one "
2354 let str ..= "\<C-Left> three"
2355 let str ..= "\<End>\<S-Right>four "
2356 let str ..= "\<S-Left> six"
2357 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2358 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2359 call assert_equal("\"one two three four five six seven", @/)
2360 set rightleftcmd&
2361 set rightleft&
2362endfunc
2363
2364" Test for using <C-\>e in the command line to evaluate an expression
2365func Test_cmdline_expr()
2366 " Evaluate an expression from the beginning of a command line
2367 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2368 call assert_equal('"hello', @:)
2369
2370 " Use an invalid expression for <C-\>e
2371 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2372
2373 " Insert literal <CTRL-\> in the command line
2374 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2375 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002376endfunc
2377
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002378" This was making the insert position negative
2379func Test_cmdline_expr_register()
2380 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2381endfunc
2382
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002383" Test for 'imcmdline' and 'imsearch'
2384" This test doesn't actually test the input method functionality.
2385func Test_cmdline_inputmethod()
2386 new
2387 call setline(1, ['', 'abc', ''])
2388 set imcmdline
2389
2390 call feedkeys(":\"abc\<CR>", 'xt')
2391 call assert_equal("\"abc", @:)
2392 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2393 call assert_equal("\"abc", @:)
2394 call feedkeys("/abc\<CR>", 'xt')
2395 call assert_equal([2, 1], [line('.'), col('.')])
2396 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2397 call assert_equal([2, 1], [line('.'), col('.')])
2398
2399 set imsearch=2
2400 call cursor(1, 1)
2401 call feedkeys("/abc\<CR>", 'xt')
2402 call assert_equal([2, 1], [line('.'), col('.')])
2403 call cursor(1, 1)
2404 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2405 call assert_equal([2, 1], [line('.'), col('.')])
2406 set imdisable
2407 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2408 call assert_equal([2, 1], [line('.'), col('.')])
2409 set imdisable&
2410 set imsearch&
2411
2412 set imcmdline&
2413 %bwipe!
2414endfunc
2415
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002416" Test for using CTRL-_ in the command line with 'allowrevins'
2417func Test_cmdline_revins()
2418 CheckNotMSWindows
2419 CheckFeature rightleft
2420 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2421 call assert_equal("\"abc\<c-_>", @:)
2422 set allowrevins
2423 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2424 call assert_equal('"abcñèæ', @:)
2425 set allowrevins&
2426endfunc
2427
2428" Test for typing UTF-8 composing characters in the command line
2429func Test_cmdline_composing_chars()
2430 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2431 call assert_equal('"ゔ', @:)
2432endfunc
2433
Bram Moolenaar0e717042020-04-27 19:29:01 +02002434" test that ";" works to find a match at the start of the first line
2435func Test_zero_line_search()
2436 new
2437 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2438 call cursor(1,1)
2439 0;/pattern/d
2440 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2441 q!
2442endfunc
2443
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002444func Test_read_shellcmd()
2445 CheckUnix
2446 if executable('ls')
2447 " There should be ls in the $PATH
2448 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2449 call assert_match('^"r! .*\<ls\>', @:)
2450 endif
2451
2452 if executable('rm')
2453 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2454 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2455 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002456
2457 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2458 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2459 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002460 endif
2461endfunc
2462
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002463" Test for going up and down the directory tree using 'wildmenu'
2464func Test_wildmenu_dirstack()
2465 CheckUnix
2466 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002467 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002468 call writefile([], 'Xwildmenu/file1_1.txt')
2469 call writefile([], 'Xwildmenu/file1_2.txt')
2470 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2471 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2472 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2473 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2474 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2475 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002476 set wildmenu
2477
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002478 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002479 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002480 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002481 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002482 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002483 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002484 call assert_equal('"e ../../dir3/', @:)
2485 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2486 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002487 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002488 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002489 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002490 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002491 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002492 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2493 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002494
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002495 set wildmenu&
2496endfunc
2497
obcat71c6f7a2021-05-13 20:23:10 +02002498" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002499" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2500" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002501func Test_recalling_cmdline()
2502 CheckFeature cmdline_hist
2503
2504 let g:cmdlines = []
2505 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2506
2507 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002508 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2509 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2510 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2511 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002512 "\ TODO: {'name': 'debug', ...}
2513 \]
2514 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002515 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2516 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2517 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2518 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2519 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002520 \]
2521 let prefix = 'vi'
2522 for h in histories
2523 call histadd(h.name, 'vim')
2524 call histadd(h.name, 'virtue')
2525 call histadd(h.name, 'Virgo')
2526 call histadd(h.name, 'vogue')
2527 call histadd(h.name, 'emacs')
2528 for k in keypairs
2529 let g:cmdlines = []
2530 let keyseqs = h.enter
2531 \ .. prefix
2532 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2533 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2534 \ .. h.exit
2535 call feedkeys(keyseqs, 'xt')
2536 call histdel(h.name, -1) " delete the history added by feedkeys above
2537 let expect = k.prefixmatch
2538 \ ? ['virtue', 'vim', 'virtue', prefix]
2539 \ : ['emacs', 'vogue', 'emacs', prefix]
2540 call assert_equal(expect, g:cmdlines)
2541 endfor
2542 endfor
2543
2544 unlet g:cmdlines
2545 cunmap <Plug>(save-cmdline)
2546endfunc
2547
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002548func Test_cmd_map_cmdlineChanged()
2549 let g:log = []
2550 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002551 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002552 autocmd!
2553 autocmd CmdlineChanged : let g:log += [getcmdline()]
2554 augroup END
2555
2556 call feedkeys(":\<F1>\<CR>", 'xt')
2557 call assert_equal(['l', 'ls'], g:log)
2558
Bram Moolenaar796139a2021-05-18 21:38:45 +02002559 let @b = 'b'
2560 cnoremap <F1> a<C-R>b
2561 let g:log = []
2562 call feedkeys(":\<F1>\<CR>", 'xt')
2563 call assert_equal(['a', 'ab'], g:log)
2564
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002565 unlet g:log
2566 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002567 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002568 autocmd!
2569 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002570 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002571endfunc
2572
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002573" Test for the 'suffixes' option
2574func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002575 call writefile([], 'Xsuffile', 'D')
2576 call writefile([], 'Xsuffile.c', 'D')
2577 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002578 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002579 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2580 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2581 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2582 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002583 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002584 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2585 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2586 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2587 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002588 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002589 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2590 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2591 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2592 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002593 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002594 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002595 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2596 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002597endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002598
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002599" Test for using a popup menu for the command line completion matches
2600" (wildoptions=pum)
2601func Test_wildmenu_pum()
2602 CheckRunVimInTerminal
2603
2604 let commands =<< trim [CODE]
2605 set wildmenu
2606 set wildoptions=pum
2607 set shm+=I
2608 set noruler
2609 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002610
2611 func CmdCompl(a, b, c)
2612 return repeat(['aaaa'], 120)
2613 endfunc
2614 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002615
2616 func MyStatusLine() abort
2617 return 'status'
2618 endfunc
2619 func SetupStatusline()
2620 set statusline=%!MyStatusLine()
2621 set laststatus=2
2622 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002623
2624 func MyTabLine()
2625 return 'my tab line'
2626 endfunc
2627 func SetupTabline()
2628 set statusline=
2629 set tabline=%!MyTabLine()
2630 set showtabline=2
2631 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002632
2633 func DoFeedKeys()
2634 let &wildcharm = char2nr("\t")
2635 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2636 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002637 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002638 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002639
2640 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2641
2642 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002643 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2644
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002645 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002646 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002647 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2648
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002649 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002650 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002651 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2652
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002653 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002654 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002655 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2656
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002657 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002658 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002659 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2660
2661 " pressing <C-E> should end completion and go back to the original match
2662 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002663 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2664
2665 " pressing <C-Y> should select the current match and end completion
2666 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002667 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2668
2669 " With 'wildmode' set to 'longest,full', completing a match should display
2670 " the longest match, the wildmenu should not be displayed.
2671 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2672 call TermWait(buf)
2673 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002674 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2675
2676 " pressing <Tab> should display the wildmenu
2677 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002678 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2679
2680 " pressing <Tab> second time should select the next entry in the menu
2681 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002682 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2683
2684 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002685 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002686 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002687 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2688
2689 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002690 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2691
2692 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002693 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2694
2695 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002696 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002697 call writefile([], 'Xnamedir/XfileA')
2698 call writefile([], 'Xnamedir/XdirA/XfileB')
2699 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002700
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002701 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002702 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2703
2704 " Pressing <Right> on a directory name should go into that directory
2705 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002706 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2707
2708 " Pressing <Left> on a directory name should go to the parent directory
2709 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002710 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2711
2712 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002713 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002714 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002715 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2716
2717 " Pressing <C-D> when the popup menu is displayed should remove the popup
2718 " menu
2719 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002720 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2721
2722 " Pressing <S-Tab> should open the popup menu with the last entry selected
2723 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002724 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2725
2726 " Pressing <Esc> should close the popup menu and cancel the cmd line
2727 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002728 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2729
2730 " Typing a character when the popup is open, should close the popup
2731 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002732 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2733
2734 " When the popup is open, entering the cmdline window should close the popup
2735 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002736 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2737 call term_sendkeys(buf, ":q\<CR>")
2738
2739 " After the last popup menu item, <C-N> should show the original string
2740 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002741 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2742
2743 " Use the popup menu for the command name
2744 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002745 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2746
2747 " Pressing the left arrow should remove the popup menu
2748 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002749 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2750
2751 " Pressing <BS> should remove the popup menu and erase the last character
2752 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002753 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2754
2755 " Pressing <C-W> should remove the popup menu and erase the previous word
2756 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002757 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2758
2759 " Pressing <C-U> should remove the popup menu and erase the entire line
2760 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002761 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2762
2763 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2764 " the cmdline from history
2765 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002766 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2767
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002768 " Check "list" still works
2769 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2770 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002771 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2772 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002773 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2774
rbtnn68cc2b82022-02-09 11:55:47 +00002775 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002776 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002777 call writefile([], 'Xnamedir/あいう/abc')
2778 call writefile([], 'Xnamedir/あいう/xyz')
2779 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002780
2781 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002782 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002783 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2784
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002785 " Pressing <C-A> when the popup menu is displayed should list all the
2786 " matches and pressing a key after that should remove the popup menu
2787 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2788 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2789 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2790
2791 " Pressing <C-A> when the popup menu is displayed should list all the
2792 " matches and pressing <Left> after that should move the cursor
2793 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2794 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2795 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2796
2797 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2798 " should be displayed correctly on the screen.
2799 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2800 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2801
2802 " After using <C-A> to expand all the filename matches, pressing <Up>
2803 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002804 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002805 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2806 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2807 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2808
2809 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2810 " crash Vim
2811 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2812 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2813
Bram Moolenaar414acd32022-02-10 21:09:45 +00002814 " After removing the pum the command line is redrawn
2815 call term_sendkeys(buf, ":edit foo\<CR>")
2816 call term_sendkeys(buf, ":edit bar\<CR>")
2817 call term_sendkeys(buf, ":ls\<CR>")
2818 call term_sendkeys(buf, ":com\<Tab> ")
2819 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002820 call term_sendkeys(buf, "\<C-U>\<CR>")
2821
2822 " Esc still works to abort the command when 'statusline' is set
2823 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2824 call term_sendkeys(buf, ":si\<Tab>")
2825 call term_sendkeys(buf, "\<Esc>")
2826 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002827
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002828 " Esc still works to abort the command when 'tabline' is set
2829 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2830 call term_sendkeys(buf, ":si\<Tab>")
2831 call term_sendkeys(buf, "\<Esc>")
2832 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2833
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002834 " popup is cleared also when 'lazyredraw' is set
2835 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2836 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2837 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2838 call term_sendkeys(buf, "\<Esc>")
2839
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002840 " Pressing <PageDown> should scroll the menu downward
2841 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2842 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2843 call term_sendkeys(buf, "\<PageDown>")
2844 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2845 call term_sendkeys(buf, "\<PageDown>")
2846 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2847 call term_sendkeys(buf, "\<PageDown>")
2848 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2849 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2850 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2851
2852 " Pressing <PageUp> should scroll the menu upward
2853 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2854 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2855 call term_sendkeys(buf, "\<PageUp>")
2856 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2857 call term_sendkeys(buf, "\<PageUp>")
2858 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2859 call term_sendkeys(buf, "\<PageUp>")
2860 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2861
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002862 " pressing <C-E> to end completion should work in middle of the line too
2863 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2864 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2865 call term_sendkeys(buf, "\<C-E>")
2866 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2867
2868 " pressing <C-Y> should select the current match and end completion
2869 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2870 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2871
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002872 call term_sendkeys(buf, "\<C-U>\<CR>")
2873 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002874endfunc
2875
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002876" Test for wildmenumode() with the cmdline popup menu
2877func Test_wildmenumode_with_pum()
2878 set wildmenu
2879 set wildoptions=pum
2880 cnoremap <expr> <F2> wildmenumode()
2881 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2882 call assert_equal('"sign define10', @:)
2883 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2884 call assert_equal('"sign define jump list place undefine unplace0', @:)
2885 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2886 call assert_equal('"sign 0', @:)
2887 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2888 call assert_equal('"sign define0', @:)
2889 set nowildmenu wildoptions&
2890 cunmap <F2>
2891endfunc
2892
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002893func Test_wildmenu_with_pum_foldexpr()
2894 CheckRunVimInTerminal
2895
2896 let lines =<< trim END
2897 call setline(1, ['folded one', 'folded two', 'some more text'])
2898 func MyFoldText()
2899 return 'foo'
2900 endfunc
2901 set foldtext=MyFoldText() wildoptions=pum
2902 normal ggzfj
2903 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002904 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002905 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2906 call term_sendkeys(buf, ":set\<Tab>")
2907 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2908
2909 call term_sendkeys(buf, "\<Esc>")
2910 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2911
2912 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002913endfunc
2914
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002915" Test for opening the cmdline completion popup menu from the terminal window.
2916" The popup menu should be positioned correctly over the status line of the
2917" bottom-most window.
2918func Test_wildmenu_pum_from_terminal()
2919 CheckRunVimInTerminal
2920 let python = PythonProg()
2921 call CheckPython(python)
2922
2923 %bw!
2924 let cmds = ['set wildmenu wildoptions=pum']
2925 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2926 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002927 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002928 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2929 call term_sendkeys(buf, "\r\r\r")
2930 call term_wait(buf)
2931 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2932 call term_wait(buf)
2933 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2934 call term_wait(buf)
2935 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002936endfunc
2937
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002938func Test_wildmenu_pum_odd_wildchar()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002939 CheckRunVimInTerminal
2940
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002941 " Test odd wildchar interactions with pum. Make sure they behave properly
2942 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002943 let lines =<< trim END
2944 set wildoptions=pum
2945 set wildchar=<C-E>
2946 END
2947 call writefile(lines, 'XwildmenuTest', 'D')
2948 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2949
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002950 call term_sendkeys(buf, ":\<C-E>")
2951 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002952
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002953 " <C-E> being a wildchar takes priority over its original functionality
2954 call term_sendkeys(buf, "\<C-E>")
2955 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2956
2957 call term_sendkeys(buf, "\<Esc>")
2958 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2959
2960 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
2961 " command-line, and we need to make sure to clean up properly.
2962 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
2963 call term_sendkeys(buf, ":\<Esc>")
2964 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2965
2966 call term_sendkeys(buf, "\<Esc>")
2967 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2968
2969 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
2970 " and we again need to make sure we clean up properly.
2971 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
2972 call term_sendkeys(buf, ":\<C-\>\<C-\>")
2973 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2974
2975 call term_sendkeys(buf, "\<C-N>")
2976 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2977
2978 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002979endfunc
2980
zeertzjq883018f2024-06-15 15:37:11 +02002981" Test that 'rightleft' should not affect cmdline completion popup menu.
2982func Test_wildmenu_pum_rightleft()
2983 CheckFeature rightleft
2984 CheckScreendump
2985
2986 let lines =<< trim END
2987 set wildoptions=pum
2988 set rightleft
2989 END
2990 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
2991 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
2992
2993 call term_sendkeys(buf, ":sign \<Tab>")
2994 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
2995
2996 call StopVimInTerminal(buf)
2997endfunc
2998
Girish Palya4ec46f32025-03-04 20:56:30 +01002999" Test highlighting when pattern matches non-first character of item
3000func Test_wildmenu_pum_hl_nonfirst()
3001 CheckScreendump
3002 let lines =<< trim END
3003 set wildoptions=pum wildchar=<tab> wildmode=noselect,full
3004 hi PmenuMatchSel ctermfg=6 ctermbg=7
3005 hi PmenuMatch ctermfg=4 ctermbg=225
3006 func T(a, c, p)
3007 return ["oneA", "o neBneB", "aoneC"]
3008 endfunc
3009 command -nargs=1 -complete=customlist,T MyCmd
3010 END
3011
3012 call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D')
3013 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50})
3014
3015 call term_sendkeys(buf, ":MyCmd ne\<tab>")
3016 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {})
3017 call term_sendkeys(buf, "\<Esc>")
3018 call StopVimInTerminal(buf)
3019endfunc
3020
zeertzjqd8c93402024-06-17 18:25:32 +02003021" Test highlighting matched text in cmdline completion popup menu.
3022func Test_wildmenu_pum_hl_match()
3023 CheckScreendump
3024
3025 let lines =<< trim END
3026 set wildoptions=pum,fuzzy
3027 hi PmenuMatchSel ctermfg=6 ctermbg=7
3028 hi PmenuMatch ctermfg=4 ctermbg=225
3029 END
3030 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
3031 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
3032
3033 call term_sendkeys(buf, ":sign plc\<Tab>")
3034 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
3035 call term_sendkeys(buf, "\<Tab>")
3036 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
3037 call term_sendkeys(buf, "\<Tab>")
3038 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
3039 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
3040 call TermWait(buf)
3041 call term_sendkeys(buf, ":sign un\<Tab>")
3042 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
3043 call term_sendkeys(buf, "\<Tab>")
3044 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
3045 call term_sendkeys(buf, "\<Tab>")
3046 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
3047 call term_sendkeys(buf, "\<Esc>")
3048
3049 call StopVimInTerminal(buf)
3050endfunc
3051
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003052" Test for completion after a :substitute command followed by a pipe (|)
3053" character
3054func Test_cmdline_complete_substitute()
3055 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
3056 call assert_equal("\"s | \t", @:)
3057 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
3058 call assert_equal("\"s/ | \t", @:)
3059 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
3060 call assert_equal("\"s/one | \t", @:)
3061 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
3062 call assert_equal("\"s/one/ | \t", @:)
3063 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
3064 call assert_equal("\"s/one/two | \t", @:)
3065 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
3066 call assert_equal('"s/one/two/ | chistory', @:)
3067 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
3068 call assert_equal("\"s/one/two/g \t", @:)
3069 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
3070 call assert_equal("\"s/one/two/g | chistory", @:)
3071 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
3072 call assert_equal("\"s/one/t\\/ | \t", @:)
3073 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
3074 call assert_equal('"s/one/t"o/ | chistory', @:)
3075 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
3076 call assert_equal('"s/one/t|o/ | chistory', @:)
3077 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
3078 call assert_equal("\"&\t", @:)
3079endfunc
3080
3081" Test for the :dlist command completion
3082func Test_cmdline_complete_dlist()
3083 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
3084 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
3085 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
3086 call assert_equal("\"dlist 10 /pat/ \t", @:)
3087 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
3088 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
3089 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
3090 call assert_equal("\"dlist 10 /pat\\\t", @:)
3091 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
3092 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
3093endfunc
3094
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003095" argument list (only for :argdel) fuzzy completion
3096func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003097 argadd change.py count.py charge.py
3098 set wildoptions&
3099 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3100 call assert_equal('"argdel cge', @:)
3101 set wildoptions=fuzzy
3102 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3103 call assert_equal('"argdel change.py charge.py', @:)
3104 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003105 set wildoptions&
3106endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003107
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003108" autocmd group name fuzzy completion
3109func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003110 set wildoptions&
3111 augroup MyFuzzyGroup
3112 augroup END
3113 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3114 call assert_equal('"augroup mfg', @:)
3115 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3116 call assert_equal('"augroup MyFuzzyGroup', @:)
3117 set wildoptions=fuzzy
3118 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3119 call assert_equal('"augroup MyFuzzyGroup', @:)
3120 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal('"augroup My*p', @:)
3122 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003123 set wildoptions&
3124endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003125
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003126" buffer name fuzzy completion
3127func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003128 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003129 " Use a long name to reduce the risk of matching a random directory name
3130 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003131 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003132 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3133 call assert_equal('"b SRFWL', @:)
3134 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3135 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003136 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003137 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3139 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003141 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003142 set wildoptions&
3143endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003144
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003145" buffer name (full path) fuzzy completion
3146func Test_fuzzy_completion_bufname_fullpath()
3147 CheckUnix
3148 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003149 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003150 edit Xcmd/Xstate/Xfile.js
3151 cd Xcmd/Xstate
3152 enew
3153 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3154 call assert_equal('"b CmdStateFile', @:)
3155 set wildoptions=fuzzy
3156 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3157 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
3158 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003159 set wildoptions&
3160endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003161
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003162" :behave suboptions fuzzy completion
3163func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003164 set wildoptions&
3165 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3166 call assert_equal('"behave xm', @:)
3167 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3168 call assert_equal('"behave xterm', @:)
3169 set wildoptions=fuzzy
3170 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3171 call assert_equal('"behave xterm', @:)
3172 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3173 call assert_equal('"behave xt*m', @:)
3174 let g:Sline = ''
3175 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
3176 call assert_equal('mswin', g:Sline)
3177 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003178 set wildoptions&
3179endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003180
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003181" " colorscheme name fuzzy completion - NOT supported
3182" func Test_fuzzy_completion_colorscheme()
3183" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003184
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003185" built-in command name fuzzy completion
3186func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003187 set wildoptions&
3188 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3189 call assert_equal('"sbwin', @:)
3190 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3191 call assert_equal('"sbrewind', @:)
3192 set wildoptions=fuzzy
3193 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3194 call assert_equal('"sbrewind', @:)
3195 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3196 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003197 set wildoptions&
3198endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003199
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003200" " compiler name fuzzy completion - NOT supported
3201" func Test_fuzzy_completion_compiler()
3202" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003203
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003204" :cscope suboptions fuzzy completion
3205func Test_fuzzy_completion_cscope()
3206 CheckFeature cscope
3207 set wildoptions&
3208 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3209 call assert_equal('"cscope ret', @:)
3210 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3211 call assert_equal('"cscope reset', @:)
3212 set wildoptions=fuzzy
3213 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3214 call assert_equal('"cscope reset', @:)
3215 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3216 call assert_equal('"cscope re*t', @:)
3217 set wildoptions&
3218endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003219
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003220" :diffget/:diffput buffer name fuzzy completion
3221func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003222 new SomeBuffer
3223 diffthis
3224 new OtherBuffer
3225 diffthis
3226 set wildoptions&
3227 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal('"diffget sbuf', @:)
3229 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3230 call assert_equal('"diffput sbuf', @:)
3231 set wildoptions=fuzzy
3232 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3233 call assert_equal('"diffget SomeBuffer', @:)
3234 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3235 call assert_equal('"diffput SomeBuffer', @:)
3236 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003237 set wildoptions&
3238endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003239
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003240" " directory name fuzzy completion - NOT supported
3241" func Test_fuzzy_completion_dirname()
3242" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003243
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003244" environment variable name fuzzy completion
3245func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003246 set wildoptions&
3247 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3248 call assert_equal('"echo $VUT', @:)
3249 set wildoptions=fuzzy
3250 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3251 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003252 set wildoptions&
3253endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003254
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003255" autocmd event fuzzy completion
3256func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003257 set wildoptions&
3258 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3259 call assert_equal('"autocmd BWout', @:)
3260 set wildoptions=fuzzy
3261 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3262 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003263 set wildoptions&
3264endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003265
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003266" vim expression fuzzy completion
3267func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003268 let g:PerPlaceCount = 10
3269 set wildoptions&
3270 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3271 call assert_equal('"let c = ppc', @:)
3272 set wildoptions=fuzzy
3273 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3274 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003275 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003276endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003277
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003278" " file name fuzzy completion - NOT supported
3279" func Test_fuzzy_completion_filename()
3280" endfunc
3281
3282" " files in path fuzzy completion - NOT supported
3283" func Test_fuzzy_completion_filesinpath()
3284" endfunc
3285
3286" " filetype name fuzzy completion - NOT supported
3287" func Test_fuzzy_completion_filetype()
3288" endfunc
3289
3290" user defined function name completion
3291func Test_fuzzy_completion_userdefined_func()
3292 set wildoptions&
3293 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3294 call assert_equal('"call Test_f_u_f', @:)
3295 set wildoptions=fuzzy
3296 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3297 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3298 set wildoptions&
3299endfunc
3300
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003301" <SNR> functions should be sorted to the end
3302func Test_fuzzy_completion_userdefined_snr_func()
3303 func s:Sendmail()
3304 endfunc
3305 func SendSomemail()
3306 endfunc
3307 func S1e2n3dmail()
3308 endfunc
3309 set wildoptions=fuzzy
3310 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003311 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003312 set wildoptions&
3313 delfunc s:Sendmail
3314 delfunc SendSomemail
3315 delfunc S1e2n3dmail
3316endfunc
3317
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003318" user defined command name completion
3319func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003320 set wildoptions&
3321 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3322 call assert_equal('"MsFeat', @:)
3323 set wildoptions=fuzzy
3324 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3325 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003326 set wildoptions&
3327endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003328
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003329" " :help tag fuzzy completion - NOT supported
3330" func Test_fuzzy_completion_helptag()
3331" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003332
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003333" highlight group name fuzzy completion
3334func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003335 set wildoptions&
3336 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3337 call assert_equal('"highlight SKey', @:)
3338 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3339 call assert_equal('"highlight SpecialKey', @:)
3340 set wildoptions=fuzzy
3341 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3342 call assert_equal('"highlight SpecialKey', @:)
3343 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3344 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003345 set wildoptions&
3346endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003347
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003348" :history suboptions fuzzy completion
3349func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003350 set wildoptions&
3351 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3352 call assert_equal('"history dg', @:)
3353 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3354 call assert_equal('"history search', @:)
3355 set wildoptions=fuzzy
3356 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3357 call assert_equal('"history debug', @:)
3358 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3359 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003360 set wildoptions&
3361endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003362
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003363" :language locale name fuzzy completion
3364func Test_fuzzy_completion_lang()
3365 CheckUnix
3366 set wildoptions&
3367 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3368 call assert_equal('"lang psx', @:)
3369 set wildoptions=fuzzy
3370 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3371 call assert_equal('"lang POSIX', @:)
3372 set wildoptions&
3373endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003374
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003375" :mapclear buffer argument fuzzy completion
3376func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003377 set wildoptions&
3378 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3379 call assert_equal('"mapclear buf', @:)
3380 set wildoptions=fuzzy
3381 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3382 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003383 set wildoptions&
3384endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003385
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003386" map name fuzzy completion
3387func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003388 " test regex completion works
3389 set wildoptions=fuzzy
3390 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3391 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003392 nmap <plug>MyLongMap :p<CR>
3393 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3394 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3395 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3396 call assert_equal("\"nmap MLM \t", @:)
3397 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3398 call assert_equal("\"nmap <F2> one two \t", @:)
3399 " duplicate entries should be removed
3400 vmap <plug>MyLongMap :<C-U>#<CR>
3401 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3402 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3403 nunmap <plug>MyLongMap
3404 vunmap <plug>MyLongMap
3405 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3406 call assert_equal("\"nmap ABC\t", @:)
3407 " results should be sorted by best match
3408 nmap <Plug>format :
3409 nmap <Plug>goformat :
3410 nmap <Plug>TestFOrmat :
3411 nmap <Plug>fendoff :
3412 nmap <Plug>state :
3413 nmap <Plug>FendingOff :
3414 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3415 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3416 nunmap <Plug>format
3417 nunmap <Plug>goformat
3418 nunmap <Plug>TestFOrmat
3419 nunmap <Plug>fendoff
3420 nunmap <Plug>state
3421 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003422 set wildoptions&
3423endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003424
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003425" abbreviation fuzzy completion
3426func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003427 set wildoptions=fuzzy
3428 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3429 call assert_equal("\"iabbr <nowait>", @:)
3430 iabbr WaitForCompletion WFC
3431 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3432 call assert_equal("\"iabbr WaitForCompletion", @:)
3433 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3434 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003435
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003436 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003437 set wildoptions&
3438endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003439
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003440" menu name fuzzy completion
3441func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003442 CheckFeature menu
3443
3444 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003445 set wildoptions&
3446 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3447 call assert_equal('"menu pup', @:)
3448 set wildoptions=fuzzy
3449 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3450 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003451
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003452 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003453 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003454endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003455
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003456" :messages suboptions fuzzy completion
3457func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003458 set wildoptions&
3459 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3460 call assert_equal('"messages clr', @:)
3461 set wildoptions=fuzzy
3462 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3463 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003464 set wildoptions&
3465endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003466
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003467" :set option name fuzzy completion
3468func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003469 set wildoptions&
3470 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3471 call assert_equal('"set brkopt', @:)
3472 set wildoptions=fuzzy
3473 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3474 call assert_equal('"set breakindentopt', @:)
3475 set wildoptions&
3476 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3477 call assert_equal('"set fixendofline', @:)
3478 set wildoptions=fuzzy
3479 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3480 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003481 set wildoptions&
3482endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003483
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003484" :set <term_option>
3485func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003486 set wildoptions&
3487 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3488 call assert_equal('"set t_EC', @:)
3489 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3490 call assert_equal('"set <t_EC>', @:)
3491 set wildoptions=fuzzy
3492 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3493 call assert_equal('"set t_EC', @:)
3494 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3495 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003496 set wildoptions&
3497endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003498
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003499" " :packadd directory name fuzzy completion - NOT supported
3500" func Test_fuzzy_completion_packadd()
3501" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003502
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003503" " shell command name fuzzy completion - NOT supported
3504" func Test_fuzzy_completion_shellcmd()
3505" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003506
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003507" :sign suboptions fuzzy completion
3508func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003509 set wildoptions&
3510 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3511 call assert_equal('"sign ufe', @:)
3512 set wildoptions=fuzzy
3513 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3514 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003515 set wildoptions&
3516endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003517
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003518" :syntax suboptions fuzzy completion
3519func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003520 set wildoptions&
3521 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3522 call assert_equal('"syntax kwd', @:)
3523 set wildoptions=fuzzy
3524 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3525 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003526 set wildoptions&
3527endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003528
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003529" syntax group name fuzzy completion
3530func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003531 set wildoptions&
3532 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3533 call assert_equal('"syntax list mpar', @:)
3534 set wildoptions=fuzzy
3535 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3536 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003537 set wildoptions&
3538endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003539
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003540" :syntime suboptions fuzzy completion
3541func Test_fuzzy_completion_syntime()
3542 CheckFeature profile
3543 set wildoptions&
3544 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3545 call assert_equal('"syntime clr', @:)
3546 set wildoptions=fuzzy
3547 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3548 call assert_equal('"syntime clear', @:)
3549 set wildoptions&
3550endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003551
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003552" " tag name fuzzy completion - NOT supported
3553" func Test_fuzzy_completion_tagname()
3554" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003555
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003556" " tag name and file fuzzy completion - NOT supported
3557" func Test_fuzzy_completion_tagfile()
3558" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003559
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003560" " user names fuzzy completion - how to test this functionality?
3561" func Test_fuzzy_completion_username()
3562" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003563
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003564" user defined variable name fuzzy completion
3565func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003566 let g:SomeVariable=10
3567 set wildoptions&
3568 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3569 call assert_equal('"let SVar', @:)
3570 set wildoptions=fuzzy
3571 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3572 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003573 set wildoptions&
3574endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003575
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003576" Test for sorting the results by the best match
3577func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003578 %bw!
3579 command T123format :
3580 command T123goformat :
3581 command T123TestFOrmat :
3582 command T123fendoff :
3583 command T123state :
3584 command T123FendingOff :
3585 set wildoptions=fuzzy
3586 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3587 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3588 delcommand T123format
3589 delcommand T123goformat
3590 delcommand T123TestFOrmat
3591 delcommand T123fendoff
3592 delcommand T123state
3593 delcommand T123FendingOff
3594 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003595 set wildoptions&
3596endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003597
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003598" Test for fuzzy completion of a command with lower case letters and a number
3599func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003600 command Foo2Bar :
3601 set wildoptions=fuzzy
3602 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3603 call assert_equal('"Foo2Bar', @:)
3604 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3605 call assert_equal('"Foo2Bar', @:)
3606 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3607 call assert_equal('"Foo2Bar', @:)
3608 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003609 set wildoptions&
3610endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003611
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003612" Test for command completion for a command starting with 'k'
3613func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003614 command KillKillKill :
3615 set wildoptions&
3616 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3617 call assert_equal("\"killkill\<Tab>", @:)
3618 set wildoptions=fuzzy
3619 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3620 call assert_equal('"KillKillKill', @:)
3621 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003622 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003623endfunc
3624
3625" Test for fuzzy completion for user defined custom completion function
3626func Test_fuzzy_completion_custom_func()
3627 func Tcompl(a, c, p)
3628 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3629 endfunc
3630 command -nargs=* -complete=custom,Tcompl Fuzzy :
3631 set wildoptions&
3632 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3633 call assert_equal("\"Fuzzy format", @:)
3634 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3635 call assert_equal("\"Fuzzy xy", @:)
3636 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3637 call assert_equal("\"Fuzzy ttt", @:)
3638 set wildoptions=fuzzy
3639 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3640 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3641 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3642 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3643 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3644 call assert_equal("\"Fuzzy xy", @:)
3645 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3646 call assert_equal("\"Fuzzy TestFOrmat", @:)
3647 delcom Fuzzy
3648 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003649endfunc
3650
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003651" Test for fuzzy completion in the middle of a cmdline instead of at the end
3652func Test_fuzzy_completion_in_middle()
3653 set wildoptions=fuzzy
3654 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3655 call assert_equal("\"set wildchar wildcharm wrap", @:)
3656
3657 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3658 call assert_equal("\"args ++encoding= zz", @:)
3659 set wildoptions&
3660endfunc
3661
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003662" Test for :breakadd argument completion
3663func Test_cmdline_complete_breakadd()
3664 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3665 call assert_equal("\"breakadd expr file func here", @:)
3666 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3667 call assert_equal("\"breakadd expr", @:)
3668 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3669 call assert_equal("\"breakadd expr", @:)
3670 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3671 call assert_equal("\"breakadd here", @:)
3672 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3673 call assert_equal("\"breakadd here", @:)
3674 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3675 call assert_equal("\"breakadd abc", @:)
3676 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3677 let l = getcompletion('not', 'breakpoint')
3678 call assert_equal([], l)
3679
3680 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003681 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003682 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3683 call assert_equal("\"breakadd file Xscript", @:)
3684 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3685 call assert_equal("\"breakadd file Xscript", @:)
3686 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3687 call assert_equal("\"breakadd file 20 Xscript", @:)
3688 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3689 call assert_equal("\"breakadd file 20 Xscript", @:)
3690 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3691 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3692 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3693 call assert_equal("\"breakadd file 20\t", @:)
3694 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3695 call assert_equal("\"breakadd file 20x\t", @:)
3696 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3697 call assert_equal("\"breakadd file Xscript ", @:)
3698 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3699 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003700
3701 " Test for :breakadd func [lnum] <function>
3702 func Xbreak_func()
3703 endfunc
3704 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3705 call assert_equal("\"breakadd func Xbreak_func", @:)
3706 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3707 call assert_equal("\"breakadd func Xbreak_func", @:)
3708 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3709 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3710 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3711 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3712 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3713 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3714 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3715 call assert_equal("\"breakadd func 20\t", @:)
3716 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3717 call assert_equal("\"breakadd func 20x\t", @:)
3718 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3719 call assert_equal("\"breakadd func Xbreak_func ", @:)
3720 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3721 call assert_equal("\"breakadd func X1B2C3", @:)
3722 delfunc Xbreak_func
3723
3724 " Test for :breakadd expr <expression>
3725 let g:Xtest_var = 10
3726 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3727 call assert_equal("\"breakadd expr Xtest_var", @:)
3728 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3729 call assert_equal("\"breakadd expr Xtest_var", @:)
3730 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3731 call assert_equal("\"breakadd expr Xtest_var ", @:)
3732 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3733 call assert_equal("\"breakadd expr X1B2C3", @:)
3734 unlet g:Xtest_var
3735
3736 " Test for :breakadd here
3737 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3738 call assert_equal("\"breakadd here Xtest", @:)
3739 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3740 call assert_equal("\"breakadd here Xtest", @:)
3741 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3742 call assert_equal("\"breakadd here ", @:)
3743endfunc
3744
3745" Test for :breakdel argument completion
3746func Test_cmdline_complete_breakdel()
3747 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3748 call assert_equal("\"breakdel file func here", @:)
3749 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3750 call assert_equal("\"breakdel file", @:)
3751 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3752 call assert_equal("\"breakdel file", @:)
3753 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3754 call assert_equal("\"breakdel here", @:)
3755 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3756 call assert_equal("\"breakdel here", @:)
3757 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3758 call assert_equal("\"breakdel abc", @:)
3759
3760 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003761 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003762 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3763 call assert_equal("\"breakdel file Xscript", @:)
3764 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3765 call assert_equal("\"breakdel file Xscript", @:)
3766 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3767 call assert_equal("\"breakdel file 20 Xscript", @:)
3768 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3769 call assert_equal("\"breakdel file 20 Xscript", @:)
3770 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3771 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3772 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3773 call assert_equal("\"breakdel file 20\t", @:)
3774 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3775 call assert_equal("\"breakdel file 20x\t", @:)
3776 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3777 call assert_equal("\"breakdel file Xscript ", @:)
3778 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3779 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003780
3781 " Test for :breakdel func [lnum] <function>
3782 func Xbreak_func()
3783 endfunc
3784 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3785 call assert_equal("\"breakdel func Xbreak_func", @:)
3786 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3787 call assert_equal("\"breakdel func Xbreak_func", @:)
3788 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3789 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3790 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3791 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3792 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3793 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3794 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3795 call assert_equal("\"breakdel func 20\t", @:)
3796 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3797 call assert_equal("\"breakdel func 20x\t", @:)
3798 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3799 call assert_equal("\"breakdel func Xbreak_func ", @:)
3800 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3801 call assert_equal("\"breakdel func X1B2C3", @:)
3802 delfunc Xbreak_func
3803
3804 " Test for :breakdel here
3805 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3806 call assert_equal("\"breakdel here Xtest", @:)
3807 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3808 call assert_equal("\"breakdel here Xtest", @:)
3809 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3810 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003811endfunc
3812
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003813" Test for :scriptnames argument completion
3814func Test_cmdline_complete_scriptnames()
3815 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003816 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003817 source Xa1b2c3.vim
3818 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3819 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3820 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3821 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3822 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3823 call assert_equal("\"script b2c3", @:)
3824 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3825 call assert_match("\"script 2\<Tab>$", @:)
3826 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3827 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3828 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3829 call assert_equal("\"script ", @:)
3830 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3831 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3832 new
3833 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3834 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3835 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003836 set wildmenu&
3837endfunc
3838
Bram Moolenaard8893442022-05-06 20:38:47 +01003839" this was going over the end of IObuff
3840func Test_report_error_with_composing()
3841 let caught = 'no'
3842 try
3843 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3844 catch /E492:/
3845 let caught = 'yes'
3846 endtry
3847 call assert_equal('yes', caught)
3848endfunc
3849
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003850" Test for expanding 2-letter and 3-letter :substitute command arguments.
3851" These commands don't accept an argument.
3852func Test_cmdline_complete_substitute_short()
3853 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3854 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3855 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3856 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3857 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3858 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3859 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3860 endfor
3861endfunc
3862
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003863" Test for shellcmdline command argument completion
3864func Test_cmdline_complete_shellcmdline_argument()
3865 command -nargs=+ -complete=shellcmdline MyCmd
3866
3867 set wildoptions=fuzzy
3868
3869 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3870 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003871 call assert_equal(['test_cmdline.vim'],
3872 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003873
3874 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3875 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003876 call assert_equal([],
3877 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003878
3879 let compl1 = getcompletion('', 'file')[0]
3880 let compl2 = getcompletion('', 'file')[1]
3881 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3882 call assert_equal('"MyCmd vim ' .. compl1, @:)
3883
3884 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3885 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3886
3887 let compl = getcompletion('', 'file')[1]
3888 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3889 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3890
3891 set wildoptions&
3892 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3893 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003894 call assert_equal(['test_cmdline.vim'],
3895 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003896
3897 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3898 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003899 call assert_equal([],
3900 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003901
3902 let compl1 = getcompletion('', 'file')[0]
3903 let compl2 = getcompletion('', 'file')[1]
3904 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3905 call assert_equal('"MyCmd vim ' .. compl1, @:)
3906
3907 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3908 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3909
3910 let compl = getcompletion('', 'file')[1]
3911 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3912 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3913
3914 delcommand MyCmd
3915endfunc
3916
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003917" Test for :! shell command argument completion
3918func Test_cmdline_complete_bang_cmd_argument()
3919 set wildoptions=fuzzy
3920 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3921 call assert_equal('"!vim test_cmdline.vim', @:)
3922 set wildoptions&
3923 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3924 call assert_equal('"!vim test_cmdline.vim', @:)
3925endfunc
3926
zeertzjq961b2e52023-04-17 15:53:24 +01003927func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003928 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003929endfunc
3930
3931func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003932 call assert_equal(0, getcmdpos())
3933 call assert_equal(0, getcmdscreenpos())
3934 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003935 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01003936
zeertzjqa821b602024-06-18 20:31:08 +02003937 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01003938 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003939 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003940 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003941 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003942 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003943 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02003944
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003945 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
3946 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02003947 let g:results = []
3948 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
3949 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
3950 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003951 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
3952 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
3953 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02003954
3955 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01003956 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003957endfunc
3958
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003959func Test_recursive_register()
3960 let @= = ''
3961 silent! ?e/
3962 let caught = 'no'
3963 try
3964 normal //
3965 catch /E169:/
3966 let caught = 'yes'
3967 endtry
3968 call assert_equal('yes', caught)
3969endfunc
3970
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003971func Test_long_error_message()
3972 " the error should be truncated, not overrun IObuff
3973 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3974endfunc
3975
zeertzjq6791adc2022-07-26 20:42:25 +01003976func Test_cmdline_redraw_tabline()
3977 CheckRunVimInTerminal
3978
3979 let lines =<< trim END
3980 set showtabline=2
3981 autocmd CmdlineEnter * set tabline=foo
3982 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003983 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003984 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3985 call term_sendkeys(buf, ':')
3986 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3987
3988 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003989endfunc
3990
zeertzjqb82a2ab2022-08-21 14:33:57 +01003991func Test_wildmenu_pum_disable_while_shown()
3992 set wildoptions=pum
3993 set wildmenu
3994 cnoremap <F2> <Cmd>set nowildmenu<CR>
3995 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3996 call assert_equal(0, pumvisible())
3997 cunmap <F2>
3998 set wildoptions& wildmenu&
3999endfunc
4000
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004001func Test_setcmdline()
4002 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01004003 call assert_equal(0, setcmdline(test_null_string()))
4004 call assert_equal('', getcmdline())
4005 call assert_equal(1, getcmdpos())
4006
4007 call assert_equal(0, setcmdline(''[: -1]))
4008 call assert_equal('', getcmdline())
4009 call assert_equal(1, getcmdpos())
4010
zeertzjq54acb902022-08-29 16:21:25 +01004011 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004012 call assert_equal(0, setcmdline(a:text))
4013 call assert_equal(a:text, getcmdline())
4014 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01004015 call assert_equal(getcmdtype(), g:cmdtype)
4016 unlet g:cmdtype
4017 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004018
4019 call assert_equal(0, setcmdline(a:text, a:pos))
4020 call assert_equal(a:text, getcmdline())
4021 call assert_equal(a:pos, getcmdpos())
4022
4023 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01004024 call assert_fails('call setcmdline({}, 0)', 'E1174:')
4025 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004026
4027 return ''
4028 endfunc
4029
4030 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
4031 call assert_equal('set rtp?', @:)
4032
zeertzjq54acb902022-08-29 16:21:25 +01004033 call feedkeys(":let g:str = input('? ')\<CR>", 't')
4034 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
4035 call assert_equal('foo', g:str)
4036 unlet g:str
4037
4038 delfunc SetText
4039
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004040 " setcmdline() returns 1 when not editing the command line.
4041 call assert_equal(1, 'foo'->setcmdline())
4042
4043 " Called in custom function
4044 func CustomComplete(A, L, P)
4045 call assert_equal(0, setcmdline("DoCmd "))
4046 return "January\nFebruary\nMars\n"
4047 endfunc
4048
4049 com! -nargs=* -complete=custom,CustomComplete DoCmd :
4050 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
4051 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01004052 delcom DoCmd
4053 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004054
4055 " Called in <expr>
4056 cnoremap <expr>a setcmdline('let foo=')
4057 call feedkeys(":a\<CR>", 'tx')
4058 call assert_equal('let foo=0', @:)
4059 cunmap a
4060endfunc
4061
Sean Dewarfc8a6012023-04-17 16:41:20 +01004062func Test_rulerformat_position()
4063 CheckScreendump
4064
4065 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
4066 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
4067 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
4068 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
4069 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
4070
4071 " clean up
4072 call StopVimInTerminal(buf)
4073endfunc
4074
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01004075" Test for using "%!" in 'rulerformat' to use a function
4076func Test_rulerformat_function()
4077 CheckScreendump
4078
4079 let lines =<< trim END
4080 func TestRulerFn()
4081 return '10,20%=30%%'
4082 endfunc
4083 END
4084 call writefile(lines, 'Xrulerformat_function', 'D')
4085
4086 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
4087 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
4088 call term_sendkeys(buf, ":redraw!\<CR>")
4089 call term_wait(buf)
4090 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
4091
4092 " clean up
4093 call StopVimInTerminal(buf)
4094endfunc
4095
zeertzjqe4c79d32023-08-15 22:41:53 +02004096func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004097 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004098
zeertzjqe4c79d32023-08-15 22:41:53 +02004099 call assert_equal(getcompletion('', 'cmdline'),
4100 \ getcompletion('TestCompletion ', 'cmdline'))
4101 call assert_equal(['<buffer>'],
4102 \ getcompletion('TestCompletion map <bu', 'cmdline'))
4103
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004104 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004105endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02004106
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004107func Test_custom_completion()
4108 func CustomComplete1(lead, line, pos)
4109 return "a\nb\nc"
4110 endfunc
4111 func CustomComplete2(lead, line, pos)
4112 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
4113 endfunc
4114 func Check_custom_completion()
4115 call assert_equal('custom,CustomComplete1', getcmdcompltype())
4116 return ''
4117 endfunc
4118 func Check_customlist_completion()
4119 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
4120 return ''
4121 endfunc
4122
4123 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
4124 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
4125
4126 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
4127 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
4128
4129 call assert_fails("call getcompletion('', 'custom')", 'E475:')
4130 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
4131
zeertzjq757f3212024-04-15 19:01:04 +02004132 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
4133 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
4134 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004135
4136 delcom Test1
4137 delcom Test2
4138
4139 delfunc CustomComplete1
4140 delfunc CustomComplete2
4141 delfunc Check_custom_completion
4142 delfunc Check_customlist_completion
4143endfunc
4144
zeertzjq28a23602023-09-29 19:58:35 +02004145func Test_custom_completion_with_glob()
4146 func TestGlobComplete(A, L, P)
4147 return split(glob('Xglob*'), "\n")
4148 endfunc
4149
4150 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
4151 call writefile([], 'Xglob1', 'D')
4152 call writefile([], 'Xglob2', 'D')
4153
4154 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
4155 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
4156
4157 delcommand TestGlobComplete
4158 delfunc TestGlobComplete
4159endfunc
4160
Christian Brabandt8610f742024-01-12 17:34:40 +01004161func Test_window_size_stays_same_after_changing_cmdheight()
4162 set laststatus=2
4163 let expected = winheight(0)
4164 function! Function_name() abort
4165 call feedkeys(":"..repeat('x', &columns), 'x')
4166 let &cmdheight=2
4167 let &cmdheight=1
4168 redraw
4169 endfunction
4170 call Function_name()
4171 call assert_equal(expected, winheight(0))
4172endfunc
4173
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01004174" verify that buffer-completion finds all buffer names matching a pattern
4175func Test_buffer_completion()
4176 " should return empty list
4177 call assert_equal([], getcompletion('', 'buffer'))
4178
4179 call mkdir('Xbuf_complete', 'R')
4180 e Xbuf_complete/Foobar.c
4181 e Xbuf_complete/MyFoobar.c
4182 e AFoobar.h
4183 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
4184
4185 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
4186 call assert_equal(expected, getcompletion('Foo', 'buffer'))
4187 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
4188 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
4189endfunc
4190
Anton Sharonov49528da2024-04-14 20:02:24 +02004191" :set t_??
4192func Test_term_option()
4193 set wildoptions&
4194 let _cpo = &cpo
4195 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004196 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02004197 let expected='"set t_AB t_AF t_AU t_AL t_al t_bc t_BE t_BD t_cd t_ce t_Ce t_CF t_cl t_cm'
4198 \ .. ' t_Co t_CS t_Cs t_cs t_CV t_da t_db t_DL t_dl t_ds t_Ds t_EC t_EI t_fs t_fd t_fe'
4199 \ .. ' t_GP t_IE t_IS t_ke t_ks t_le t_mb t_md t_me t_mr t_ms t_nd t_op t_RF t_RB t_RC'
4200 \ .. ' t_RI t_Ri t_RK t_RS t_RT t_RV t_Sb t_SC t_se t_Sf t_SH t_SI t_Si t_so t_SR t_sr'
4201 \ .. ' t_ST t_Te t_te t_TE t_ti t_TI t_Ts t_ts t_u7 t_ue t_us t_Us t_ut t_vb t_ve t_vi'
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004202 \ .. ' t_VS t_vs t_WP t_WS t_XM t_xn t_xs t_ZH t_ZR t_8f t_8b t_8u t_xo .*'
Anton Sharonov49528da2024-04-14 20:02:24 +02004203 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004204 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004205 let &cpo = _cpo
4206endfunc
4207
Christian Brabandt70a11a62024-07-26 19:13:55 +02004208func Test_ex_command_completion()
4209 " required for :*
4210 set cpo+=*
4211 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
4212 " :++ and :-- are only valid in Vim9 Script context, so they can be ignored
4213 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004214 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004215 call assert_equal(0, exists(':ke'))
4216 call assert_equal(1, exists(':kee'))
4217 call assert_equal(1, exists(':keep'))
4218 call assert_equal(1, exists(':keepm'))
4219 call assert_equal(1, exists(':keepma'))
4220 call assert_equal(1, exists(':keepmar'))
4221 call assert_equal(1, exists(':keepmark'))
4222 call assert_equal(2, exists(':keepmarks'))
4223 call assert_equal(2, exists(':keepalt'))
4224 call assert_equal(2, exists(':keepjumps'))
4225 call assert_equal(2, exists(':keeppatterns'))
4226 set cpo-=*
4227endfunc
4228
zeertzjq5df3cb22024-10-07 21:05:06 +02004229func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004230 CheckMSWindows
4231 let save_shellslash = &shellslash
4232 set noshellslash
4233 call system('mkdir XXXa\_b')
4234 defer delete('XXXa', 'rf')
4235 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4236 call assert_equal('"cd XXXa\_b\', @:)
4237 let &shellslash = save_shellslash
4238endfunc
4239
Bram Moolenaar309976e2019-12-05 18:16:33 +01004240" vim: shiftwidth=2 sts=2 expandtab