blob: 042710c2aae77a22d63be3c12b5f249fbbf51419 [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Bram Moolenaar4facea32019-10-12 20:17:40 +02003source check.vim
4source screendump.vim
Bram Moolenaar24ebd832020-03-16 21:25:24 +01005source view_util.vim
Bram Moolenaarc82dd862020-06-07 17:30:33 +02006source shared.vim
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00007import './vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02008
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00009func SetUp()
10 func SaveLastScreenLine()
11 let g:Sline = Screenline(&lines - 1)
12 return ''
13 endfunc
14 cnoremap <expr> <F4> SaveLastScreenLine()
15endfunc
16
17func TearDown()
18 delfunc SaveLastScreenLine
19 cunmap <F4>
20endfunc
21
Bram Moolenaarae3150e2016-06-11 23:22:36 +020022func Test_complete_tab()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010023 call writefile(['testfile'], 'Xtestfile', 'D')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020024 call feedkeys(":e Xtest\t\r", "tx")
25 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020026
27 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
28 call feedkeys(":e %\t\r", "tx")
29 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020030endfunc
31
32func Test_complete_list()
33 " We can't see the output, but at least we check the code runs properly.
34 call feedkeys(":e test\<C-D>\r", "tx")
35 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010036
37 " If a command doesn't support completion, then CTRL-D should be literally
38 " used.
39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000041
42 " Test for displaying the tail of the completion matches
43 set wildmode=longest,full
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010044 call mkdir('Xtest', 'R')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000045 call writefile([], 'Xtest/a.c')
46 call writefile([], 'Xtest/a.h')
47 let g:Sline = ''
48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49 call assert_equal('a.c a.h', g:Sline)
50 call assert_equal('"e Xtest/', @:)
51 if has('win32')
52 " Test for 'completeslash'
53 set completeslash=backslash
54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000056 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000058 set completeslash=slash
59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000061 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000063 set completeslash&
64 endif
65
66 " Test for displaying the tail with wildcards
67 let g:Sline = ''
68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
70 call assert_equal('"e Xtes?/', @:)
71 let g:Sline = ''
72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
74 call assert_equal('"e Xtes*/', @:)
75 let g:Sline = ''
76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77 call assert_equal(':e Xtes[/', g:Sline)
78 call assert_equal('"e Xtes[/', @:)
79
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000080 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020081endfunc
82
83func Test_complete_wildmenu()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010084 call mkdir('Xwilddir1/Xdir2', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010085 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
86 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
87 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
88 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020089 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010090
91 " Pressing <Tab> completes, and moves to next files when pressing again.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010092 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010093 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010094 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020095 call assert_equal('testfile2', getline(1))
96
Bram Moolenaar37db6422019-03-28 21:26:23 +010097 " <S-Tab> is like <Tab> but begin with the last match and then go to
98 " previous.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010099 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100100 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100101 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100102 call assert_equal('testfile1', getline(1))
103
104 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100105 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100106 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100107 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100108 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100109 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100110 call assert_equal('testfile1', getline(1))
111
112 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100113 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100114 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100115 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100116 call assert_equal('testfile1', getline(1))
117
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100118 " this fails in some Unix GUIs, not sure why
119 if !has('unix') || !has('gui_running')
120 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
121 " different than 'wildchar'.
122 set wildcharm=<C-Z>
123 cnoremap <C-J> <Down><C-Z>
124 cnoremap <C-K> <Up><C-Z>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100125 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100126 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100127 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100128 call assert_equal('testfile1', getline(1))
129 set wildcharm=0
130 cunmap <C-J>
131 cunmap <C-K>
132 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100133
Bram Moolenaar578fe942020-02-27 21:32:51 +0100134 " Test for canceling the wild menu by adding a character
135 redrawstatus
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100136 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
137 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100138
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100139 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100140 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
142 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
143 cd -
144
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000145 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100146 cnoremap <expr> <F2> wildmenumode()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100147 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
148 call assert_equal('"cd Xwilddir1/0', @:)
149 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
150 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100151 cunmap <F2>
152
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000153 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
154 " After this pressing <Left> or <Right> should not change the selection.
155 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
156 call assert_equal('"sign define', @:)
157 call histadd('cmd', 'TestWildMenu')
158 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
159 call assert_equal('"TestWildMenu', @:)
160
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200161 " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match
162 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx')
163 call assert_equal('"sign un yy zz', @:)
164
165 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx')
166 call assert_equal('"sign unplace yy zz', @:)
167
Bram Moolenaar37db6422019-03-28 21:26:23 +0100168 " cleanup
169 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200170 set nowildmenu
171endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100172
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173func Test_wildmenu_screendump()
174 CheckScreendump
175
176 let lines =<< trim [SCRIPT]
177 set wildmenu hlsearch
178 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100179 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200180
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200181 " Test simple wildmenu
Bram Moolenaara60053b2020-09-03 16:50:13 +0200182 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
183 call term_sendkeys(buf, ":vim\<Tab>")
184 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
185
186 call term_sendkeys(buf, "\<Tab>")
187 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
188
189 call term_sendkeys(buf, "\<Tab>")
190 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
191
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200192 " Looped back to the original value
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100193 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200194 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200195
196 " Test that the wild menu is cleared properly
197 call term_sendkeys(buf, " ")
198 call VerifyScreenDump(buf, 'Test_wildmenu_5', {})
199
200 " Test that a different wildchar still works
201 call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>")
202 call term_sendkeys(buf, ":vim\<Esc>")
203 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
204
205 " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
206 " sure clean up is properly done in edge case like this.
Bram Moolenaara60053b2020-09-03 16:50:13 +0200207 call term_sendkeys(buf, "\<Esc>")
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200208 call VerifyScreenDump(buf, 'Test_wildmenu_6', {})
Bram Moolenaara60053b2020-09-03 16:50:13 +0200209
210 " clean up
211 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200212endfunc
213
Bram Moolenaara653e532022-04-19 11:38:24 +0100214func Test_redraw_in_autocmd()
215 CheckScreendump
216
217 let lines =<< trim END
218 set cmdheight=2
219 autocmd CmdlineChanged * redraw
220 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100221 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100222
223 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
224 call term_sendkeys(buf, ":for i in range(3)\<CR>")
225 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
226
227 call term_sendkeys(buf, "let i =")
228 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
229
230 " clean up
231 call term_sendkeys(buf, "\<CR>")
232 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100233endfunc
234
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100235func Test_redrawstatus_in_autocmd()
236 CheckScreendump
237
238 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100239 set laststatus=2
240 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100241 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100242 END
243 call writefile(lines, 'XTest_redrawstatus', 'D')
244
245 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100246 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100247 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
248 call term_sendkeys(buf, ":foobar")
249 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100250 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100251 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100252 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100253 " with cmdheight=1 messages have scrolled when typing :endfor
254 call term_sendkeys(buf, "\<CR>:endfor")
255 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
256 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
257 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
258 call term_sendkeys(buf, ":for in in range(3)")
259 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
260 call term_sendkeys(buf, "\<CR>:endfor")
261 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100262
263 " clean up
264 call term_sendkeys(buf, "\<CR>")
265 call StopVimInTerminal(buf)
266endfunc
267
Bram Moolenaarf797e302022-08-11 13:17:30 +0100268func Test_changing_cmdheight()
269 CheckScreendump
270
271 let lines =<< trim END
272 set cmdheight=1 laststatus=2
nwounkn2e485672024-11-11 21:48:30 +0100273 func EchoOne()
274 set laststatus=2 cmdheight=1
275 echo 'foo'
276 echo 'bar'
277 set cmdheight=2
278 endfunc
Bram Moolenaar0816f472022-10-05 15:42:32 +0100279 func EchoTwo()
280 set laststatus=2
281 set cmdheight=5
282 echo 'foo'
283 echo 'bar'
284 set cmdheight=1
285 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100286 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100287 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100288
289 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
290 call term_sendkeys(buf, ":resize -3\<CR>")
291 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
292
Luuk van Baale15cbc12025-01-04 17:18:08 +0100293 " :resize now also changes 'cmdheight' accordingly
294 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100295 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
296
297 " using more space moves the status line up
298 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
299 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
300
301 " reducing cmdheight moves status line down
Luuk van Baalc97e8692025-01-06 18:58:21 +0100302 call term_sendkeys(buf, ":set cmdheight-=3\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100303 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
304
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000305 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100306 call term_sendkeys(buf, ":resize -1\<CR>")
307 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
308 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
309
Bram Moolenaar0816f472022-10-05 15:42:32 +0100310 " setting 'cmdheight' works after outputting two messages
311 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
312 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
313
Luuk van Baalc97e8692025-01-06 18:58:21 +0100314 " increasing 'cmdheight' doesn't clear the messages that need hit-enter
nwounkn2e485672024-11-11 21:48:30 +0100315 call term_sendkeys(buf, ":call EchoOne()\<CR>")
316 call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})
317
Luuk van Baalc97e8692025-01-06 18:58:21 +0100318 " window commands do not reduce 'cmdheight' to value lower than :set by user
319 call term_sendkeys(buf, "\<CR>:wincmd _\<CR>")
320 call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {})
321
Bram Moolenaarf797e302022-08-11 13:17:30 +0100322 " clean up
323 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100324endfunc
325
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100326func Test_cmdheight_tabline()
327 CheckScreendump
328
329 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
330 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
331
332 " clean up
333 call StopVimInTerminal(buf)
334endfunc
335
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100336func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100337 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
338 call assert_equal('"map <unique> <silent>', getreg(':'))
339 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
340 call assert_equal('"map <script> <unique>', getreg(':'))
341 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
342 call assert_equal('"map <expr> <script>', getreg(':'))
343 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
344 call assert_equal('"map <buffer> <expr>', getreg(':'))
345 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
346 call assert_equal('"map <nowait> <buffer>', getreg(':'))
347 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
348 call assert_equal('"map <special> <nowait>', getreg(':'))
349 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
350 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200351
Bram Moolenaar1776a282019-05-03 16:05:41 +0200352 map <Middle>x middle
353
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200354 map ,f commaf
355 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200356 map <Left> left
357 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200358 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
359 call assert_equal('"map ,f', getreg(':'))
360 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
361 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200362 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
363 call assert_equal('"map <Left>', getreg(':'))
364 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200365 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000366 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
367 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200368 unmap ,f
369 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200370 unmap <Left>
371 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200372
zeertzjqc3a26c62023-02-17 16:40:20 +0000373 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200374 map <Left> left
375 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
376 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200377 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200378 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000379 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
380 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200381 unmap <Left>
382
383 set cpo+=<
384 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200385 exe "set t_k6=\<Esc>[17~"
386 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200387 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
388 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200389 if !has('gui_running')
390 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
391 call assert_equal("\"map <F6>x", getreg(':'))
392 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200393 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200394 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200395 set cpo-=<
396
397 set cpo+=B
398 map <Left> left
399 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
400 call assert_equal('"map <Left>', getreg(':'))
401 unmap <Left>
402 set cpo-=B
403
404 set cpo+=k
405 map <Left> left
406 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
407 call assert_equal('"map <Left>', getreg(':'))
408 unmap <Left>
409 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200410
Bram Moolenaar531be472020-09-23 22:38:05 +0200411 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
412
Bram Moolenaar1776a282019-05-03 16:05:41 +0200413 unmap <Middle>x
414 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100415endfunc
416
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100417func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100418 hi Aardig ctermfg=green
419 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000420 call assert_equal('"match Aardig', @:)
Yee Cheng China7b81202025-02-23 09:32:47 +0100421 call feedkeys(":match NON\<Tab>\<Home>\"\<CR>", 'xt')
422 call assert_equal('"match NONE', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000423 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
424 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100425endfunc
426
427func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100428 hi Aardig ctermfg=green
429 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
430 call assert_equal('"hi Aardig', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100431
432 " hi default
Bram Moolenaarea588152017-04-10 22:45:30 +0200433 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
434 call assert_equal('"hi default Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100435 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
436 call assert_equal('"hi default', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100437 call feedkeys(":hi default link Aa\<Tab>\<Home>\"\<CR>", 'xt')
438 call assert_equal('"hi default link Aardig', getreg(':'))
439
440 " hi clear only accepts one parameter
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100441 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
442 call assert_equal('"hi clear', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100443 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
444 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200445 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
Yee Cheng China7b81202025-02-23 09:32:47 +0100446 call assert_equal("\"hi clear Aardig Aard\<Tab>", getreg(':'))
447 " hi link accepts up to two parameters
448 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
449 call assert_equal('"hi link', getreg(':'))
450 call assert_equal('"hi link', getreg(':'))
451 call feedkeys(":hi link Aa\<Tab>\<Home>\"\<CR>", 'xt')
452 call assert_equal('"hi link Aardig', getreg(':'))
453 call feedkeys(":hi link Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
454 call assert_equal("\"hi link Aardig Aardig", getreg(':'))
455 call feedkeys(":hi link Aardig Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
456 call assert_equal("\"hi link Aardig Aardig Aard\<Tab>", getreg(':'))
457 " hi link will complete to "NONE" for second parameter
458 call feedkeys(":hi link NON\<Tab>\<Home>\"\<CR>", 'xt')
459 call assert_equal("\"hi link NonText", getreg(':'))
460 call feedkeys(":hi link Aardig NON\<Tab>\<Home>\"\<CR>", 'xt')
461 call assert_equal("\"hi link Aardig NONE", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200462
463 " A cleared group does not show up in completions.
464 hi Anders ctermfg=green
465 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
466 hi clear Aardig
467 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
468 hi clear Anders
469 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100470endfunc
471
Bram Moolenaar75e15672020-06-28 13:10:22 +0200472" Test for command-line expansion of "hi Ni " (easter egg)
473func Test_highlight_easter_egg()
474 call test_override('ui_delay', 1)
475 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
476 call assert_equal("\"hi Ni \<Tab>", @:)
477 call test_override('ALL', 0)
478endfunc
479
Yee Cheng China7b81202025-02-23 09:32:47 +0100480func Test_highlight_group_completion()
481 " Test completing keys
482 call assert_equal('term=', getcompletion('hi Foo ', 'cmdline')[0])
483 call assert_equal('ctermfg=', getcompletion('hi Foo c*fg', 'cmdline')[0])
484 call assert_equal('NONE', getcompletion('hi Foo NON', 'cmdline')[0])
485 set wildoptions+=fuzzy
486 call assert_equal('ctermbg=', getcompletion('hi Foo cmbg', 'cmdline')[0])
487 set wildoptions-=fuzzy
488
489 " Test completing the current value
490 hi FooBar term=bold,underline cterm=undercurl ctermfg=lightgray ctermbg=12 ctermul=34
491 call assert_equal('bold,underline', getcompletion('hi FooBar term=', 'cmdline')[0])
492 call assert_equal('undercurl', getcompletion('hi FooBar cterm=', 'cmdline')[0])
493 call assert_equal('7', getcompletion('hi FooBar ctermfg=', 'cmdline')[0])
494 call assert_equal('12', getcompletion('hi FooBar ctermbg=', 'cmdline')[0])
495 call assert_equal('34', getcompletion('hi FooBar ctermul=', 'cmdline')[0])
496
497 " "bold,underline" is unique and creates an extra item. "undercurl" and
498 " should be de-duplicated
499 call assert_equal(len(getcompletion('hi FooBar term=', 'cmdline')),
500 \ 1 + len(getcompletion('hi FooBar cterm=', 'cmdline')))
501
502 " don't complete original value if we have user input already, similar to
503 " behavior in :set <option>=<pattern>
504 call assert_equal(['bold'], getcompletion('hi FooBar term=bol', 'cmdline'))
505 call assert_equal([], getcompletion('hi FooBar ctermfg=1', 'cmdline'))
506
507 " start/stop do not fill their current value now as they are more
508 " complicated
509 hi FooBar start=123 stop=234
510 call assert_equal([], getcompletion('hi FooBar start=', 'cmdline'))
511 call assert_equal([], getcompletion('hi FooBar stop=', 'cmdline'))
512
513 if has("gui") || has("termguicolors")
514 hi FooBar gui=italic guifg=#112233 guibg=brown1 guisp=green
515 call assert_equal('italic', getcompletion('hi FooBar gui=', 'cmdline')[0])
516 call assert_equal('#112233', getcompletion('hi FooBar guifg=', 'cmdline')[0])
517 call assert_equal('brown1', getcompletion('hi FooBar guibg=', 'cmdline')[0])
518 call assert_equal('green', getcompletion('hi FooBar guisp=', 'cmdline')[0])
519
520 " Check that existing value is de-duplicated and doesn't show up later
521 call assert_equal(1, count(getcompletion('hi FooBar guibg=', 'cmdline'), 'brown1'))
522 endif
523
524 " Test completing attributes
525 call assert_equal(['underdouble', 'underdotted'], getcompletion('hi DoesNotExist term=un*erdo*', 'cmdline'))
526 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=NON', 'cmdline')[0])
527 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=', 'cmdline')[-1]) " NONE should be at the end and not sorted
528 call assert_equal('bold', getcompletion('hi DoesNotExist cterm=underline,bo', 'cmdline')[0]) " complete after comma
529 if has("gui") || has("termguicolors")
530 set wildoptions+=fuzzy
531 call assert_equal('italic', getcompletion('hi DoesNotExist gui=itic', 'cmdline')[0])
532 set wildoptions-=fuzzy
533 endif
534
535 " Test completing cterm colors
536 call assert_equal('fg', getcompletion('hi FooBar ctermbg=f*g', 'cmdline')[0])
537 call assert_equal('fg', getcompletion('hi DoesNotExist ctermbg=f*g', 'cmdline')[0])
538 call assert_equal('NONE', getcompletion('hi FooBar ctermfg=NON', 'cmdline')[0])
539 call assert_equal('NONE', getcompletion('hi DoesNotExist ctermfg=NON', 'cmdline')[0])
540 set wildoptions+=fuzzy
541 call assert_equal('Black', getcompletion('hi FooBar ctermul=blck', 'cmdline')[0])
542 call assert_equal('Black', getcompletion('hi DoesNotExist ctermul=blck', 'cmdline')[0])
543 set wildoptions-=fuzzy
544
545 " Test completing gui colors
546 if has("gui") || has("termguicolors")
547 call assert_equal('fg', getcompletion('hi FooBar guibg=f*g', 'cmdline')[0])
548 call assert_equal('fg', getcompletion('hi DoesNotExist guibg=f*g', 'cmdline')[0])
549 call assert_equal('NONE', getcompletion('hi FooBar guifg=NON', 'cmdline')[0])
550 call assert_equal('NONE', getcompletion('hi DoesNotExist guifg=NON', 'cmdline')[0])
551 set wildoptions=fuzzy
552 call assert_equal('limegreen', getcompletion('hi FooBar guisp=limgrn', 'cmdline')[0])
553 call assert_equal('limegreen', getcompletion('hi DoesNotExist guisp=limgrn', 'cmdline')[0])
554 set wildoptions-=fuzzy
555
556 " Test pruning bad color names with space. Vim doesn't support them.
557 let v:colornames['foobar with space'] = '#123456'
558 let v:colornames['foobarwithoutspace'] = '#234567'
559 call assert_equal(['foobarwithoutspace'], getcompletion('hi FooBar guibg=foobarw', 'cmdline'))
560
561 " Test specialized sorting. First few items are special values that
562 " go first, after that it's a sorted list of color names.
563 call assert_equal(['fg','bg','NONE'], getcompletion('hi DoesNotExist guifg=', 'cmdline')[0:2])
564 let completed_colors=getcompletion('hi DoesNotExist guifg=', 'cmdline')[3:]
565 let gui_colors_no_space=filter(copy(v:colornames), {key,val -> match(key, ' ')==-1})
566 call assert_equal(len(gui_colors_no_space), len(completed_colors))
567 call assert_equal(sort(copy(completed_colors)), completed_colors)
568
569 " Test that the specialized sorting still works if we have some pattern matches
570 let completed_colors=getcompletion('hi DoesNotExist guifg=*blue*', 'cmdline')
571 call assert_equal(sort(copy(completed_colors)), completed_colors)
572 call assert_equal('aliceblue', completed_colors[0])
573 endif
574endfunc
575
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200576func Test_getcompletion()
577 let groupcount = len(getcompletion('', 'event'))
578 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200579 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200580 call assert_true(matchcount > 0)
581 call assert_true(groupcount > matchcount)
582
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200583 if has('menu')
584 source $VIMRUNTIME/menu.vim
585 let matchcount = len(getcompletion('', 'menu'))
586 call assert_true(matchcount > 0)
587 call assert_equal(['File.'], getcompletion('File', 'menu'))
588 call assert_true(matchcount > 0)
589 let matchcount = len(getcompletion('File.', 'menu'))
590 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000591 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200592 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200593
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200594 let l = getcompletion('v:n', 'var')
595 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200596 let l = getcompletion('v:notexists', 'var')
597 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200598
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200599 args a.c b.c
600 let l = getcompletion('', 'arglist')
601 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000602 let l = getcompletion('a.', 'buffer')
603 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200604 %argdelete
605
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200606 let l = getcompletion('', 'augroup')
607 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200608 let l = getcompletion('blahblah', 'augroup')
609 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200610
611 let l = getcompletion('', 'behave')
612 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200613 let l = getcompletion('not', 'behave')
614 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200615
616 let l = getcompletion('', 'color')
617 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200618 let l = getcompletion('dirty', 'color')
619 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200620
621 let l = getcompletion('', 'command')
622 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200623 let l = getcompletion('awake', 'command')
624 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200625
626 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200627 call assert_true(index(l, 'samples/') >= 0)
628 let l = getcompletion('NoMatch', 'dir')
629 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200630
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100631 if glob('~/*') !=# ''
632 let l = getcompletion('~/', 'dir')
633 call assert_true(l[0][0] ==# '~')
634 endif
635
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200636 let l = getcompletion('exe', 'expression')
637 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200638 let l = getcompletion('kill', 'expression')
639 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200640
641 let l = getcompletion('tag', 'function')
642 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200643 let l = getcompletion('paint', 'function')
644 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200645
Kota Kato90c23532023-01-18 15:27:38 +0000646 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000647 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000648 let l = getcompletion('ruby', 'function')
649 call assert_equal([], l)
650 endif
651
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200652 let Flambda = {-> 'hello'}
653 let l = getcompletion('', 'function')
654 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200655 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200656
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200657 let l = getcompletion('run', 'file')
658 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200659 let l = getcompletion('walk', 'file')
660 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200661 set wildignore=*.vim
662 let l = getcompletion('run', 'file', 1)
663 call assert_true(index(l, 'runtest.vim') < 0)
664 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000665 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100666 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000667 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
668 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200669
670 let l = getcompletion('ha', 'filetype')
671 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200672 let l = getcompletion('horse', 'filetype')
673 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200674
Doug Kearns81642d92024-01-04 22:37:44 +0100675 if has('keymap')
676 let l = getcompletion('acc', 'keymap')
677 call assert_true(index(l, 'accents') >= 0)
678 let l = getcompletion('nullkeymap', 'keymap')
679 call assert_equal([], l)
680 endif
681
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200682 let l = getcompletion('z', 'syntax')
683 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200684 let l = getcompletion('emacs', 'syntax')
685 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200686
687 let l = getcompletion('jikes', 'compiler')
688 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200689 let l = getcompletion('break', 'compiler')
690 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200691
692 let l = getcompletion('last', 'help')
693 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200694 let l = getcompletion('giveup', 'help')
695 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200696
697 let l = getcompletion('time', 'option')
698 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200699 let l = getcompletion('space', 'option')
700 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200701
702 let l = getcompletion('er', 'highlight')
703 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200704 let l = getcompletion('dark', 'highlight')
705 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200706
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200707 let l = getcompletion('', 'messages')
708 call assert_true(index(l, 'clear') >= 0)
709 let l = getcompletion('not', 'messages')
710 call assert_equal([], l)
711
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200712 let l = getcompletion('', 'mapclear')
713 call assert_true(index(l, '<buffer>') >= 0)
714 let l = getcompletion('not', 'mapclear')
715 call assert_equal([], l)
716
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200717 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200718 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200719 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
720 let root = has('win32') ? 'C:\\' : '/'
721 let l = getcompletion(root, 'shellcmd')
722 let expected = map(filter(glob(root . '*', 0, 1),
723 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
724 call assert_equal(expected, l)
725
Bram Moolenaarb650b982016-08-05 20:35:13 +0200726 if has('cscope')
727 let l = getcompletion('', 'cscope')
728 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
729 call assert_equal(cmds, l)
730 " using cmdline completion must not change the result
731 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
732 let l = getcompletion('', 'cscope')
733 call assert_equal(cmds, l)
734 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
735 let l = getcompletion('find ', 'cscope')
736 call assert_equal(keys, l)
737 endif
738
Bram Moolenaar7522f692016-08-06 14:12:50 +0200739 if has('signs')
740 sign define Testing linehl=Comment
741 let l = getcompletion('', 'sign')
742 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
743 call assert_equal(cmds, l)
744 " using cmdline completion must not change the result
745 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
746 let l = getcompletion('', 'sign')
747 call assert_equal(cmds, l)
748 let l = getcompletion('list ', 'sign')
749 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000750 let l = getcompletion('de*', 'sign')
751 call assert_equal(['define'], l)
752 let l = getcompletion('p?', 'sign')
753 call assert_equal(['place'], l)
754 let l = getcompletion('j.', 'sign')
755 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200756 endif
757
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200758 " Command line completion tests
759 let l = getcompletion('cd ', 'cmdline')
760 call assert_true(index(l, 'samples/') >= 0)
761 let l = getcompletion('cd NoMatch', 'cmdline')
762 call assert_equal([], l)
763 let l = getcompletion('let v:n', 'cmdline')
764 call assert_true(index(l, 'v:null') >= 0)
765 let l = getcompletion('let v:notexists', 'cmdline')
766 call assert_equal([], l)
767 let l = getcompletion('call tag', 'cmdline')
768 call assert_true(index(l, 'taglist(') >= 0)
769 let l = getcompletion('call paint', 'cmdline')
770 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200771 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
772 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200773
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100774 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000775 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100776 return "oneA\noneB\noneC"
777 endfunc
778 command -nargs=1 -complete=custom,T MyCmd
779 let l = getcompletion('MyCmd ', 'cmdline')
780 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000781 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100782
783 delcommand MyCmd
784 delfunc T
ii144785fe02021-11-21 12:13:56 +0000785 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100786
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200787 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200788 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
789 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200790 if has('cmdline_hist')
791 call add(names, 'history')
792 endif
793 if has('gettext')
794 call add(names, 'locale')
795 endif
796 if has('profile')
797 call add(names, 'syntime')
798 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200799
800 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100801 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200802
803 for name in names
804 let matchcount = len(getcompletion('', name))
805 call assert_true(matchcount >= 0, 'No matches for ' . name)
806 endfor
807
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200808 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200809
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000810 edit a~b
811 enew
812 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
813 bw a~b
814
815 if has('unix')
816 edit Xtest\
817 enew
818 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
819 bw Xtest\
820 endif
821
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100822 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200823 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100824 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200825endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200826
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000827func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000828 " Get a dialog in the GUI
829 CheckNotGui
830
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000831 " This was using uninitialized memory.
832 let lines =<< trim END
833 set verbose=6
834 norm @=ٷ
835 qall!
836 END
837 call writefile(lines, 'XmultiScript', 'D')
838 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
839endfunc
840
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000841" Test for getcompletion() with "fuzzy" in 'wildoptions'
842func Test_getcompletion_wildoptions()
843 let save_wildoptions = &wildoptions
844 set wildoptions&
845 let l = getcompletion('space', 'option')
846 call assert_equal([], l)
847 let l = getcompletion('ier', 'command')
848 call assert_equal([], l)
849 set wildoptions=fuzzy
850 let l = getcompletion('space', 'option')
851 call assert_true(index(l, 'backspace') >= 0)
852 let l = getcompletion('ier', 'command')
853 call assert_true(index(l, 'compiler') >= 0)
854 let &wildoptions = save_wildoptions
855endfunc
856
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000857func Test_complete_autoload_error()
858 let save_rtp = &rtp
859 let lines =<< trim END
860 vim9script
861 export def Complete(..._): string
862 return 'match'
863 enddef
864 echo this will cause an error
865 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100866 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000867 call writefile(lines, 'Xdir/autoload/script.vim')
868 exe 'set rtp+=' .. getcwd() .. '/Xdir'
869
870 let lines =<< trim END
871 vim9script
872 import autoload 'script.vim'
873 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
874 &wildcharm = char2nr("\<Tab>")
875 feedkeys(":Cmd \<Tab>", 'xt')
876 END
877 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
878
879 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000880endfunc
881
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100882func Test_fullcommand()
883 let tests = {
884 \ '': '',
885 \ ':': '',
886 \ ':::': '',
887 \ ':::5': '',
888 \ 'not_a_cmd': '',
889 \ 'Check': '',
890 \ 'syntax': 'syntax',
891 \ ':syntax': 'syntax',
892 \ '::::syntax': 'syntax',
893 \ 'sy': 'syntax',
894 \ 'syn': 'syntax',
895 \ 'synt': 'syntax',
896 \ ':sy': 'syntax',
897 \ '::::sy': 'syntax',
898 \ 'match': 'match',
899 \ '2match': 'match',
900 \ '3match': 'match',
901 \ 'aboveleft': 'aboveleft',
902 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100903 \ 'en': 'endif',
904 \ 'end': 'endif',
905 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100906 \ 's': 'substitute',
907 \ '5s': 'substitute',
908 \ ':5s': 'substitute',
909 \ "'<,'>s": 'substitute',
910 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100911 \ 'CheckLin': 'CheckLinux',
912 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100913 \ }
914
915 for [in, want] in items(tests)
916 call assert_equal(want, fullcommand(in))
917 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200918 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100919
920 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200921
922 command -buffer BufferLocalCommand :
923 command GlobalCommand :
924 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
925 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
926 delcommand BufferLocalCommand
927 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100928endfunc
929
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200930func Test_shellcmd_completion()
931 let save_path = $PATH
932
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100933 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200934 call writefile([''], 'Xpathdir/Xfile.exe')
935 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
936
937 " Set PATH to example directory without trailing slash.
938 let $PATH = getcwd() . '/Xpathdir'
939
940 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
941 " dirs in the PATH, even though they won't be executed. We check that only
942 " subdirs of the PWD and executables from the PATH are included in the
943 " suggestions.
944 let actual = getcompletion('X', 'shellcmd')
945 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
946 call insert(expected, 'Xfile.exe')
947 call assert_equal(expected, actual)
948
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200949 let $PATH = save_path
950endfunc
951
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200952func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100953 call mkdir('a/b/c', 'pR')
954 call writefile(['asdfasdf'], 'a/b/c/fileXname')
955 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
956 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200957 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200958endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100959
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100960func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100961 let @a = "def"
962 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
963 call assert_equal('"abc def ghi', @:)
964
965 new
966 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
967
968 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
969 call assert_equal('"aaa asdf bbb', @:)
970
971 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
972 call assert_equal('"aaa /tmp/some bbb', @:)
973
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200974 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
975 call assert_equal('"aaa '.getline(1).' bbb', @:)
976
Bram Moolenaar21efc362016-12-03 14:05:49 +0100977 set incsearch
978 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
979 call assert_equal('"aaa verylongword bbb', @:)
980
981 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
982 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100983
984 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
985 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100986 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200987
988 " Error while typing a command used to cause that it was not executed
989 " in the end.
990 new
991 try
992 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
993 catch /^Vim\%((\a\+)\)\=:E32/
994 " ignore error E32
995 endtry
996 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100997
Bram Moolenaar578fe942020-02-27 21:32:51 +0100998 " Try to paste an invalid register using <C-R>
999 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
1000 call assert_equal('"onetwo', @:)
1001
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001002 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +01001003 let @a = "xy\<C-H>z"
1004 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
1005 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001006 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
1007 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001008 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
1009 call assert_equal("\"xy\<C-H>z", @:)
1010
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001011 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
1012 let @a = "xy\<C-V>z"
1013 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
1014 call assert_equal('"xyz', @:)
1015 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
1016 call assert_equal("\"xy\<C-V>z", @:)
1017
Bram Moolenaar578fe942020-02-27 21:32:51 +01001018 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
1019
Bram Moolenaar72532d32018-04-07 19:09:09 +02001020 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +01001021endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001022
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001023func Test_cmdline_remove_char()
1024 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001025
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001026 for e in ['utf8', 'latin1']
1027 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001028
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001029 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
1030 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001031
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001032 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
1033 call assert_equal('"abcdef', @:)
1034
1035 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
1036 call assert_equal('"abc ghi', @:, e)
1037
1038 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
1039 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +01001040
1041 " This was going before the start in latin1.
1042 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001043 endfor
1044
1045 let &encoding = encoding_save
1046endfunc
1047
zeertzjqff2b79d2024-02-26 20:38:36 +01001048func Test_cmdline_del_utf8()
1049 let @s = '⒌'
1050 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1051 call assert_equal('",,', @:)
1052
1053 let @s = 'a̳'
1054 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1055 call assert_equal('",,', @:)
1056
1057 let @s = 'β̳'
1058 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1059 call assert_equal('",,', @:)
1060
1061 if has('arabic')
1062 let @s = 'لا'
1063 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1064 call assert_equal('",,', @:)
1065 endif
1066endfunc
1067
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001068func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001069 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001070
1071 set keymap=esperanto
1072 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
1073 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
1074 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001075endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001076
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001077func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001078 new
1079 2;'(
1080 2;')
1081 quit
1082endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +01001083
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001084func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001085 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001086 new
1087 source Xtest.vim
1088 " Trigger calling validate_cursor()
1089 diffsp Xtest.vim
1090 quit!
1091 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001092endfunc
1093
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +01001094func Test_mark_from_line_zero()
1095 " this was reading past the end of the first (empty) line
1096 new
1097 norm oxxxx
1098 call assert_fails("0;'(", 'E20:')
1099 bwipe!
1100endfunc
1101
Bram Moolenaarba47b512017-01-24 21:18:19 +01001102func Test_cmdline_complete_wildoptions()
1103 help
1104 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1105 let a = join(sort(split(@:)),' ')
1106 set wildoptions=tagfile
1107 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1108 let b = join(sort(split(@:)),' ')
1109 call assert_equal(a, b)
1110 bw!
1111endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001112
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001113func Test_cmdline_complete_user_cmd()
1114 command! -complete=color -nargs=1 Foo :
1115 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1116 call assert_equal('"Foo blue', @:)
1117 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1118 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001119 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1120 call assert_equal('"Foo a blue', @:)
1121 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1122 call assert_equal('"Foo b\', @:)
1123 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1124 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001125 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001126
1127 redraw
1128 call assert_equal('~', Screenline(&lines - 1))
1129 command! FooOne :
1130 command! FooTwo :
1131
1132 set nowildmenu
1133 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1134 call assert_equal('"FooOne', @:)
1135 call assert_equal('~', Screenline(&lines - 1))
1136
1137 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1138 call assert_equal('"FooTwo', @:)
1139 call assert_equal('~', Screenline(&lines - 1))
1140
1141 delcommand FooOne
1142 delcommand FooTwo
1143 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001144endfunc
1145
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001146func Test_complete_user_cmd()
1147 command FooBar echo 'global'
1148 command -buffer FooBar echo 'local'
1149 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1150 call assert_equal('"FooBar', @:)
1151
1152 delcommand -buffer FooBar
1153 delcommand FooBar
1154endfunc
1155
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001156func s:ScriptLocalFunction()
1157 echo 'yes'
1158endfunc
1159
1160func Test_cmdline_complete_user_func()
1161 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001162 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001163 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1164 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001165
1166 " g: prefix also works
1167 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1168 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001169
1170 " using g: prefix does not result in just "g:" matches from a lambda
1171 let Fx = { a -> a }
1172 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1173 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001174
1175 " existence of script-local dict function does not break user function name
1176 " completion
1177 function s:a_dict_func() dict
1178 endfunction
1179 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1180 call assert_match('"call Test_cmdline_complete_user_', @:)
1181 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001182endfunc
1183
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001184func Test_cmdline_complete_user_names()
1185 if has('unix') && executable('whoami')
1186 let whoami = systemlist('whoami')[0]
1187 let first_letter = whoami[0]
1188 if len(first_letter) > 0
1189 " Trying completion of :e ~x where x is the first letter of
1190 " the user name should complete to at least the user name.
1191 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1192 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1193 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001194 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001195 " Just in case: check that the system has an Administrator account.
1196 let names = system('net user')
1197 if names =~ 'Administrator'
1198 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001199 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001200 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001201 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001202 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001203 else
1204 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001205 endif
1206endfunc
1207
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001208func Test_cmdline_complete_shellcmdline()
1209 CheckExecutable whoami
1210 command -nargs=1 -complete=shellcmdline MyCmd
1211
1212 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1213 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001214 let l = getcompletion('whoam', 'shellcmdline')
1215 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001216
1217 delcommand MyCmd
1218endfunc
1219
Bram Moolenaar297610b2019-12-27 17:20:55 +01001220func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001221 CheckExecutable whoami
1222 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1223 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001224endfunc
1225
Bram Moolenaar8b633132020-03-20 18:20:51 +01001226func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001227 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1228 call assert_equal(lang, v:lc_time)
1229
1230 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1231 call assert_equal(lang, v:ctype)
1232
1233 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1234 call assert_equal(lang, v:collate)
1235
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001236 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001237 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001238
1239 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001240 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001241
Bram Moolenaarec680282020-06-12 19:35:32 +02001242 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001243
Bram Moolenaarec680282020-06-12 19:35:32 +02001244 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1245 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001246
Bram Moolenaarec680282020-06-12 19:35:32 +02001247 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1248 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001249
Bram Moolenaarec680282020-06-12 19:35:32 +02001250 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1251 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001252
1253 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1254 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001255endfunc
1256
Bram Moolenaar297610b2019-12-27 17:20:55 +01001257func Test_cmdline_complete_env_variable()
1258 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001259 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1260 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001261 unlet $X_VIM_TEST_COMPLETE_ENV
1262endfunc
1263
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001264func Test_cmdline_complete_expression()
1265 let g:SomeVar = 'blah'
1266 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1267 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1268 call assert_match('"' .. cmd .. ' SomeVar', @:)
1269 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1270 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1271 endfor
1272 unlet g:SomeVar
1273endfunc
1274
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001275func Test_cmdline_complete_argopt()
1276 " completion for ++opt=arg for file commands
1277 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1278 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1279 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1280
1281 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001282 " Test ++ff in the middle of the cmdline
1283 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1284 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001285
1286 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1287 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1288 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1289 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1290 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1291
1292 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1293
1294 " completion should skip the ++opt and continue
1295 call writefile([], 'Xaaaaa.txt', 'D')
1296 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1297 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1298
1299 if has('terminal')
1300 " completion for terminal's [options]
1301 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1302 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1303 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1304
1305 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1306
1307 " :terminal completion should skip the ++opt when considering what is the
1308 " first option, which is a list of shell commands, unlike second option
1309 " onwards.
1310 let first_param = getcompletion('terminal ', 'cmdline')
1311 let second_param = getcompletion('terminal foo ', 'cmdline')
1312 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1313 call assert_equal(first_param, skipped_opt_param)
1314 call assert_notequal(first_param, second_param)
1315 endif
1316endfunc
1317
Bram Moolenaar47016f52021-08-26 16:39:58 +02001318" Unique function name for completion below
1319func s:WeirdFunc()
1320 echo 'weird'
1321endfunc
1322
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001323" Test for various command-line completion
1324func Test_cmdline_complete_various()
1325 " completion for a command starting with a comment
1326 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1327 call assert_equal("\" :|\"\<C-A>", @:)
1328
1329 " completion for a range followed by a comment
1330 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1331 call assert_equal("\"1,2\"\<C-A>", @:)
1332
1333 " completion for :k command
1334 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1335 call assert_equal("\"ka\<C-A>", @:)
1336
Doug Kearnsea842022024-09-29 17:17:41 +02001337 " completion for :keepmarks command
1338 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1339 call assert_equal("\"kee edit", @:)
1340
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001341 " completion for short version of the :s command
1342 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1343 call assert_equal("\"sI \<C-A>", @:)
1344
1345 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001346 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001347 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001348 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001349 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001350 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1351 call assert_equal("\"w >> Xfile1", @:)
1352 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001353
1354 " completion for :w ! and :r ! commands
1355 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1356 call assert_equal("\"w !invalid_xyz_cmd", @:)
1357 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1358 call assert_equal("\"r !invalid_xyz_cmd", @:)
1359
1360 " completion for :>> and :<< commands
1361 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1362 call assert_equal("\">>>\<C-A>", @:)
1363 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1364 call assert_equal("\"<<<\<C-A>", @:)
1365
1366 " completion for command with +cmd argument
1367 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1368 call assert_equal("\"buffer +/pat Xabc", @:)
1369 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1370 call assert_equal("\"buffer +/pat\<C-A>", @:)
1371
1372 " completion for a command with a trailing comment
1373 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1374 call assert_equal("\"ls \" comment\<C-A>", @:)
1375
1376 " completion for a command with a trailing command
1377 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1378 call assert_equal("\"ls | ls", @:)
1379
1380 " completion for a command with an CTRL-V escaped argument
1381 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1382 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1383
1384 " completion for a command that doesn't take additional arguments
1385 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1386 call assert_equal("\"all abc\<C-A>", @:)
1387
zeertzjqd3de1782022-09-01 12:58:52 +01001388 " completion for :wincmd with :horizontal modifier
1389 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1390 call assert_equal("\"horizontal wincmd", @:)
1391
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001392 " completion for a command with a command modifier
1393 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1394 call assert_equal("\"topleft new", @:)
1395
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001396 " completion for vim9 and legacy commands
1397 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1398 call assert_equal("\"vim9 call strlen(", @:)
1399 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1400 call assert_equal("\"legac call strlen(", @:)
1401
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001402 " completion for the :disassemble command
1403 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1404 call assert_equal("\"disas debug", @:)
1405 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1406 call assert_equal("\"disas profile", @:)
1407 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1408 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1409 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1410 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001411 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1412 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001413
Bram Moolenaar47016f52021-08-26 16:39:58 +02001414 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001415 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001416
naohiro onodfe04db2021-09-12 15:45:10 +02001417 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1418 call assert_match('"disas <SNR>\d\+_', @:)
1419 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1420 call assert_match('"disas debug <SNR>\d\+_', @:)
1421
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001422 " completion for the :match command
1423 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1424 call assert_equal("\"match Search /pat/\<C-A>", @:)
1425
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001426 " completion for the :doautocmd command
1427 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1428 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1429
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001430 " completion of autocmd group after comma
1431 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1432 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1433
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001434 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001435 call writefile([], 'Xvarfile1', 'D')
1436 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001437 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1438 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001439
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001440 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001441 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001442 augroup END
1443 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001444 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001445
1446 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001447 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1448 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001449 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1450 call assert_equal("\"au XTest.test", @:)
1451
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001452 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001453
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001454 " autocmd pattern completion
1455 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1456 call assert_equal("\"au BufEnter *.py\t", @:)
1457
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001458 " completion for the :unlet command
1459 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1460 call assert_equal("\"unlet one two", @:)
1461
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001462 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001463 " FIXME: what should happen on MS-Windows?
1464 if !has('win32')
1465 edit \{someFile}
1466 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1467 call assert_equal("\"buf {someFile}", @:)
1468 bwipe {someFile}
1469 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001470
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001471 " completion for the :bdelete command
1472 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1473 call assert_equal("\"bdel a b c", @:)
1474
1475 " completion for the :mapclear command
1476 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1477 call assert_equal("\"mapclear <buffer>", @:)
1478
1479 " completion for user defined commands with menu names
1480 menu Test.foo :ls<CR>
1481 com -nargs=* -complete=menu MyCmd
1482 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1483 call assert_equal('"MyCmd Test.', @:)
1484 delcom MyCmd
1485 unmenu Test
1486
1487 " completion for user defined commands with mappings
1488 mapclear
1489 map <F3> :ls<CR>
1490 com -nargs=* -complete=mapping MyCmd
1491 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001492 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001493 mapclear
1494 delcom MyCmd
1495
Yee Cheng Chin54844852023-10-09 18:12:31 +02001496 " Prepare for path completion
1497 call mkdir('Xa b c', 'D')
1498 defer delete('Xcomma,foobar.txt')
1499 call writefile([], 'Xcomma,foobar.txt')
1500
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001501 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001502 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1503 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1504 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001505
1506 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001507 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1508 call assert_equal('"set dir=Xa\ b\ c/', @:)
1509 set dir&
1510
1511 " completion for :set tags= / set dictionary= with escaped commas
1512 if has('win32')
1513 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1514 " '\,'
1515 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1516 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1517
1518 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1519 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1520
1521 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1522 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1523
1524 " completion for :set dictionary= with escaped commas (same behavior, but
1525 " different internal code path from 'set tags=' for escaping the output)
1526 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1527 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1528 else
1529 " In other platforms, backslashes are rounded down (since '\,' itself will
1530 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1531 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1532 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1533
1534 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1535 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1536
1537 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1538 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1539
1540 " completion for :set dictionary= with escaped commas (same behavior, but
1541 " different internal code path from 'set tags=' for escaping the output)
1542 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1543 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1544 endif
1545 set tags&
1546 set dictionary&
1547
1548 " completion for :set makeprg= with no escaped commas
1549 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1550 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1551
1552 if !has('win32')
1553 " Cannot create file with backslash in file name in Windows, so only test
1554 " this elsewhere.
1555 defer delete('Xcomma\,fooslash.txt')
1556 call writefile([], 'Xcomma\,fooslash.txt')
1557 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1558 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1559 endif
1560 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001561
1562 " completion for the :py3 commands
1563 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1564 call assert_equal('"py3 py3do py3file', @:)
1565
Bram Moolenaardf749a22021-03-28 15:29:43 +02001566 " completion for the :vim9 commands
1567 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1568 call assert_equal('"vim9cmd vim9script', @:)
1569
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001570 " redir @" is not the start of a comment. So complete after that
1571 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1572 call assert_equal('"redir @" | cwindow', @:)
1573
1574 " completion after a backtick
1575 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1576 call assert_equal('"e `a1b2c', @:)
1577
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001578 " completion for :language command with an invalid argument
1579 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1580 call assert_equal("\"language dummy \t", @:)
1581
1582 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001583 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1584 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001585
1586 " completion with ambiguous user defined commands
1587 com TCmd1 echo 'TCmd1'
1588 com TCmd2 echo 'TCmd2'
1589 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1590 call assert_equal('"TCmd ', @:)
1591 delcom TCmd1
1592 delcom TCmd2
1593
1594 " completion after a range followed by a pipe (|) character
1595 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1596 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001597
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001598 " completion after a :global command
1599 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1600 call assert_equal('"g/a/chistory', @:)
1601 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1602 call assert_equal("\"g/a\\/chist\t", @:)
1603
Bram Moolenaar9c929712020-09-07 22:05:28 +02001604 " use <Esc> as the 'wildchar' for completion
1605 set wildchar=<Esc>
1606 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1607 call assert_equal('"g/a\xb/clearjumps', @:)
1608 " pressing <esc> twice should cancel the command
1609 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1610 call assert_equal('"g/a\xb/clearjumps', @:)
1611 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001612
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001613 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001614 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001615 call writefile([], '~Xtest')
1616 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1617 call assert_equal('"e \~Xtest', @:)
1618 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001619
1620 " should be able to complete a file name that has a '*'
1621 call writefile([], 'Xx*Yy')
1622 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1623 call assert_equal('"e Xx\*Yy', @:)
1624 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001625
1626 " use a literal star
1627 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1628 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001629 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001630
1631 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1632 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001633endfunc
1634
zeertzjq094dd152023-06-15 22:51:57 +01001635" Test that expanding a pattern doesn't interfere with cmdline completion.
1636func Test_expand_during_cmdline_completion()
1637 func ExpandStuff()
1638 badd <script>:p:h/README.*
1639 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1640 $bwipe
1641 call assert_equal('README.txt', expand('README.*'))
1642 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1643 endfunc
1644 augroup test_CmdlineChanged
1645 autocmd!
1646 autocmd CmdlineChanged * call ExpandStuff()
1647 augroup END
1648
1649 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1650 call assert_equal('"sign place', @:)
1651
1652 augroup test_CmdlineChanged
1653 au!
1654 augroup END
1655 augroup! test_CmdlineChanged
1656 delfunc ExpandStuff
1657endfunc
1658
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001659" Test for 'wildignorecase'
1660func Test_cmdline_wildignorecase()
1661 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001662 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001663 set wildignorecase
1664 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1665 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001666 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001667 let g:Sline = ''
1668 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1669 call assert_equal('"e xt', @:)
1670 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001671 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001672endfunc
1673
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001674func Test_cmdline_write_alternatefile()
1675 new
1676 call setline('.', ['one', 'two'])
1677 f foo.txt
1678 new
1679 f #-A
1680 call assert_equal('foo.txt-A', expand('%'))
1681 f #<-B.txt
1682 call assert_equal('foo-B.txt', expand('%'))
1683 f %<
1684 call assert_equal('foo-B', expand('%'))
1685 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001686 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001687 bw!
1688 f foo-B.txt
1689 f %<-A
1690 call assert_equal('foo-B-A', expand('%'))
1691 bw!
1692 bw!
1693endfunc
1694
Bram Moolenaarf5724372022-09-02 19:45:15 +01001695func Test_cmdline_expand_cur_alt_file()
1696 enew
1697 file http://some.com/file.txt
1698 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1699 call assert_equal('"e http://some.com/file.txt', @:)
1700 edit another
1701 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1702 call assert_equal('"e http://some.com/file.txt', @:)
1703 bwipe
1704 bwipe http://some.com/file.txt
1705endfunc
1706
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001707" using a leading backslash here
1708set cpo+=C
1709
1710func Test_cmdline_search_range()
1711 new
1712 call setline(1, ['a', 'b', 'c', 'd'])
1713 /d
1714 1,\/s/b/B/
1715 call assert_equal('B', getline(2))
1716
1717 /a
1718 $
1719 \?,4s/c/C/
1720 call assert_equal('C', getline(3))
1721
1722 call setline(1, ['a', 'b', 'c', 'd'])
1723 %s/c/c/
1724 1,\&s/b/B/
1725 call assert_equal('B', getline(2))
1726
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001727 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001728 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001729
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001730 bwipe!
1731endfunc
1732
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001733" Test for the tick mark (') in an excmd range
1734func Test_tick_mark_in_range()
1735 " If only the tick is passed as a range and no command is specified, there
1736 " should not be an error
1737 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001738 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001739 call assert_fails("',print", 'E78:')
1740endfunc
1741
1742" Test for using a line number followed by a search pattern as range
1743func Test_lnum_and_pattern_as_range()
1744 new
1745 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1746 let @" = ''
1747 2/foo/yank
1748 call assert_equal("foo 3\n", @")
1749 call assert_equal(1, line('.'))
1750 close!
1751endfunc
1752
Bram Moolenaar65189a12017-02-06 22:22:17 +01001753" Tests for getcmdline(), getcmdpos() and getcmdtype()
1754func Check_cmdline(cmdtype)
1755 call assert_equal('MyCmd a', getcmdline())
1756 call assert_equal(8, getcmdpos())
1757 call assert_equal(a:cmdtype, getcmdtype())
1758 return ''
1759endfunc
1760
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001761set cpo&
1762
Shougo Matsushita69084282024-09-23 20:34:47 +02001763func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001764 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1765
1766 let cmdtype = ''
1767 debuggreedy
1768 call feedkeys(":debug echo 'test'\<CR>", "t")
1769 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1770 call feedkeys("cont\<CR>", "xt")
1771 0debuggreedy
1772 call assert_equal('>', cmdtype)
1773
1774 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1775 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1776
1777 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001778 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001779
1780 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1781
1782 cnoremap <expr> <F6> Check_cmdline('=')
1783 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1784 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001785
1786 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001787
1788 call assert_equal('', getcmdprompt())
1789 augroup test_CmdlineEnter
1790 autocmd!
1791 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1792 augroup END
1793 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1794 call assert_equal('Answer?', g:cmdprompt)
1795 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001796 call feedkeys(":\<CR>\<ESC>", "xt")
1797 call assert_equal('', g:cmdprompt)
1798 call assert_equal('', getcmdprompt())
1799
1800 let str = "C" .. repeat("c", 1023) .. "xyz"
1801 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1802 call assert_equal(str, g:cmdprompt)
1803
1804 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1805 call assert_equal('Ans?', g:cmdprompt)
1806 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001807
1808 augroup test_CmdlineEnter
1809 au!
1810 augroup END
1811 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001812endfunc
1813
Bram Moolenaar52604f22017-04-07 16:17:39 +02001814func Test_verbosefile()
1815 set verbosefile=Xlog
1816 echomsg 'foo'
1817 echomsg 'bar'
1818 set verbosefile=
1819 let log = readfile('Xlog')
1820 call assert_match("foo\nbar", join(log, "\n"))
1821 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001822
1823 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001824 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001825endfunc
1826
Bram Moolenaar4facea32019-10-12 20:17:40 +02001827func Test_verbose_option()
1828 CheckScreendump
1829
1830 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001831 " clear the TermResponse autocommand from defaults.vim
1832 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001833 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1834 call feedkeys("\r", 't') " for the hit-enter prompt
1835 set verbose=20
1836 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001837 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001838
1839 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001840 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001841 call term_sendkeys(buf, ":DoSomething\<CR>")
1842 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1843
1844 " clean up
1845 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001846endfunc
1847
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001848func Test_setcmdpos()
1849 func InsertTextAtPos(text, pos)
1850 call assert_equal(0, setcmdpos(a:pos))
1851 return a:text
1852 endfunc
1853
1854 " setcmdpos() with position in the middle of the command line.
1855 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1856 call assert_equal('"1ab2', @:)
1857
1858 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1859 call assert_equal('"1b2a', @:)
1860
1861 " setcmdpos() with position beyond the end of the command line.
1862 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1863 call assert_equal('"12ab', @:)
1864
1865 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001866 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001867endfunc
1868
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001869func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001870 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001871 let encoding_save = &encoding
1872
1873 for e in encodings
1874 exe 'set encoding=' . e
1875
1876 " Test overstrike in the middle of the command line.
1877 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001878 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001879
1880 " Test overstrike going beyond end of command line.
1881 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001882 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001883
1884 " Test toggling insert/overstrike a few times.
1885 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001886 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001887 endfor
1888
Bram Moolenaar30276f22019-01-24 17:59:39 +01001889 " Test overstrike with multi-byte characters.
1890 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001891 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001892
1893 let &encoding = encoding_save
1894endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001895
Bram Moolenaar52410572019-10-27 05:12:45 +01001896func Test_buffers_lastused()
1897 " check that buffers are sorted by time when wildmode has lastused
1898 call test_settime(1550020000) " middle
1899 edit bufa
1900 enew
1901 call test_settime(1550030000) " newest
1902 edit bufb
1903 enew
1904 call test_settime(1550010000) " oldest
1905 edit bufc
1906 enew
1907 call test_settime(0)
1908 enew
1909
1910 call assert_equal(['bufa', 'bufb', 'bufc'],
1911 \ getcompletion('', 'buffer'))
1912
1913 let save_wildmode = &wildmode
1914 set wildmode=full:lastused
1915
1916 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1917 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1918 call assert_equal('b bufb', X)
1919 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1920 call assert_equal('b bufa', X)
1921 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1922 call assert_equal('b bufc', X)
1923 enew
1924
1925 edit other
1926 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1927 call assert_equal('b bufb', X)
1928 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1929 call assert_equal('b bufa', X)
1930 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1931 call assert_equal('b bufc', X)
1932 enew
1933
1934 let &wildmode = save_wildmode
1935
1936 bwipeout bufa
1937 bwipeout bufb
1938 bwipeout bufc
1939endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001940
Bram Moolenaar479950f2020-01-19 15:45:17 +01001941func Test_cmdlineclear_tabenter()
1942 CheckScreendump
1943
1944 let lines =<< trim [SCRIPT]
1945 call setline(1, range(30))
1946 [SCRIPT]
1947
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001948 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001949 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001950 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001951 " in one tab make the command line higher with CTRL-W -
1952 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1953 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1954
1955 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001956endfunc
1957
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001958" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001959func Test_cmdline_expand_special()
1960 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001961 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001962 call assert_fails('e <afile>', 'E495:')
1963 call assert_fails('e <abuf>', 'E496:')
1964 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001965
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001966 call writefile([], 'Xfile.cpp', 'D')
1967 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001968 new Xfile.cpp
1969 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1970 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1971 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001972endfunc
1973
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001974" Test for backtick expression in the command line
1975func Test_cmd_backtick()
1976 %argd
1977 argadd `=['a', 'b', 'c']`
1978 call assert_equal(['a', 'b', 'c'], argv())
1979 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001980
1981 argadd `echo abc def`
1982 call assert_equal(['abc def'], argv())
1983 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001984endfunc
1985
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001986" Test for the :! command
1987func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001988 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001989
1990 let lines =<< trim [SCRIPT]
1991 " Test for no previous command
1992 call assert_fails('!!', 'E34:')
1993 set nomore
1994 " Test for cmdline expansion with :!
1995 call setline(1, 'foo!')
1996 silent !echo <cWORD> > Xfile.out
1997 call assert_equal(['foo!'], readfile('Xfile.out'))
1998 " Test for using previous command
1999 silent !echo \! !
2000 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
2001 call writefile(v:errors, 'Xresult')
2002 call delete('Xfile.out')
2003 qall!
2004 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002005 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002006 if RunVim([], [], '--clean -S Xscript')
2007 call assert_equal([], readfile('Xresult'))
2008 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002009 call delete('Xresult')
2010endfunc
2011
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002012" Test error: "E135: *Filter* Autocommands must not change current buffer"
2013func Test_cmd_bang_E135()
2014 new
2015 call setline(1, ['a', 'b', 'c', 'd'])
2016 augroup test_cmd_filter_E135
2017 au!
2018 autocmd FilterReadPost * help
2019 augroup END
2020 call assert_fails('2,3!echo "x"', 'E135:')
2021
2022 augroup test_cmd_filter_E135
2023 au!
2024 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002025 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002026 %bwipe!
2027endfunc
2028
shane.xb.qian4e7590e2022-11-08 21:40:04 +00002029func Test_cmd_bang_args()
2030 new
2031 :.!
2032 call assert_equal(0, v:shell_error)
2033
2034 " Note that below there is one space char after the '!'. This caused a
2035 " shell error in the past, see https://github.com/vim/vim/issues/11495.
2036 :.!
2037 call assert_equal(0, v:shell_error)
2038 bwipe!
2039
2040 CheckUnix
2041 :.!pwd
2042 call assert_equal(0, v:shell_error)
2043 :.! pwd
2044 call assert_equal(0, v:shell_error)
2045
2046 " Note there is one space after 'pwd'.
2047 :.! pwd
2048 call assert_equal(0, v:shell_error)
2049
2050 " Note there are two spaces after 'pwd'.
2051 :.! pwd
2052 call assert_equal(0, v:shell_error)
2053 :.!ls ~
2054 call assert_equal(0, v:shell_error)
2055
2056 " Note there is one space char after '~'.
2057 :.!ls ~
2058 call assert_equal(0, v:shell_error)
2059
2060 " Note there are two spaces after '~'.
2061 :.!ls ~
2062 call assert_equal(0, v:shell_error)
2063
2064 :.!echo "foo"
2065 call assert_equal(getline('.'), "foo")
2066 :.!echo "foo "
2067 call assert_equal(getline('.'), "foo ")
2068 :.!echo " foo "
2069 call assert_equal(getline('.'), " foo ")
2070 :.!echo " foo "
2071 call assert_equal(getline('.'), " foo ")
2072
2073 %bwipe!
2074endfunc
2075
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002076" Test for using ~ for home directory in cmdline completion matches
2077func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002078 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002079 call writefile([], 'Xexpdir/Xfile1')
2080 call writefile([], 'Xexpdir/Xfile2')
2081 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002082 let save_HOME = $HOME
2083 let $HOME = getcwd()
2084 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
2085 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
2086 let $HOME = save_HOME
2087 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002088endfunc
2089
Bram Moolenaar578fe942020-02-27 21:32:51 +01002090" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
2091" or insert mode (when 'insertmode' is set)
2092func Test_cmdline_ctrl_g()
2093 new
2094 call setline(1, 'abc')
2095 call cursor(1, 3)
2096 " If command line is entered from insert mode, using C-\ C-G should back to
2097 " insert mode
2098 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
2099 call assert_equal('abxyc', getline(1))
2100 call assert_equal(4, col('.'))
2101
2102 " If command line is entered in 'insertmode', using C-\ C-G should back to
2103 " 'insertmode'
2104 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
2105 call assert_equal('ab12xyc', getline(1))
2106 close!
2107endfunc
2108
Bram Moolenaar578fe942020-02-27 21:32:51 +01002109" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002110func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01002111 func T(a, c, p)
2112 return "oneA\noneB\noneC"
2113 endfunc
2114 command -nargs=1 -complete=custom,T MyCmd
2115
Bram Moolenaar578fe942020-02-27 21:32:51 +01002116 set nowildmenu
2117 set wildmode=full,list
2118 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002119 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002120 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002121 call assert_equal('"MyCmd oneA', @:)
2122
2123 set wildmode=longest,full
2124 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2125 call assert_equal('"MyCmd one', @:)
2126 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2127 call assert_equal('"MyCmd oneC', @:)
2128
2129 set wildmode=longest
2130 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2131 call assert_equal('"MyCmd one', @:)
2132
2133 set wildmode=list:longest
2134 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002135 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002136 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002137 call assert_equal('"MyCmd one', @:)
2138
2139 set wildmode=""
2140 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2141 call assert_equal('"MyCmd oneA', @:)
2142
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002143 " Test for wildmode=longest with 'fileignorecase' set
2144 set wildmode=longest
2145 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002146 argadd AAA AAAA AAAAA
2147 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2148 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002149 set fileignorecase&
2150
2151 " Test for listing files with wildmode=list
2152 set wildmode=list
2153 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002154 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002155 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002156 call assert_equal('"b A', @:)
2157
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002158 " when using longest completion match, matches shorter than the argument
2159 " should be ignored (happens with :help)
2160 set wildmode=longest,full
2161 set wildmenu
2162 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2163 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002164 " non existing file
2165 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2166 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002167 set wildmenu&
2168
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002169 " Test for longest file name completion with 'fileignorecase'
2170 " On MS-Windows, file names are case insensitive.
2171 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002172 call writefile([], 'XTESTfoo', 'D')
2173 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002174 set nofileignorecase
2175 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2176 call assert_equal('"e XTESTfoo', @:)
2177 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2178 call assert_equal('"e Xtestbar', @:)
2179 set fileignorecase
2180 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2181 call assert_equal('"e Xtest', @:)
2182 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2183 call assert_equal('"e Xtest', @:)
2184 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002185 endif
2186
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002187 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002188 delcommand MyCmd
2189 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002190 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002191 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002192endfunc
2193
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002194func Test_wildmode()
2195 " Test with utf-8 encoding
2196 call Wildmode_tests()
2197
2198 " Test with latin1 encoding
2199 let save_encoding = &encoding
2200 set encoding=latin1
2201 call Wildmode_tests()
2202 let &encoding = save_encoding
2203endfunc
2204
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002205func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002206 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002207 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002208 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002209 let lines =<< trim END
2210 func vim8#Complete(a, c, p)
2211 return "oneA\noneB\noneC"
2212 endfunc
2213 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002214 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002215
2216 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2217 set nowildmenu
2218 set wildmode=full,list
2219 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2220 call assert_equal('"MyCmd oneA oneB oneC', @:)
2221
2222 let &rtp = save_rtp
2223 set wildmode& wildmenu&
2224 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002225endfunc
2226
Bram Moolenaar578fe942020-02-27 21:32:51 +01002227" Test for interrupting the command-line completion
2228func Test_interrupt_compl()
2229 func F(lead, cmdl, p)
2230 if a:lead =~ 'tw'
2231 call interrupt()
2232 return
2233 endif
2234 return "one\ntwo\nthree"
2235 endfunc
2236 command -nargs=1 -complete=custom,F Tcmd
2237
2238 set nowildmenu
2239 set wildmode=full
2240 let interrupted = 0
2241 try
2242 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2243 catch /^Vim:Interrupt$/
2244 let interrupted = 1
2245 endtry
2246 call assert_equal(1, interrupted)
2247
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002248 let interrupted = 0
2249 try
2250 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2251 catch /^Vim:Interrupt$/
2252 let interrupted = 1
2253 endtry
2254 call assert_equal(1, interrupted)
2255
Bram Moolenaar578fe942020-02-27 21:32:51 +01002256 delcommand Tcmd
2257 delfunc F
2258 set wildmode&
2259endfunc
2260
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002261" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002262func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002263 let str = ":one two\<C-U>"
2264 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002265 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002266 let str ..= "\<Left>five\<Right>"
2267 let str ..= "\<Home>two "
2268 let str ..= "\<C-Left>one "
2269 let str ..= "\<C-Right> three"
2270 let str ..= "\<End>\<S-Left>four "
2271 let str ..= "\<S-Right> six"
2272 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2273 call feedkeys(str, 'xt')
2274 call assert_equal("\"one two three four five six seven", @:)
2275endfunc
2276
2277" Test for moving the cursor on the / command line in 'rightleft' mode
2278func Test_cmdline_edit_rightleft()
2279 CheckFeature rightleft
2280 set rightleft
2281 set rightleftcmd=search
2282 let str = "/one two\<C-U>"
2283 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002284 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002285 let str ..= "\<Right>five\<Left>"
2286 let str ..= "\<Home>two "
2287 let str ..= "\<C-Right>one "
2288 let str ..= "\<C-Left> three"
2289 let str ..= "\<End>\<S-Right>four "
2290 let str ..= "\<S-Left> six"
2291 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2292 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2293 call assert_equal("\"one two three four five six seven", @/)
2294 set rightleftcmd&
2295 set rightleft&
2296endfunc
2297
2298" Test for using <C-\>e in the command line to evaluate an expression
2299func Test_cmdline_expr()
2300 " Evaluate an expression from the beginning of a command line
2301 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2302 call assert_equal('"hello', @:)
2303
2304 " Use an invalid expression for <C-\>e
2305 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2306
2307 " Insert literal <CTRL-\> in the command line
2308 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2309 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002310endfunc
2311
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002312" This was making the insert position negative
2313func Test_cmdline_expr_register()
2314 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2315endfunc
2316
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002317" Test for 'imcmdline' and 'imsearch'
2318" This test doesn't actually test the input method functionality.
2319func Test_cmdline_inputmethod()
2320 new
2321 call setline(1, ['', 'abc', ''])
2322 set imcmdline
2323
2324 call feedkeys(":\"abc\<CR>", 'xt')
2325 call assert_equal("\"abc", @:)
2326 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2327 call assert_equal("\"abc", @:)
2328 call feedkeys("/abc\<CR>", 'xt')
2329 call assert_equal([2, 1], [line('.'), col('.')])
2330 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2331 call assert_equal([2, 1], [line('.'), col('.')])
2332
2333 set imsearch=2
2334 call cursor(1, 1)
2335 call feedkeys("/abc\<CR>", 'xt')
2336 call assert_equal([2, 1], [line('.'), col('.')])
2337 call cursor(1, 1)
2338 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2339 call assert_equal([2, 1], [line('.'), col('.')])
2340 set imdisable
2341 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2342 call assert_equal([2, 1], [line('.'), col('.')])
2343 set imdisable&
2344 set imsearch&
2345
2346 set imcmdline&
2347 %bwipe!
2348endfunc
2349
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002350" Test for using CTRL-_ in the command line with 'allowrevins'
2351func Test_cmdline_revins()
2352 CheckNotMSWindows
2353 CheckFeature rightleft
2354 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2355 call assert_equal("\"abc\<c-_>", @:)
2356 set allowrevins
2357 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2358 call assert_equal('"abcñèæ', @:)
2359 set allowrevins&
2360endfunc
2361
2362" Test for typing UTF-8 composing characters in the command line
2363func Test_cmdline_composing_chars()
2364 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2365 call assert_equal('"ゔ', @:)
2366endfunc
2367
Bram Moolenaar0e717042020-04-27 19:29:01 +02002368" test that ";" works to find a match at the start of the first line
2369func Test_zero_line_search()
2370 new
2371 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2372 call cursor(1,1)
2373 0;/pattern/d
2374 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2375 q!
2376endfunc
2377
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002378func Test_read_shellcmd()
2379 CheckUnix
2380 if executable('ls')
2381 " There should be ls in the $PATH
2382 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2383 call assert_match('^"r! .*\<ls\>', @:)
2384 endif
2385
2386 if executable('rm')
2387 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2388 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2389 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002390
2391 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2392 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2393 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002394 endif
2395endfunc
2396
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002397" Test for going up and down the directory tree using 'wildmenu'
2398func Test_wildmenu_dirstack()
2399 CheckUnix
2400 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002401 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002402 call writefile([], 'Xwildmenu/file1_1.txt')
2403 call writefile([], 'Xwildmenu/file1_2.txt')
2404 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2405 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2406 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2407 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2408 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2409 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002410 set wildmenu
2411
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002412 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002413 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002414 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002415 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002416 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002417 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002418 call assert_equal('"e ../../dir3/', @:)
2419 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2420 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002421 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002422 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002423 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002424 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002425 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002426 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2427 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002428
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002429 set wildmenu&
2430endfunc
2431
obcat71c6f7a2021-05-13 20:23:10 +02002432" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002433" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2434" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002435func Test_recalling_cmdline()
2436 CheckFeature cmdline_hist
2437
2438 let g:cmdlines = []
2439 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2440
2441 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002442 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2443 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2444 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2445 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002446 "\ TODO: {'name': 'debug', ...}
2447 \]
2448 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002449 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2450 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2451 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2452 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2453 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002454 \]
2455 let prefix = 'vi'
2456 for h in histories
2457 call histadd(h.name, 'vim')
2458 call histadd(h.name, 'virtue')
2459 call histadd(h.name, 'Virgo')
2460 call histadd(h.name, 'vogue')
2461 call histadd(h.name, 'emacs')
2462 for k in keypairs
2463 let g:cmdlines = []
2464 let keyseqs = h.enter
2465 \ .. prefix
2466 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2467 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2468 \ .. h.exit
2469 call feedkeys(keyseqs, 'xt')
2470 call histdel(h.name, -1) " delete the history added by feedkeys above
2471 let expect = k.prefixmatch
2472 \ ? ['virtue', 'vim', 'virtue', prefix]
2473 \ : ['emacs', 'vogue', 'emacs', prefix]
2474 call assert_equal(expect, g:cmdlines)
2475 endfor
2476 endfor
2477
2478 unlet g:cmdlines
2479 cunmap <Plug>(save-cmdline)
2480endfunc
2481
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002482func Test_cmd_map_cmdlineChanged()
2483 let g:log = []
2484 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002485 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002486 autocmd!
2487 autocmd CmdlineChanged : let g:log += [getcmdline()]
2488 augroup END
2489
2490 call feedkeys(":\<F1>\<CR>", 'xt')
2491 call assert_equal(['l', 'ls'], g:log)
2492
Bram Moolenaar796139a2021-05-18 21:38:45 +02002493 let @b = 'b'
2494 cnoremap <F1> a<C-R>b
2495 let g:log = []
2496 call feedkeys(":\<F1>\<CR>", 'xt')
2497 call assert_equal(['a', 'ab'], g:log)
2498
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002499 unlet g:log
2500 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002501 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002502 autocmd!
2503 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002504 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002505endfunc
2506
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002507" Test for the 'suffixes' option
2508func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002509 call writefile([], 'Xsuffile', 'D')
2510 call writefile([], 'Xsuffile.c', 'D')
2511 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002512 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002513 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2514 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2515 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2516 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002517 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002518 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2519 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2520 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2521 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002522 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002523 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2524 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2525 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2526 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002527 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002528 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002529 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2530 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002531endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002532
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002533" Test for using a popup menu for the command line completion matches
2534" (wildoptions=pum)
2535func Test_wildmenu_pum()
2536 CheckRunVimInTerminal
2537
2538 let commands =<< trim [CODE]
2539 set wildmenu
2540 set wildoptions=pum
2541 set shm+=I
2542 set noruler
2543 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002544
2545 func CmdCompl(a, b, c)
2546 return repeat(['aaaa'], 120)
2547 endfunc
2548 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002549
2550 func MyStatusLine() abort
2551 return 'status'
2552 endfunc
2553 func SetupStatusline()
2554 set statusline=%!MyStatusLine()
2555 set laststatus=2
2556 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002557
2558 func MyTabLine()
2559 return 'my tab line'
2560 endfunc
2561 func SetupTabline()
2562 set statusline=
2563 set tabline=%!MyTabLine()
2564 set showtabline=2
2565 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002566
2567 func DoFeedKeys()
2568 let &wildcharm = char2nr("\t")
2569 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2570 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002571 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002572 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002573
2574 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2575
2576 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002577 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2578
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002579 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002580 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002581 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2582
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002583 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002584 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002585 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2586
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002587 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002588 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002589 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2590
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002591 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002592 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002593 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2594
2595 " pressing <C-E> should end completion and go back to the original match
2596 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002597 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2598
2599 " pressing <C-Y> should select the current match and end completion
2600 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002601 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2602
2603 " With 'wildmode' set to 'longest,full', completing a match should display
2604 " the longest match, the wildmenu should not be displayed.
2605 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2606 call TermWait(buf)
2607 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002608 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2609
2610 " pressing <Tab> should display the wildmenu
2611 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002612 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2613
2614 " pressing <Tab> second time should select the next entry in the menu
2615 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002616 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2617
2618 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002619 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002620 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002621 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2622
2623 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002624 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2625
2626 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002627 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2628
2629 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002630 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002631 call writefile([], 'Xnamedir/XfileA')
2632 call writefile([], 'Xnamedir/XdirA/XfileB')
2633 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002634
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002635 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002636 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2637
2638 " Pressing <Right> on a directory name should go into that directory
2639 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002640 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2641
2642 " Pressing <Left> on a directory name should go to the parent directory
2643 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002644 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2645
2646 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002647 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002648 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002649 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2650
2651 " Pressing <C-D> when the popup menu is displayed should remove the popup
2652 " menu
2653 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002654 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2655
2656 " Pressing <S-Tab> should open the popup menu with the last entry selected
2657 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002658 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2659
2660 " Pressing <Esc> should close the popup menu and cancel the cmd line
2661 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002662 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2663
2664 " Typing a character when the popup is open, should close the popup
2665 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002666 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2667
2668 " When the popup is open, entering the cmdline window should close the popup
2669 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002670 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2671 call term_sendkeys(buf, ":q\<CR>")
2672
2673 " After the last popup menu item, <C-N> should show the original string
2674 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002675 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2676
2677 " Use the popup menu for the command name
2678 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002679 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2680
2681 " Pressing the left arrow should remove the popup menu
2682 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002683 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2684
2685 " Pressing <BS> should remove the popup menu and erase the last character
2686 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002687 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2688
2689 " Pressing <C-W> should remove the popup menu and erase the previous word
2690 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002691 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2692
2693 " Pressing <C-U> should remove the popup menu and erase the entire line
2694 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002695 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2696
2697 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2698 " the cmdline from history
2699 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002700 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2701
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002702 " Check "list" still works
2703 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2704 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002705 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2706 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002707 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2708
rbtnn68cc2b82022-02-09 11:55:47 +00002709 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002710 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002711 call writefile([], 'Xnamedir/あいう/abc')
2712 call writefile([], 'Xnamedir/あいう/xyz')
2713 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002714
2715 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002716 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002717 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2718
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002719 " Pressing <C-A> when the popup menu is displayed should list all the
2720 " matches and pressing a key after that should remove the popup menu
2721 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2722 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2723 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2724
2725 " Pressing <C-A> when the popup menu is displayed should list all the
2726 " matches and pressing <Left> after that should move the cursor
2727 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2728 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2729 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2730
2731 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2732 " should be displayed correctly on the screen.
2733 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2734 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2735
2736 " After using <C-A> to expand all the filename matches, pressing <Up>
2737 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002738 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002739 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2740 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2741 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2742
2743 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2744 " crash Vim
2745 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2746 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2747
Bram Moolenaar414acd32022-02-10 21:09:45 +00002748 " After removing the pum the command line is redrawn
2749 call term_sendkeys(buf, ":edit foo\<CR>")
2750 call term_sendkeys(buf, ":edit bar\<CR>")
2751 call term_sendkeys(buf, ":ls\<CR>")
2752 call term_sendkeys(buf, ":com\<Tab> ")
2753 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002754 call term_sendkeys(buf, "\<C-U>\<CR>")
2755
2756 " Esc still works to abort the command when 'statusline' is set
2757 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2758 call term_sendkeys(buf, ":si\<Tab>")
2759 call term_sendkeys(buf, "\<Esc>")
2760 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002761
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002762 " Esc still works to abort the command when 'tabline' is set
2763 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2764 call term_sendkeys(buf, ":si\<Tab>")
2765 call term_sendkeys(buf, "\<Esc>")
2766 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2767
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002768 " popup is cleared also when 'lazyredraw' is set
2769 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2770 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2771 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2772 call term_sendkeys(buf, "\<Esc>")
2773
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002774 " Pressing <PageDown> should scroll the menu downward
2775 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2776 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2777 call term_sendkeys(buf, "\<PageDown>")
2778 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2779 call term_sendkeys(buf, "\<PageDown>")
2780 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2781 call term_sendkeys(buf, "\<PageDown>")
2782 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2783 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2784 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2785
2786 " Pressing <PageUp> should scroll the menu upward
2787 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2788 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2789 call term_sendkeys(buf, "\<PageUp>")
2790 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2791 call term_sendkeys(buf, "\<PageUp>")
2792 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2793 call term_sendkeys(buf, "\<PageUp>")
2794 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2795
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002796 " pressing <C-E> to end completion should work in middle of the line too
2797 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2798 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2799 call term_sendkeys(buf, "\<C-E>")
2800 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2801
2802 " pressing <C-Y> should select the current match and end completion
2803 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2804 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2805
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002806 call term_sendkeys(buf, "\<C-U>\<CR>")
2807 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002808endfunc
2809
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002810" Test for wildmenumode() with the cmdline popup menu
2811func Test_wildmenumode_with_pum()
2812 set wildmenu
2813 set wildoptions=pum
2814 cnoremap <expr> <F2> wildmenumode()
2815 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2816 call assert_equal('"sign define10', @:)
2817 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2818 call assert_equal('"sign define jump list place undefine unplace0', @:)
2819 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2820 call assert_equal('"sign 0', @:)
2821 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2822 call assert_equal('"sign define0', @:)
2823 set nowildmenu wildoptions&
2824 cunmap <F2>
2825endfunc
2826
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002827func Test_wildmenu_with_pum_foldexpr()
2828 CheckRunVimInTerminal
2829
2830 let lines =<< trim END
2831 call setline(1, ['folded one', 'folded two', 'some more text'])
2832 func MyFoldText()
2833 return 'foo'
2834 endfunc
2835 set foldtext=MyFoldText() wildoptions=pum
2836 normal ggzfj
2837 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002838 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002839 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2840 call term_sendkeys(buf, ":set\<Tab>")
2841 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2842
2843 call term_sendkeys(buf, "\<Esc>")
2844 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2845
2846 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002847endfunc
2848
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002849" Test for opening the cmdline completion popup menu from the terminal window.
2850" The popup menu should be positioned correctly over the status line of the
2851" bottom-most window.
2852func Test_wildmenu_pum_from_terminal()
2853 CheckRunVimInTerminal
2854 let python = PythonProg()
2855 call CheckPython(python)
2856
2857 %bw!
2858 let cmds = ['set wildmenu wildoptions=pum']
2859 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2860 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002861 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002862 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2863 call term_sendkeys(buf, "\r\r\r")
2864 call term_wait(buf)
2865 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2866 call term_wait(buf)
2867 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2868 call term_wait(buf)
2869 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002870endfunc
2871
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002872func Test_wildmenu_pum_odd_wildchar()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002873 CheckRunVimInTerminal
2874
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002875 " Test odd wildchar interactions with pum. Make sure they behave properly
2876 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002877 let lines =<< trim END
2878 set wildoptions=pum
2879 set wildchar=<C-E>
2880 END
2881 call writefile(lines, 'XwildmenuTest', 'D')
2882 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2883
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002884 call term_sendkeys(buf, ":\<C-E>")
2885 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002886
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002887 " <C-E> being a wildchar takes priority over its original functionality
2888 call term_sendkeys(buf, "\<C-E>")
2889 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2890
2891 call term_sendkeys(buf, "\<Esc>")
2892 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2893
2894 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
2895 " command-line, and we need to make sure to clean up properly.
2896 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
2897 call term_sendkeys(buf, ":\<Esc>")
2898 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2899
2900 call term_sendkeys(buf, "\<Esc>")
2901 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2902
2903 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
2904 " and we again need to make sure we clean up properly.
2905 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
2906 call term_sendkeys(buf, ":\<C-\>\<C-\>")
2907 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2908
2909 call term_sendkeys(buf, "\<C-N>")
2910 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2911
2912 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002913endfunc
2914
zeertzjq883018f2024-06-15 15:37:11 +02002915" Test that 'rightleft' should not affect cmdline completion popup menu.
2916func Test_wildmenu_pum_rightleft()
2917 CheckFeature rightleft
2918 CheckScreendump
2919
2920 let lines =<< trim END
2921 set wildoptions=pum
2922 set rightleft
2923 END
2924 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
2925 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
2926
2927 call term_sendkeys(buf, ":sign \<Tab>")
2928 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
2929
2930 call StopVimInTerminal(buf)
2931endfunc
2932
zeertzjqd8c93402024-06-17 18:25:32 +02002933" Test highlighting matched text in cmdline completion popup menu.
2934func Test_wildmenu_pum_hl_match()
2935 CheckScreendump
2936
2937 let lines =<< trim END
2938 set wildoptions=pum,fuzzy
2939 hi PmenuMatchSel ctermfg=6 ctermbg=7
2940 hi PmenuMatch ctermfg=4 ctermbg=225
2941 END
2942 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
2943 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
2944
2945 call term_sendkeys(buf, ":sign plc\<Tab>")
2946 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
2947 call term_sendkeys(buf, "\<Tab>")
2948 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
2949 call term_sendkeys(buf, "\<Tab>")
2950 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
2951 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
2952 call TermWait(buf)
2953 call term_sendkeys(buf, ":sign un\<Tab>")
2954 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
2955 call term_sendkeys(buf, "\<Tab>")
2956 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
2957 call term_sendkeys(buf, "\<Tab>")
2958 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
2959 call term_sendkeys(buf, "\<Esc>")
2960
2961 call StopVimInTerminal(buf)
2962endfunc
2963
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002964" Test for completion after a :substitute command followed by a pipe (|)
2965" character
2966func Test_cmdline_complete_substitute()
2967 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2968 call assert_equal("\"s | \t", @:)
2969 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2970 call assert_equal("\"s/ | \t", @:)
2971 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2972 call assert_equal("\"s/one | \t", @:)
2973 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2974 call assert_equal("\"s/one/ | \t", @:)
2975 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2976 call assert_equal("\"s/one/two | \t", @:)
2977 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2978 call assert_equal('"s/one/two/ | chistory', @:)
2979 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2980 call assert_equal("\"s/one/two/g \t", @:)
2981 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2982 call assert_equal("\"s/one/two/g | chistory", @:)
2983 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2984 call assert_equal("\"s/one/t\\/ | \t", @:)
2985 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2986 call assert_equal('"s/one/t"o/ | chistory', @:)
2987 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2988 call assert_equal('"s/one/t|o/ | chistory', @:)
2989 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2990 call assert_equal("\"&\t", @:)
2991endfunc
2992
2993" Test for the :dlist command completion
2994func Test_cmdline_complete_dlist()
2995 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2996 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2997 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2998 call assert_equal("\"dlist 10 /pat/ \t", @:)
2999 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
3000 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
3001 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
3002 call assert_equal("\"dlist 10 /pat\\\t", @:)
3003 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
3004 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
3005endfunc
3006
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003007" argument list (only for :argdel) fuzzy completion
3008func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003009 argadd change.py count.py charge.py
3010 set wildoptions&
3011 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3012 call assert_equal('"argdel cge', @:)
3013 set wildoptions=fuzzy
3014 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3015 call assert_equal('"argdel change.py charge.py', @:)
3016 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003017 set wildoptions&
3018endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003019
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003020" autocmd group name fuzzy completion
3021func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003022 set wildoptions&
3023 augroup MyFuzzyGroup
3024 augroup END
3025 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3026 call assert_equal('"augroup mfg', @:)
3027 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3028 call assert_equal('"augroup MyFuzzyGroup', @:)
3029 set wildoptions=fuzzy
3030 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3031 call assert_equal('"augroup MyFuzzyGroup', @:)
3032 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3033 call assert_equal('"augroup My*p', @:)
3034 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003035 set wildoptions&
3036endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003037
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003038" buffer name fuzzy completion
3039func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003040 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003041 " Use a long name to reduce the risk of matching a random directory name
3042 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003043 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003044 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3045 call assert_equal('"b SRFWL', @:)
3046 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3047 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003048 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003049 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3050 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3051 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3052 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003053 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003054 set wildoptions&
3055endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003056
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003057" buffer name (full path) fuzzy completion
3058func Test_fuzzy_completion_bufname_fullpath()
3059 CheckUnix
3060 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003061 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003062 edit Xcmd/Xstate/Xfile.js
3063 cd Xcmd/Xstate
3064 enew
3065 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3066 call assert_equal('"b CmdStateFile', @:)
3067 set wildoptions=fuzzy
3068 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3069 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
3070 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003071 set wildoptions&
3072endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003073
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003074" :behave suboptions fuzzy completion
3075func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003076 set wildoptions&
3077 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3078 call assert_equal('"behave xm', @:)
3079 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3080 call assert_equal('"behave xterm', @:)
3081 set wildoptions=fuzzy
3082 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3083 call assert_equal('"behave xterm', @:)
3084 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3085 call assert_equal('"behave xt*m', @:)
3086 let g:Sline = ''
3087 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
3088 call assert_equal('mswin', g:Sline)
3089 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003090 set wildoptions&
3091endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003092
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003093" " colorscheme name fuzzy completion - NOT supported
3094" func Test_fuzzy_completion_colorscheme()
3095" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003096
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003097" built-in command name fuzzy completion
3098func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003099 set wildoptions&
3100 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3101 call assert_equal('"sbwin', @:)
3102 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3103 call assert_equal('"sbrewind', @:)
3104 set wildoptions=fuzzy
3105 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3106 call assert_equal('"sbrewind', @:)
3107 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3108 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003109 set wildoptions&
3110endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003111
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003112" " compiler name fuzzy completion - NOT supported
3113" func Test_fuzzy_completion_compiler()
3114" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003115
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003116" :cscope suboptions fuzzy completion
3117func Test_fuzzy_completion_cscope()
3118 CheckFeature cscope
3119 set wildoptions&
3120 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal('"cscope ret', @:)
3122 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3123 call assert_equal('"cscope reset', @:)
3124 set wildoptions=fuzzy
3125 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3126 call assert_equal('"cscope reset', @:)
3127 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3128 call assert_equal('"cscope re*t', @:)
3129 set wildoptions&
3130endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003131
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003132" :diffget/:diffput buffer name fuzzy completion
3133func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003134 new SomeBuffer
3135 diffthis
3136 new OtherBuffer
3137 diffthis
3138 set wildoptions&
3139 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal('"diffget sbuf', @:)
3141 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal('"diffput sbuf', @:)
3143 set wildoptions=fuzzy
3144 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3145 call assert_equal('"diffget SomeBuffer', @:)
3146 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3147 call assert_equal('"diffput SomeBuffer', @:)
3148 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003149 set wildoptions&
3150endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003151
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003152" " directory name fuzzy completion - NOT supported
3153" func Test_fuzzy_completion_dirname()
3154" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003155
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003156" environment variable name fuzzy completion
3157func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003158 set wildoptions&
3159 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3160 call assert_equal('"echo $VUT', @:)
3161 set wildoptions=fuzzy
3162 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3163 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003164 set wildoptions&
3165endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003166
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003167" autocmd event fuzzy completion
3168func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003169 set wildoptions&
3170 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3171 call assert_equal('"autocmd BWout', @:)
3172 set wildoptions=fuzzy
3173 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3174 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003175 set wildoptions&
3176endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003177
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003178" vim expression fuzzy completion
3179func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003180 let g:PerPlaceCount = 10
3181 set wildoptions&
3182 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3183 call assert_equal('"let c = ppc', @:)
3184 set wildoptions=fuzzy
3185 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3186 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003187 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003188endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003189
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003190" " file name fuzzy completion - NOT supported
3191" func Test_fuzzy_completion_filename()
3192" endfunc
3193
3194" " files in path fuzzy completion - NOT supported
3195" func Test_fuzzy_completion_filesinpath()
3196" endfunc
3197
3198" " filetype name fuzzy completion - NOT supported
3199" func Test_fuzzy_completion_filetype()
3200" endfunc
3201
3202" user defined function name completion
3203func Test_fuzzy_completion_userdefined_func()
3204 set wildoptions&
3205 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3206 call assert_equal('"call Test_f_u_f', @:)
3207 set wildoptions=fuzzy
3208 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3209 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3210 set wildoptions&
3211endfunc
3212
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003213" <SNR> functions should be sorted to the end
3214func Test_fuzzy_completion_userdefined_snr_func()
3215 func s:Sendmail()
3216 endfunc
3217 func SendSomemail()
3218 endfunc
3219 func S1e2n3dmail()
3220 endfunc
3221 set wildoptions=fuzzy
3222 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003223 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003224 set wildoptions&
3225 delfunc s:Sendmail
3226 delfunc SendSomemail
3227 delfunc S1e2n3dmail
3228endfunc
3229
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003230" user defined command name completion
3231func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003232 set wildoptions&
3233 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3234 call assert_equal('"MsFeat', @:)
3235 set wildoptions=fuzzy
3236 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3237 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003238 set wildoptions&
3239endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003240
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003241" " :help tag fuzzy completion - NOT supported
3242" func Test_fuzzy_completion_helptag()
3243" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003244
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003245" highlight group name fuzzy completion
3246func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003247 set wildoptions&
3248 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3249 call assert_equal('"highlight SKey', @:)
3250 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3251 call assert_equal('"highlight SpecialKey', @:)
3252 set wildoptions=fuzzy
3253 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3254 call assert_equal('"highlight SpecialKey', @:)
3255 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3256 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003257 set wildoptions&
3258endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003259
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003260" :history suboptions fuzzy completion
3261func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003262 set wildoptions&
3263 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal('"history dg', @:)
3265 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3266 call assert_equal('"history search', @:)
3267 set wildoptions=fuzzy
3268 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3269 call assert_equal('"history debug', @:)
3270 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3271 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003272 set wildoptions&
3273endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003274
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003275" :language locale name fuzzy completion
3276func Test_fuzzy_completion_lang()
3277 CheckUnix
3278 set wildoptions&
3279 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3280 call assert_equal('"lang psx', @:)
3281 set wildoptions=fuzzy
3282 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3283 call assert_equal('"lang POSIX', @:)
3284 set wildoptions&
3285endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003286
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003287" :mapclear buffer argument fuzzy completion
3288func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003289 set wildoptions&
3290 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3291 call assert_equal('"mapclear buf', @:)
3292 set wildoptions=fuzzy
3293 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3294 call assert_equal('"mapclear <buffer>', @:)
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" map name fuzzy completion
3299func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003300 " test regex completion works
3301 set wildoptions=fuzzy
3302 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3303 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003304 nmap <plug>MyLongMap :p<CR>
3305 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3306 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3307 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3308 call assert_equal("\"nmap MLM \t", @:)
3309 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3310 call assert_equal("\"nmap <F2> one two \t", @:)
3311 " duplicate entries should be removed
3312 vmap <plug>MyLongMap :<C-U>#<CR>
3313 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3314 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3315 nunmap <plug>MyLongMap
3316 vunmap <plug>MyLongMap
3317 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3318 call assert_equal("\"nmap ABC\t", @:)
3319 " results should be sorted by best match
3320 nmap <Plug>format :
3321 nmap <Plug>goformat :
3322 nmap <Plug>TestFOrmat :
3323 nmap <Plug>fendoff :
3324 nmap <Plug>state :
3325 nmap <Plug>FendingOff :
3326 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3327 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3328 nunmap <Plug>format
3329 nunmap <Plug>goformat
3330 nunmap <Plug>TestFOrmat
3331 nunmap <Plug>fendoff
3332 nunmap <Plug>state
3333 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003334 set wildoptions&
3335endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003336
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003337" abbreviation fuzzy completion
3338func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003339 set wildoptions=fuzzy
3340 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3341 call assert_equal("\"iabbr <nowait>", @:)
3342 iabbr WaitForCompletion WFC
3343 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3344 call assert_equal("\"iabbr WaitForCompletion", @:)
3345 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3346 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003347
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003348 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003349 set wildoptions&
3350endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003351
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003352" menu name fuzzy completion
3353func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003354 CheckFeature menu
3355
3356 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003357 set wildoptions&
3358 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3359 call assert_equal('"menu pup', @:)
3360 set wildoptions=fuzzy
3361 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3362 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003363
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003364 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003365 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003366endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003367
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003368" :messages suboptions fuzzy completion
3369func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003370 set wildoptions&
3371 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3372 call assert_equal('"messages clr', @:)
3373 set wildoptions=fuzzy
3374 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3375 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003376 set wildoptions&
3377endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003378
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003379" :set option name fuzzy completion
3380func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003381 set wildoptions&
3382 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3383 call assert_equal('"set brkopt', @:)
3384 set wildoptions=fuzzy
3385 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3386 call assert_equal('"set breakindentopt', @:)
3387 set wildoptions&
3388 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3389 call assert_equal('"set fixendofline', @:)
3390 set wildoptions=fuzzy
3391 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3392 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003393 set wildoptions&
3394endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003395
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003396" :set <term_option>
3397func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003398 set wildoptions&
3399 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3400 call assert_equal('"set t_EC', @:)
3401 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3402 call assert_equal('"set <t_EC>', @:)
3403 set wildoptions=fuzzy
3404 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3405 call assert_equal('"set t_EC', @:)
3406 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3407 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003408 set wildoptions&
3409endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003410
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003411" " :packadd directory name fuzzy completion - NOT supported
3412" func Test_fuzzy_completion_packadd()
3413" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003414
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003415" " shell command name fuzzy completion - NOT supported
3416" func Test_fuzzy_completion_shellcmd()
3417" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003418
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003419" :sign suboptions fuzzy completion
3420func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003421 set wildoptions&
3422 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3423 call assert_equal('"sign ufe', @:)
3424 set wildoptions=fuzzy
3425 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3426 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003427 set wildoptions&
3428endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003429
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003430" :syntax suboptions fuzzy completion
3431func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003432 set wildoptions&
3433 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3434 call assert_equal('"syntax kwd', @:)
3435 set wildoptions=fuzzy
3436 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3437 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003438 set wildoptions&
3439endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003440
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003441" syntax group name fuzzy completion
3442func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003443 set wildoptions&
3444 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3445 call assert_equal('"syntax list mpar', @:)
3446 set wildoptions=fuzzy
3447 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3448 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003449 set wildoptions&
3450endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003451
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003452" :syntime suboptions fuzzy completion
3453func Test_fuzzy_completion_syntime()
3454 CheckFeature profile
3455 set wildoptions&
3456 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3457 call assert_equal('"syntime clr', @:)
3458 set wildoptions=fuzzy
3459 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3460 call assert_equal('"syntime clear', @:)
3461 set wildoptions&
3462endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003463
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003464" " tag name fuzzy completion - NOT supported
3465" func Test_fuzzy_completion_tagname()
3466" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003467
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003468" " tag name and file fuzzy completion - NOT supported
3469" func Test_fuzzy_completion_tagfile()
3470" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003471
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003472" " user names fuzzy completion - how to test this functionality?
3473" func Test_fuzzy_completion_username()
3474" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003475
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003476" user defined variable name fuzzy completion
3477func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003478 let g:SomeVariable=10
3479 set wildoptions&
3480 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3481 call assert_equal('"let SVar', @:)
3482 set wildoptions=fuzzy
3483 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3484 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003485 set wildoptions&
3486endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003487
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003488" Test for sorting the results by the best match
3489func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003490 %bw!
3491 command T123format :
3492 command T123goformat :
3493 command T123TestFOrmat :
3494 command T123fendoff :
3495 command T123state :
3496 command T123FendingOff :
3497 set wildoptions=fuzzy
3498 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3499 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3500 delcommand T123format
3501 delcommand T123goformat
3502 delcommand T123TestFOrmat
3503 delcommand T123fendoff
3504 delcommand T123state
3505 delcommand T123FendingOff
3506 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003507 set wildoptions&
3508endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003509
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003510" Test for fuzzy completion of a command with lower case letters and a number
3511func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003512 command Foo2Bar :
3513 set wildoptions=fuzzy
3514 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3515 call assert_equal('"Foo2Bar', @:)
3516 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3517 call assert_equal('"Foo2Bar', @:)
3518 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3519 call assert_equal('"Foo2Bar', @:)
3520 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003521 set wildoptions&
3522endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003523
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003524" Test for command completion for a command starting with 'k'
3525func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003526 command KillKillKill :
3527 set wildoptions&
3528 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3529 call assert_equal("\"killkill\<Tab>", @:)
3530 set wildoptions=fuzzy
3531 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3532 call assert_equal('"KillKillKill', @:)
3533 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003534 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003535endfunc
3536
3537" Test for fuzzy completion for user defined custom completion function
3538func Test_fuzzy_completion_custom_func()
3539 func Tcompl(a, c, p)
3540 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3541 endfunc
3542 command -nargs=* -complete=custom,Tcompl Fuzzy :
3543 set wildoptions&
3544 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3545 call assert_equal("\"Fuzzy format", @:)
3546 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3547 call assert_equal("\"Fuzzy xy", @:)
3548 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3549 call assert_equal("\"Fuzzy ttt", @:)
3550 set wildoptions=fuzzy
3551 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3552 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3553 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3554 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3555 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3556 call assert_equal("\"Fuzzy xy", @:)
3557 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3558 call assert_equal("\"Fuzzy TestFOrmat", @:)
3559 delcom Fuzzy
3560 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003561endfunc
3562
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003563" Test for fuzzy completion in the middle of a cmdline instead of at the end
3564func Test_fuzzy_completion_in_middle()
3565 set wildoptions=fuzzy
3566 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3567 call assert_equal("\"set wildchar wildcharm wrap", @:)
3568
3569 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3570 call assert_equal("\"args ++encoding= zz", @:)
3571 set wildoptions&
3572endfunc
3573
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003574" Test for :breakadd argument completion
3575func Test_cmdline_complete_breakadd()
3576 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3577 call assert_equal("\"breakadd expr file func here", @:)
3578 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3579 call assert_equal("\"breakadd expr", @:)
3580 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3581 call assert_equal("\"breakadd expr", @:)
3582 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3583 call assert_equal("\"breakadd here", @:)
3584 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3585 call assert_equal("\"breakadd here", @:)
3586 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3587 call assert_equal("\"breakadd abc", @:)
3588 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3589 let l = getcompletion('not', 'breakpoint')
3590 call assert_equal([], l)
3591
3592 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003593 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003594 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3595 call assert_equal("\"breakadd file Xscript", @:)
3596 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3597 call assert_equal("\"breakadd file Xscript", @:)
3598 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3599 call assert_equal("\"breakadd file 20 Xscript", @:)
3600 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3601 call assert_equal("\"breakadd file 20 Xscript", @:)
3602 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3603 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3604 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3605 call assert_equal("\"breakadd file 20\t", @:)
3606 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3607 call assert_equal("\"breakadd file 20x\t", @:)
3608 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3609 call assert_equal("\"breakadd file Xscript ", @:)
3610 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3611 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003612
3613 " Test for :breakadd func [lnum] <function>
3614 func Xbreak_func()
3615 endfunc
3616 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3617 call assert_equal("\"breakadd func Xbreak_func", @:)
3618 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3619 call assert_equal("\"breakadd func Xbreak_func", @:)
3620 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3621 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3622 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3623 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3624 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3625 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3626 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3627 call assert_equal("\"breakadd func 20\t", @:)
3628 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3629 call assert_equal("\"breakadd func 20x\t", @:)
3630 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3631 call assert_equal("\"breakadd func Xbreak_func ", @:)
3632 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3633 call assert_equal("\"breakadd func X1B2C3", @:)
3634 delfunc Xbreak_func
3635
3636 " Test for :breakadd expr <expression>
3637 let g:Xtest_var = 10
3638 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3639 call assert_equal("\"breakadd expr Xtest_var", @:)
3640 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3641 call assert_equal("\"breakadd expr Xtest_var", @:)
3642 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3643 call assert_equal("\"breakadd expr Xtest_var ", @:)
3644 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3645 call assert_equal("\"breakadd expr X1B2C3", @:)
3646 unlet g:Xtest_var
3647
3648 " Test for :breakadd here
3649 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3650 call assert_equal("\"breakadd here Xtest", @:)
3651 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3652 call assert_equal("\"breakadd here Xtest", @:)
3653 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3654 call assert_equal("\"breakadd here ", @:)
3655endfunc
3656
3657" Test for :breakdel argument completion
3658func Test_cmdline_complete_breakdel()
3659 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3660 call assert_equal("\"breakdel file func here", @:)
3661 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3662 call assert_equal("\"breakdel file", @:)
3663 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3664 call assert_equal("\"breakdel file", @:)
3665 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3666 call assert_equal("\"breakdel here", @:)
3667 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3668 call assert_equal("\"breakdel here", @:)
3669 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3670 call assert_equal("\"breakdel abc", @:)
3671
3672 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003673 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003674 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3675 call assert_equal("\"breakdel file Xscript", @:)
3676 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3677 call assert_equal("\"breakdel file Xscript", @:)
3678 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3679 call assert_equal("\"breakdel file 20 Xscript", @:)
3680 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3681 call assert_equal("\"breakdel file 20 Xscript", @:)
3682 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3683 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3684 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3685 call assert_equal("\"breakdel file 20\t", @:)
3686 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3687 call assert_equal("\"breakdel file 20x\t", @:)
3688 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3689 call assert_equal("\"breakdel file Xscript ", @:)
3690 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3691 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003692
3693 " Test for :breakdel func [lnum] <function>
3694 func Xbreak_func()
3695 endfunc
3696 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3697 call assert_equal("\"breakdel func Xbreak_func", @:)
3698 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3699 call assert_equal("\"breakdel func Xbreak_func", @:)
3700 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3701 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3702 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3703 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3704 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3705 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3706 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3707 call assert_equal("\"breakdel func 20\t", @:)
3708 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3709 call assert_equal("\"breakdel func 20x\t", @:)
3710 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3711 call assert_equal("\"breakdel func Xbreak_func ", @:)
3712 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3713 call assert_equal("\"breakdel func X1B2C3", @:)
3714 delfunc Xbreak_func
3715
3716 " Test for :breakdel here
3717 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3718 call assert_equal("\"breakdel here Xtest", @:)
3719 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3720 call assert_equal("\"breakdel here Xtest", @:)
3721 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3722 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003723endfunc
3724
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003725" Test for :scriptnames argument completion
3726func Test_cmdline_complete_scriptnames()
3727 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003728 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003729 source Xa1b2c3.vim
3730 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3731 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3732 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3733 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3734 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3735 call assert_equal("\"script b2c3", @:)
3736 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3737 call assert_match("\"script 2\<Tab>$", @:)
3738 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3739 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3740 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3741 call assert_equal("\"script ", @:)
3742 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3743 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3744 new
3745 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3746 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3747 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003748 set wildmenu&
3749endfunc
3750
Bram Moolenaard8893442022-05-06 20:38:47 +01003751" this was going over the end of IObuff
3752func Test_report_error_with_composing()
3753 let caught = 'no'
3754 try
3755 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3756 catch /E492:/
3757 let caught = 'yes'
3758 endtry
3759 call assert_equal('yes', caught)
3760endfunc
3761
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003762" Test for expanding 2-letter and 3-letter :substitute command arguments.
3763" These commands don't accept an argument.
3764func Test_cmdline_complete_substitute_short()
3765 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3766 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3767 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3768 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3769 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3770 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3771 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3772 endfor
3773endfunc
3774
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003775" Test for shellcmdline command argument completion
3776func Test_cmdline_complete_shellcmdline_argument()
3777 command -nargs=+ -complete=shellcmdline MyCmd
3778
3779 set wildoptions=fuzzy
3780
3781 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3782 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003783 call assert_equal(['test_cmdline.vim'],
3784 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003785
3786 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3787 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003788 call assert_equal([],
3789 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003790
3791 let compl1 = getcompletion('', 'file')[0]
3792 let compl2 = getcompletion('', 'file')[1]
3793 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3794 call assert_equal('"MyCmd vim ' .. compl1, @:)
3795
3796 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3797 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3798
3799 let compl = getcompletion('', 'file')[1]
3800 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3801 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3802
3803 set wildoptions&
3804 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3805 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003806 call assert_equal(['test_cmdline.vim'],
3807 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003808
3809 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3810 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003811 call assert_equal([],
3812 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003813
3814 let compl1 = getcompletion('', 'file')[0]
3815 let compl2 = getcompletion('', 'file')[1]
3816 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3817 call assert_equal('"MyCmd vim ' .. compl1, @:)
3818
3819 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3820 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3821
3822 let compl = getcompletion('', 'file')[1]
3823 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3824 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3825
3826 delcommand MyCmd
3827endfunc
3828
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003829" Test for :! shell command argument completion
3830func Test_cmdline_complete_bang_cmd_argument()
3831 set wildoptions=fuzzy
3832 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3833 call assert_equal('"!vim test_cmdline.vim', @:)
3834 set wildoptions&
3835 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3836 call assert_equal('"!vim test_cmdline.vim', @:)
3837endfunc
3838
zeertzjq961b2e52023-04-17 15:53:24 +01003839func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003840 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003841endfunc
3842
3843func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003844 call assert_equal(0, getcmdpos())
3845 call assert_equal(0, getcmdscreenpos())
3846 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003847 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01003848
zeertzjqa821b602024-06-18 20:31:08 +02003849 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01003850 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003851 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003852 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003853 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003854 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003855 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02003856
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003857 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
3858 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02003859 let g:results = []
3860 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
3861 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
3862 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003863 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
3864 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
3865 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02003866
3867 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01003868 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003869endfunc
3870
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003871func Test_recursive_register()
3872 let @= = ''
3873 silent! ?e/
3874 let caught = 'no'
3875 try
3876 normal //
3877 catch /E169:/
3878 let caught = 'yes'
3879 endtry
3880 call assert_equal('yes', caught)
3881endfunc
3882
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003883func Test_long_error_message()
3884 " the error should be truncated, not overrun IObuff
3885 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3886endfunc
3887
zeertzjq6791adc2022-07-26 20:42:25 +01003888func Test_cmdline_redraw_tabline()
3889 CheckRunVimInTerminal
3890
3891 let lines =<< trim END
3892 set showtabline=2
3893 autocmd CmdlineEnter * set tabline=foo
3894 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003895 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003896 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3897 call term_sendkeys(buf, ':')
3898 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3899
3900 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003901endfunc
3902
zeertzjqb82a2ab2022-08-21 14:33:57 +01003903func Test_wildmenu_pum_disable_while_shown()
3904 set wildoptions=pum
3905 set wildmenu
3906 cnoremap <F2> <Cmd>set nowildmenu<CR>
3907 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3908 call assert_equal(0, pumvisible())
3909 cunmap <F2>
3910 set wildoptions& wildmenu&
3911endfunc
3912
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003913func Test_setcmdline()
3914 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01003915 call assert_equal(0, setcmdline(test_null_string()))
3916 call assert_equal('', getcmdline())
3917 call assert_equal(1, getcmdpos())
3918
3919 call assert_equal(0, setcmdline(''[: -1]))
3920 call assert_equal('', getcmdline())
3921 call assert_equal(1, getcmdpos())
3922
zeertzjq54acb902022-08-29 16:21:25 +01003923 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003924 call assert_equal(0, setcmdline(a:text))
3925 call assert_equal(a:text, getcmdline())
3926 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003927 call assert_equal(getcmdtype(), g:cmdtype)
3928 unlet g:cmdtype
3929 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003930
3931 call assert_equal(0, setcmdline(a:text, a:pos))
3932 call assert_equal(a:text, getcmdline())
3933 call assert_equal(a:pos, getcmdpos())
3934
3935 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003936 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3937 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003938
3939 return ''
3940 endfunc
3941
3942 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3943 call assert_equal('set rtp?', @:)
3944
zeertzjq54acb902022-08-29 16:21:25 +01003945 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3946 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3947 call assert_equal('foo', g:str)
3948 unlet g:str
3949
3950 delfunc SetText
3951
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003952 " setcmdline() returns 1 when not editing the command line.
3953 call assert_equal(1, 'foo'->setcmdline())
3954
3955 " Called in custom function
3956 func CustomComplete(A, L, P)
3957 call assert_equal(0, setcmdline("DoCmd "))
3958 return "January\nFebruary\nMars\n"
3959 endfunc
3960
3961 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3962 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3963 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003964 delcom DoCmd
3965 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003966
3967 " Called in <expr>
3968 cnoremap <expr>a setcmdline('let foo=')
3969 call feedkeys(":a\<CR>", 'tx')
3970 call assert_equal('let foo=0', @:)
3971 cunmap a
3972endfunc
3973
Sean Dewarfc8a6012023-04-17 16:41:20 +01003974func Test_rulerformat_position()
3975 CheckScreendump
3976
3977 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
3978 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
3979 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
3980 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
3981 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
3982
3983 " clean up
3984 call StopVimInTerminal(buf)
3985endfunc
3986
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01003987" Test for using "%!" in 'rulerformat' to use a function
3988func Test_rulerformat_function()
3989 CheckScreendump
3990
3991 let lines =<< trim END
3992 func TestRulerFn()
3993 return '10,20%=30%%'
3994 endfunc
3995 END
3996 call writefile(lines, 'Xrulerformat_function', 'D')
3997
3998 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
3999 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
4000 call term_sendkeys(buf, ":redraw!\<CR>")
4001 call term_wait(buf)
4002 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
4003
4004 " clean up
4005 call StopVimInTerminal(buf)
4006endfunc
4007
zeertzjqe4c79d32023-08-15 22:41:53 +02004008func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004009 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004010
zeertzjqe4c79d32023-08-15 22:41:53 +02004011 call assert_equal(getcompletion('', 'cmdline'),
4012 \ getcompletion('TestCompletion ', 'cmdline'))
4013 call assert_equal(['<buffer>'],
4014 \ getcompletion('TestCompletion map <bu', 'cmdline'))
4015
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004016 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004017endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02004018
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004019func Test_custom_completion()
4020 func CustomComplete1(lead, line, pos)
4021 return "a\nb\nc"
4022 endfunc
4023 func CustomComplete2(lead, line, pos)
4024 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
4025 endfunc
4026 func Check_custom_completion()
4027 call assert_equal('custom,CustomComplete1', getcmdcompltype())
4028 return ''
4029 endfunc
4030 func Check_customlist_completion()
4031 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
4032 return ''
4033 endfunc
4034
4035 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
4036 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
4037
4038 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
4039 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
4040
4041 call assert_fails("call getcompletion('', 'custom')", 'E475:')
4042 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
4043
zeertzjq757f3212024-04-15 19:01:04 +02004044 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
4045 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
4046 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004047
4048 delcom Test1
4049 delcom Test2
4050
4051 delfunc CustomComplete1
4052 delfunc CustomComplete2
4053 delfunc Check_custom_completion
4054 delfunc Check_customlist_completion
4055endfunc
4056
zeertzjq28a23602023-09-29 19:58:35 +02004057func Test_custom_completion_with_glob()
4058 func TestGlobComplete(A, L, P)
4059 return split(glob('Xglob*'), "\n")
4060 endfunc
4061
4062 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
4063 call writefile([], 'Xglob1', 'D')
4064 call writefile([], 'Xglob2', 'D')
4065
4066 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
4067 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
4068
4069 delcommand TestGlobComplete
4070 delfunc TestGlobComplete
4071endfunc
4072
Christian Brabandt8610f742024-01-12 17:34:40 +01004073func Test_window_size_stays_same_after_changing_cmdheight()
4074 set laststatus=2
4075 let expected = winheight(0)
4076 function! Function_name() abort
4077 call feedkeys(":"..repeat('x', &columns), 'x')
4078 let &cmdheight=2
4079 let &cmdheight=1
4080 redraw
4081 endfunction
4082 call Function_name()
4083 call assert_equal(expected, winheight(0))
4084endfunc
4085
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01004086" verify that buffer-completion finds all buffer names matching a pattern
4087func Test_buffer_completion()
4088 " should return empty list
4089 call assert_equal([], getcompletion('', 'buffer'))
4090
4091 call mkdir('Xbuf_complete', 'R')
4092 e Xbuf_complete/Foobar.c
4093 e Xbuf_complete/MyFoobar.c
4094 e AFoobar.h
4095 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
4096
4097 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
4098 call assert_equal(expected, getcompletion('Foo', 'buffer'))
4099 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
4100 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
4101endfunc
4102
Anton Sharonov49528da2024-04-14 20:02:24 +02004103" :set t_??
4104func Test_term_option()
4105 set wildoptions&
4106 let _cpo = &cpo
4107 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004108 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02004109 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'
4110 \ .. ' 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'
4111 \ .. ' 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'
4112 \ .. ' 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'
4113 \ .. ' 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 +02004114 \ .. ' 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 +02004115 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004116 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004117 let &cpo = _cpo
4118endfunc
4119
Christian Brabandt70a11a62024-07-26 19:13:55 +02004120func Test_ex_command_completion()
4121 " required for :*
4122 set cpo+=*
4123 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
4124 " :++ and :-- are only valid in Vim9 Script context, so they can be ignored
4125 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004126 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004127 call assert_equal(0, exists(':ke'))
4128 call assert_equal(1, exists(':kee'))
4129 call assert_equal(1, exists(':keep'))
4130 call assert_equal(1, exists(':keepm'))
4131 call assert_equal(1, exists(':keepma'))
4132 call assert_equal(1, exists(':keepmar'))
4133 call assert_equal(1, exists(':keepmark'))
4134 call assert_equal(2, exists(':keepmarks'))
4135 call assert_equal(2, exists(':keepalt'))
4136 call assert_equal(2, exists(':keepjumps'))
4137 call assert_equal(2, exists(':keeppatterns'))
4138 set cpo-=*
4139endfunc
4140
zeertzjq5df3cb22024-10-07 21:05:06 +02004141func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004142 CheckMSWindows
4143 let save_shellslash = &shellslash
4144 set noshellslash
4145 call system('mkdir XXXa\_b')
4146 defer delete('XXXa', 'rf')
4147 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4148 call assert_equal('"cd XXXa\_b\', @:)
4149 let &shellslash = save_shellslash
4150endfunc
4151
Bram Moolenaar309976e2019-12-05 18:16:33 +01004152" vim: shiftwidth=2 sts=2 expandtab