blob: dfebb400b53644b91aaf85c20289097b570399a3 [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', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100421 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000422 call assert_equal('"match none', @:)
423 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(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200431 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
432 call assert_equal('"hi default Aardig', getreg(':'))
433 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
434 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100435 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
436 call assert_equal('"hi link', getreg(':'))
437 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
438 call assert_equal('"hi default', getreg(':'))
439 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
440 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200441 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
442 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
443 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
444 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200445
446 " A cleared group does not show up in completions.
447 hi Anders ctermfg=green
448 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
449 hi clear Aardig
450 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
451 hi clear Anders
452 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100453endfunc
454
Bram Moolenaar75e15672020-06-28 13:10:22 +0200455" Test for command-line expansion of "hi Ni " (easter egg)
456func Test_highlight_easter_egg()
457 call test_override('ui_delay', 1)
458 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
459 call assert_equal("\"hi Ni \<Tab>", @:)
460 call test_override('ALL', 0)
461endfunc
462
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200463func Test_getcompletion()
464 let groupcount = len(getcompletion('', 'event'))
465 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200466 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200467 call assert_true(matchcount > 0)
468 call assert_true(groupcount > matchcount)
469
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200470 if has('menu')
471 source $VIMRUNTIME/menu.vim
472 let matchcount = len(getcompletion('', 'menu'))
473 call assert_true(matchcount > 0)
474 call assert_equal(['File.'], getcompletion('File', 'menu'))
475 call assert_true(matchcount > 0)
476 let matchcount = len(getcompletion('File.', 'menu'))
477 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000478 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200479 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200480
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200481 let l = getcompletion('v:n', 'var')
482 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200483 let l = getcompletion('v:notexists', 'var')
484 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200485
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200486 args a.c b.c
487 let l = getcompletion('', 'arglist')
488 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000489 let l = getcompletion('a.', 'buffer')
490 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200491 %argdelete
492
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200493 let l = getcompletion('', 'augroup')
494 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200495 let l = getcompletion('blahblah', 'augroup')
496 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200497
498 let l = getcompletion('', 'behave')
499 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200500 let l = getcompletion('not', 'behave')
501 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200502
503 let l = getcompletion('', 'color')
504 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200505 let l = getcompletion('dirty', 'color')
506 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200507
508 let l = getcompletion('', 'command')
509 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200510 let l = getcompletion('awake', 'command')
511 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200512
513 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200514 call assert_true(index(l, 'samples/') >= 0)
515 let l = getcompletion('NoMatch', 'dir')
516 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200517
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100518 if glob('~/*') !=# ''
519 let l = getcompletion('~/', 'dir')
520 call assert_true(l[0][0] ==# '~')
521 endif
522
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200523 let l = getcompletion('exe', 'expression')
524 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200525 let l = getcompletion('kill', 'expression')
526 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200527
528 let l = getcompletion('tag', 'function')
529 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200530 let l = getcompletion('paint', 'function')
531 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200532
Kota Kato90c23532023-01-18 15:27:38 +0000533 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000534 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000535 let l = getcompletion('ruby', 'function')
536 call assert_equal([], l)
537 endif
538
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200539 let Flambda = {-> 'hello'}
540 let l = getcompletion('', 'function')
541 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200542 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200543
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200544 let l = getcompletion('run', 'file')
545 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200546 let l = getcompletion('walk', 'file')
547 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200548 set wildignore=*.vim
549 let l = getcompletion('run', 'file', 1)
550 call assert_true(index(l, 'runtest.vim') < 0)
551 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000552 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100553 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000554 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
555 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200556
557 let l = getcompletion('ha', 'filetype')
558 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200559 let l = getcompletion('horse', 'filetype')
560 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200561
Doug Kearns81642d92024-01-04 22:37:44 +0100562 if has('keymap')
563 let l = getcompletion('acc', 'keymap')
564 call assert_true(index(l, 'accents') >= 0)
565 let l = getcompletion('nullkeymap', 'keymap')
566 call assert_equal([], l)
567 endif
568
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200569 let l = getcompletion('z', 'syntax')
570 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200571 let l = getcompletion('emacs', 'syntax')
572 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200573
574 let l = getcompletion('jikes', 'compiler')
575 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200576 let l = getcompletion('break', 'compiler')
577 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200578
579 let l = getcompletion('last', 'help')
580 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200581 let l = getcompletion('giveup', 'help')
582 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200583
584 let l = getcompletion('time', 'option')
585 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200586 let l = getcompletion('space', 'option')
587 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200588
589 let l = getcompletion('er', 'highlight')
590 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200591 let l = getcompletion('dark', 'highlight')
592 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200593
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200594 let l = getcompletion('', 'messages')
595 call assert_true(index(l, 'clear') >= 0)
596 let l = getcompletion('not', 'messages')
597 call assert_equal([], l)
598
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200599 let l = getcompletion('', 'mapclear')
600 call assert_true(index(l, '<buffer>') >= 0)
601 let l = getcompletion('not', 'mapclear')
602 call assert_equal([], l)
603
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200604 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200605 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200606 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
607 let root = has('win32') ? 'C:\\' : '/'
608 let l = getcompletion(root, 'shellcmd')
609 let expected = map(filter(glob(root . '*', 0, 1),
610 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
611 call assert_equal(expected, l)
612
Bram Moolenaarb650b982016-08-05 20:35:13 +0200613 if has('cscope')
614 let l = getcompletion('', 'cscope')
615 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
616 call assert_equal(cmds, l)
617 " using cmdline completion must not change the result
618 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
619 let l = getcompletion('', 'cscope')
620 call assert_equal(cmds, l)
621 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
622 let l = getcompletion('find ', 'cscope')
623 call assert_equal(keys, l)
624 endif
625
Bram Moolenaar7522f692016-08-06 14:12:50 +0200626 if has('signs')
627 sign define Testing linehl=Comment
628 let l = getcompletion('', 'sign')
629 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
630 call assert_equal(cmds, l)
631 " using cmdline completion must not change the result
632 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
633 let l = getcompletion('', 'sign')
634 call assert_equal(cmds, l)
635 let l = getcompletion('list ', 'sign')
636 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000637 let l = getcompletion('de*', 'sign')
638 call assert_equal(['define'], l)
639 let l = getcompletion('p?', 'sign')
640 call assert_equal(['place'], l)
641 let l = getcompletion('j.', 'sign')
642 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200643 endif
644
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200645 " Command line completion tests
646 let l = getcompletion('cd ', 'cmdline')
647 call assert_true(index(l, 'samples/') >= 0)
648 let l = getcompletion('cd NoMatch', 'cmdline')
649 call assert_equal([], l)
650 let l = getcompletion('let v:n', 'cmdline')
651 call assert_true(index(l, 'v:null') >= 0)
652 let l = getcompletion('let v:notexists', 'cmdline')
653 call assert_equal([], l)
654 let l = getcompletion('call tag', 'cmdline')
655 call assert_true(index(l, 'taglist(') >= 0)
656 let l = getcompletion('call paint', 'cmdline')
657 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200658 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
659 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200660
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100661 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000662 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100663 return "oneA\noneB\noneC"
664 endfunc
665 command -nargs=1 -complete=custom,T MyCmd
666 let l = getcompletion('MyCmd ', 'cmdline')
667 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000668 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100669
670 delcommand MyCmd
671 delfunc T
ii144785fe02021-11-21 12:13:56 +0000672 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100673
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200674 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200675 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
676 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200677 if has('cmdline_hist')
678 call add(names, 'history')
679 endif
680 if has('gettext')
681 call add(names, 'locale')
682 endif
683 if has('profile')
684 call add(names, 'syntime')
685 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200686
687 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100688 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200689
690 for name in names
691 let matchcount = len(getcompletion('', name))
692 call assert_true(matchcount >= 0, 'No matches for ' . name)
693 endfor
694
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200695 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200696
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000697 edit a~b
698 enew
699 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
700 bw a~b
701
702 if has('unix')
703 edit Xtest\
704 enew
705 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
706 bw Xtest\
707 endif
708
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100709 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200710 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100711 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200712endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200713
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000714func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000715 " Get a dialog in the GUI
716 CheckNotGui
717
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000718 " This was using uninitialized memory.
719 let lines =<< trim END
720 set verbose=6
721 norm @=ٷ
722 qall!
723 END
724 call writefile(lines, 'XmultiScript', 'D')
725 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
726endfunc
727
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000728" Test for getcompletion() with "fuzzy" in 'wildoptions'
729func Test_getcompletion_wildoptions()
730 let save_wildoptions = &wildoptions
731 set wildoptions&
732 let l = getcompletion('space', 'option')
733 call assert_equal([], l)
734 let l = getcompletion('ier', 'command')
735 call assert_equal([], l)
736 set wildoptions=fuzzy
737 let l = getcompletion('space', 'option')
738 call assert_true(index(l, 'backspace') >= 0)
739 let l = getcompletion('ier', 'command')
740 call assert_true(index(l, 'compiler') >= 0)
741 let &wildoptions = save_wildoptions
742endfunc
743
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000744func Test_complete_autoload_error()
745 let save_rtp = &rtp
746 let lines =<< trim END
747 vim9script
748 export def Complete(..._): string
749 return 'match'
750 enddef
751 echo this will cause an error
752 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100753 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000754 call writefile(lines, 'Xdir/autoload/script.vim')
755 exe 'set rtp+=' .. getcwd() .. '/Xdir'
756
757 let lines =<< trim END
758 vim9script
759 import autoload 'script.vim'
760 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
761 &wildcharm = char2nr("\<Tab>")
762 feedkeys(":Cmd \<Tab>", 'xt')
763 END
764 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
765
766 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000767endfunc
768
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100769func Test_fullcommand()
770 let tests = {
771 \ '': '',
772 \ ':': '',
773 \ ':::': '',
774 \ ':::5': '',
775 \ 'not_a_cmd': '',
776 \ 'Check': '',
777 \ 'syntax': 'syntax',
778 \ ':syntax': 'syntax',
779 \ '::::syntax': 'syntax',
780 \ 'sy': 'syntax',
781 \ 'syn': 'syntax',
782 \ 'synt': 'syntax',
783 \ ':sy': 'syntax',
784 \ '::::sy': 'syntax',
785 \ 'match': 'match',
786 \ '2match': 'match',
787 \ '3match': 'match',
788 \ 'aboveleft': 'aboveleft',
789 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100790 \ 'en': 'endif',
791 \ 'end': 'endif',
792 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100793 \ 's': 'substitute',
794 \ '5s': 'substitute',
795 \ ':5s': 'substitute',
796 \ "'<,'>s": 'substitute',
797 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100798 \ 'CheckLin': 'CheckLinux',
799 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100800 \ }
801
802 for [in, want] in items(tests)
803 call assert_equal(want, fullcommand(in))
804 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200805 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100806
807 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200808
809 command -buffer BufferLocalCommand :
810 command GlobalCommand :
811 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
812 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
813 delcommand BufferLocalCommand
814 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100815endfunc
816
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200817func Test_shellcmd_completion()
818 let save_path = $PATH
819
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100820 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200821 call writefile([''], 'Xpathdir/Xfile.exe')
822 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
823
824 " Set PATH to example directory without trailing slash.
825 let $PATH = getcwd() . '/Xpathdir'
826
827 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
828 " dirs in the PATH, even though they won't be executed. We check that only
829 " subdirs of the PWD and executables from the PATH are included in the
830 " suggestions.
831 let actual = getcompletion('X', 'shellcmd')
832 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
833 call insert(expected, 'Xfile.exe')
834 call assert_equal(expected, actual)
835
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200836 let $PATH = save_path
837endfunc
838
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200839func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100840 call mkdir('a/b/c', 'pR')
841 call writefile(['asdfasdf'], 'a/b/c/fileXname')
842 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
843 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200844 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200845endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100846
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100847func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100848 let @a = "def"
849 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
850 call assert_equal('"abc def ghi', @:)
851
852 new
853 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
854
855 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
856 call assert_equal('"aaa asdf bbb', @:)
857
858 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
859 call assert_equal('"aaa /tmp/some bbb', @:)
860
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200861 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
862 call assert_equal('"aaa '.getline(1).' bbb', @:)
863
Bram Moolenaar21efc362016-12-03 14:05:49 +0100864 set incsearch
865 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
866 call assert_equal('"aaa verylongword bbb', @:)
867
868 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
869 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100870
871 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
872 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100873 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200874
875 " Error while typing a command used to cause that it was not executed
876 " in the end.
877 new
878 try
879 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
880 catch /^Vim\%((\a\+)\)\=:E32/
881 " ignore error E32
882 endtry
883 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100884
Bram Moolenaar578fe942020-02-27 21:32:51 +0100885 " Try to paste an invalid register using <C-R>
886 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
887 call assert_equal('"onetwo', @:)
888
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100889 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100890 let @a = "xy\<C-H>z"
891 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
892 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100893 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
894 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100895 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
896 call assert_equal("\"xy\<C-H>z", @:)
897
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100898 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
899 let @a = "xy\<C-V>z"
900 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
901 call assert_equal('"xyz', @:)
902 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
903 call assert_equal("\"xy\<C-V>z", @:)
904
Bram Moolenaar578fe942020-02-27 21:32:51 +0100905 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
906
Bram Moolenaar72532d32018-04-07 19:09:09 +0200907 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100908endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100909
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100910func Test_cmdline_remove_char()
911 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100912
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100913 for e in ['utf8', 'latin1']
914 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100915
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100916 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
917 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100918
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100919 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
920 call assert_equal('"abcdef', @:)
921
922 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
923 call assert_equal('"abc ghi', @:, e)
924
925 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
926 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100927
928 " This was going before the start in latin1.
929 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100930 endfor
931
932 let &encoding = encoding_save
933endfunc
934
zeertzjqff2b79d2024-02-26 20:38:36 +0100935func Test_cmdline_del_utf8()
936 let @s = '⒌'
937 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
938 call assert_equal('",,', @:)
939
940 let @s = 'a̳'
941 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
942 call assert_equal('",,', @:)
943
944 let @s = 'β̳'
945 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
946 call assert_equal('",,', @:)
947
948 if has('arabic')
949 let @s = 'لا'
950 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
951 call assert_equal('",,', @:)
952 endif
953endfunc
954
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100955func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200956 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100957
958 set keymap=esperanto
959 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
960 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
961 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100962endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100963
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100964func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100965 new
966 2;'(
967 2;')
968 quit
969endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100970
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100971func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100972 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100973 new
974 source Xtest.vim
975 " Trigger calling validate_cursor()
976 diffsp Xtest.vim
977 quit!
978 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100979endfunc
980
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100981func Test_mark_from_line_zero()
982 " this was reading past the end of the first (empty) line
983 new
984 norm oxxxx
985 call assert_fails("0;'(", 'E20:')
986 bwipe!
987endfunc
988
Bram Moolenaarba47b512017-01-24 21:18:19 +0100989func Test_cmdline_complete_wildoptions()
990 help
991 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
992 let a = join(sort(split(@:)),' ')
993 set wildoptions=tagfile
994 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
995 let b = join(sort(split(@:)),' ')
996 call assert_equal(a, b)
997 bw!
998endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100999
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001000func Test_cmdline_complete_user_cmd()
1001 command! -complete=color -nargs=1 Foo :
1002 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1003 call assert_equal('"Foo blue', @:)
1004 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1005 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001006 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1007 call assert_equal('"Foo a blue', @:)
1008 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1009 call assert_equal('"Foo b\', @:)
1010 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1011 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001012 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001013
1014 redraw
1015 call assert_equal('~', Screenline(&lines - 1))
1016 command! FooOne :
1017 command! FooTwo :
1018
1019 set nowildmenu
1020 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1021 call assert_equal('"FooOne', @:)
1022 call assert_equal('~', Screenline(&lines - 1))
1023
1024 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1025 call assert_equal('"FooTwo', @:)
1026 call assert_equal('~', Screenline(&lines - 1))
1027
1028 delcommand FooOne
1029 delcommand FooTwo
1030 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001031endfunc
1032
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001033func Test_complete_user_cmd()
1034 command FooBar echo 'global'
1035 command -buffer FooBar echo 'local'
1036 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1037 call assert_equal('"FooBar', @:)
1038
1039 delcommand -buffer FooBar
1040 delcommand FooBar
1041endfunc
1042
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001043func s:ScriptLocalFunction()
1044 echo 'yes'
1045endfunc
1046
1047func Test_cmdline_complete_user_func()
1048 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001049 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001050 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1051 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001052
1053 " g: prefix also works
1054 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1055 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001056
1057 " using g: prefix does not result in just "g:" matches from a lambda
1058 let Fx = { a -> a }
1059 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1060 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001061
1062 " existence of script-local dict function does not break user function name
1063 " completion
1064 function s:a_dict_func() dict
1065 endfunction
1066 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1067 call assert_match('"call Test_cmdline_complete_user_', @:)
1068 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001069endfunc
1070
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001071func Test_cmdline_complete_user_names()
1072 if has('unix') && executable('whoami')
1073 let whoami = systemlist('whoami')[0]
1074 let first_letter = whoami[0]
1075 if len(first_letter) > 0
1076 " Trying completion of :e ~x where x is the first letter of
1077 " the user name should complete to at least the user name.
1078 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1079 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1080 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001081 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001082 " Just in case: check that the system has an Administrator account.
1083 let names = system('net user')
1084 if names =~ 'Administrator'
1085 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001086 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001087 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001088 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001089 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001090 else
1091 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001092 endif
1093endfunc
1094
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001095func Test_cmdline_complete_shellcmdline()
1096 CheckExecutable whoami
1097 command -nargs=1 -complete=shellcmdline MyCmd
1098
1099 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1100 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001101 let l = getcompletion('whoam', 'shellcmdline')
1102 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001103
1104 delcommand MyCmd
1105endfunc
1106
Bram Moolenaar297610b2019-12-27 17:20:55 +01001107func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001108 CheckExecutable whoami
1109 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1110 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001111endfunc
1112
Bram Moolenaar8b633132020-03-20 18:20:51 +01001113func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001114 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1115 call assert_equal(lang, v:lc_time)
1116
1117 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1118 call assert_equal(lang, v:ctype)
1119
1120 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1121 call assert_equal(lang, v:collate)
1122
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001123 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001124 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001125
1126 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001127 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001128
Bram Moolenaarec680282020-06-12 19:35:32 +02001129 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001130
Bram Moolenaarec680282020-06-12 19:35:32 +02001131 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1132 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001133
Bram Moolenaarec680282020-06-12 19:35:32 +02001134 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1135 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001136
Bram Moolenaarec680282020-06-12 19:35:32 +02001137 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1138 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001139
1140 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1141 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001142endfunc
1143
Bram Moolenaar297610b2019-12-27 17:20:55 +01001144func Test_cmdline_complete_env_variable()
1145 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001146 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1147 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001148 unlet $X_VIM_TEST_COMPLETE_ENV
1149endfunc
1150
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001151func Test_cmdline_complete_expression()
1152 let g:SomeVar = 'blah'
1153 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1154 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1155 call assert_match('"' .. cmd .. ' SomeVar', @:)
1156 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1157 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1158 endfor
1159 unlet g:SomeVar
1160endfunc
1161
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001162func Test_cmdline_complete_argopt()
1163 " completion for ++opt=arg for file commands
1164 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1165 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1166 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1167
1168 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001169 " Test ++ff in the middle of the cmdline
1170 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1171 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001172
1173 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1174 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1175 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1176 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1177 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1178
1179 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1180
1181 " completion should skip the ++opt and continue
1182 call writefile([], 'Xaaaaa.txt', 'D')
1183 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1184 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1185
1186 if has('terminal')
1187 " completion for terminal's [options]
1188 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1189 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1190 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1191
1192 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1193
1194 " :terminal completion should skip the ++opt when considering what is the
1195 " first option, which is a list of shell commands, unlike second option
1196 " onwards.
1197 let first_param = getcompletion('terminal ', 'cmdline')
1198 let second_param = getcompletion('terminal foo ', 'cmdline')
1199 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1200 call assert_equal(first_param, skipped_opt_param)
1201 call assert_notequal(first_param, second_param)
1202 endif
1203endfunc
1204
Bram Moolenaar47016f52021-08-26 16:39:58 +02001205" Unique function name for completion below
1206func s:WeirdFunc()
1207 echo 'weird'
1208endfunc
1209
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001210" Test for various command-line completion
1211func Test_cmdline_complete_various()
1212 " completion for a command starting with a comment
1213 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1214 call assert_equal("\" :|\"\<C-A>", @:)
1215
1216 " completion for a range followed by a comment
1217 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1218 call assert_equal("\"1,2\"\<C-A>", @:)
1219
1220 " completion for :k command
1221 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1222 call assert_equal("\"ka\<C-A>", @:)
1223
Doug Kearnsea842022024-09-29 17:17:41 +02001224 " completion for :keepmarks command
1225 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1226 call assert_equal("\"kee edit", @:)
1227
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001228 " completion for short version of the :s command
1229 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1230 call assert_equal("\"sI \<C-A>", @:)
1231
1232 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001233 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001234 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001235 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001236 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001237 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1238 call assert_equal("\"w >> Xfile1", @:)
1239 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001240
1241 " completion for :w ! and :r ! commands
1242 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1243 call assert_equal("\"w !invalid_xyz_cmd", @:)
1244 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1245 call assert_equal("\"r !invalid_xyz_cmd", @:)
1246
1247 " completion for :>> and :<< commands
1248 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1249 call assert_equal("\">>>\<C-A>", @:)
1250 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1251 call assert_equal("\"<<<\<C-A>", @:)
1252
1253 " completion for command with +cmd argument
1254 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1255 call assert_equal("\"buffer +/pat Xabc", @:)
1256 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1257 call assert_equal("\"buffer +/pat\<C-A>", @:)
1258
1259 " completion for a command with a trailing comment
1260 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1261 call assert_equal("\"ls \" comment\<C-A>", @:)
1262
1263 " completion for a command with a trailing command
1264 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1265 call assert_equal("\"ls | ls", @:)
1266
1267 " completion for a command with an CTRL-V escaped argument
1268 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1269 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1270
1271 " completion for a command that doesn't take additional arguments
1272 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1273 call assert_equal("\"all abc\<C-A>", @:)
1274
zeertzjqd3de1782022-09-01 12:58:52 +01001275 " completion for :wincmd with :horizontal modifier
1276 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1277 call assert_equal("\"horizontal wincmd", @:)
1278
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001279 " completion for a command with a command modifier
1280 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1281 call assert_equal("\"topleft new", @:)
1282
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001283 " completion for vim9 and legacy commands
1284 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1285 call assert_equal("\"vim9 call strlen(", @:)
1286 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1287 call assert_equal("\"legac call strlen(", @:)
1288
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001289 " completion for the :disassemble command
1290 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1291 call assert_equal("\"disas debug", @:)
1292 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1293 call assert_equal("\"disas profile", @:)
1294 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1295 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1296 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1297 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001298 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1299 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001300
Bram Moolenaar47016f52021-08-26 16:39:58 +02001301 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001302 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001303
naohiro onodfe04db2021-09-12 15:45:10 +02001304 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1305 call assert_match('"disas <SNR>\d\+_', @:)
1306 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1307 call assert_match('"disas debug <SNR>\d\+_', @:)
1308
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001309 " completion for the :match command
1310 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1311 call assert_equal("\"match Search /pat/\<C-A>", @:)
1312
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001313 " completion for the :doautocmd command
1314 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1315 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1316
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001317 " completion of autocmd group after comma
1318 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1319 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1320
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001321 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001322 call writefile([], 'Xvarfile1', 'D')
1323 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001324 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1325 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001326
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001327 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001328 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001329 augroup END
1330 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001331 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001332
1333 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001334 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1335 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001336 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1337 call assert_equal("\"au XTest.test", @:)
1338
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001339 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001340
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001341 " autocmd pattern completion
1342 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1343 call assert_equal("\"au BufEnter *.py\t", @:)
1344
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001345 " completion for the :unlet command
1346 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1347 call assert_equal("\"unlet one two", @:)
1348
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001349 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001350 " FIXME: what should happen on MS-Windows?
1351 if !has('win32')
1352 edit \{someFile}
1353 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1354 call assert_equal("\"buf {someFile}", @:)
1355 bwipe {someFile}
1356 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001357
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001358 " completion for the :bdelete command
1359 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1360 call assert_equal("\"bdel a b c", @:)
1361
1362 " completion for the :mapclear command
1363 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1364 call assert_equal("\"mapclear <buffer>", @:)
1365
1366 " completion for user defined commands with menu names
1367 menu Test.foo :ls<CR>
1368 com -nargs=* -complete=menu MyCmd
1369 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1370 call assert_equal('"MyCmd Test.', @:)
1371 delcom MyCmd
1372 unmenu Test
1373
1374 " completion for user defined commands with mappings
1375 mapclear
1376 map <F3> :ls<CR>
1377 com -nargs=* -complete=mapping MyCmd
1378 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001379 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001380 mapclear
1381 delcom MyCmd
1382
Yee Cheng Chin54844852023-10-09 18:12:31 +02001383 " Prepare for path completion
1384 call mkdir('Xa b c', 'D')
1385 defer delete('Xcomma,foobar.txt')
1386 call writefile([], 'Xcomma,foobar.txt')
1387
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001388 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001389 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1390 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1391 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001392
1393 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001394 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1395 call assert_equal('"set dir=Xa\ b\ c/', @:)
1396 set dir&
1397
1398 " completion for :set tags= / set dictionary= with escaped commas
1399 if has('win32')
1400 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1401 " '\,'
1402 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1403 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1404
1405 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1406 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1407
1408 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1409 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1410
1411 " completion for :set dictionary= with escaped commas (same behavior, but
1412 " different internal code path from 'set tags=' for escaping the output)
1413 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1414 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1415 else
1416 " In other platforms, backslashes are rounded down (since '\,' itself will
1417 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1418 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1419 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1420
1421 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1422 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1423
1424 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1425 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1426
1427 " completion for :set dictionary= with escaped commas (same behavior, but
1428 " different internal code path from 'set tags=' for escaping the output)
1429 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1430 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1431 endif
1432 set tags&
1433 set dictionary&
1434
1435 " completion for :set makeprg= with no escaped commas
1436 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1437 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1438
1439 if !has('win32')
1440 " Cannot create file with backslash in file name in Windows, so only test
1441 " this elsewhere.
1442 defer delete('Xcomma\,fooslash.txt')
1443 call writefile([], 'Xcomma\,fooslash.txt')
1444 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1445 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1446 endif
1447 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001448
1449 " completion for the :py3 commands
1450 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1451 call assert_equal('"py3 py3do py3file', @:)
1452
Bram Moolenaardf749a22021-03-28 15:29:43 +02001453 " completion for the :vim9 commands
1454 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1455 call assert_equal('"vim9cmd vim9script', @:)
1456
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001457 " redir @" is not the start of a comment. So complete after that
1458 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1459 call assert_equal('"redir @" | cwindow', @:)
1460
1461 " completion after a backtick
1462 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1463 call assert_equal('"e `a1b2c', @:)
1464
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001465 " completion for :language command with an invalid argument
1466 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1467 call assert_equal("\"language dummy \t", @:)
1468
1469 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001470 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1471 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001472
1473 " completion with ambiguous user defined commands
1474 com TCmd1 echo 'TCmd1'
1475 com TCmd2 echo 'TCmd2'
1476 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1477 call assert_equal('"TCmd ', @:)
1478 delcom TCmd1
1479 delcom TCmd2
1480
1481 " completion after a range followed by a pipe (|) character
1482 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1483 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001484
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001485 " completion after a :global command
1486 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1487 call assert_equal('"g/a/chistory', @:)
1488 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1489 call assert_equal("\"g/a\\/chist\t", @:)
1490
Bram Moolenaar9c929712020-09-07 22:05:28 +02001491 " use <Esc> as the 'wildchar' for completion
1492 set wildchar=<Esc>
1493 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1494 call assert_equal('"g/a\xb/clearjumps', @:)
1495 " pressing <esc> twice should cancel the command
1496 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1497 call assert_equal('"g/a\xb/clearjumps', @:)
1498 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001499
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001500 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001501 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001502 call writefile([], '~Xtest')
1503 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1504 call assert_equal('"e \~Xtest', @:)
1505 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001506
1507 " should be able to complete a file name that has a '*'
1508 call writefile([], 'Xx*Yy')
1509 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1510 call assert_equal('"e Xx\*Yy', @:)
1511 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001512
1513 " use a literal star
1514 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1515 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001516 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001517
1518 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1519 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001520endfunc
1521
zeertzjq094dd152023-06-15 22:51:57 +01001522" Test that expanding a pattern doesn't interfere with cmdline completion.
1523func Test_expand_during_cmdline_completion()
1524 func ExpandStuff()
1525 badd <script>:p:h/README.*
1526 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1527 $bwipe
1528 call assert_equal('README.txt', expand('README.*'))
1529 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1530 endfunc
1531 augroup test_CmdlineChanged
1532 autocmd!
1533 autocmd CmdlineChanged * call ExpandStuff()
1534 augroup END
1535
1536 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1537 call assert_equal('"sign place', @:)
1538
1539 augroup test_CmdlineChanged
1540 au!
1541 augroup END
1542 augroup! test_CmdlineChanged
1543 delfunc ExpandStuff
1544endfunc
1545
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001546" Test for 'wildignorecase'
1547func Test_cmdline_wildignorecase()
1548 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001549 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001550 set wildignorecase
1551 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1552 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001553 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001554 let g:Sline = ''
1555 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1556 call assert_equal('"e xt', @:)
1557 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001558 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001559endfunc
1560
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001561func Test_cmdline_write_alternatefile()
1562 new
1563 call setline('.', ['one', 'two'])
1564 f foo.txt
1565 new
1566 f #-A
1567 call assert_equal('foo.txt-A', expand('%'))
1568 f #<-B.txt
1569 call assert_equal('foo-B.txt', expand('%'))
1570 f %<
1571 call assert_equal('foo-B', expand('%'))
1572 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001573 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001574 bw!
1575 f foo-B.txt
1576 f %<-A
1577 call assert_equal('foo-B-A', expand('%'))
1578 bw!
1579 bw!
1580endfunc
1581
Bram Moolenaarf5724372022-09-02 19:45:15 +01001582func Test_cmdline_expand_cur_alt_file()
1583 enew
1584 file http://some.com/file.txt
1585 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1586 call assert_equal('"e http://some.com/file.txt', @:)
1587 edit another
1588 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1589 call assert_equal('"e http://some.com/file.txt', @:)
1590 bwipe
1591 bwipe http://some.com/file.txt
1592endfunc
1593
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001594" using a leading backslash here
1595set cpo+=C
1596
1597func Test_cmdline_search_range()
1598 new
1599 call setline(1, ['a', 'b', 'c', 'd'])
1600 /d
1601 1,\/s/b/B/
1602 call assert_equal('B', getline(2))
1603
1604 /a
1605 $
1606 \?,4s/c/C/
1607 call assert_equal('C', getline(3))
1608
1609 call setline(1, ['a', 'b', 'c', 'd'])
1610 %s/c/c/
1611 1,\&s/b/B/
1612 call assert_equal('B', getline(2))
1613
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001614 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001615 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001616
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001617 bwipe!
1618endfunc
1619
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001620" Test for the tick mark (') in an excmd range
1621func Test_tick_mark_in_range()
1622 " If only the tick is passed as a range and no command is specified, there
1623 " should not be an error
1624 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001625 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001626 call assert_fails("',print", 'E78:')
1627endfunc
1628
1629" Test for using a line number followed by a search pattern as range
1630func Test_lnum_and_pattern_as_range()
1631 new
1632 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1633 let @" = ''
1634 2/foo/yank
1635 call assert_equal("foo 3\n", @")
1636 call assert_equal(1, line('.'))
1637 close!
1638endfunc
1639
Bram Moolenaar65189a12017-02-06 22:22:17 +01001640" Tests for getcmdline(), getcmdpos() and getcmdtype()
1641func Check_cmdline(cmdtype)
1642 call assert_equal('MyCmd a', getcmdline())
1643 call assert_equal(8, getcmdpos())
1644 call assert_equal(a:cmdtype, getcmdtype())
1645 return ''
1646endfunc
1647
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001648set cpo&
1649
Shougo Matsushita69084282024-09-23 20:34:47 +02001650func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001651 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1652
1653 let cmdtype = ''
1654 debuggreedy
1655 call feedkeys(":debug echo 'test'\<CR>", "t")
1656 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1657 call feedkeys("cont\<CR>", "xt")
1658 0debuggreedy
1659 call assert_equal('>', cmdtype)
1660
1661 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1662 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1663
1664 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001665 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001666
1667 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1668
1669 cnoremap <expr> <F6> Check_cmdline('=')
1670 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1671 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001672
1673 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001674
1675 call assert_equal('', getcmdprompt())
1676 augroup test_CmdlineEnter
1677 autocmd!
1678 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1679 augroup END
1680 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1681 call assert_equal('Answer?', g:cmdprompt)
1682 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001683 call feedkeys(":\<CR>\<ESC>", "xt")
1684 call assert_equal('', g:cmdprompt)
1685 call assert_equal('', getcmdprompt())
1686
1687 let str = "C" .. repeat("c", 1023) .. "xyz"
1688 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1689 call assert_equal(str, g:cmdprompt)
1690
1691 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1692 call assert_equal('Ans?', g:cmdprompt)
1693 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001694
1695 augroup test_CmdlineEnter
1696 au!
1697 augroup END
1698 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001699endfunc
1700
Bram Moolenaar52604f22017-04-07 16:17:39 +02001701func Test_verbosefile()
1702 set verbosefile=Xlog
1703 echomsg 'foo'
1704 echomsg 'bar'
1705 set verbosefile=
1706 let log = readfile('Xlog')
1707 call assert_match("foo\nbar", join(log, "\n"))
1708 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001709
1710 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001711 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001712endfunc
1713
Bram Moolenaar4facea32019-10-12 20:17:40 +02001714func Test_verbose_option()
1715 CheckScreendump
1716
1717 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001718 " clear the TermResponse autocommand from defaults.vim
1719 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001720 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1721 call feedkeys("\r", 't') " for the hit-enter prompt
1722 set verbose=20
1723 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001724 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001725
1726 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001727 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001728 call term_sendkeys(buf, ":DoSomething\<CR>")
1729 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1730
1731 " clean up
1732 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001733endfunc
1734
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001735func Test_setcmdpos()
1736 func InsertTextAtPos(text, pos)
1737 call assert_equal(0, setcmdpos(a:pos))
1738 return a:text
1739 endfunc
1740
1741 " setcmdpos() with position in the middle of the command line.
1742 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1743 call assert_equal('"1ab2', @:)
1744
1745 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1746 call assert_equal('"1b2a', @:)
1747
1748 " setcmdpos() with position beyond the end of the command line.
1749 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1750 call assert_equal('"12ab', @:)
1751
1752 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001753 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001754endfunc
1755
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001756func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001757 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001758 let encoding_save = &encoding
1759
1760 for e in encodings
1761 exe 'set encoding=' . e
1762
1763 " Test overstrike in the middle of the command line.
1764 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001765 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001766
1767 " Test overstrike going beyond end of command line.
1768 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001769 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001770
1771 " Test toggling insert/overstrike a few times.
1772 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001773 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001774 endfor
1775
Bram Moolenaar30276f22019-01-24 17:59:39 +01001776 " Test overstrike with multi-byte characters.
1777 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001778 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001779
1780 let &encoding = encoding_save
1781endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001782
Bram Moolenaar52410572019-10-27 05:12:45 +01001783func Test_buffers_lastused()
1784 " check that buffers are sorted by time when wildmode has lastused
1785 call test_settime(1550020000) " middle
1786 edit bufa
1787 enew
1788 call test_settime(1550030000) " newest
1789 edit bufb
1790 enew
1791 call test_settime(1550010000) " oldest
1792 edit bufc
1793 enew
1794 call test_settime(0)
1795 enew
1796
1797 call assert_equal(['bufa', 'bufb', 'bufc'],
1798 \ getcompletion('', 'buffer'))
1799
1800 let save_wildmode = &wildmode
1801 set wildmode=full:lastused
1802
1803 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1804 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1805 call assert_equal('b bufb', X)
1806 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1807 call assert_equal('b bufa', X)
1808 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1809 call assert_equal('b bufc', X)
1810 enew
1811
1812 edit other
1813 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1814 call assert_equal('b bufb', X)
1815 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1816 call assert_equal('b bufa', X)
1817 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1818 call assert_equal('b bufc', X)
1819 enew
1820
1821 let &wildmode = save_wildmode
1822
1823 bwipeout bufa
1824 bwipeout bufb
1825 bwipeout bufc
1826endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001827
Bram Moolenaar479950f2020-01-19 15:45:17 +01001828func Test_cmdlineclear_tabenter()
1829 CheckScreendump
1830
1831 let lines =<< trim [SCRIPT]
1832 call setline(1, range(30))
1833 [SCRIPT]
1834
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001835 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001836 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001837 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001838 " in one tab make the command line higher with CTRL-W -
1839 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1840 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1841
1842 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001843endfunc
1844
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001845" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001846func Test_cmdline_expand_special()
1847 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001848 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001849 call assert_fails('e <afile>', 'E495:')
1850 call assert_fails('e <abuf>', 'E496:')
1851 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001852
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001853 call writefile([], 'Xfile.cpp', 'D')
1854 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001855 new Xfile.cpp
1856 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1857 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1858 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001859endfunc
1860
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001861" Test for backtick expression in the command line
1862func Test_cmd_backtick()
1863 %argd
1864 argadd `=['a', 'b', 'c']`
1865 call assert_equal(['a', 'b', 'c'], argv())
1866 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001867
1868 argadd `echo abc def`
1869 call assert_equal(['abc def'], argv())
1870 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001871endfunc
1872
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001873" Test for the :! command
1874func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001875 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001876
1877 let lines =<< trim [SCRIPT]
1878 " Test for no previous command
1879 call assert_fails('!!', 'E34:')
1880 set nomore
1881 " Test for cmdline expansion with :!
1882 call setline(1, 'foo!')
1883 silent !echo <cWORD> > Xfile.out
1884 call assert_equal(['foo!'], readfile('Xfile.out'))
1885 " Test for using previous command
1886 silent !echo \! !
1887 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1888 call writefile(v:errors, 'Xresult')
1889 call delete('Xfile.out')
1890 qall!
1891 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001892 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001893 if RunVim([], [], '--clean -S Xscript')
1894 call assert_equal([], readfile('Xresult'))
1895 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001896 call delete('Xresult')
1897endfunc
1898
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001899" Test error: "E135: *Filter* Autocommands must not change current buffer"
1900func Test_cmd_bang_E135()
1901 new
1902 call setline(1, ['a', 'b', 'c', 'd'])
1903 augroup test_cmd_filter_E135
1904 au!
1905 autocmd FilterReadPost * help
1906 augroup END
1907 call assert_fails('2,3!echo "x"', 'E135:')
1908
1909 augroup test_cmd_filter_E135
1910 au!
1911 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01001912 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001913 %bwipe!
1914endfunc
1915
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001916func Test_cmd_bang_args()
1917 new
1918 :.!
1919 call assert_equal(0, v:shell_error)
1920
1921 " Note that below there is one space char after the '!'. This caused a
1922 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1923 :.!
1924 call assert_equal(0, v:shell_error)
1925 bwipe!
1926
1927 CheckUnix
1928 :.!pwd
1929 call assert_equal(0, v:shell_error)
1930 :.! pwd
1931 call assert_equal(0, v:shell_error)
1932
1933 " Note there is one space after 'pwd'.
1934 :.! pwd
1935 call assert_equal(0, v:shell_error)
1936
1937 " Note there are two spaces after 'pwd'.
1938 :.! pwd
1939 call assert_equal(0, v:shell_error)
1940 :.!ls ~
1941 call assert_equal(0, v:shell_error)
1942
1943 " Note there is one space char after '~'.
1944 :.!ls ~
1945 call assert_equal(0, v:shell_error)
1946
1947 " Note there are two spaces after '~'.
1948 :.!ls ~
1949 call assert_equal(0, v:shell_error)
1950
1951 :.!echo "foo"
1952 call assert_equal(getline('.'), "foo")
1953 :.!echo "foo "
1954 call assert_equal(getline('.'), "foo ")
1955 :.!echo " foo "
1956 call assert_equal(getline('.'), " foo ")
1957 :.!echo " foo "
1958 call assert_equal(getline('.'), " foo ")
1959
1960 %bwipe!
1961endfunc
1962
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001963" Test for using ~ for home directory in cmdline completion matches
1964func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001965 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001966 call writefile([], 'Xexpdir/Xfile1')
1967 call writefile([], 'Xexpdir/Xfile2')
1968 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001969 let save_HOME = $HOME
1970 let $HOME = getcwd()
1971 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1972 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1973 let $HOME = save_HOME
1974 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001975endfunc
1976
Bram Moolenaar578fe942020-02-27 21:32:51 +01001977" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1978" or insert mode (when 'insertmode' is set)
1979func Test_cmdline_ctrl_g()
1980 new
1981 call setline(1, 'abc')
1982 call cursor(1, 3)
1983 " If command line is entered from insert mode, using C-\ C-G should back to
1984 " insert mode
1985 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1986 call assert_equal('abxyc', getline(1))
1987 call assert_equal(4, col('.'))
1988
1989 " If command line is entered in 'insertmode', using C-\ C-G should back to
1990 " 'insertmode'
1991 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1992 call assert_equal('ab12xyc', getline(1))
1993 close!
1994endfunc
1995
Bram Moolenaar578fe942020-02-27 21:32:51 +01001996" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001997func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001998 func T(a, c, p)
1999 return "oneA\noneB\noneC"
2000 endfunc
2001 command -nargs=1 -complete=custom,T MyCmd
2002
Bram Moolenaar578fe942020-02-27 21:32:51 +01002003 set nowildmenu
2004 set wildmode=full,list
2005 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002006 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002007 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002008 call assert_equal('"MyCmd oneA', @:)
2009
2010 set wildmode=longest,full
2011 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2012 call assert_equal('"MyCmd one', @:)
2013 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2014 call assert_equal('"MyCmd oneC', @:)
2015
2016 set wildmode=longest
2017 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2018 call assert_equal('"MyCmd one', @:)
2019
2020 set wildmode=list:longest
2021 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002022 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002023 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002024 call assert_equal('"MyCmd one', @:)
2025
2026 set wildmode=""
2027 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2028 call assert_equal('"MyCmd oneA', @:)
2029
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002030 " Test for wildmode=longest with 'fileignorecase' set
2031 set wildmode=longest
2032 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002033 argadd AAA AAAA AAAAA
2034 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2035 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002036 set fileignorecase&
2037
2038 " Test for listing files with wildmode=list
2039 set wildmode=list
2040 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002041 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002042 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002043 call assert_equal('"b A', @:)
2044
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002045 " when using longest completion match, matches shorter than the argument
2046 " should be ignored (happens with :help)
2047 set wildmode=longest,full
2048 set wildmenu
2049 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2050 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002051 " non existing file
2052 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2053 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002054 set wildmenu&
2055
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002056 " Test for longest file name completion with 'fileignorecase'
2057 " On MS-Windows, file names are case insensitive.
2058 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002059 call writefile([], 'XTESTfoo', 'D')
2060 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002061 set nofileignorecase
2062 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2063 call assert_equal('"e XTESTfoo', @:)
2064 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2065 call assert_equal('"e Xtestbar', @:)
2066 set fileignorecase
2067 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2068 call assert_equal('"e Xtest', @:)
2069 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2070 call assert_equal('"e Xtest', @:)
2071 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002072 endif
2073
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002074 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002075 delcommand MyCmd
2076 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002077 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002078 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002079endfunc
2080
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002081func Test_wildmode()
2082 " Test with utf-8 encoding
2083 call Wildmode_tests()
2084
2085 " Test with latin1 encoding
2086 let save_encoding = &encoding
2087 set encoding=latin1
2088 call Wildmode_tests()
2089 let &encoding = save_encoding
2090endfunc
2091
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002092func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002093 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002094 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002095 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002096 let lines =<< trim END
2097 func vim8#Complete(a, c, p)
2098 return "oneA\noneB\noneC"
2099 endfunc
2100 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002101 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002102
2103 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2104 set nowildmenu
2105 set wildmode=full,list
2106 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2107 call assert_equal('"MyCmd oneA oneB oneC', @:)
2108
2109 let &rtp = save_rtp
2110 set wildmode& wildmenu&
2111 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002112endfunc
2113
Bram Moolenaar578fe942020-02-27 21:32:51 +01002114" Test for interrupting the command-line completion
2115func Test_interrupt_compl()
2116 func F(lead, cmdl, p)
2117 if a:lead =~ 'tw'
2118 call interrupt()
2119 return
2120 endif
2121 return "one\ntwo\nthree"
2122 endfunc
2123 command -nargs=1 -complete=custom,F Tcmd
2124
2125 set nowildmenu
2126 set wildmode=full
2127 let interrupted = 0
2128 try
2129 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2130 catch /^Vim:Interrupt$/
2131 let interrupted = 1
2132 endtry
2133 call assert_equal(1, interrupted)
2134
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002135 let interrupted = 0
2136 try
2137 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2138 catch /^Vim:Interrupt$/
2139 let interrupted = 1
2140 endtry
2141 call assert_equal(1, interrupted)
2142
Bram Moolenaar578fe942020-02-27 21:32:51 +01002143 delcommand Tcmd
2144 delfunc F
2145 set wildmode&
2146endfunc
2147
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002148" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002149func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002150 let str = ":one two\<C-U>"
2151 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002152 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002153 let str ..= "\<Left>five\<Right>"
2154 let str ..= "\<Home>two "
2155 let str ..= "\<C-Left>one "
2156 let str ..= "\<C-Right> three"
2157 let str ..= "\<End>\<S-Left>four "
2158 let str ..= "\<S-Right> six"
2159 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2160 call feedkeys(str, 'xt')
2161 call assert_equal("\"one two three four five six seven", @:)
2162endfunc
2163
2164" Test for moving the cursor on the / command line in 'rightleft' mode
2165func Test_cmdline_edit_rightleft()
2166 CheckFeature rightleft
2167 set rightleft
2168 set rightleftcmd=search
2169 let str = "/one two\<C-U>"
2170 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002171 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002172 let str ..= "\<Right>five\<Left>"
2173 let str ..= "\<Home>two "
2174 let str ..= "\<C-Right>one "
2175 let str ..= "\<C-Left> three"
2176 let str ..= "\<End>\<S-Right>four "
2177 let str ..= "\<S-Left> six"
2178 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2179 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2180 call assert_equal("\"one two three four five six seven", @/)
2181 set rightleftcmd&
2182 set rightleft&
2183endfunc
2184
2185" Test for using <C-\>e in the command line to evaluate an expression
2186func Test_cmdline_expr()
2187 " Evaluate an expression from the beginning of a command line
2188 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2189 call assert_equal('"hello', @:)
2190
2191 " Use an invalid expression for <C-\>e
2192 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2193
2194 " Insert literal <CTRL-\> in the command line
2195 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2196 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002197endfunc
2198
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002199" This was making the insert position negative
2200func Test_cmdline_expr_register()
2201 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2202endfunc
2203
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002204" Test for 'imcmdline' and 'imsearch'
2205" This test doesn't actually test the input method functionality.
2206func Test_cmdline_inputmethod()
2207 new
2208 call setline(1, ['', 'abc', ''])
2209 set imcmdline
2210
2211 call feedkeys(":\"abc\<CR>", 'xt')
2212 call assert_equal("\"abc", @:)
2213 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2214 call assert_equal("\"abc", @:)
2215 call feedkeys("/abc\<CR>", 'xt')
2216 call assert_equal([2, 1], [line('.'), col('.')])
2217 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2218 call assert_equal([2, 1], [line('.'), col('.')])
2219
2220 set imsearch=2
2221 call cursor(1, 1)
2222 call feedkeys("/abc\<CR>", 'xt')
2223 call assert_equal([2, 1], [line('.'), col('.')])
2224 call cursor(1, 1)
2225 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2226 call assert_equal([2, 1], [line('.'), col('.')])
2227 set imdisable
2228 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2229 call assert_equal([2, 1], [line('.'), col('.')])
2230 set imdisable&
2231 set imsearch&
2232
2233 set imcmdline&
2234 %bwipe!
2235endfunc
2236
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002237" Test for using CTRL-_ in the command line with 'allowrevins'
2238func Test_cmdline_revins()
2239 CheckNotMSWindows
2240 CheckFeature rightleft
2241 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2242 call assert_equal("\"abc\<c-_>", @:)
2243 set allowrevins
2244 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2245 call assert_equal('"abcñèæ', @:)
2246 set allowrevins&
2247endfunc
2248
2249" Test for typing UTF-8 composing characters in the command line
2250func Test_cmdline_composing_chars()
2251 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2252 call assert_equal('"ゔ', @:)
2253endfunc
2254
Bram Moolenaar0e717042020-04-27 19:29:01 +02002255" test that ";" works to find a match at the start of the first line
2256func Test_zero_line_search()
2257 new
2258 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2259 call cursor(1,1)
2260 0;/pattern/d
2261 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2262 q!
2263endfunc
2264
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002265func Test_read_shellcmd()
2266 CheckUnix
2267 if executable('ls')
2268 " There should be ls in the $PATH
2269 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2270 call assert_match('^"r! .*\<ls\>', @:)
2271 endif
2272
2273 if executable('rm')
2274 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2275 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2276 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002277
2278 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2279 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2280 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002281 endif
2282endfunc
2283
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002284" Test for going up and down the directory tree using 'wildmenu'
2285func Test_wildmenu_dirstack()
2286 CheckUnix
2287 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002288 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002289 call writefile([], 'Xwildmenu/file1_1.txt')
2290 call writefile([], 'Xwildmenu/file1_2.txt')
2291 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2292 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2293 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2294 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2295 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2296 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002297 set wildmenu
2298
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002299 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002300 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002301 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002302 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002303 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002304 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002305 call assert_equal('"e ../../dir3/', @:)
2306 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2307 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002308 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002309 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002310 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002311 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002312 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002313 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2314 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002315
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002316 set wildmenu&
2317endfunc
2318
obcat71c6f7a2021-05-13 20:23:10 +02002319" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002320" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2321" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002322func Test_recalling_cmdline()
2323 CheckFeature cmdline_hist
2324
2325 let g:cmdlines = []
2326 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2327
2328 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002329 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2330 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2331 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2332 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002333 "\ TODO: {'name': 'debug', ...}
2334 \]
2335 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002336 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2337 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2338 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2339 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2340 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002341 \]
2342 let prefix = 'vi'
2343 for h in histories
2344 call histadd(h.name, 'vim')
2345 call histadd(h.name, 'virtue')
2346 call histadd(h.name, 'Virgo')
2347 call histadd(h.name, 'vogue')
2348 call histadd(h.name, 'emacs')
2349 for k in keypairs
2350 let g:cmdlines = []
2351 let keyseqs = h.enter
2352 \ .. prefix
2353 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2354 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2355 \ .. h.exit
2356 call feedkeys(keyseqs, 'xt')
2357 call histdel(h.name, -1) " delete the history added by feedkeys above
2358 let expect = k.prefixmatch
2359 \ ? ['virtue', 'vim', 'virtue', prefix]
2360 \ : ['emacs', 'vogue', 'emacs', prefix]
2361 call assert_equal(expect, g:cmdlines)
2362 endfor
2363 endfor
2364
2365 unlet g:cmdlines
2366 cunmap <Plug>(save-cmdline)
2367endfunc
2368
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002369func Test_cmd_map_cmdlineChanged()
2370 let g:log = []
2371 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002372 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002373 autocmd!
2374 autocmd CmdlineChanged : let g:log += [getcmdline()]
2375 augroup END
2376
2377 call feedkeys(":\<F1>\<CR>", 'xt')
2378 call assert_equal(['l', 'ls'], g:log)
2379
Bram Moolenaar796139a2021-05-18 21:38:45 +02002380 let @b = 'b'
2381 cnoremap <F1> a<C-R>b
2382 let g:log = []
2383 call feedkeys(":\<F1>\<CR>", 'xt')
2384 call assert_equal(['a', 'ab'], g:log)
2385
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002386 unlet g:log
2387 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002388 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002389 autocmd!
2390 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002391 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002392endfunc
2393
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002394" Test for the 'suffixes' option
2395func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002396 call writefile([], 'Xsuffile', 'D')
2397 call writefile([], 'Xsuffile.c', 'D')
2398 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002399 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002400 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2401 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2402 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2403 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002404 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002405 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2406 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2407 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2408 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002409 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002410 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2411 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2412 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2413 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002414 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002415 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002416 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2417 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002418endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002419
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002420" Test for using a popup menu for the command line completion matches
2421" (wildoptions=pum)
2422func Test_wildmenu_pum()
2423 CheckRunVimInTerminal
2424
2425 let commands =<< trim [CODE]
2426 set wildmenu
2427 set wildoptions=pum
2428 set shm+=I
2429 set noruler
2430 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002431
2432 func CmdCompl(a, b, c)
2433 return repeat(['aaaa'], 120)
2434 endfunc
2435 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002436
2437 func MyStatusLine() abort
2438 return 'status'
2439 endfunc
2440 func SetupStatusline()
2441 set statusline=%!MyStatusLine()
2442 set laststatus=2
2443 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002444
2445 func MyTabLine()
2446 return 'my tab line'
2447 endfunc
2448 func SetupTabline()
2449 set statusline=
2450 set tabline=%!MyTabLine()
2451 set showtabline=2
2452 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002453
2454 func DoFeedKeys()
2455 let &wildcharm = char2nr("\t")
2456 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2457 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002458 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002459 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002460
2461 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2462
2463 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002464 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2465
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002466 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002467 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002468 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2469
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002470 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002471 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002472 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2473
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002474 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002475 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002476 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2477
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002478 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002479 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002480 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2481
2482 " pressing <C-E> should end completion and go back to the original match
2483 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002484 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2485
2486 " pressing <C-Y> should select the current match and end completion
2487 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002488 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2489
2490 " With 'wildmode' set to 'longest,full', completing a match should display
2491 " the longest match, the wildmenu should not be displayed.
2492 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2493 call TermWait(buf)
2494 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002495 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2496
2497 " pressing <Tab> should display the wildmenu
2498 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002499 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2500
2501 " pressing <Tab> second time should select the next entry in the menu
2502 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002503 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2504
2505 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002506 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002507 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002508 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2509
2510 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002511 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2512
2513 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002514 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2515
2516 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002517 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002518 call writefile([], 'Xnamedir/XfileA')
2519 call writefile([], 'Xnamedir/XdirA/XfileB')
2520 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002521
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002522 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002523 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2524
2525 " Pressing <Right> on a directory name should go into that directory
2526 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002527 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2528
2529 " Pressing <Left> on a directory name should go to the parent directory
2530 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002531 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2532
2533 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002534 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002535 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002536 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2537
2538 " Pressing <C-D> when the popup menu is displayed should remove the popup
2539 " menu
2540 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002541 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2542
2543 " Pressing <S-Tab> should open the popup menu with the last entry selected
2544 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002545 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2546
2547 " Pressing <Esc> should close the popup menu and cancel the cmd line
2548 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002549 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2550
2551 " Typing a character when the popup is open, should close the popup
2552 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002553 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2554
2555 " When the popup is open, entering the cmdline window should close the popup
2556 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002557 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2558 call term_sendkeys(buf, ":q\<CR>")
2559
2560 " After the last popup menu item, <C-N> should show the original string
2561 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002562 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2563
2564 " Use the popup menu for the command name
2565 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002566 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2567
2568 " Pressing the left arrow should remove the popup menu
2569 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002570 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2571
2572 " Pressing <BS> should remove the popup menu and erase the last character
2573 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002574 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2575
2576 " Pressing <C-W> should remove the popup menu and erase the previous word
2577 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002578 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2579
2580 " Pressing <C-U> should remove the popup menu and erase the entire line
2581 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002582 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2583
2584 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2585 " the cmdline from history
2586 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002587 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2588
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002589 " Check "list" still works
2590 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2591 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002592 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2593 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002594 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2595
rbtnn68cc2b82022-02-09 11:55:47 +00002596 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002597 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002598 call writefile([], 'Xnamedir/あいう/abc')
2599 call writefile([], 'Xnamedir/あいう/xyz')
2600 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002601
2602 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002603 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002604 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2605
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002606 " Pressing <C-A> when the popup menu is displayed should list all the
2607 " matches and pressing a key after that should remove the popup menu
2608 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2609 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2610 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2611
2612 " Pressing <C-A> when the popup menu is displayed should list all the
2613 " matches and pressing <Left> after that should move the cursor
2614 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2615 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2616 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2617
2618 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2619 " should be displayed correctly on the screen.
2620 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2621 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2622
2623 " After using <C-A> to expand all the filename matches, pressing <Up>
2624 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002625 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002626 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2627 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2628 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2629
2630 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2631 " crash Vim
2632 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2633 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2634
Bram Moolenaar414acd32022-02-10 21:09:45 +00002635 " After removing the pum the command line is redrawn
2636 call term_sendkeys(buf, ":edit foo\<CR>")
2637 call term_sendkeys(buf, ":edit bar\<CR>")
2638 call term_sendkeys(buf, ":ls\<CR>")
2639 call term_sendkeys(buf, ":com\<Tab> ")
2640 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002641 call term_sendkeys(buf, "\<C-U>\<CR>")
2642
2643 " Esc still works to abort the command when 'statusline' is set
2644 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2645 call term_sendkeys(buf, ":si\<Tab>")
2646 call term_sendkeys(buf, "\<Esc>")
2647 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002648
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002649 " Esc still works to abort the command when 'tabline' is set
2650 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2651 call term_sendkeys(buf, ":si\<Tab>")
2652 call term_sendkeys(buf, "\<Esc>")
2653 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2654
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002655 " popup is cleared also when 'lazyredraw' is set
2656 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2657 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2658 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2659 call term_sendkeys(buf, "\<Esc>")
2660
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002661 " Pressing <PageDown> should scroll the menu downward
2662 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2663 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2664 call term_sendkeys(buf, "\<PageDown>")
2665 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2666 call term_sendkeys(buf, "\<PageDown>")
2667 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2668 call term_sendkeys(buf, "\<PageDown>")
2669 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2670 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2671 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2672
2673 " Pressing <PageUp> should scroll the menu upward
2674 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2675 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2676 call term_sendkeys(buf, "\<PageUp>")
2677 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2678 call term_sendkeys(buf, "\<PageUp>")
2679 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2680 call term_sendkeys(buf, "\<PageUp>")
2681 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2682
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002683 " pressing <C-E> to end completion should work in middle of the line too
2684 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2685 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2686 call term_sendkeys(buf, "\<C-E>")
2687 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2688
2689 " pressing <C-Y> should select the current match and end completion
2690 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2691 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2692
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002693 call term_sendkeys(buf, "\<C-U>\<CR>")
2694 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002695endfunc
2696
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002697" Test for wildmenumode() with the cmdline popup menu
2698func Test_wildmenumode_with_pum()
2699 set wildmenu
2700 set wildoptions=pum
2701 cnoremap <expr> <F2> wildmenumode()
2702 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2703 call assert_equal('"sign define10', @:)
2704 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2705 call assert_equal('"sign define jump list place undefine unplace0', @:)
2706 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2707 call assert_equal('"sign 0', @:)
2708 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2709 call assert_equal('"sign define0', @:)
2710 set nowildmenu wildoptions&
2711 cunmap <F2>
2712endfunc
2713
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002714func Test_wildmenu_with_pum_foldexpr()
2715 CheckRunVimInTerminal
2716
2717 let lines =<< trim END
2718 call setline(1, ['folded one', 'folded two', 'some more text'])
2719 func MyFoldText()
2720 return 'foo'
2721 endfunc
2722 set foldtext=MyFoldText() wildoptions=pum
2723 normal ggzfj
2724 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002725 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002726 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2727 call term_sendkeys(buf, ":set\<Tab>")
2728 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2729
2730 call term_sendkeys(buf, "\<Esc>")
2731 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2732
2733 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002734endfunc
2735
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002736" Test for opening the cmdline completion popup menu from the terminal window.
2737" The popup menu should be positioned correctly over the status line of the
2738" bottom-most window.
2739func Test_wildmenu_pum_from_terminal()
2740 CheckRunVimInTerminal
2741 let python = PythonProg()
2742 call CheckPython(python)
2743
2744 %bw!
2745 let cmds = ['set wildmenu wildoptions=pum']
2746 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2747 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002748 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002749 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2750 call term_sendkeys(buf, "\r\r\r")
2751 call term_wait(buf)
2752 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2753 call term_wait(buf)
2754 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2755 call term_wait(buf)
2756 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002757endfunc
2758
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002759func Test_wildmenu_pum_odd_wildchar()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002760 CheckRunVimInTerminal
2761
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002762 " Test odd wildchar interactions with pum. Make sure they behave properly
2763 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002764 let lines =<< trim END
2765 set wildoptions=pum
2766 set wildchar=<C-E>
2767 END
2768 call writefile(lines, 'XwildmenuTest', 'D')
2769 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2770
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002771 call term_sendkeys(buf, ":\<C-E>")
2772 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002773
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002774 " <C-E> being a wildchar takes priority over its original functionality
2775 call term_sendkeys(buf, "\<C-E>")
2776 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2777
2778 call term_sendkeys(buf, "\<Esc>")
2779 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2780
2781 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
2782 " command-line, and we need to make sure to clean up properly.
2783 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
2784 call term_sendkeys(buf, ":\<Esc>")
2785 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2786
2787 call term_sendkeys(buf, "\<Esc>")
2788 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2789
2790 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
2791 " and we again need to make sure we clean up properly.
2792 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
2793 call term_sendkeys(buf, ":\<C-\>\<C-\>")
2794 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2795
2796 call term_sendkeys(buf, "\<C-N>")
2797 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2798
2799 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002800endfunc
2801
zeertzjq883018f2024-06-15 15:37:11 +02002802" Test that 'rightleft' should not affect cmdline completion popup menu.
2803func Test_wildmenu_pum_rightleft()
2804 CheckFeature rightleft
2805 CheckScreendump
2806
2807 let lines =<< trim END
2808 set wildoptions=pum
2809 set rightleft
2810 END
2811 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
2812 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
2813
2814 call term_sendkeys(buf, ":sign \<Tab>")
2815 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
2816
2817 call StopVimInTerminal(buf)
2818endfunc
2819
zeertzjqd8c93402024-06-17 18:25:32 +02002820" Test highlighting matched text in cmdline completion popup menu.
2821func Test_wildmenu_pum_hl_match()
2822 CheckScreendump
2823
2824 let lines =<< trim END
2825 set wildoptions=pum,fuzzy
2826 hi PmenuMatchSel ctermfg=6 ctermbg=7
2827 hi PmenuMatch ctermfg=4 ctermbg=225
2828 END
2829 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
2830 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
2831
2832 call term_sendkeys(buf, ":sign plc\<Tab>")
2833 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
2834 call term_sendkeys(buf, "\<Tab>")
2835 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
2836 call term_sendkeys(buf, "\<Tab>")
2837 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
2838 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
2839 call TermWait(buf)
2840 call term_sendkeys(buf, ":sign un\<Tab>")
2841 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
2842 call term_sendkeys(buf, "\<Tab>")
2843 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
2844 call term_sendkeys(buf, "\<Tab>")
2845 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
2846 call term_sendkeys(buf, "\<Esc>")
2847
2848 call StopVimInTerminal(buf)
2849endfunc
2850
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002851" Test for completion after a :substitute command followed by a pipe (|)
2852" character
2853func Test_cmdline_complete_substitute()
2854 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2855 call assert_equal("\"s | \t", @:)
2856 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2857 call assert_equal("\"s/ | \t", @:)
2858 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2859 call assert_equal("\"s/one | \t", @:)
2860 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2861 call assert_equal("\"s/one/ | \t", @:)
2862 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2863 call assert_equal("\"s/one/two | \t", @:)
2864 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2865 call assert_equal('"s/one/two/ | chistory', @:)
2866 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2867 call assert_equal("\"s/one/two/g \t", @:)
2868 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2869 call assert_equal("\"s/one/two/g | chistory", @:)
2870 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2871 call assert_equal("\"s/one/t\\/ | \t", @:)
2872 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2873 call assert_equal('"s/one/t"o/ | chistory', @:)
2874 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2875 call assert_equal('"s/one/t|o/ | chistory', @:)
2876 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2877 call assert_equal("\"&\t", @:)
2878endfunc
2879
2880" Test for the :dlist command completion
2881func Test_cmdline_complete_dlist()
2882 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2883 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2884 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2885 call assert_equal("\"dlist 10 /pat/ \t", @:)
2886 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2887 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2888 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2889 call assert_equal("\"dlist 10 /pat\\\t", @:)
2890 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2891 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2892endfunc
2893
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002894" argument list (only for :argdel) fuzzy completion
2895func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002896 argadd change.py count.py charge.py
2897 set wildoptions&
2898 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2899 call assert_equal('"argdel cge', @:)
2900 set wildoptions=fuzzy
2901 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2902 call assert_equal('"argdel change.py charge.py', @:)
2903 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002904 set wildoptions&
2905endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002906
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002907" autocmd group name fuzzy completion
2908func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002909 set wildoptions&
2910 augroup MyFuzzyGroup
2911 augroup END
2912 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2913 call assert_equal('"augroup mfg', @:)
2914 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2915 call assert_equal('"augroup MyFuzzyGroup', @:)
2916 set wildoptions=fuzzy
2917 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2918 call assert_equal('"augroup MyFuzzyGroup', @:)
2919 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2920 call assert_equal('"augroup My*p', @:)
2921 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002922 set wildoptions&
2923endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002924
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002925" buffer name fuzzy completion
2926func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002927 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002928 " Use a long name to reduce the risk of matching a random directory name
2929 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002930 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002931 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2932 call assert_equal('"b SRFWL', @:)
2933 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2934 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002935 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002936 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2937 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2938 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2939 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002940 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002941 set wildoptions&
2942endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002943
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002944" buffer name (full path) fuzzy completion
2945func Test_fuzzy_completion_bufname_fullpath()
2946 CheckUnix
2947 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002948 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002949 edit Xcmd/Xstate/Xfile.js
2950 cd Xcmd/Xstate
2951 enew
2952 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2953 call assert_equal('"b CmdStateFile', @:)
2954 set wildoptions=fuzzy
2955 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2956 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2957 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002958 set wildoptions&
2959endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002960
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002961" :behave suboptions fuzzy completion
2962func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002963 set wildoptions&
2964 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2965 call assert_equal('"behave xm', @:)
2966 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2967 call assert_equal('"behave xterm', @:)
2968 set wildoptions=fuzzy
2969 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2970 call assert_equal('"behave xterm', @:)
2971 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2972 call assert_equal('"behave xt*m', @:)
2973 let g:Sline = ''
2974 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2975 call assert_equal('mswin', g:Sline)
2976 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002977 set wildoptions&
2978endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002979
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002980" " colorscheme name fuzzy completion - NOT supported
2981" func Test_fuzzy_completion_colorscheme()
2982" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002983
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002984" built-in command name fuzzy completion
2985func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002986 set wildoptions&
2987 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2988 call assert_equal('"sbwin', @:)
2989 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2990 call assert_equal('"sbrewind', @:)
2991 set wildoptions=fuzzy
2992 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2993 call assert_equal('"sbrewind', @:)
2994 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2995 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002996 set wildoptions&
2997endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002998
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002999" " compiler name fuzzy completion - NOT supported
3000" func Test_fuzzy_completion_compiler()
3001" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003002
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003003" :cscope suboptions fuzzy completion
3004func Test_fuzzy_completion_cscope()
3005 CheckFeature cscope
3006 set wildoptions&
3007 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3008 call assert_equal('"cscope ret', @:)
3009 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3010 call assert_equal('"cscope reset', @:)
3011 set wildoptions=fuzzy
3012 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3013 call assert_equal('"cscope reset', @:)
3014 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3015 call assert_equal('"cscope re*t', @:)
3016 set wildoptions&
3017endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003018
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003019" :diffget/:diffput buffer name fuzzy completion
3020func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003021 new SomeBuffer
3022 diffthis
3023 new OtherBuffer
3024 diffthis
3025 set wildoptions&
3026 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3027 call assert_equal('"diffget sbuf', @:)
3028 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3029 call assert_equal('"diffput sbuf', @:)
3030 set wildoptions=fuzzy
3031 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3032 call assert_equal('"diffget SomeBuffer', @:)
3033 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3034 call assert_equal('"diffput SomeBuffer', @:)
3035 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003036 set wildoptions&
3037endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003038
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003039" " directory name fuzzy completion - NOT supported
3040" func Test_fuzzy_completion_dirname()
3041" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003042
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003043" environment variable name fuzzy completion
3044func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003045 set wildoptions&
3046 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3047 call assert_equal('"echo $VUT', @:)
3048 set wildoptions=fuzzy
3049 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3050 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003051 set wildoptions&
3052endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003053
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003054" autocmd event fuzzy completion
3055func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003056 set wildoptions&
3057 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3058 call assert_equal('"autocmd BWout', @:)
3059 set wildoptions=fuzzy
3060 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3061 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003062 set wildoptions&
3063endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003064
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003065" vim expression fuzzy completion
3066func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003067 let g:PerPlaceCount = 10
3068 set wildoptions&
3069 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3070 call assert_equal('"let c = ppc', @:)
3071 set wildoptions=fuzzy
3072 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3073 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003074 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003075endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003076
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003077" " file name fuzzy completion - NOT supported
3078" func Test_fuzzy_completion_filename()
3079" endfunc
3080
3081" " files in path fuzzy completion - NOT supported
3082" func Test_fuzzy_completion_filesinpath()
3083" endfunc
3084
3085" " filetype name fuzzy completion - NOT supported
3086" func Test_fuzzy_completion_filetype()
3087" endfunc
3088
3089" user defined function name completion
3090func Test_fuzzy_completion_userdefined_func()
3091 set wildoptions&
3092 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3093 call assert_equal('"call Test_f_u_f', @:)
3094 set wildoptions=fuzzy
3095 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3096 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3097 set wildoptions&
3098endfunc
3099
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003100" <SNR> functions should be sorted to the end
3101func Test_fuzzy_completion_userdefined_snr_func()
3102 func s:Sendmail()
3103 endfunc
3104 func SendSomemail()
3105 endfunc
3106 func S1e2n3dmail()
3107 endfunc
3108 set wildoptions=fuzzy
3109 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003110 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003111 set wildoptions&
3112 delfunc s:Sendmail
3113 delfunc SendSomemail
3114 delfunc S1e2n3dmail
3115endfunc
3116
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003117" user defined command name completion
3118func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003119 set wildoptions&
3120 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal('"MsFeat', @:)
3122 set wildoptions=fuzzy
3123 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3124 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003125 set wildoptions&
3126endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003127
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003128" " :help tag fuzzy completion - NOT supported
3129" func Test_fuzzy_completion_helptag()
3130" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003131
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003132" highlight group name fuzzy completion
3133func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003134 set wildoptions&
3135 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3136 call assert_equal('"highlight SKey', @:)
3137 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal('"highlight SpecialKey', @:)
3139 set wildoptions=fuzzy
3140 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3141 call assert_equal('"highlight SpecialKey', @:)
3142 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3143 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003144 set wildoptions&
3145endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003146
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003147" :history suboptions fuzzy completion
3148func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003149 set wildoptions&
3150 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3151 call assert_equal('"history dg', @:)
3152 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3153 call assert_equal('"history search', @:)
3154 set wildoptions=fuzzy
3155 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3156 call assert_equal('"history debug', @:)
3157 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal('"history se*h', @:)
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" :language locale name fuzzy completion
3163func Test_fuzzy_completion_lang()
3164 CheckUnix
3165 set wildoptions&
3166 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3167 call assert_equal('"lang psx', @:)
3168 set wildoptions=fuzzy
3169 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3170 call assert_equal('"lang POSIX', @:)
3171 set wildoptions&
3172endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003173
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003174" :mapclear buffer argument fuzzy completion
3175func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003176 set wildoptions&
3177 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal('"mapclear buf', @:)
3179 set wildoptions=fuzzy
3180 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3181 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003182 set wildoptions&
3183endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003184
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003185" map name fuzzy completion
3186func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003187 " test regex completion works
3188 set wildoptions=fuzzy
3189 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3190 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003191 nmap <plug>MyLongMap :p<CR>
3192 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3193 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3194 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3195 call assert_equal("\"nmap MLM \t", @:)
3196 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3197 call assert_equal("\"nmap <F2> one two \t", @:)
3198 " duplicate entries should be removed
3199 vmap <plug>MyLongMap :<C-U>#<CR>
3200 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3201 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3202 nunmap <plug>MyLongMap
3203 vunmap <plug>MyLongMap
3204 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3205 call assert_equal("\"nmap ABC\t", @:)
3206 " results should be sorted by best match
3207 nmap <Plug>format :
3208 nmap <Plug>goformat :
3209 nmap <Plug>TestFOrmat :
3210 nmap <Plug>fendoff :
3211 nmap <Plug>state :
3212 nmap <Plug>FendingOff :
3213 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3214 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3215 nunmap <Plug>format
3216 nunmap <Plug>goformat
3217 nunmap <Plug>TestFOrmat
3218 nunmap <Plug>fendoff
3219 nunmap <Plug>state
3220 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003221 set wildoptions&
3222endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003223
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003224" abbreviation fuzzy completion
3225func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003226 set wildoptions=fuzzy
3227 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal("\"iabbr <nowait>", @:)
3229 iabbr WaitForCompletion WFC
3230 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3231 call assert_equal("\"iabbr WaitForCompletion", @:)
3232 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3233 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003234
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003235 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003236 set wildoptions&
3237endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003238
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003239" menu name fuzzy completion
3240func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003241 CheckFeature menu
3242
3243 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003244 set wildoptions&
3245 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3246 call assert_equal('"menu pup', @:)
3247 set wildoptions=fuzzy
3248 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3249 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003250
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003251 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003252 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003253endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003254
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003255" :messages suboptions fuzzy completion
3256func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003257 set wildoptions&
3258 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3259 call assert_equal('"messages clr', @:)
3260 set wildoptions=fuzzy
3261 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3262 call assert_equal('"messages clear', @:)
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" :set option name fuzzy completion
3267func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003268 set wildoptions&
3269 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3270 call assert_equal('"set brkopt', @:)
3271 set wildoptions=fuzzy
3272 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3273 call assert_equal('"set breakindentopt', @:)
3274 set wildoptions&
3275 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3276 call assert_equal('"set fixendofline', @:)
3277 set wildoptions=fuzzy
3278 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3279 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003280 set wildoptions&
3281endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003282
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003283" :set <term_option>
3284func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003285 set wildoptions&
3286 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3287 call assert_equal('"set t_EC', @:)
3288 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3289 call assert_equal('"set <t_EC>', @:)
3290 set wildoptions=fuzzy
3291 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3292 call assert_equal('"set t_EC', @:)
3293 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3294 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003295 set wildoptions&
3296endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003297
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003298" " :packadd directory name fuzzy completion - NOT supported
3299" func Test_fuzzy_completion_packadd()
3300" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003301
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003302" " shell command name fuzzy completion - NOT supported
3303" func Test_fuzzy_completion_shellcmd()
3304" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003305
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003306" :sign suboptions fuzzy completion
3307func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003308 set wildoptions&
3309 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3310 call assert_equal('"sign ufe', @:)
3311 set wildoptions=fuzzy
3312 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3313 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003314 set wildoptions&
3315endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003316
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003317" :syntax suboptions fuzzy completion
3318func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003319 set wildoptions&
3320 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3321 call assert_equal('"syntax kwd', @:)
3322 set wildoptions=fuzzy
3323 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3324 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003325 set wildoptions&
3326endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003327
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003328" syntax group name fuzzy completion
3329func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003330 set wildoptions&
3331 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3332 call assert_equal('"syntax list mpar', @:)
3333 set wildoptions=fuzzy
3334 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3335 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003336 set wildoptions&
3337endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003338
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003339" :syntime suboptions fuzzy completion
3340func Test_fuzzy_completion_syntime()
3341 CheckFeature profile
3342 set wildoptions&
3343 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3344 call assert_equal('"syntime clr', @:)
3345 set wildoptions=fuzzy
3346 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3347 call assert_equal('"syntime clear', @:)
3348 set wildoptions&
3349endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003350
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003351" " tag name fuzzy completion - NOT supported
3352" func Test_fuzzy_completion_tagname()
3353" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003354
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003355" " tag name and file fuzzy completion - NOT supported
3356" func Test_fuzzy_completion_tagfile()
3357" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003358
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003359" " user names fuzzy completion - how to test this functionality?
3360" func Test_fuzzy_completion_username()
3361" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003362
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003363" user defined variable name fuzzy completion
3364func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003365 let g:SomeVariable=10
3366 set wildoptions&
3367 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3368 call assert_equal('"let SVar', @:)
3369 set wildoptions=fuzzy
3370 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3371 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003372 set wildoptions&
3373endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003374
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003375" Test for sorting the results by the best match
3376func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003377 %bw!
3378 command T123format :
3379 command T123goformat :
3380 command T123TestFOrmat :
3381 command T123fendoff :
3382 command T123state :
3383 command T123FendingOff :
3384 set wildoptions=fuzzy
3385 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3386 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3387 delcommand T123format
3388 delcommand T123goformat
3389 delcommand T123TestFOrmat
3390 delcommand T123fendoff
3391 delcommand T123state
3392 delcommand T123FendingOff
3393 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003394 set wildoptions&
3395endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003396
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003397" Test for fuzzy completion of a command with lower case letters and a number
3398func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003399 command Foo2Bar :
3400 set wildoptions=fuzzy
3401 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3402 call assert_equal('"Foo2Bar', @:)
3403 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3404 call assert_equal('"Foo2Bar', @:)
3405 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3406 call assert_equal('"Foo2Bar', @:)
3407 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003408 set wildoptions&
3409endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003410
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003411" Test for command completion for a command starting with 'k'
3412func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003413 command KillKillKill :
3414 set wildoptions&
3415 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3416 call assert_equal("\"killkill\<Tab>", @:)
3417 set wildoptions=fuzzy
3418 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3419 call assert_equal('"KillKillKill', @:)
3420 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003421 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003422endfunc
3423
3424" Test for fuzzy completion for user defined custom completion function
3425func Test_fuzzy_completion_custom_func()
3426 func Tcompl(a, c, p)
3427 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3428 endfunc
3429 command -nargs=* -complete=custom,Tcompl Fuzzy :
3430 set wildoptions&
3431 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3432 call assert_equal("\"Fuzzy format", @:)
3433 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3434 call assert_equal("\"Fuzzy xy", @:)
3435 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3436 call assert_equal("\"Fuzzy ttt", @:)
3437 set wildoptions=fuzzy
3438 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3439 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3440 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3441 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3442 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3443 call assert_equal("\"Fuzzy xy", @:)
3444 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3445 call assert_equal("\"Fuzzy TestFOrmat", @:)
3446 delcom Fuzzy
3447 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003448endfunc
3449
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003450" Test for fuzzy completion in the middle of a cmdline instead of at the end
3451func Test_fuzzy_completion_in_middle()
3452 set wildoptions=fuzzy
3453 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3454 call assert_equal("\"set wildchar wildcharm wrap", @:)
3455
3456 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3457 call assert_equal("\"args ++encoding= zz", @:)
3458 set wildoptions&
3459endfunc
3460
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003461" Test for :breakadd argument completion
3462func Test_cmdline_complete_breakadd()
3463 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3464 call assert_equal("\"breakadd expr file func here", @:)
3465 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3466 call assert_equal("\"breakadd expr", @:)
3467 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3468 call assert_equal("\"breakadd expr", @:)
3469 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3470 call assert_equal("\"breakadd here", @:)
3471 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3472 call assert_equal("\"breakadd here", @:)
3473 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3474 call assert_equal("\"breakadd abc", @:)
3475 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3476 let l = getcompletion('not', 'breakpoint')
3477 call assert_equal([], l)
3478
3479 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003480 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003481 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3482 call assert_equal("\"breakadd file Xscript", @:)
3483 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3484 call assert_equal("\"breakadd file Xscript", @:)
3485 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3486 call assert_equal("\"breakadd file 20 Xscript", @:)
3487 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3488 call assert_equal("\"breakadd file 20 Xscript", @:)
3489 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3490 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3491 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3492 call assert_equal("\"breakadd file 20\t", @:)
3493 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3494 call assert_equal("\"breakadd file 20x\t", @:)
3495 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3496 call assert_equal("\"breakadd file Xscript ", @:)
3497 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3498 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003499
3500 " Test for :breakadd func [lnum] <function>
3501 func Xbreak_func()
3502 endfunc
3503 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3504 call assert_equal("\"breakadd func Xbreak_func", @:)
3505 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3506 call assert_equal("\"breakadd func Xbreak_func", @:)
3507 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3508 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3509 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3510 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3511 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3512 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3513 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3514 call assert_equal("\"breakadd func 20\t", @:)
3515 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3516 call assert_equal("\"breakadd func 20x\t", @:)
3517 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3518 call assert_equal("\"breakadd func Xbreak_func ", @:)
3519 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3520 call assert_equal("\"breakadd func X1B2C3", @:)
3521 delfunc Xbreak_func
3522
3523 " Test for :breakadd expr <expression>
3524 let g:Xtest_var = 10
3525 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3526 call assert_equal("\"breakadd expr Xtest_var", @:)
3527 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3528 call assert_equal("\"breakadd expr Xtest_var", @:)
3529 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3530 call assert_equal("\"breakadd expr Xtest_var ", @:)
3531 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3532 call assert_equal("\"breakadd expr X1B2C3", @:)
3533 unlet g:Xtest_var
3534
3535 " Test for :breakadd here
3536 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3537 call assert_equal("\"breakadd here Xtest", @:)
3538 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3539 call assert_equal("\"breakadd here Xtest", @:)
3540 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3541 call assert_equal("\"breakadd here ", @:)
3542endfunc
3543
3544" Test for :breakdel argument completion
3545func Test_cmdline_complete_breakdel()
3546 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3547 call assert_equal("\"breakdel file func here", @:)
3548 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3549 call assert_equal("\"breakdel file", @:)
3550 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3551 call assert_equal("\"breakdel file", @:)
3552 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3553 call assert_equal("\"breakdel here", @:)
3554 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3555 call assert_equal("\"breakdel here", @:)
3556 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3557 call assert_equal("\"breakdel abc", @:)
3558
3559 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003560 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003561 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3562 call assert_equal("\"breakdel file Xscript", @:)
3563 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3564 call assert_equal("\"breakdel file Xscript", @:)
3565 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3566 call assert_equal("\"breakdel file 20 Xscript", @:)
3567 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3568 call assert_equal("\"breakdel file 20 Xscript", @:)
3569 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3570 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3571 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3572 call assert_equal("\"breakdel file 20\t", @:)
3573 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3574 call assert_equal("\"breakdel file 20x\t", @:)
3575 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3576 call assert_equal("\"breakdel file Xscript ", @:)
3577 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3578 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003579
3580 " Test for :breakdel func [lnum] <function>
3581 func Xbreak_func()
3582 endfunc
3583 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3584 call assert_equal("\"breakdel func Xbreak_func", @:)
3585 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3586 call assert_equal("\"breakdel func Xbreak_func", @:)
3587 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3588 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3589 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3590 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3591 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3592 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3593 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3594 call assert_equal("\"breakdel func 20\t", @:)
3595 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3596 call assert_equal("\"breakdel func 20x\t", @:)
3597 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3598 call assert_equal("\"breakdel func Xbreak_func ", @:)
3599 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3600 call assert_equal("\"breakdel func X1B2C3", @:)
3601 delfunc Xbreak_func
3602
3603 " Test for :breakdel here
3604 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3605 call assert_equal("\"breakdel here Xtest", @:)
3606 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3607 call assert_equal("\"breakdel here Xtest", @:)
3608 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3609 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003610endfunc
3611
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003612" Test for :scriptnames argument completion
3613func Test_cmdline_complete_scriptnames()
3614 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003615 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003616 source Xa1b2c3.vim
3617 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3618 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3619 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3620 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3621 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3622 call assert_equal("\"script b2c3", @:)
3623 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3624 call assert_match("\"script 2\<Tab>$", @:)
3625 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3626 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3627 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3628 call assert_equal("\"script ", @:)
3629 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3630 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3631 new
3632 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3633 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3634 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003635 set wildmenu&
3636endfunc
3637
Bram Moolenaard8893442022-05-06 20:38:47 +01003638" this was going over the end of IObuff
3639func Test_report_error_with_composing()
3640 let caught = 'no'
3641 try
3642 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3643 catch /E492:/
3644 let caught = 'yes'
3645 endtry
3646 call assert_equal('yes', caught)
3647endfunc
3648
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003649" Test for expanding 2-letter and 3-letter :substitute command arguments.
3650" These commands don't accept an argument.
3651func Test_cmdline_complete_substitute_short()
3652 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3653 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3654 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3655 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3656 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3657 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3658 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3659 endfor
3660endfunc
3661
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003662" Test for shellcmdline command argument completion
3663func Test_cmdline_complete_shellcmdline_argument()
3664 command -nargs=+ -complete=shellcmdline MyCmd
3665
3666 set wildoptions=fuzzy
3667
3668 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3669 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003670 call assert_equal(['test_cmdline.vim'],
3671 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003672
3673 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3674 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003675 call assert_equal([],
3676 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003677
3678 let compl1 = getcompletion('', 'file')[0]
3679 let compl2 = getcompletion('', 'file')[1]
3680 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3681 call assert_equal('"MyCmd vim ' .. compl1, @:)
3682
3683 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3684 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3685
3686 let compl = getcompletion('', 'file')[1]
3687 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3688 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3689
3690 set wildoptions&
3691 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3692 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003693 call assert_equal(['test_cmdline.vim'],
3694 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003695
3696 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3697 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003698 call assert_equal([],
3699 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003700
3701 let compl1 = getcompletion('', 'file')[0]
3702 let compl2 = getcompletion('', 'file')[1]
3703 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3704 call assert_equal('"MyCmd vim ' .. compl1, @:)
3705
3706 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3707 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3708
3709 let compl = getcompletion('', 'file')[1]
3710 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3711 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3712
3713 delcommand MyCmd
3714endfunc
3715
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003716" Test for :! shell command argument completion
3717func Test_cmdline_complete_bang_cmd_argument()
3718 set wildoptions=fuzzy
3719 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3720 call assert_equal('"!vim test_cmdline.vim', @:)
3721 set wildoptions&
3722 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3723 call assert_equal('"!vim test_cmdline.vim', @:)
3724endfunc
3725
zeertzjq961b2e52023-04-17 15:53:24 +01003726func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003727 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003728endfunc
3729
3730func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003731 call assert_equal(0, getcmdpos())
3732 call assert_equal(0, getcmdscreenpos())
3733 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003734 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01003735
zeertzjqa821b602024-06-18 20:31:08 +02003736 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01003737 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003738 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003739 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003740 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003741 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003742 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02003743
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003744 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
3745 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02003746 let g:results = []
3747 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
3748 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
3749 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003750 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
3751 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
3752 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02003753
3754 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01003755 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003756endfunc
3757
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003758func Test_recursive_register()
3759 let @= = ''
3760 silent! ?e/
3761 let caught = 'no'
3762 try
3763 normal //
3764 catch /E169:/
3765 let caught = 'yes'
3766 endtry
3767 call assert_equal('yes', caught)
3768endfunc
3769
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003770func Test_long_error_message()
3771 " the error should be truncated, not overrun IObuff
3772 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3773endfunc
3774
zeertzjq6791adc2022-07-26 20:42:25 +01003775func Test_cmdline_redraw_tabline()
3776 CheckRunVimInTerminal
3777
3778 let lines =<< trim END
3779 set showtabline=2
3780 autocmd CmdlineEnter * set tabline=foo
3781 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003782 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003783 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3784 call term_sendkeys(buf, ':')
3785 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3786
3787 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003788endfunc
3789
zeertzjqb82a2ab2022-08-21 14:33:57 +01003790func Test_wildmenu_pum_disable_while_shown()
3791 set wildoptions=pum
3792 set wildmenu
3793 cnoremap <F2> <Cmd>set nowildmenu<CR>
3794 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3795 call assert_equal(0, pumvisible())
3796 cunmap <F2>
3797 set wildoptions& wildmenu&
3798endfunc
3799
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003800func Test_setcmdline()
3801 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01003802 call assert_equal(0, setcmdline(test_null_string()))
3803 call assert_equal('', getcmdline())
3804 call assert_equal(1, getcmdpos())
3805
3806 call assert_equal(0, setcmdline(''[: -1]))
3807 call assert_equal('', getcmdline())
3808 call assert_equal(1, getcmdpos())
3809
zeertzjq54acb902022-08-29 16:21:25 +01003810 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003811 call assert_equal(0, setcmdline(a:text))
3812 call assert_equal(a:text, getcmdline())
3813 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003814 call assert_equal(getcmdtype(), g:cmdtype)
3815 unlet g:cmdtype
3816 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003817
3818 call assert_equal(0, setcmdline(a:text, a:pos))
3819 call assert_equal(a:text, getcmdline())
3820 call assert_equal(a:pos, getcmdpos())
3821
3822 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003823 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3824 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003825
3826 return ''
3827 endfunc
3828
3829 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3830 call assert_equal('set rtp?', @:)
3831
zeertzjq54acb902022-08-29 16:21:25 +01003832 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3833 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3834 call assert_equal('foo', g:str)
3835 unlet g:str
3836
3837 delfunc SetText
3838
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003839 " setcmdline() returns 1 when not editing the command line.
3840 call assert_equal(1, 'foo'->setcmdline())
3841
3842 " Called in custom function
3843 func CustomComplete(A, L, P)
3844 call assert_equal(0, setcmdline("DoCmd "))
3845 return "January\nFebruary\nMars\n"
3846 endfunc
3847
3848 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3849 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3850 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003851 delcom DoCmd
3852 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003853
3854 " Called in <expr>
3855 cnoremap <expr>a setcmdline('let foo=')
3856 call feedkeys(":a\<CR>", 'tx')
3857 call assert_equal('let foo=0', @:)
3858 cunmap a
3859endfunc
3860
Sean Dewarfc8a6012023-04-17 16:41:20 +01003861func Test_rulerformat_position()
3862 CheckScreendump
3863
3864 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
3865 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
3866 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
3867 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
3868 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
3869
3870 " clean up
3871 call StopVimInTerminal(buf)
3872endfunc
3873
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01003874" Test for using "%!" in 'rulerformat' to use a function
3875func Test_rulerformat_function()
3876 CheckScreendump
3877
3878 let lines =<< trim END
3879 func TestRulerFn()
3880 return '10,20%=30%%'
3881 endfunc
3882 END
3883 call writefile(lines, 'Xrulerformat_function', 'D')
3884
3885 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
3886 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
3887 call term_sendkeys(buf, ":redraw!\<CR>")
3888 call term_wait(buf)
3889 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
3890
3891 " clean up
3892 call StopVimInTerminal(buf)
3893endfunc
3894
zeertzjqe4c79d32023-08-15 22:41:53 +02003895func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003896 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003897
zeertzjqe4c79d32023-08-15 22:41:53 +02003898 call assert_equal(getcompletion('', 'cmdline'),
3899 \ getcompletion('TestCompletion ', 'cmdline'))
3900 call assert_equal(['<buffer>'],
3901 \ getcompletion('TestCompletion map <bu', 'cmdline'))
3902
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003903 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003904endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02003905
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003906func Test_custom_completion()
3907 func CustomComplete1(lead, line, pos)
3908 return "a\nb\nc"
3909 endfunc
3910 func CustomComplete2(lead, line, pos)
3911 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
3912 endfunc
3913 func Check_custom_completion()
3914 call assert_equal('custom,CustomComplete1', getcmdcompltype())
3915 return ''
3916 endfunc
3917 func Check_customlist_completion()
3918 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
3919 return ''
3920 endfunc
3921
3922 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
3923 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
3924
3925 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
3926 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
3927
3928 call assert_fails("call getcompletion('', 'custom')", 'E475:')
3929 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
3930
zeertzjq757f3212024-04-15 19:01:04 +02003931 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
3932 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
3933 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003934
3935 delcom Test1
3936 delcom Test2
3937
3938 delfunc CustomComplete1
3939 delfunc CustomComplete2
3940 delfunc Check_custom_completion
3941 delfunc Check_customlist_completion
3942endfunc
3943
zeertzjq28a23602023-09-29 19:58:35 +02003944func Test_custom_completion_with_glob()
3945 func TestGlobComplete(A, L, P)
3946 return split(glob('Xglob*'), "\n")
3947 endfunc
3948
3949 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
3950 call writefile([], 'Xglob1', 'D')
3951 call writefile([], 'Xglob2', 'D')
3952
3953 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
3954 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
3955
3956 delcommand TestGlobComplete
3957 delfunc TestGlobComplete
3958endfunc
3959
Christian Brabandt8610f742024-01-12 17:34:40 +01003960func Test_window_size_stays_same_after_changing_cmdheight()
3961 set laststatus=2
3962 let expected = winheight(0)
3963 function! Function_name() abort
3964 call feedkeys(":"..repeat('x', &columns), 'x')
3965 let &cmdheight=2
3966 let &cmdheight=1
3967 redraw
3968 endfunction
3969 call Function_name()
3970 call assert_equal(expected, winheight(0))
3971endfunc
3972
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01003973" verify that buffer-completion finds all buffer names matching a pattern
3974func Test_buffer_completion()
3975 " should return empty list
3976 call assert_equal([], getcompletion('', 'buffer'))
3977
3978 call mkdir('Xbuf_complete', 'R')
3979 e Xbuf_complete/Foobar.c
3980 e Xbuf_complete/MyFoobar.c
3981 e AFoobar.h
3982 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
3983
3984 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
3985 call assert_equal(expected, getcompletion('Foo', 'buffer'))
3986 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
3987 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
3988endfunc
3989
Anton Sharonov49528da2024-04-14 20:02:24 +02003990" :set t_??
3991func Test_term_option()
3992 set wildoptions&
3993 let _cpo = &cpo
3994 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02003995 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02003996 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'
3997 \ .. ' 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'
3998 \ .. ' 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'
3999 \ .. ' 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'
4000 \ .. ' 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 +02004001 \ .. ' 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 +02004002 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004003 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004004 let &cpo = _cpo
4005endfunc
4006
Christian Brabandt70a11a62024-07-26 19:13:55 +02004007func Test_ex_command_completion()
4008 " required for :*
4009 set cpo+=*
4010 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
4011 " :++ and :-- are only valid in Vim9 Script context, so they can be ignored
4012 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004013 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004014 call assert_equal(0, exists(':ke'))
4015 call assert_equal(1, exists(':kee'))
4016 call assert_equal(1, exists(':keep'))
4017 call assert_equal(1, exists(':keepm'))
4018 call assert_equal(1, exists(':keepma'))
4019 call assert_equal(1, exists(':keepmar'))
4020 call assert_equal(1, exists(':keepmark'))
4021 call assert_equal(2, exists(':keepmarks'))
4022 call assert_equal(2, exists(':keepalt'))
4023 call assert_equal(2, exists(':keepjumps'))
4024 call assert_equal(2, exists(':keeppatterns'))
4025 set cpo-=*
4026endfunc
4027
zeertzjq5df3cb22024-10-07 21:05:06 +02004028func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004029 CheckMSWindows
4030 let save_shellslash = &shellslash
4031 set noshellslash
4032 call system('mkdir XXXa\_b')
4033 defer delete('XXXa', 'rf')
4034 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4035 call assert_equal('"cd XXXa\_b\', @:)
4036 let &shellslash = save_shellslash
4037endfunc
4038
Bram Moolenaar309976e2019-12-05 18:16:33 +01004039" vim: shiftwidth=2 sts=2 expandtab