blob: be4ae4e184ccf5f0e66c84b3471a88ea51d4fc86 [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Bram Moolenaar4facea32019-10-12 20:17:40 +02003source check.vim
4source screendump.vim
Bram Moolenaar24ebd832020-03-16 21:25:24 +01005source view_util.vim
Bram Moolenaarc82dd862020-06-07 17:30:33 +02006source shared.vim
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00007import './vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02008
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00009func SetUp()
10 func SaveLastScreenLine()
11 let g:Sline = Screenline(&lines - 1)
12 return ''
13 endfunc
14 cnoremap <expr> <F4> SaveLastScreenLine()
15endfunc
16
17func TearDown()
18 delfunc SaveLastScreenLine
19 cunmap <F4>
20endfunc
21
Bram Moolenaarae3150e2016-06-11 23:22:36 +020022func Test_complete_tab()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010023 call writefile(['testfile'], 'Xtestfile', 'D')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020024 call feedkeys(":e Xtest\t\r", "tx")
25 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020026
27 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
28 call feedkeys(":e %\t\r", "tx")
29 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020030endfunc
31
32func Test_complete_list()
33 " We can't see the output, but at least we check the code runs properly.
34 call feedkeys(":e test\<C-D>\r", "tx")
35 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010036
37 " If a command doesn't support completion, then CTRL-D should be literally
38 " used.
39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000041
42 " Test for displaying the tail of the completion matches
43 set wildmode=longest,full
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010044 call mkdir('Xtest', 'R')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000045 call writefile([], 'Xtest/a.c')
46 call writefile([], 'Xtest/a.h')
47 let g:Sline = ''
48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49 call assert_equal('a.c a.h', g:Sline)
50 call assert_equal('"e Xtest/', @:)
51 if has('win32')
52 " Test for 'completeslash'
53 set completeslash=backslash
54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000056 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000058 set completeslash=slash
59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000061 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000063 set completeslash&
64 endif
65
66 " Test for displaying the tail with wildcards
67 let g:Sline = ''
68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
70 call assert_equal('"e Xtes?/', @:)
71 let g:Sline = ''
72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
74 call assert_equal('"e Xtes*/', @:)
75 let g:Sline = ''
76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77 call assert_equal(':e Xtes[/', g:Sline)
78 call assert_equal('"e Xtes[/', @:)
79
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000080 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020081endfunc
82
83func Test_complete_wildmenu()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010084 call mkdir('Xwilddir1/Xdir2', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010085 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
86 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
87 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
88 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020089 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010090
91 " Pressing <Tab> completes, and moves to next files when pressing again.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010092 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010093 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010094 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020095 call assert_equal('testfile2', getline(1))
96
Bram Moolenaar37db6422019-03-28 21:26:23 +010097 " <S-Tab> is like <Tab> but begin with the last match and then go to
98 " previous.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010099 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100100 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100101 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100102 call assert_equal('testfile1', getline(1))
103
104 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100105 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100106 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100107 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100108 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100109 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100110 call assert_equal('testfile1', getline(1))
111
112 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100113 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100114 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100115 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100116 call assert_equal('testfile1', getline(1))
117
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100118 " this fails in some Unix GUIs, not sure why
119 if !has('unix') || !has('gui_running')
120 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
121 " different than 'wildchar'.
122 set wildcharm=<C-Z>
123 cnoremap <C-J> <Down><C-Z>
124 cnoremap <C-K> <Up><C-Z>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100125 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100126 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100127 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100128 call assert_equal('testfile1', getline(1))
129 set wildcharm=0
130 cunmap <C-J>
131 cunmap <C-K>
132 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100133
Bram Moolenaar578fe942020-02-27 21:32:51 +0100134 " Test for canceling the wild menu by adding a character
135 redrawstatus
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100136 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
137 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100138
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100139 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100140 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
142 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
143 cd -
144
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000145 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100146 cnoremap <expr> <F2> wildmenumode()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100147 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
148 call assert_equal('"cd Xwilddir1/0', @:)
149 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
150 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100151 cunmap <F2>
152
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000153 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
154 " After this pressing <Left> or <Right> should not change the selection.
155 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
156 call assert_equal('"sign define', @:)
157 call histadd('cmd', 'TestWildMenu')
158 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
159 call assert_equal('"TestWildMenu', @:)
160
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200161 " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match
162 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx')
163 call assert_equal('"sign un yy zz', @:)
164
165 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx')
166 call assert_equal('"sign unplace yy zz', @:)
167
Bram Moolenaar37db6422019-03-28 21:26:23 +0100168 " cleanup
169 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200170 set nowildmenu
171endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100172
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173func Test_wildmenu_screendump()
174 CheckScreendump
175
176 let lines =<< trim [SCRIPT]
177 set wildmenu hlsearch
178 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100179 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200180
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200181 " Test simple wildmenu
Bram Moolenaara60053b2020-09-03 16:50:13 +0200182 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
183 call term_sendkeys(buf, ":vim\<Tab>")
184 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
185
186 call term_sendkeys(buf, "\<Tab>")
187 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
188
189 call term_sendkeys(buf, "\<Tab>")
190 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
191
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200192 " Looped back to the original value
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100193 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200194 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200195
196 " Test that the wild menu is cleared properly
197 call term_sendkeys(buf, " ")
198 call VerifyScreenDump(buf, 'Test_wildmenu_5', {})
199
200 " Test that a different wildchar still works
201 call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>")
202 call term_sendkeys(buf, ":vim\<Esc>")
203 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
204
205 " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
206 " sure clean up is properly done in edge case like this.
Bram Moolenaara60053b2020-09-03 16:50:13 +0200207 call term_sendkeys(buf, "\<Esc>")
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200208 call VerifyScreenDump(buf, 'Test_wildmenu_6', {})
Bram Moolenaara60053b2020-09-03 16:50:13 +0200209
210 " clean up
211 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200212endfunc
213
Bram Moolenaara653e532022-04-19 11:38:24 +0100214func Test_redraw_in_autocmd()
215 CheckScreendump
216
217 let lines =<< trim END
218 set cmdheight=2
219 autocmd CmdlineChanged * redraw
220 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100221 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100222
223 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
224 call term_sendkeys(buf, ":for i in range(3)\<CR>")
225 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
226
227 call term_sendkeys(buf, "let i =")
228 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
229
230 " clean up
231 call term_sendkeys(buf, "\<CR>")
232 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100233endfunc
234
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100235func Test_redrawstatus_in_autocmd()
236 CheckScreendump
237
238 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100239 set laststatus=2
240 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100241 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100242 END
243 call writefile(lines, 'XTest_redrawstatus', 'D')
244
245 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100246 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100247 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
248 call term_sendkeys(buf, ":foobar")
249 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100250 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100251 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100252 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100253 " with cmdheight=1 messages have scrolled when typing :endfor
254 call term_sendkeys(buf, "\<CR>:endfor")
255 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
256 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
257 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
258 call term_sendkeys(buf, ":for in in range(3)")
259 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
260 call term_sendkeys(buf, "\<CR>:endfor")
261 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100262
263 " clean up
264 call term_sendkeys(buf, "\<CR>")
265 call StopVimInTerminal(buf)
266endfunc
267
Bram Moolenaarf797e302022-08-11 13:17:30 +0100268func Test_changing_cmdheight()
269 CheckScreendump
270
271 let lines =<< trim END
272 set cmdheight=1 laststatus=2
nwounkn2e485672024-11-11 21:48:30 +0100273 func EchoOne()
274 set laststatus=2 cmdheight=1
275 echo 'foo'
276 echo 'bar'
277 set cmdheight=2
278 endfunc
Bram Moolenaar0816f472022-10-05 15:42:32 +0100279 func EchoTwo()
280 set laststatus=2
281 set cmdheight=5
282 echo 'foo'
283 echo 'bar'
284 set cmdheight=1
285 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100286 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100287 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100288
289 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
290 call term_sendkeys(buf, ":resize -3\<CR>")
291 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
292
Luuk van Baale15cbc12025-01-04 17:18:08 +0100293 " :resize now also changes 'cmdheight' accordingly
294 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100295 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
296
297 " using more space moves the status line up
298 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
299 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
300
301 " reducing cmdheight moves status line down
Luuk van Baalc97e8692025-01-06 18:58:21 +0100302 call term_sendkeys(buf, ":set cmdheight-=3\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100303 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
304
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000305 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100306 call term_sendkeys(buf, ":resize -1\<CR>")
307 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
308 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
309
Bram Moolenaar0816f472022-10-05 15:42:32 +0100310 " setting 'cmdheight' works after outputting two messages
311 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
312 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
313
Luuk van Baalc97e8692025-01-06 18:58:21 +0100314 " increasing 'cmdheight' doesn't clear the messages that need hit-enter
nwounkn2e485672024-11-11 21:48:30 +0100315 call term_sendkeys(buf, ":call EchoOne()\<CR>")
316 call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})
317
Luuk van Baalc97e8692025-01-06 18:58:21 +0100318 " window commands do not reduce 'cmdheight' to value lower than :set by user
319 call term_sendkeys(buf, "\<CR>:wincmd _\<CR>")
320 call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {})
321
Bram Moolenaarf797e302022-08-11 13:17:30 +0100322 " clean up
323 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100324endfunc
325
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100326func Test_cmdheight_tabline()
327 CheckScreendump
328
329 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
330 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
331
332 " clean up
333 call StopVimInTerminal(buf)
334endfunc
335
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100336func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100337 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
338 call assert_equal('"map <unique> <silent>', getreg(':'))
339 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
340 call assert_equal('"map <script> <unique>', getreg(':'))
341 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
342 call assert_equal('"map <expr> <script>', getreg(':'))
343 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
344 call assert_equal('"map <buffer> <expr>', getreg(':'))
345 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
346 call assert_equal('"map <nowait> <buffer>', getreg(':'))
347 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
348 call assert_equal('"map <special> <nowait>', getreg(':'))
349 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
350 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200351
Bram Moolenaar1776a282019-05-03 16:05:41 +0200352 map <Middle>x middle
353
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200354 map ,f commaf
355 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200356 map <Left> left
357 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200358 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
359 call assert_equal('"map ,f', getreg(':'))
360 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
361 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200362 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
363 call assert_equal('"map <Left>', getreg(':'))
364 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200365 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000366 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
367 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200368 unmap ,f
369 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200370 unmap <Left>
371 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200372
zeertzjqc3a26c62023-02-17 16:40:20 +0000373 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200374 map <Left> left
375 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
376 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200377 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200378 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000379 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
380 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200381 unmap <Left>
382
383 set cpo+=<
384 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200385 exe "set t_k6=\<Esc>[17~"
386 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200387 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
388 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200389 if !has('gui_running')
390 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
391 call assert_equal("\"map <F6>x", getreg(':'))
392 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200393 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200394 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200395 set cpo-=<
396
397 set cpo+=B
398 map <Left> left
399 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
400 call assert_equal('"map <Left>', getreg(':'))
401 unmap <Left>
402 set cpo-=B
403
404 set cpo+=k
405 map <Left> left
406 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
407 call assert_equal('"map <Left>', getreg(':'))
408 unmap <Left>
409 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200410
Bram Moolenaar531be472020-09-23 22:38:05 +0200411 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
412
Bram Moolenaar1776a282019-05-03 16:05:41 +0200413 unmap <Middle>x
414 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100415endfunc
416
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100417func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100418 hi Aardig ctermfg=green
419 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000420 call assert_equal('"match Aardig', @:)
Yee Cheng China7b81202025-02-23 09:32:47 +0100421 call feedkeys(":match NON\<Tab>\<Home>\"\<CR>", 'xt')
422 call assert_equal('"match NONE', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000423 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
424 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100425endfunc
426
427func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100428 hi Aardig ctermfg=green
429 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
430 call assert_equal('"hi Aardig', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100431
432 " hi default
Bram Moolenaarea588152017-04-10 22:45:30 +0200433 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
434 call assert_equal('"hi default Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100435 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
436 call assert_equal('"hi default', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100437 call feedkeys(":hi default link Aa\<Tab>\<Home>\"\<CR>", 'xt')
438 call assert_equal('"hi default link Aardig', getreg(':'))
439
440 " hi clear only accepts one parameter
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100441 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
442 call assert_equal('"hi clear', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100443 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
444 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200445 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
Yee Cheng China7b81202025-02-23 09:32:47 +0100446 call assert_equal("\"hi clear Aardig Aard\<Tab>", getreg(':'))
447 " hi link accepts up to two parameters
448 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
449 call assert_equal('"hi link', getreg(':'))
450 call assert_equal('"hi link', getreg(':'))
451 call feedkeys(":hi link Aa\<Tab>\<Home>\"\<CR>", 'xt')
452 call assert_equal('"hi link Aardig', getreg(':'))
453 call feedkeys(":hi link Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
454 call assert_equal("\"hi link Aardig Aardig", getreg(':'))
455 call feedkeys(":hi link Aardig Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
456 call assert_equal("\"hi link Aardig Aardig Aard\<Tab>", getreg(':'))
457 " hi link will complete to "NONE" for second parameter
458 call feedkeys(":hi link NON\<Tab>\<Home>\"\<CR>", 'xt')
459 call assert_equal("\"hi link NonText", getreg(':'))
460 call feedkeys(":hi link Aardig NON\<Tab>\<Home>\"\<CR>", 'xt')
461 call assert_equal("\"hi link Aardig NONE", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200462
463 " A cleared group does not show up in completions.
464 hi Anders ctermfg=green
465 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
466 hi clear Aardig
467 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
468 hi clear Anders
469 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100470endfunc
471
Bram Moolenaar75e15672020-06-28 13:10:22 +0200472" Test for command-line expansion of "hi Ni " (easter egg)
473func Test_highlight_easter_egg()
474 call test_override('ui_delay', 1)
475 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
476 call assert_equal("\"hi Ni \<Tab>", @:)
477 call test_override('ALL', 0)
478endfunc
479
Yee Cheng China7b81202025-02-23 09:32:47 +0100480func Test_highlight_group_completion()
481 " Test completing keys
482 call assert_equal('term=', getcompletion('hi Foo ', 'cmdline')[0])
483 call assert_equal('ctermfg=', getcompletion('hi Foo c*fg', 'cmdline')[0])
484 call assert_equal('NONE', getcompletion('hi Foo NON', 'cmdline')[0])
485 set wildoptions+=fuzzy
486 call assert_equal('ctermbg=', getcompletion('hi Foo cmbg', 'cmdline')[0])
487 set wildoptions-=fuzzy
488
489 " Test completing the current value
490 hi FooBar term=bold,underline cterm=undercurl ctermfg=lightgray ctermbg=12 ctermul=34
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100491 hi AlmostEmpty term=bold
Yee Cheng China7b81202025-02-23 09:32:47 +0100492 call assert_equal('bold,underline', getcompletion('hi FooBar term=', 'cmdline')[0])
493 call assert_equal('undercurl', getcompletion('hi FooBar cterm=', 'cmdline')[0])
494 call assert_equal('7', getcompletion('hi FooBar ctermfg=', 'cmdline')[0])
495 call assert_equal('12', getcompletion('hi FooBar ctermbg=', 'cmdline')[0])
496 call assert_equal('34', getcompletion('hi FooBar ctermul=', 'cmdline')[0])
497
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100498 " highlight group exists, but no value was set. Should not complete to
499 " existing value
500 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermfg=', 'cmdline')[0])
501 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermbg=', 'cmdline')[0])
502 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermul=', 'cmdline')[0])
503 call assert_equal('bold', getcompletion('hi AlmostEmpty cterm=', 'cmdline')[0])
504
505 " "bold,underline" is unique and creates an extra item. "undercurl" isn't
506 " and should be de-duplicated.
Yee Cheng China7b81202025-02-23 09:32:47 +0100507 call assert_equal(len(getcompletion('hi FooBar term=', 'cmdline')),
508 \ 1 + len(getcompletion('hi FooBar cterm=', 'cmdline')))
509
510 " don't complete original value if we have user input already, similar to
511 " behavior in :set <option>=<pattern>
512 call assert_equal(['bold'], getcompletion('hi FooBar term=bol', 'cmdline'))
513 call assert_equal([], getcompletion('hi FooBar ctermfg=1', 'cmdline'))
514
515 " start/stop do not fill their current value now as they are more
516 " complicated
517 hi FooBar start=123 stop=234
518 call assert_equal([], getcompletion('hi FooBar start=', 'cmdline'))
519 call assert_equal([], getcompletion('hi FooBar stop=', 'cmdline'))
520
521 if has("gui") || has("termguicolors")
522 hi FooBar gui=italic guifg=#112233 guibg=brown1 guisp=green
523 call assert_equal('italic', getcompletion('hi FooBar gui=', 'cmdline')[0])
524 call assert_equal('#112233', getcompletion('hi FooBar guifg=', 'cmdline')[0])
525 call assert_equal('brown1', getcompletion('hi FooBar guibg=', 'cmdline')[0])
526 call assert_equal('green', getcompletion('hi FooBar guisp=', 'cmdline')[0])
527
528 " Check that existing value is de-duplicated and doesn't show up later
529 call assert_equal(1, count(getcompletion('hi FooBar guibg=', 'cmdline'), 'brown1'))
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100530
531 " highlight group exists, but no value was set. Should not complete to
532 " existing value
533 call assert_equal('fg', getcompletion('hi AlmostEmpty guifg=', 'cmdline')[0])
534 call assert_equal('fg', getcompletion('hi AlmostEmpty guibg=', 'cmdline')[0])
535 call assert_equal('fg', getcompletion('hi AlmostEmpty guisp=', 'cmdline')[0])
536 call assert_equal('bold', getcompletion('hi AlmostEmpty gui=', 'cmdline')[0])
Yee Cheng China7b81202025-02-23 09:32:47 +0100537 endif
538
539 " Test completing attributes
540 call assert_equal(['underdouble', 'underdotted'], getcompletion('hi DoesNotExist term=un*erdo*', 'cmdline'))
541 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=NON', 'cmdline')[0])
542 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=', 'cmdline')[-1]) " NONE should be at the end and not sorted
543 call assert_equal('bold', getcompletion('hi DoesNotExist cterm=underline,bo', 'cmdline')[0]) " complete after comma
544 if has("gui") || has("termguicolors")
545 set wildoptions+=fuzzy
546 call assert_equal('italic', getcompletion('hi DoesNotExist gui=itic', 'cmdline')[0])
547 set wildoptions-=fuzzy
548 endif
549
550 " Test completing cterm colors
551 call assert_equal('fg', getcompletion('hi FooBar ctermbg=f*g', 'cmdline')[0])
552 call assert_equal('fg', getcompletion('hi DoesNotExist ctermbg=f*g', 'cmdline')[0])
553 call assert_equal('NONE', getcompletion('hi FooBar ctermfg=NON', 'cmdline')[0])
554 call assert_equal('NONE', getcompletion('hi DoesNotExist ctermfg=NON', 'cmdline')[0])
555 set wildoptions+=fuzzy
556 call assert_equal('Black', getcompletion('hi FooBar ctermul=blck', 'cmdline')[0])
557 call assert_equal('Black', getcompletion('hi DoesNotExist ctermul=blck', 'cmdline')[0])
558 set wildoptions-=fuzzy
559
560 " Test completing gui colors
561 if has("gui") || has("termguicolors")
562 call assert_equal('fg', getcompletion('hi FooBar guibg=f*g', 'cmdline')[0])
563 call assert_equal('fg', getcompletion('hi DoesNotExist guibg=f*g', 'cmdline')[0])
564 call assert_equal('NONE', getcompletion('hi FooBar guifg=NON', 'cmdline')[0])
565 call assert_equal('NONE', getcompletion('hi DoesNotExist guifg=NON', 'cmdline')[0])
566 set wildoptions=fuzzy
567 call assert_equal('limegreen', getcompletion('hi FooBar guisp=limgrn', 'cmdline')[0])
568 call assert_equal('limegreen', getcompletion('hi DoesNotExist guisp=limgrn', 'cmdline')[0])
569 set wildoptions-=fuzzy
570
571 " Test pruning bad color names with space. Vim doesn't support them.
572 let v:colornames['foobar with space'] = '#123456'
573 let v:colornames['foobarwithoutspace'] = '#234567'
574 call assert_equal(['foobarwithoutspace'], getcompletion('hi FooBar guibg=foobarw', 'cmdline'))
575
576 " Test specialized sorting. First few items are special values that
577 " go first, after that it's a sorted list of color names.
578 call assert_equal(['fg','bg','NONE'], getcompletion('hi DoesNotExist guifg=', 'cmdline')[0:2])
579 let completed_colors=getcompletion('hi DoesNotExist guifg=', 'cmdline')[3:]
580 let gui_colors_no_space=filter(copy(v:colornames), {key,val -> match(key, ' ')==-1})
581 call assert_equal(len(gui_colors_no_space), len(completed_colors))
582 call assert_equal(sort(copy(completed_colors)), completed_colors)
583
584 " Test that the specialized sorting still works if we have some pattern matches
585 let completed_colors=getcompletion('hi DoesNotExist guifg=*blue*', 'cmdline')
586 call assert_equal(sort(copy(completed_colors)), completed_colors)
587 call assert_equal('aliceblue', completed_colors[0])
588 endif
589endfunc
590
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200591func Test_getcompletion()
592 let groupcount = len(getcompletion('', 'event'))
593 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200594 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200595 call assert_true(matchcount > 0)
596 call assert_true(groupcount > matchcount)
597
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200598 if has('menu')
599 source $VIMRUNTIME/menu.vim
600 let matchcount = len(getcompletion('', 'menu'))
601 call assert_true(matchcount > 0)
602 call assert_equal(['File.'], getcompletion('File', 'menu'))
603 call assert_true(matchcount > 0)
604 let matchcount = len(getcompletion('File.', 'menu'))
605 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000606 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200607 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200608
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200609 let l = getcompletion('v:n', 'var')
610 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200611 let l = getcompletion('v:notexists', 'var')
612 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200613
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200614 args a.c b.c
615 let l = getcompletion('', 'arglist')
616 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000617 let l = getcompletion('a.', 'buffer')
618 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200619 %argdelete
620
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200621 let l = getcompletion('', 'augroup')
622 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200623 let l = getcompletion('blahblah', 'augroup')
624 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200625
626 let l = getcompletion('', 'behave')
627 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200628 let l = getcompletion('not', 'behave')
629 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200630
631 let l = getcompletion('', 'color')
632 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200633 let l = getcompletion('dirty', 'color')
634 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200635
636 let l = getcompletion('', 'command')
637 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200638 let l = getcompletion('awake', 'command')
639 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200640
641 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200642 call assert_true(index(l, 'samples/') >= 0)
643 let l = getcompletion('NoMatch', 'dir')
644 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200645
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100646 if glob('~/*') !=# ''
647 let l = getcompletion('~/', 'dir')
648 call assert_true(l[0][0] ==# '~')
649 endif
650
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200651 let l = getcompletion('exe', 'expression')
652 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200653 let l = getcompletion('kill', 'expression')
654 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200655
656 let l = getcompletion('tag', 'function')
657 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200658 let l = getcompletion('paint', 'function')
659 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200660
Kota Kato90c23532023-01-18 15:27:38 +0000661 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000662 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000663 let l = getcompletion('ruby', 'function')
664 call assert_equal([], l)
665 endif
666
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200667 let Flambda = {-> 'hello'}
668 let l = getcompletion('', 'function')
669 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200670 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200671
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200672 let l = getcompletion('run', 'file')
673 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200674 let l = getcompletion('walk', 'file')
675 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200676 set wildignore=*.vim
677 let l = getcompletion('run', 'file', 1)
678 call assert_true(index(l, 'runtest.vim') < 0)
679 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000680 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100681 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000682 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
683 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200684
685 let l = getcompletion('ha', 'filetype')
686 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200687 let l = getcompletion('horse', 'filetype')
688 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200689
Doug Kearns81642d92024-01-04 22:37:44 +0100690 if has('keymap')
691 let l = getcompletion('acc', 'keymap')
692 call assert_true(index(l, 'accents') >= 0)
693 let l = getcompletion('nullkeymap', 'keymap')
694 call assert_equal([], l)
695 endif
696
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200697 let l = getcompletion('z', 'syntax')
698 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200699 let l = getcompletion('emacs', 'syntax')
700 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200701
702 let l = getcompletion('jikes', 'compiler')
703 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200704 let l = getcompletion('break', 'compiler')
705 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200706
707 let l = getcompletion('last', 'help')
708 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200709 let l = getcompletion('giveup', 'help')
710 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200711
712 let l = getcompletion('time', 'option')
713 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200714 let l = getcompletion('space', 'option')
715 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200716
717 let l = getcompletion('er', 'highlight')
718 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200719 let l = getcompletion('dark', 'highlight')
720 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200721
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200722 let l = getcompletion('', 'messages')
723 call assert_true(index(l, 'clear') >= 0)
724 let l = getcompletion('not', 'messages')
725 call assert_equal([], l)
726
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200727 let l = getcompletion('', 'mapclear')
728 call assert_true(index(l, '<buffer>') >= 0)
729 let l = getcompletion('not', 'mapclear')
730 call assert_equal([], l)
731
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200732 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200733 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200734 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
735 let root = has('win32') ? 'C:\\' : '/'
736 let l = getcompletion(root, 'shellcmd')
737 let expected = map(filter(glob(root . '*', 0, 1),
738 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
739 call assert_equal(expected, l)
740
Bram Moolenaarb650b982016-08-05 20:35:13 +0200741 if has('cscope')
742 let l = getcompletion('', 'cscope')
743 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
744 call assert_equal(cmds, l)
745 " using cmdline completion must not change the result
746 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
747 let l = getcompletion('', 'cscope')
748 call assert_equal(cmds, l)
749 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
750 let l = getcompletion('find ', 'cscope')
751 call assert_equal(keys, l)
752 endif
753
Bram Moolenaar7522f692016-08-06 14:12:50 +0200754 if has('signs')
755 sign define Testing linehl=Comment
756 let l = getcompletion('', 'sign')
757 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
758 call assert_equal(cmds, l)
759 " using cmdline completion must not change the result
760 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
761 let l = getcompletion('', 'sign')
762 call assert_equal(cmds, l)
763 let l = getcompletion('list ', 'sign')
764 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000765 let l = getcompletion('de*', 'sign')
766 call assert_equal(['define'], l)
767 let l = getcompletion('p?', 'sign')
768 call assert_equal(['place'], l)
769 let l = getcompletion('j.', 'sign')
770 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200771 endif
772
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200773 " Command line completion tests
774 let l = getcompletion('cd ', 'cmdline')
775 call assert_true(index(l, 'samples/') >= 0)
776 let l = getcompletion('cd NoMatch', 'cmdline')
777 call assert_equal([], l)
778 let l = getcompletion('let v:n', 'cmdline')
779 call assert_true(index(l, 'v:null') >= 0)
780 let l = getcompletion('let v:notexists', 'cmdline')
781 call assert_equal([], l)
782 let l = getcompletion('call tag', 'cmdline')
783 call assert_true(index(l, 'taglist(') >= 0)
784 let l = getcompletion('call paint', 'cmdline')
785 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200786 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
787 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200788
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100789 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000790 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100791 return "oneA\noneB\noneC"
792 endfunc
793 command -nargs=1 -complete=custom,T MyCmd
794 let l = getcompletion('MyCmd ', 'cmdline')
795 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000796 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100797
798 delcommand MyCmd
799 delfunc T
ii144785fe02021-11-21 12:13:56 +0000800 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100801
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200802 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200803 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
804 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200805 if has('cmdline_hist')
806 call add(names, 'history')
807 endif
808 if has('gettext')
809 call add(names, 'locale')
810 endif
811 if has('profile')
812 call add(names, 'syntime')
813 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200814
815 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100816 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200817
818 for name in names
819 let matchcount = len(getcompletion('', name))
820 call assert_true(matchcount >= 0, 'No matches for ' . name)
821 endfor
822
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200823 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200824
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000825 edit a~b
826 enew
827 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
828 bw a~b
829
830 if has('unix')
831 edit Xtest\
832 enew
833 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
834 bw Xtest\
835 endif
836
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100837 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200838 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100839 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200840endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200841
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000842func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000843 " Get a dialog in the GUI
844 CheckNotGui
845
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000846 " This was using uninitialized memory.
847 let lines =<< trim END
848 set verbose=6
849 norm @=ٷ
850 qall!
851 END
852 call writefile(lines, 'XmultiScript', 'D')
853 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
854endfunc
855
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000856" Test for getcompletion() with "fuzzy" in 'wildoptions'
857func Test_getcompletion_wildoptions()
858 let save_wildoptions = &wildoptions
859 set wildoptions&
860 let l = getcompletion('space', 'option')
861 call assert_equal([], l)
862 let l = getcompletion('ier', 'command')
863 call assert_equal([], l)
864 set wildoptions=fuzzy
865 let l = getcompletion('space', 'option')
866 call assert_true(index(l, 'backspace') >= 0)
867 let l = getcompletion('ier', 'command')
868 call assert_true(index(l, 'compiler') >= 0)
869 let &wildoptions = save_wildoptions
870endfunc
871
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000872func Test_complete_autoload_error()
873 let save_rtp = &rtp
874 let lines =<< trim END
875 vim9script
876 export def Complete(..._): string
877 return 'match'
878 enddef
879 echo this will cause an error
880 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100881 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000882 call writefile(lines, 'Xdir/autoload/script.vim')
883 exe 'set rtp+=' .. getcwd() .. '/Xdir'
884
885 let lines =<< trim END
886 vim9script
887 import autoload 'script.vim'
888 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
889 &wildcharm = char2nr("\<Tab>")
890 feedkeys(":Cmd \<Tab>", 'xt')
891 END
892 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
893
894 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000895endfunc
896
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100897func Test_fullcommand()
898 let tests = {
899 \ '': '',
900 \ ':': '',
901 \ ':::': '',
902 \ ':::5': '',
903 \ 'not_a_cmd': '',
904 \ 'Check': '',
905 \ 'syntax': 'syntax',
906 \ ':syntax': 'syntax',
907 \ '::::syntax': 'syntax',
908 \ 'sy': 'syntax',
909 \ 'syn': 'syntax',
910 \ 'synt': 'syntax',
911 \ ':sy': 'syntax',
912 \ '::::sy': 'syntax',
913 \ 'match': 'match',
914 \ '2match': 'match',
915 \ '3match': 'match',
916 \ 'aboveleft': 'aboveleft',
917 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100918 \ 'en': 'endif',
919 \ 'end': 'endif',
920 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100921 \ 's': 'substitute',
922 \ '5s': 'substitute',
923 \ ':5s': 'substitute',
924 \ "'<,'>s": 'substitute',
925 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100926 \ 'CheckLin': 'CheckLinux',
927 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100928 \ }
929
930 for [in, want] in items(tests)
931 call assert_equal(want, fullcommand(in))
932 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200933 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100934
935 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200936
937 command -buffer BufferLocalCommand :
938 command GlobalCommand :
939 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
940 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
941 delcommand BufferLocalCommand
942 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100943endfunc
944
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200945func Test_shellcmd_completion()
946 let save_path = $PATH
947
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100948 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200949 call writefile([''], 'Xpathdir/Xfile.exe')
950 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
951
952 " Set PATH to example directory without trailing slash.
953 let $PATH = getcwd() . '/Xpathdir'
954
955 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
956 " dirs in the PATH, even though they won't be executed. We check that only
957 " subdirs of the PWD and executables from the PATH are included in the
958 " suggestions.
959 let actual = getcompletion('X', 'shellcmd')
960 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
961 call insert(expected, 'Xfile.exe')
962 call assert_equal(expected, actual)
963
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200964 let $PATH = save_path
965endfunc
966
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200967func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100968 call mkdir('a/b/c', 'pR')
969 call writefile(['asdfasdf'], 'a/b/c/fileXname')
970 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
971 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200972 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200973endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100974
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100975func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100976 let @a = "def"
977 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
978 call assert_equal('"abc def ghi', @:)
979
980 new
981 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
982
983 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
984 call assert_equal('"aaa asdf bbb', @:)
985
986 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
987 call assert_equal('"aaa /tmp/some bbb', @:)
988
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200989 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
990 call assert_equal('"aaa '.getline(1).' bbb', @:)
991
Bram Moolenaar21efc362016-12-03 14:05:49 +0100992 set incsearch
993 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
994 call assert_equal('"aaa verylongword bbb', @:)
995
996 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
997 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100998
999 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
1000 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +01001001 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +02001002
1003 " Error while typing a command used to cause that it was not executed
1004 " in the end.
1005 new
1006 try
1007 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
1008 catch /^Vim\%((\a\+)\)\=:E32/
1009 " ignore error E32
1010 endtry
1011 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001012
Bram Moolenaar578fe942020-02-27 21:32:51 +01001013 " Try to paste an invalid register using <C-R>
1014 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
1015 call assert_equal('"onetwo', @:)
1016
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001017 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +01001018 let @a = "xy\<C-H>z"
1019 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
1020 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001021 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
1022 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001023 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
1024 call assert_equal("\"xy\<C-H>z", @:)
1025
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001026 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
1027 let @a = "xy\<C-V>z"
1028 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
1029 call assert_equal('"xyz', @:)
1030 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
1031 call assert_equal("\"xy\<C-V>z", @:)
1032
Bram Moolenaar578fe942020-02-27 21:32:51 +01001033 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
1034
Bram Moolenaar72532d32018-04-07 19:09:09 +02001035 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +01001036endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001037
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001038func Test_cmdline_remove_char()
1039 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001040
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001041 for e in ['utf8', 'latin1']
1042 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001043
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001044 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
1045 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001046
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001047 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
1048 call assert_equal('"abcdef', @:)
1049
1050 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
1051 call assert_equal('"abc ghi', @:, e)
1052
1053 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
1054 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +01001055
1056 " This was going before the start in latin1.
1057 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001058 endfor
1059
1060 let &encoding = encoding_save
1061endfunc
1062
zeertzjqff2b79d2024-02-26 20:38:36 +01001063func Test_cmdline_del_utf8()
1064 let @s = ''
1065 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1066 call assert_equal('",,', @:)
1067
1068 let @s = 'a̳'
1069 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1070 call assert_equal('",,', @:)
1071
1072 let @s = 'β̳'
1073 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1074 call assert_equal('",,', @:)
1075
1076 if has('arabic')
1077 let @s = 'لا'
1078 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1079 call assert_equal('",,', @:)
1080 endif
1081endfunc
1082
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001083func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001084 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001085
1086 set keymap=esperanto
1087 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
1088 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
1089 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001090endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001091
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001092func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001093 new
1094 2;'(
1095 2;')
1096 quit
1097endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +01001098
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001099func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001100 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001101 new
1102 source Xtest.vim
1103 " Trigger calling validate_cursor()
1104 diffsp Xtest.vim
1105 quit!
1106 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001107endfunc
1108
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +01001109func Test_mark_from_line_zero()
1110 " this was reading past the end of the first (empty) line
1111 new
1112 norm oxxxx
1113 call assert_fails("0;'(", 'E20:')
1114 bwipe!
1115endfunc
1116
Bram Moolenaarba47b512017-01-24 21:18:19 +01001117func Test_cmdline_complete_wildoptions()
1118 help
1119 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1120 let a = join(sort(split(@:)),' ')
1121 set wildoptions=tagfile
1122 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1123 let b = join(sort(split(@:)),' ')
1124 call assert_equal(a, b)
1125 bw!
1126endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001127
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001128func Test_cmdline_complete_user_cmd()
1129 command! -complete=color -nargs=1 Foo :
1130 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1131 call assert_equal('"Foo blue', @:)
1132 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1133 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001134 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1135 call assert_equal('"Foo a blue', @:)
1136 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1137 call assert_equal('"Foo b\', @:)
1138 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1139 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001140 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001141
1142 redraw
1143 call assert_equal('~', Screenline(&lines - 1))
1144 command! FooOne :
1145 command! FooTwo :
1146
1147 set nowildmenu
1148 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1149 call assert_equal('"FooOne', @:)
1150 call assert_equal('~', Screenline(&lines - 1))
1151
1152 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1153 call assert_equal('"FooTwo', @:)
1154 call assert_equal('~', Screenline(&lines - 1))
1155
1156 delcommand FooOne
1157 delcommand FooTwo
1158 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001159endfunc
1160
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001161func Test_complete_user_cmd()
1162 command FooBar echo 'global'
1163 command -buffer FooBar echo 'local'
1164 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1165 call assert_equal('"FooBar', @:)
1166
1167 delcommand -buffer FooBar
1168 delcommand FooBar
1169endfunc
1170
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001171func s:ScriptLocalFunction()
1172 echo 'yes'
1173endfunc
1174
1175func Test_cmdline_complete_user_func()
1176 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001177 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001178 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1179 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001180
1181 " g: prefix also works
1182 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1183 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001184
1185 " using g: prefix does not result in just "g:" matches from a lambda
1186 let Fx = { a -> a }
1187 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1188 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001189
1190 " existence of script-local dict function does not break user function name
1191 " completion
1192 function s:a_dict_func() dict
1193 endfunction
1194 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1195 call assert_match('"call Test_cmdline_complete_user_', @:)
1196 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001197endfunc
1198
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001199func Test_cmdline_complete_user_names()
1200 if has('unix') && executable('whoami')
1201 let whoami = systemlist('whoami')[0]
1202 let first_letter = whoami[0]
1203 if len(first_letter) > 0
1204 " Trying completion of :e ~x where x is the first letter of
1205 " the user name should complete to at least the user name.
1206 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1207 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1208 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001209 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001210 " Just in case: check that the system has an Administrator account.
1211 let names = system('net user')
1212 if names =~ 'Administrator'
1213 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001214 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001215 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001216 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001217 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001218 else
1219 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001220 endif
1221endfunc
1222
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001223func Test_cmdline_complete_shellcmdline()
1224 CheckExecutable whoami
1225 command -nargs=1 -complete=shellcmdline MyCmd
1226
1227 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1228 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001229 let l = getcompletion('whoam', 'shellcmdline')
1230 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001231
1232 delcommand MyCmd
1233endfunc
1234
Bram Moolenaar297610b2019-12-27 17:20:55 +01001235func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001236 CheckExecutable whoami
1237 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1238 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001239endfunc
1240
Bram Moolenaar8b633132020-03-20 18:20:51 +01001241func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001242 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1243 call assert_equal(lang, v:lc_time)
1244
1245 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1246 call assert_equal(lang, v:ctype)
1247
1248 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1249 call assert_equal(lang, v:collate)
1250
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001251 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001252 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001253
1254 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001255 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001256
Bram Moolenaarec680282020-06-12 19:35:32 +02001257 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001258
Bram Moolenaarec680282020-06-12 19:35:32 +02001259 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1260 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001261
Bram Moolenaarec680282020-06-12 19:35:32 +02001262 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1263 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001264
Bram Moolenaarec680282020-06-12 19:35:32 +02001265 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1266 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001267
1268 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1269 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001270endfunc
1271
Bram Moolenaar297610b2019-12-27 17:20:55 +01001272func Test_cmdline_complete_env_variable()
1273 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001274 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1275 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001276 unlet $X_VIM_TEST_COMPLETE_ENV
1277endfunc
1278
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001279func Test_cmdline_complete_expression()
1280 let g:SomeVar = 'blah'
1281 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1282 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1283 call assert_match('"' .. cmd .. ' SomeVar', @:)
1284 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1285 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1286 endfor
1287 unlet g:SomeVar
1288endfunc
1289
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001290func Test_cmdline_complete_argopt()
1291 " completion for ++opt=arg for file commands
1292 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1293 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1294 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1295
1296 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001297 " Test ++ff in the middle of the cmdline
1298 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1299 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001300
1301 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1302 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1303 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1304 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1305 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1306
1307 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1308
1309 " completion should skip the ++opt and continue
1310 call writefile([], 'Xaaaaa.txt', 'D')
1311 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1312 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1313
1314 if has('terminal')
1315 " completion for terminal's [options]
1316 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1317 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1318 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1319
1320 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1321
1322 " :terminal completion should skip the ++opt when considering what is the
1323 " first option, which is a list of shell commands, unlike second option
1324 " onwards.
1325 let first_param = getcompletion('terminal ', 'cmdline')
1326 let second_param = getcompletion('terminal foo ', 'cmdline')
1327 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1328 call assert_equal(first_param, skipped_opt_param)
1329 call assert_notequal(first_param, second_param)
1330 endif
1331endfunc
1332
Bram Moolenaar47016f52021-08-26 16:39:58 +02001333" Unique function name for completion below
1334func s:WeirdFunc()
1335 echo 'weird'
1336endfunc
1337
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001338" Test for various command-line completion
1339func Test_cmdline_complete_various()
1340 " completion for a command starting with a comment
1341 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1342 call assert_equal("\" :|\"\<C-A>", @:)
1343
1344 " completion for a range followed by a comment
1345 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1346 call assert_equal("\"1,2\"\<C-A>", @:)
1347
1348 " completion for :k command
1349 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1350 call assert_equal("\"ka\<C-A>", @:)
1351
Doug Kearnsea842022024-09-29 17:17:41 +02001352 " completion for :keepmarks command
1353 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1354 call assert_equal("\"kee edit", @:)
1355
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001356 " completion for short version of the :s command
1357 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1358 call assert_equal("\"sI \<C-A>", @:)
1359
1360 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001361 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001362 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001363 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001364 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001365 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1366 call assert_equal("\"w >> Xfile1", @:)
1367 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001368
1369 " completion for :w ! and :r ! commands
1370 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1371 call assert_equal("\"w !invalid_xyz_cmd", @:)
1372 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1373 call assert_equal("\"r !invalid_xyz_cmd", @:)
1374
1375 " completion for :>> and :<< commands
1376 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1377 call assert_equal("\">>>\<C-A>", @:)
1378 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1379 call assert_equal("\"<<<\<C-A>", @:)
1380
1381 " completion for command with +cmd argument
1382 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1383 call assert_equal("\"buffer +/pat Xabc", @:)
1384 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1385 call assert_equal("\"buffer +/pat\<C-A>", @:)
1386
1387 " completion for a command with a trailing comment
1388 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1389 call assert_equal("\"ls \" comment\<C-A>", @:)
1390
1391 " completion for a command with a trailing command
1392 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1393 call assert_equal("\"ls | ls", @:)
1394
1395 " completion for a command with an CTRL-V escaped argument
1396 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1397 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1398
1399 " completion for a command that doesn't take additional arguments
1400 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1401 call assert_equal("\"all abc\<C-A>", @:)
1402
zeertzjqd3de1782022-09-01 12:58:52 +01001403 " completion for :wincmd with :horizontal modifier
1404 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1405 call assert_equal("\"horizontal wincmd", @:)
1406
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001407 " completion for a command with a command modifier
1408 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1409 call assert_equal("\"topleft new", @:)
1410
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001411 " completion for vim9 and legacy commands
1412 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1413 call assert_equal("\"vim9 call strlen(", @:)
1414 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1415 call assert_equal("\"legac call strlen(", @:)
1416
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001417 " completion for the :disassemble command
1418 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1419 call assert_equal("\"disas debug", @:)
1420 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1421 call assert_equal("\"disas profile", @:)
1422 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1423 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1424 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1425 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001426 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1427 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001428
Bram Moolenaar47016f52021-08-26 16:39:58 +02001429 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001430 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001431
naohiro onodfe04db2021-09-12 15:45:10 +02001432 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1433 call assert_match('"disas <SNR>\d\+_', @:)
1434 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1435 call assert_match('"disas debug <SNR>\d\+_', @:)
1436
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001437 " completion for the :match command
1438 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1439 call assert_equal("\"match Search /pat/\<C-A>", @:)
1440
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001441 " completion for the :doautocmd command
1442 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1443 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1444
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001445 " completion of autocmd group after comma
1446 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1447 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1448
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001449 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001450 call writefile([], 'Xvarfile1', 'D')
1451 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001452 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1453 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001454
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001455 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001456 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001457 augroup END
1458 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001459 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001460
1461 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001462 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1463 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001464 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1465 call assert_equal("\"au XTest.test", @:)
1466
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001467 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001468
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001469 " autocmd pattern completion
1470 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1471 call assert_equal("\"au BufEnter *.py\t", @:)
1472
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001473 " completion for the :unlet command
1474 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1475 call assert_equal("\"unlet one two", @:)
1476
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001477 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001478 " FIXME: what should happen on MS-Windows?
1479 if !has('win32')
1480 edit \{someFile}
1481 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1482 call assert_equal("\"buf {someFile}", @:)
1483 bwipe {someFile}
1484 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001485
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001486 " completion for the :bdelete command
1487 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1488 call assert_equal("\"bdel a b c", @:)
1489
1490 " completion for the :mapclear command
1491 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1492 call assert_equal("\"mapclear <buffer>", @:)
1493
1494 " completion for user defined commands with menu names
1495 menu Test.foo :ls<CR>
1496 com -nargs=* -complete=menu MyCmd
1497 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1498 call assert_equal('"MyCmd Test.', @:)
1499 delcom MyCmd
1500 unmenu Test
1501
1502 " completion for user defined commands with mappings
1503 mapclear
1504 map <F3> :ls<CR>
1505 com -nargs=* -complete=mapping MyCmd
1506 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001507 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001508 mapclear
1509 delcom MyCmd
1510
Yee Cheng Chin54844852023-10-09 18:12:31 +02001511 " Prepare for path completion
1512 call mkdir('Xa b c', 'D')
1513 defer delete('Xcomma,foobar.txt')
1514 call writefile([], 'Xcomma,foobar.txt')
1515
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001516 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001517 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1518 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1519 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001520
1521 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001522 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1523 call assert_equal('"set dir=Xa\ b\ c/', @:)
1524 set dir&
1525
1526 " completion for :set tags= / set dictionary= with escaped commas
1527 if has('win32')
1528 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1529 " '\,'
1530 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1531 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1532
1533 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1534 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1535
1536 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1537 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1538
1539 " completion for :set dictionary= with escaped commas (same behavior, but
1540 " different internal code path from 'set tags=' for escaping the output)
1541 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1542 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1543 else
1544 " In other platforms, backslashes are rounded down (since '\,' itself will
1545 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1546 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1547 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1548
1549 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1550 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1551
1552 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1553 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1554
1555 " completion for :set dictionary= with escaped commas (same behavior, but
1556 " different internal code path from 'set tags=' for escaping the output)
1557 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1558 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1559 endif
1560 set tags&
1561 set dictionary&
1562
1563 " completion for :set makeprg= with no escaped commas
1564 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1565 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1566
1567 if !has('win32')
1568 " Cannot create file with backslash in file name in Windows, so only test
1569 " this elsewhere.
1570 defer delete('Xcomma\,fooslash.txt')
1571 call writefile([], 'Xcomma\,fooslash.txt')
1572 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1573 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1574 endif
1575 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001576
1577 " completion for the :py3 commands
1578 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1579 call assert_equal('"py3 py3do py3file', @:)
1580
Bram Moolenaardf749a22021-03-28 15:29:43 +02001581 " completion for the :vim9 commands
1582 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1583 call assert_equal('"vim9cmd vim9script', @:)
1584
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001585 " redir @" is not the start of a comment. So complete after that
1586 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1587 call assert_equal('"redir @" | cwindow', @:)
1588
1589 " completion after a backtick
1590 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1591 call assert_equal('"e `a1b2c', @:)
1592
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001593 " completion for :language command with an invalid argument
1594 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1595 call assert_equal("\"language dummy \t", @:)
1596
1597 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001598 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1599 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001600
1601 " completion with ambiguous user defined commands
1602 com TCmd1 echo 'TCmd1'
1603 com TCmd2 echo 'TCmd2'
1604 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1605 call assert_equal('"TCmd ', @:)
1606 delcom TCmd1
1607 delcom TCmd2
1608
1609 " completion after a range followed by a pipe (|) character
1610 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1611 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001612
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001613 " completion after a :global command
1614 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1615 call assert_equal('"g/a/chistory', @:)
1616 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1617 call assert_equal("\"g/a\\/chist\t", @:)
1618
Bram Moolenaar9c929712020-09-07 22:05:28 +02001619 " use <Esc> as the 'wildchar' for completion
1620 set wildchar=<Esc>
1621 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1622 call assert_equal('"g/a\xb/clearjumps', @:)
1623 " pressing <esc> twice should cancel the command
1624 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1625 call assert_equal('"g/a\xb/clearjumps', @:)
1626 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001627
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001628 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001629 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001630 call writefile([], '~Xtest')
1631 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1632 call assert_equal('"e \~Xtest', @:)
1633 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001634
1635 " should be able to complete a file name that has a '*'
1636 call writefile([], 'Xx*Yy')
1637 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1638 call assert_equal('"e Xx\*Yy', @:)
1639 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001640
1641 " use a literal star
1642 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1643 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001644 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001645
1646 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1647 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001648endfunc
1649
zeertzjq094dd152023-06-15 22:51:57 +01001650" Test that expanding a pattern doesn't interfere with cmdline completion.
1651func Test_expand_during_cmdline_completion()
1652 func ExpandStuff()
1653 badd <script>:p:h/README.*
1654 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1655 $bwipe
1656 call assert_equal('README.txt', expand('README.*'))
1657 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1658 endfunc
1659 augroup test_CmdlineChanged
1660 autocmd!
1661 autocmd CmdlineChanged * call ExpandStuff()
1662 augroup END
1663
1664 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1665 call assert_equal('"sign place', @:)
1666
1667 augroup test_CmdlineChanged
1668 au!
1669 augroup END
1670 augroup! test_CmdlineChanged
1671 delfunc ExpandStuff
1672endfunc
1673
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001674" Test for 'wildignorecase'
1675func Test_cmdline_wildignorecase()
1676 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001677 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001678 set wildignorecase
1679 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1680 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001681 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001682 let g:Sline = ''
1683 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1684 call assert_equal('"e xt', @:)
1685 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001686 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001687endfunc
1688
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001689func Test_cmdline_write_alternatefile()
1690 new
1691 call setline('.', ['one', 'two'])
1692 f foo.txt
1693 new
1694 f #-A
1695 call assert_equal('foo.txt-A', expand('%'))
1696 f #<-B.txt
1697 call assert_equal('foo-B.txt', expand('%'))
1698 f %<
1699 call assert_equal('foo-B', expand('%'))
1700 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001701 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001702 bw!
1703 f foo-B.txt
1704 f %<-A
1705 call assert_equal('foo-B-A', expand('%'))
1706 bw!
1707 bw!
1708endfunc
1709
Bram Moolenaarf5724372022-09-02 19:45:15 +01001710func Test_cmdline_expand_cur_alt_file()
1711 enew
1712 file http://some.com/file.txt
1713 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1714 call assert_equal('"e http://some.com/file.txt', @:)
1715 edit another
1716 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1717 call assert_equal('"e http://some.com/file.txt', @:)
1718 bwipe
1719 bwipe http://some.com/file.txt
1720endfunc
1721
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001722" using a leading backslash here
1723set cpo+=C
1724
1725func Test_cmdline_search_range()
1726 new
1727 call setline(1, ['a', 'b', 'c', 'd'])
1728 /d
1729 1,\/s/b/B/
1730 call assert_equal('B', getline(2))
1731
1732 /a
1733 $
1734 \?,4s/c/C/
1735 call assert_equal('C', getline(3))
1736
1737 call setline(1, ['a', 'b', 'c', 'd'])
1738 %s/c/c/
1739 1,\&s/b/B/
1740 call assert_equal('B', getline(2))
1741
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001742 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001743 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001744
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001745 bwipe!
1746endfunc
1747
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001748" Test for the tick mark (') in an excmd range
1749func Test_tick_mark_in_range()
1750 " If only the tick is passed as a range and no command is specified, there
1751 " should not be an error
1752 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001753 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001754 call assert_fails("',print", 'E78:')
1755endfunc
1756
1757" Test for using a line number followed by a search pattern as range
1758func Test_lnum_and_pattern_as_range()
1759 new
1760 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1761 let @" = ''
1762 2/foo/yank
1763 call assert_equal("foo 3\n", @")
1764 call assert_equal(1, line('.'))
1765 close!
1766endfunc
1767
Bram Moolenaar65189a12017-02-06 22:22:17 +01001768" Tests for getcmdline(), getcmdpos() and getcmdtype()
1769func Check_cmdline(cmdtype)
1770 call assert_equal('MyCmd a', getcmdline())
1771 call assert_equal(8, getcmdpos())
1772 call assert_equal(a:cmdtype, getcmdtype())
1773 return ''
1774endfunc
1775
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001776set cpo&
1777
Shougo Matsushita69084282024-09-23 20:34:47 +02001778func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001779 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1780
1781 let cmdtype = ''
1782 debuggreedy
1783 call feedkeys(":debug echo 'test'\<CR>", "t")
1784 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1785 call feedkeys("cont\<CR>", "xt")
1786 0debuggreedy
1787 call assert_equal('>', cmdtype)
1788
1789 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1790 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1791
1792 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001793 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001794
1795 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1796
1797 cnoremap <expr> <F6> Check_cmdline('=')
1798 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1799 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001800
1801 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001802
1803 call assert_equal('', getcmdprompt())
1804 augroup test_CmdlineEnter
1805 autocmd!
1806 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1807 augroup END
1808 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1809 call assert_equal('Answer?', g:cmdprompt)
1810 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001811 call feedkeys(":\<CR>\<ESC>", "xt")
1812 call assert_equal('', g:cmdprompt)
1813 call assert_equal('', getcmdprompt())
1814
1815 let str = "C" .. repeat("c", 1023) .. "xyz"
1816 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1817 call assert_equal(str, g:cmdprompt)
1818
1819 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1820 call assert_equal('Ans?', g:cmdprompt)
1821 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001822
1823 augroup test_CmdlineEnter
1824 au!
1825 augroup END
1826 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001827endfunc
1828
Bram Moolenaar52604f22017-04-07 16:17:39 +02001829func Test_verbosefile()
1830 set verbosefile=Xlog
1831 echomsg 'foo'
1832 echomsg 'bar'
1833 set verbosefile=
1834 let log = readfile('Xlog')
1835 call assert_match("foo\nbar", join(log, "\n"))
1836 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001837
1838 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001839 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001840endfunc
1841
Bram Moolenaar4facea32019-10-12 20:17:40 +02001842func Test_verbose_option()
1843 CheckScreendump
1844
1845 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001846 " clear the TermResponse autocommand from defaults.vim
1847 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001848 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1849 call feedkeys("\r", 't') " for the hit-enter prompt
1850 set verbose=20
1851 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001852 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001853
1854 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001855 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001856 call term_sendkeys(buf, ":DoSomething\<CR>")
1857 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1858
1859 " clean up
1860 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001861endfunc
1862
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001863func Test_setcmdpos()
1864 func InsertTextAtPos(text, pos)
1865 call assert_equal(0, setcmdpos(a:pos))
1866 return a:text
1867 endfunc
1868
1869 " setcmdpos() with position in the middle of the command line.
1870 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1871 call assert_equal('"1ab2', @:)
1872
1873 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1874 call assert_equal('"1b2a', @:)
1875
1876 " setcmdpos() with position beyond the end of the command line.
1877 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1878 call assert_equal('"12ab', @:)
1879
1880 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001881 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001882endfunc
1883
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001884func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001885 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001886 let encoding_save = &encoding
1887
1888 for e in encodings
1889 exe 'set encoding=' . e
1890
1891 " Test overstrike in the middle of the command line.
1892 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001893 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001894
1895 " Test overstrike going beyond end of command line.
1896 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001897 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001898
1899 " Test toggling insert/overstrike a few times.
1900 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001901 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001902 endfor
1903
Bram Moolenaar30276f22019-01-24 17:59:39 +01001904 " Test overstrike with multi-byte characters.
1905 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001906 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001907
1908 let &encoding = encoding_save
1909endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001910
Bram Moolenaar52410572019-10-27 05:12:45 +01001911func Test_buffers_lastused()
1912 " check that buffers are sorted by time when wildmode has lastused
1913 call test_settime(1550020000) " middle
1914 edit bufa
1915 enew
1916 call test_settime(1550030000) " newest
1917 edit bufb
1918 enew
1919 call test_settime(1550010000) " oldest
1920 edit bufc
1921 enew
1922 call test_settime(0)
1923 enew
1924
1925 call assert_equal(['bufa', 'bufb', 'bufc'],
1926 \ getcompletion('', 'buffer'))
1927
1928 let save_wildmode = &wildmode
1929 set wildmode=full:lastused
1930
1931 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1932 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1933 call assert_equal('b bufb', X)
1934 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1935 call assert_equal('b bufa', X)
1936 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1937 call assert_equal('b bufc', X)
1938 enew
1939
1940 edit other
1941 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1942 call assert_equal('b bufb', X)
1943 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1944 call assert_equal('b bufa', X)
1945 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1946 call assert_equal('b bufc', X)
1947 enew
1948
1949 let &wildmode = save_wildmode
1950
1951 bwipeout bufa
1952 bwipeout bufb
1953 bwipeout bufc
1954endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001955
Bram Moolenaar479950f2020-01-19 15:45:17 +01001956func Test_cmdlineclear_tabenter()
1957 CheckScreendump
1958
1959 let lines =<< trim [SCRIPT]
1960 call setline(1, range(30))
1961 [SCRIPT]
1962
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001963 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001964 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001965 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001966 " in one tab make the command line higher with CTRL-W -
1967 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1968 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1969
1970 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001971endfunc
1972
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001973" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001974func Test_cmdline_expand_special()
1975 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001976 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001977 call assert_fails('e <afile>', 'E495:')
1978 call assert_fails('e <abuf>', 'E496:')
1979 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001980
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001981 call writefile([], 'Xfile.cpp', 'D')
1982 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001983 new Xfile.cpp
1984 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1985 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1986 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001987endfunc
1988
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001989" Test for backtick expression in the command line
1990func Test_cmd_backtick()
1991 %argd
1992 argadd `=['a', 'b', 'c']`
1993 call assert_equal(['a', 'b', 'c'], argv())
1994 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001995
1996 argadd `echo abc def`
1997 call assert_equal(['abc def'], argv())
1998 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001999endfunc
2000
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002001" Test for the :! command
2002func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002003 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002004
2005 let lines =<< trim [SCRIPT]
2006 " Test for no previous command
2007 call assert_fails('!!', 'E34:')
2008 set nomore
2009 " Test for cmdline expansion with :!
2010 call setline(1, 'foo!')
2011 silent !echo <cWORD> > Xfile.out
2012 call assert_equal(['foo!'], readfile('Xfile.out'))
2013 " Test for using previous command
2014 silent !echo \! !
2015 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
2016 call writefile(v:errors, 'Xresult')
2017 call delete('Xfile.out')
2018 qall!
2019 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002020 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002021 if RunVim([], [], '--clean -S Xscript')
2022 call assert_equal([], readfile('Xresult'))
2023 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002024 call delete('Xresult')
2025endfunc
2026
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002027" Test error: "E135: *Filter* Autocommands must not change current buffer"
2028func Test_cmd_bang_E135()
2029 new
2030 call setline(1, ['a', 'b', 'c', 'd'])
2031 augroup test_cmd_filter_E135
2032 au!
2033 autocmd FilterReadPost * help
2034 augroup END
2035 call assert_fails('2,3!echo "x"', 'E135:')
2036
2037 augroup test_cmd_filter_E135
2038 au!
2039 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002040 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002041 %bwipe!
2042endfunc
2043
shane.xb.qian4e7590e2022-11-08 21:40:04 +00002044func Test_cmd_bang_args()
2045 new
2046 :.!
2047 call assert_equal(0, v:shell_error)
2048
2049 " Note that below there is one space char after the '!'. This caused a
2050 " shell error in the past, see https://github.com/vim/vim/issues/11495.
2051 :.!
2052 call assert_equal(0, v:shell_error)
2053 bwipe!
2054
2055 CheckUnix
2056 :.!pwd
2057 call assert_equal(0, v:shell_error)
2058 :.! pwd
2059 call assert_equal(0, v:shell_error)
2060
2061 " Note there is one space after 'pwd'.
2062 :.! pwd
2063 call assert_equal(0, v:shell_error)
2064
2065 " Note there are two spaces after 'pwd'.
2066 :.! pwd
2067 call assert_equal(0, v:shell_error)
2068 :.!ls ~
2069 call assert_equal(0, v:shell_error)
2070
2071 " Note there is one space char after '~'.
2072 :.!ls ~
2073 call assert_equal(0, v:shell_error)
2074
2075 " Note there are two spaces after '~'.
2076 :.!ls ~
2077 call assert_equal(0, v:shell_error)
2078
2079 :.!echo "foo"
2080 call assert_equal(getline('.'), "foo")
2081 :.!echo "foo "
2082 call assert_equal(getline('.'), "foo ")
2083 :.!echo " foo "
2084 call assert_equal(getline('.'), " foo ")
2085 :.!echo " foo "
2086 call assert_equal(getline('.'), " foo ")
2087
2088 %bwipe!
2089endfunc
2090
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002091" Test for using ~ for home directory in cmdline completion matches
2092func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002093 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002094 call writefile([], 'Xexpdir/Xfile1')
2095 call writefile([], 'Xexpdir/Xfile2')
2096 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002097 let save_HOME = $HOME
2098 let $HOME = getcwd()
2099 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
2100 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
2101 let $HOME = save_HOME
2102 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002103endfunc
2104
Bram Moolenaar578fe942020-02-27 21:32:51 +01002105" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
2106" or insert mode (when 'insertmode' is set)
2107func Test_cmdline_ctrl_g()
2108 new
2109 call setline(1, 'abc')
2110 call cursor(1, 3)
2111 " If command line is entered from insert mode, using C-\ C-G should back to
2112 " insert mode
2113 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
2114 call assert_equal('abxyc', getline(1))
2115 call assert_equal(4, col('.'))
2116
2117 " If command line is entered in 'insertmode', using C-\ C-G should back to
2118 " 'insertmode'
2119 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
2120 call assert_equal('ab12xyc', getline(1))
2121 close!
2122endfunc
2123
Bram Moolenaar578fe942020-02-27 21:32:51 +01002124" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002125func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01002126 func T(a, c, p)
2127 return "oneA\noneB\noneC"
2128 endfunc
2129 command -nargs=1 -complete=custom,T MyCmd
2130
Bram Moolenaar578fe942020-02-27 21:32:51 +01002131 set nowildmenu
2132 set wildmode=full,list
2133 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002134 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002135 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002136 call assert_equal('"MyCmd oneA', @:)
2137
2138 set wildmode=longest,full
2139 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2140 call assert_equal('"MyCmd one', @:)
2141 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2142 call assert_equal('"MyCmd oneC', @:)
2143
2144 set wildmode=longest
2145 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2146 call assert_equal('"MyCmd one', @:)
2147
2148 set wildmode=list:longest
2149 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002150 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002151 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002152 call assert_equal('"MyCmd one', @:)
2153
2154 set wildmode=""
2155 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2156 call assert_equal('"MyCmd oneA', @:)
2157
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002158 " Test for wildmode=longest with 'fileignorecase' set
2159 set wildmode=longest
2160 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002161 argadd AAA AAAA AAAAA
2162 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2163 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002164 set fileignorecase&
2165
2166 " Test for listing files with wildmode=list
2167 set wildmode=list
2168 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002169 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002170 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002171 call assert_equal('"b A', @:)
2172
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002173 " when using longest completion match, matches shorter than the argument
2174 " should be ignored (happens with :help)
2175 set wildmode=longest,full
2176 set wildmenu
2177 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2178 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002179 " non existing file
2180 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2181 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002182 set wildmenu&
2183
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002184 " Test for longest file name completion with 'fileignorecase'
2185 " On MS-Windows, file names are case insensitive.
2186 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002187 call writefile([], 'XTESTfoo', 'D')
2188 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002189 set nofileignorecase
2190 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2191 call assert_equal('"e XTESTfoo', @:)
2192 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2193 call assert_equal('"e Xtestbar', @:)
2194 set fileignorecase
2195 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2196 call assert_equal('"e Xtest', @:)
2197 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2198 call assert_equal('"e Xtest', @:)
2199 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002200 endif
2201
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002202 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002203 delcommand MyCmd
2204 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002205 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002206 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002207endfunc
2208
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002209func Test_wildmode()
2210 " Test with utf-8 encoding
2211 call Wildmode_tests()
2212
2213 " Test with latin1 encoding
2214 let save_encoding = &encoding
2215 set encoding=latin1
2216 call Wildmode_tests()
2217 let &encoding = save_encoding
2218endfunc
2219
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002220func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002221 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002222 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002223 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002224 let lines =<< trim END
2225 func vim8#Complete(a, c, p)
2226 return "oneA\noneB\noneC"
2227 endfunc
2228 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002229 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002230
2231 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2232 set nowildmenu
2233 set wildmode=full,list
2234 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2235 call assert_equal('"MyCmd oneA oneB oneC', @:)
2236
2237 let &rtp = save_rtp
2238 set wildmode& wildmenu&
2239 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002240endfunc
2241
Bram Moolenaar578fe942020-02-27 21:32:51 +01002242" Test for interrupting the command-line completion
2243func Test_interrupt_compl()
2244 func F(lead, cmdl, p)
2245 if a:lead =~ 'tw'
2246 call interrupt()
2247 return
2248 endif
2249 return "one\ntwo\nthree"
2250 endfunc
2251 command -nargs=1 -complete=custom,F Tcmd
2252
2253 set nowildmenu
2254 set wildmode=full
2255 let interrupted = 0
2256 try
2257 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2258 catch /^Vim:Interrupt$/
2259 let interrupted = 1
2260 endtry
2261 call assert_equal(1, interrupted)
2262
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002263 let interrupted = 0
2264 try
2265 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2266 catch /^Vim:Interrupt$/
2267 let interrupted = 1
2268 endtry
2269 call assert_equal(1, interrupted)
2270
Bram Moolenaar578fe942020-02-27 21:32:51 +01002271 delcommand Tcmd
2272 delfunc F
2273 set wildmode&
2274endfunc
2275
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002276" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002277func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002278 let str = ":one two\<C-U>"
2279 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002280 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002281 let str ..= "\<Left>five\<Right>"
2282 let str ..= "\<Home>two "
2283 let str ..= "\<C-Left>one "
2284 let str ..= "\<C-Right> three"
2285 let str ..= "\<End>\<S-Left>four "
2286 let str ..= "\<S-Right> six"
2287 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2288 call feedkeys(str, 'xt')
2289 call assert_equal("\"one two three four five six seven", @:)
2290endfunc
2291
2292" Test for moving the cursor on the / command line in 'rightleft' mode
2293func Test_cmdline_edit_rightleft()
2294 CheckFeature rightleft
2295 set rightleft
2296 set rightleftcmd=search
2297 let str = "/one two\<C-U>"
2298 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002299 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002300 let str ..= "\<Right>five\<Left>"
2301 let str ..= "\<Home>two "
2302 let str ..= "\<C-Right>one "
2303 let str ..= "\<C-Left> three"
2304 let str ..= "\<End>\<S-Right>four "
2305 let str ..= "\<S-Left> six"
2306 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2307 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2308 call assert_equal("\"one two three four five six seven", @/)
2309 set rightleftcmd&
2310 set rightleft&
2311endfunc
2312
2313" Test for using <C-\>e in the command line to evaluate an expression
2314func Test_cmdline_expr()
2315 " Evaluate an expression from the beginning of a command line
2316 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2317 call assert_equal('"hello', @:)
2318
2319 " Use an invalid expression for <C-\>e
2320 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2321
2322 " Insert literal <CTRL-\> in the command line
2323 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2324 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002325endfunc
2326
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002327" This was making the insert position negative
2328func Test_cmdline_expr_register()
2329 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2330endfunc
2331
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002332" Test for 'imcmdline' and 'imsearch'
2333" This test doesn't actually test the input method functionality.
2334func Test_cmdline_inputmethod()
2335 new
2336 call setline(1, ['', 'abc', ''])
2337 set imcmdline
2338
2339 call feedkeys(":\"abc\<CR>", 'xt')
2340 call assert_equal("\"abc", @:)
2341 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2342 call assert_equal("\"abc", @:)
2343 call feedkeys("/abc\<CR>", 'xt')
2344 call assert_equal([2, 1], [line('.'), col('.')])
2345 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2346 call assert_equal([2, 1], [line('.'), col('.')])
2347
2348 set imsearch=2
2349 call cursor(1, 1)
2350 call feedkeys("/abc\<CR>", 'xt')
2351 call assert_equal([2, 1], [line('.'), col('.')])
2352 call cursor(1, 1)
2353 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2354 call assert_equal([2, 1], [line('.'), col('.')])
2355 set imdisable
2356 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2357 call assert_equal([2, 1], [line('.'), col('.')])
2358 set imdisable&
2359 set imsearch&
2360
2361 set imcmdline&
2362 %bwipe!
2363endfunc
2364
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002365" Test for using CTRL-_ in the command line with 'allowrevins'
2366func Test_cmdline_revins()
2367 CheckNotMSWindows
2368 CheckFeature rightleft
2369 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2370 call assert_equal("\"abc\<c-_>", @:)
2371 set allowrevins
2372 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2373 call assert_equal('"abcñèæ', @:)
2374 set allowrevins&
2375endfunc
2376
2377" Test for typing UTF-8 composing characters in the command line
2378func Test_cmdline_composing_chars()
2379 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2380 call assert_equal('"ゔ', @:)
2381endfunc
2382
Bram Moolenaar0e717042020-04-27 19:29:01 +02002383" test that ";" works to find a match at the start of the first line
2384func Test_zero_line_search()
2385 new
2386 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2387 call cursor(1,1)
2388 0;/pattern/d
2389 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2390 q!
2391endfunc
2392
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002393func Test_read_shellcmd()
2394 CheckUnix
2395 if executable('ls')
2396 " There should be ls in the $PATH
2397 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2398 call assert_match('^"r! .*\<ls\>', @:)
2399 endif
2400
2401 if executable('rm')
2402 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2403 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2404 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002405
2406 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2407 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2408 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002409 endif
2410endfunc
2411
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002412" Test for going up and down the directory tree using 'wildmenu'
2413func Test_wildmenu_dirstack()
2414 CheckUnix
2415 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002416 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002417 call writefile([], 'Xwildmenu/file1_1.txt')
2418 call writefile([], 'Xwildmenu/file1_2.txt')
2419 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2420 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2421 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2422 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2423 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2424 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002425 set wildmenu
2426
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002427 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002428 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002429 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002430 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002431 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002432 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002433 call assert_equal('"e ../../dir3/', @:)
2434 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2435 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002436 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002437 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002438 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002439 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002440 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002441 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2442 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002443
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002444 set wildmenu&
2445endfunc
2446
obcat71c6f7a2021-05-13 20:23:10 +02002447" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002448" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2449" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002450func Test_recalling_cmdline()
2451 CheckFeature cmdline_hist
2452
2453 let g:cmdlines = []
2454 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2455
2456 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002457 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2458 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2459 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2460 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002461 "\ TODO: {'name': 'debug', ...}
2462 \]
2463 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002464 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2465 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2466 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2467 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2468 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002469 \]
2470 let prefix = 'vi'
2471 for h in histories
2472 call histadd(h.name, 'vim')
2473 call histadd(h.name, 'virtue')
2474 call histadd(h.name, 'Virgo')
2475 call histadd(h.name, 'vogue')
2476 call histadd(h.name, 'emacs')
2477 for k in keypairs
2478 let g:cmdlines = []
2479 let keyseqs = h.enter
2480 \ .. prefix
2481 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2482 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2483 \ .. h.exit
2484 call feedkeys(keyseqs, 'xt')
2485 call histdel(h.name, -1) " delete the history added by feedkeys above
2486 let expect = k.prefixmatch
2487 \ ? ['virtue', 'vim', 'virtue', prefix]
2488 \ : ['emacs', 'vogue', 'emacs', prefix]
2489 call assert_equal(expect, g:cmdlines)
2490 endfor
2491 endfor
2492
2493 unlet g:cmdlines
2494 cunmap <Plug>(save-cmdline)
2495endfunc
2496
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002497func Test_cmd_map_cmdlineChanged()
2498 let g:log = []
2499 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002500 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002501 autocmd!
2502 autocmd CmdlineChanged : let g:log += [getcmdline()]
2503 augroup END
2504
2505 call feedkeys(":\<F1>\<CR>", 'xt')
2506 call assert_equal(['l', 'ls'], g:log)
2507
Bram Moolenaar796139a2021-05-18 21:38:45 +02002508 let @b = 'b'
2509 cnoremap <F1> a<C-R>b
2510 let g:log = []
2511 call feedkeys(":\<F1>\<CR>", 'xt')
2512 call assert_equal(['a', 'ab'], g:log)
2513
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002514 unlet g:log
2515 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002516 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002517 autocmd!
2518 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002519 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002520endfunc
2521
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002522" Test for the 'suffixes' option
2523func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002524 call writefile([], 'Xsuffile', 'D')
2525 call writefile([], 'Xsuffile.c', 'D')
2526 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002527 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002528 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2529 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2530 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2531 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002532 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002533 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2534 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2535 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2536 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002537 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002538 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2539 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2540 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2541 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002542 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002543 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002544 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2545 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002546endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002547
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002548" Test for using a popup menu for the command line completion matches
2549" (wildoptions=pum)
2550func Test_wildmenu_pum()
2551 CheckRunVimInTerminal
2552
2553 let commands =<< trim [CODE]
2554 set wildmenu
2555 set wildoptions=pum
2556 set shm+=I
2557 set noruler
2558 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002559
2560 func CmdCompl(a, b, c)
2561 return repeat(['aaaa'], 120)
2562 endfunc
2563 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002564
2565 func MyStatusLine() abort
2566 return 'status'
2567 endfunc
2568 func SetupStatusline()
2569 set statusline=%!MyStatusLine()
2570 set laststatus=2
2571 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002572
2573 func MyTabLine()
2574 return 'my tab line'
2575 endfunc
2576 func SetupTabline()
2577 set statusline=
2578 set tabline=%!MyTabLine()
2579 set showtabline=2
2580 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002581
2582 func DoFeedKeys()
2583 let &wildcharm = char2nr("\t")
2584 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2585 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002586 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002587 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002588
2589 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2590
2591 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002592 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2593
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002594 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002595 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002596 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2597
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002598 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002599 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002600 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2601
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002602 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002603 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002604 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2605
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002606 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002607 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002608 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2609
2610 " pressing <C-E> should end completion and go back to the original match
2611 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002612 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2613
2614 " pressing <C-Y> should select the current match and end completion
2615 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002616 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2617
2618 " With 'wildmode' set to 'longest,full', completing a match should display
2619 " the longest match, the wildmenu should not be displayed.
2620 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2621 call TermWait(buf)
2622 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002623 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2624
2625 " pressing <Tab> should display the wildmenu
2626 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002627 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2628
2629 " pressing <Tab> second time should select the next entry in the menu
2630 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002631 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2632
2633 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002634 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002635 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002636 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2637
2638 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002639 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2640
2641 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002642 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2643
2644 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002645 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002646 call writefile([], 'Xnamedir/XfileA')
2647 call writefile([], 'Xnamedir/XdirA/XfileB')
2648 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002649
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002650 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002651 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2652
2653 " Pressing <Right> on a directory name should go into that directory
2654 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002655 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2656
2657 " Pressing <Left> on a directory name should go to the parent directory
2658 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002659 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2660
2661 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002662 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002663 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002664 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2665
2666 " Pressing <C-D> when the popup menu is displayed should remove the popup
2667 " menu
2668 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002669 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2670
2671 " Pressing <S-Tab> should open the popup menu with the last entry selected
2672 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002673 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2674
2675 " Pressing <Esc> should close the popup menu and cancel the cmd line
2676 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002677 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2678
2679 " Typing a character when the popup is open, should close the popup
2680 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002681 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2682
2683 " When the popup is open, entering the cmdline window should close the popup
2684 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002685 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2686 call term_sendkeys(buf, ":q\<CR>")
2687
2688 " After the last popup menu item, <C-N> should show the original string
2689 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002690 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2691
2692 " Use the popup menu for the command name
2693 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002694 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2695
2696 " Pressing the left arrow should remove the popup menu
2697 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002698 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2699
2700 " Pressing <BS> should remove the popup menu and erase the last character
2701 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002702 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2703
2704 " Pressing <C-W> should remove the popup menu and erase the previous word
2705 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002706 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2707
2708 " Pressing <C-U> should remove the popup menu and erase the entire line
2709 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002710 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2711
2712 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2713 " the cmdline from history
2714 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002715 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2716
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002717 " Check "list" still works
2718 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2719 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002720 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2721 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002722 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2723
rbtnn68cc2b82022-02-09 11:55:47 +00002724 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002725 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002726 call writefile([], 'Xnamedir/あいう/abc')
2727 call writefile([], 'Xnamedir/あいう/xyz')
2728 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002729
2730 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002731 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002732 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2733
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002734 " Pressing <C-A> when the popup menu is displayed should list all the
2735 " matches and pressing a key after that should remove the popup menu
2736 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2737 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2738 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2739
2740 " Pressing <C-A> when the popup menu is displayed should list all the
2741 " matches and pressing <Left> after that should move the cursor
2742 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2743 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2744 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2745
2746 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2747 " should be displayed correctly on the screen.
2748 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2749 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2750
2751 " After using <C-A> to expand all the filename matches, pressing <Up>
2752 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002753 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002754 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2755 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2756 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2757
2758 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2759 " crash Vim
2760 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2761 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2762
Bram Moolenaar414acd32022-02-10 21:09:45 +00002763 " After removing the pum the command line is redrawn
2764 call term_sendkeys(buf, ":edit foo\<CR>")
2765 call term_sendkeys(buf, ":edit bar\<CR>")
2766 call term_sendkeys(buf, ":ls\<CR>")
2767 call term_sendkeys(buf, ":com\<Tab> ")
2768 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002769 call term_sendkeys(buf, "\<C-U>\<CR>")
2770
2771 " Esc still works to abort the command when 'statusline' is set
2772 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2773 call term_sendkeys(buf, ":si\<Tab>")
2774 call term_sendkeys(buf, "\<Esc>")
2775 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002776
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002777 " Esc still works to abort the command when 'tabline' is set
2778 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2779 call term_sendkeys(buf, ":si\<Tab>")
2780 call term_sendkeys(buf, "\<Esc>")
2781 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2782
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002783 " popup is cleared also when 'lazyredraw' is set
2784 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2785 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2786 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2787 call term_sendkeys(buf, "\<Esc>")
2788
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002789 " Pressing <PageDown> should scroll the menu downward
2790 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2791 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2792 call term_sendkeys(buf, "\<PageDown>")
2793 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2794 call term_sendkeys(buf, "\<PageDown>")
2795 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2796 call term_sendkeys(buf, "\<PageDown>")
2797 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2798 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2799 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2800
2801 " Pressing <PageUp> should scroll the menu upward
2802 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2803 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2804 call term_sendkeys(buf, "\<PageUp>")
2805 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2806 call term_sendkeys(buf, "\<PageUp>")
2807 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2808 call term_sendkeys(buf, "\<PageUp>")
2809 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2810
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002811 " pressing <C-E> to end completion should work in middle of the line too
2812 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2813 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2814 call term_sendkeys(buf, "\<C-E>")
2815 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2816
2817 " pressing <C-Y> should select the current match and end completion
2818 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2819 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2820
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002821 call term_sendkeys(buf, "\<C-U>\<CR>")
2822 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002823endfunc
2824
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002825" Test for wildmenumode() with the cmdline popup menu
2826func Test_wildmenumode_with_pum()
2827 set wildmenu
2828 set wildoptions=pum
2829 cnoremap <expr> <F2> wildmenumode()
2830 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2831 call assert_equal('"sign define10', @:)
2832 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2833 call assert_equal('"sign define jump list place undefine unplace0', @:)
2834 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2835 call assert_equal('"sign 0', @:)
2836 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2837 call assert_equal('"sign define0', @:)
2838 set nowildmenu wildoptions&
2839 cunmap <F2>
2840endfunc
2841
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002842func Test_wildmenu_with_pum_foldexpr()
2843 CheckRunVimInTerminal
2844
2845 let lines =<< trim END
2846 call setline(1, ['folded one', 'folded two', 'some more text'])
2847 func MyFoldText()
2848 return 'foo'
2849 endfunc
2850 set foldtext=MyFoldText() wildoptions=pum
2851 normal ggzfj
2852 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002853 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002854 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2855 call term_sendkeys(buf, ":set\<Tab>")
2856 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2857
2858 call term_sendkeys(buf, "\<Esc>")
2859 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2860
2861 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002862endfunc
2863
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002864" Test for opening the cmdline completion popup menu from the terminal window.
2865" The popup menu should be positioned correctly over the status line of the
2866" bottom-most window.
2867func Test_wildmenu_pum_from_terminal()
2868 CheckRunVimInTerminal
2869 let python = PythonProg()
2870 call CheckPython(python)
2871
2872 %bw!
2873 let cmds = ['set wildmenu wildoptions=pum']
2874 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2875 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002876 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002877 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2878 call term_sendkeys(buf, "\r\r\r")
2879 call term_wait(buf)
2880 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2881 call term_wait(buf)
2882 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2883 call term_wait(buf)
2884 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002885endfunc
2886
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002887func Test_wildmenu_pum_odd_wildchar()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002888 CheckRunVimInTerminal
2889
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002890 " Test odd wildchar interactions with pum. Make sure they behave properly
2891 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002892 let lines =<< trim END
2893 set wildoptions=pum
2894 set wildchar=<C-E>
2895 END
2896 call writefile(lines, 'XwildmenuTest', 'D')
2897 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2898
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002899 call term_sendkeys(buf, ":\<C-E>")
2900 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002901
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002902 " <C-E> being a wildchar takes priority over its original functionality
2903 call term_sendkeys(buf, "\<C-E>")
2904 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2905
2906 call term_sendkeys(buf, "\<Esc>")
2907 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2908
2909 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
2910 " command-line, and we need to make sure to clean up properly.
2911 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
2912 call term_sendkeys(buf, ":\<Esc>")
2913 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2914
2915 call term_sendkeys(buf, "\<Esc>")
2916 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2917
2918 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
2919 " and we again need to make sure we clean up properly.
2920 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
2921 call term_sendkeys(buf, ":\<C-\>\<C-\>")
2922 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2923
2924 call term_sendkeys(buf, "\<C-N>")
2925 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2926
2927 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002928endfunc
2929
zeertzjq883018f2024-06-15 15:37:11 +02002930" Test that 'rightleft' should not affect cmdline completion popup menu.
2931func Test_wildmenu_pum_rightleft()
2932 CheckFeature rightleft
2933 CheckScreendump
2934
2935 let lines =<< trim END
2936 set wildoptions=pum
2937 set rightleft
2938 END
2939 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
2940 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
2941
2942 call term_sendkeys(buf, ":sign \<Tab>")
2943 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
2944
2945 call StopVimInTerminal(buf)
2946endfunc
2947
zeertzjqd8c93402024-06-17 18:25:32 +02002948" Test highlighting matched text in cmdline completion popup menu.
2949func Test_wildmenu_pum_hl_match()
2950 CheckScreendump
2951
2952 let lines =<< trim END
2953 set wildoptions=pum,fuzzy
2954 hi PmenuMatchSel ctermfg=6 ctermbg=7
2955 hi PmenuMatch ctermfg=4 ctermbg=225
2956 END
2957 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
2958 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
2959
2960 call term_sendkeys(buf, ":sign plc\<Tab>")
2961 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
2962 call term_sendkeys(buf, "\<Tab>")
2963 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
2964 call term_sendkeys(buf, "\<Tab>")
2965 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
2966 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
2967 call TermWait(buf)
2968 call term_sendkeys(buf, ":sign un\<Tab>")
2969 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
2970 call term_sendkeys(buf, "\<Tab>")
2971 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
2972 call term_sendkeys(buf, "\<Tab>")
2973 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
2974 call term_sendkeys(buf, "\<Esc>")
2975
2976 call StopVimInTerminal(buf)
2977endfunc
2978
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002979" Test for completion after a :substitute command followed by a pipe (|)
2980" character
2981func Test_cmdline_complete_substitute()
2982 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2983 call assert_equal("\"s | \t", @:)
2984 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2985 call assert_equal("\"s/ | \t", @:)
2986 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2987 call assert_equal("\"s/one | \t", @:)
2988 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2989 call assert_equal("\"s/one/ | \t", @:)
2990 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2991 call assert_equal("\"s/one/two | \t", @:)
2992 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2993 call assert_equal('"s/one/two/ | chistory', @:)
2994 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2995 call assert_equal("\"s/one/two/g \t", @:)
2996 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2997 call assert_equal("\"s/one/two/g | chistory", @:)
2998 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2999 call assert_equal("\"s/one/t\\/ | \t", @:)
3000 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
3001 call assert_equal('"s/one/t"o/ | chistory', @:)
3002 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
3003 call assert_equal('"s/one/t|o/ | chistory', @:)
3004 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
3005 call assert_equal("\"&\t", @:)
3006endfunc
3007
3008" Test for the :dlist command completion
3009func Test_cmdline_complete_dlist()
3010 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
3011 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
3012 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
3013 call assert_equal("\"dlist 10 /pat/ \t", @:)
3014 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
3015 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
3016 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
3017 call assert_equal("\"dlist 10 /pat\\\t", @:)
3018 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
3019 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
3020endfunc
3021
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003022" argument list (only for :argdel) fuzzy completion
3023func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003024 argadd change.py count.py charge.py
3025 set wildoptions&
3026 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3027 call assert_equal('"argdel cge', @:)
3028 set wildoptions=fuzzy
3029 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3030 call assert_equal('"argdel change.py charge.py', @:)
3031 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003032 set wildoptions&
3033endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003034
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003035" autocmd group name fuzzy completion
3036func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003037 set wildoptions&
3038 augroup MyFuzzyGroup
3039 augroup END
3040 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3041 call assert_equal('"augroup mfg', @:)
3042 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3043 call assert_equal('"augroup MyFuzzyGroup', @:)
3044 set wildoptions=fuzzy
3045 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3046 call assert_equal('"augroup MyFuzzyGroup', @:)
3047 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3048 call assert_equal('"augroup My*p', @:)
3049 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003050 set wildoptions&
3051endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003052
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003053" buffer name fuzzy completion
3054func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003055 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003056 " Use a long name to reduce the risk of matching a random directory name
3057 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003058 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003059 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3060 call assert_equal('"b SRFWL', @:)
3061 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3062 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003063 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003064 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3065 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3066 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3067 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003068 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003069 set wildoptions&
3070endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003071
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003072" buffer name (full path) fuzzy completion
3073func Test_fuzzy_completion_bufname_fullpath()
3074 CheckUnix
3075 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003076 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003077 edit Xcmd/Xstate/Xfile.js
3078 cd Xcmd/Xstate
3079 enew
3080 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3081 call assert_equal('"b CmdStateFile', @:)
3082 set wildoptions=fuzzy
3083 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3084 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
3085 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003086 set wildoptions&
3087endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003088
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003089" :behave suboptions fuzzy completion
3090func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003091 set wildoptions&
3092 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3093 call assert_equal('"behave xm', @:)
3094 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3095 call assert_equal('"behave xterm', @:)
3096 set wildoptions=fuzzy
3097 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3098 call assert_equal('"behave xterm', @:)
3099 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3100 call assert_equal('"behave xt*m', @:)
3101 let g:Sline = ''
3102 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
3103 call assert_equal('mswin', g:Sline)
3104 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003105 set wildoptions&
3106endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003107
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003108" " colorscheme name fuzzy completion - NOT supported
3109" func Test_fuzzy_completion_colorscheme()
3110" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003111
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003112" built-in command name fuzzy completion
3113func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003114 set wildoptions&
3115 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3116 call assert_equal('"sbwin', @:)
3117 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3118 call assert_equal('"sbrewind', @:)
3119 set wildoptions=fuzzy
3120 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal('"sbrewind', @:)
3122 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3123 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003124 set wildoptions&
3125endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003126
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003127" " compiler name fuzzy completion - NOT supported
3128" func Test_fuzzy_completion_compiler()
3129" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003130
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003131" :cscope suboptions fuzzy completion
3132func Test_fuzzy_completion_cscope()
3133 CheckFeature cscope
3134 set wildoptions&
3135 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3136 call assert_equal('"cscope ret', @:)
3137 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal('"cscope reset', @:)
3139 set wildoptions=fuzzy
3140 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3141 call assert_equal('"cscope reset', @:)
3142 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3143 call assert_equal('"cscope re*t', @:)
3144 set wildoptions&
3145endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003146
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003147" :diffget/:diffput buffer name fuzzy completion
3148func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003149 new SomeBuffer
3150 diffthis
3151 new OtherBuffer
3152 diffthis
3153 set wildoptions&
3154 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3155 call assert_equal('"diffget sbuf', @:)
3156 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3157 call assert_equal('"diffput sbuf', @:)
3158 set wildoptions=fuzzy
3159 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3160 call assert_equal('"diffget SomeBuffer', @:)
3161 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3162 call assert_equal('"diffput SomeBuffer', @:)
3163 %bw!
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" " directory name fuzzy completion - NOT supported
3168" func Test_fuzzy_completion_dirname()
3169" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003170
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003171" environment variable name fuzzy completion
3172func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003173 set wildoptions&
3174 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3175 call assert_equal('"echo $VUT', @:)
3176 set wildoptions=fuzzy
3177 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003179 set wildoptions&
3180endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003181
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003182" autocmd event fuzzy completion
3183func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003184 set wildoptions&
3185 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3186 call assert_equal('"autocmd BWout', @:)
3187 set wildoptions=fuzzy
3188 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3189 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003190 set wildoptions&
3191endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003192
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003193" vim expression fuzzy completion
3194func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003195 let g:PerPlaceCount = 10
3196 set wildoptions&
3197 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3198 call assert_equal('"let c = ppc', @:)
3199 set wildoptions=fuzzy
3200 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3201 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003202 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003203endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003204
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003205" " file name fuzzy completion - NOT supported
3206" func Test_fuzzy_completion_filename()
3207" endfunc
3208
3209" " files in path fuzzy completion - NOT supported
3210" func Test_fuzzy_completion_filesinpath()
3211" endfunc
3212
3213" " filetype name fuzzy completion - NOT supported
3214" func Test_fuzzy_completion_filetype()
3215" endfunc
3216
3217" user defined function name completion
3218func Test_fuzzy_completion_userdefined_func()
3219 set wildoptions&
3220 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3221 call assert_equal('"call Test_f_u_f', @:)
3222 set wildoptions=fuzzy
3223 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3225 set wildoptions&
3226endfunc
3227
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003228" <SNR> functions should be sorted to the end
3229func Test_fuzzy_completion_userdefined_snr_func()
3230 func s:Sendmail()
3231 endfunc
3232 func SendSomemail()
3233 endfunc
3234 func S1e2n3dmail()
3235 endfunc
3236 set wildoptions=fuzzy
3237 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003238 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003239 set wildoptions&
3240 delfunc s:Sendmail
3241 delfunc SendSomemail
3242 delfunc S1e2n3dmail
3243endfunc
3244
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003245" user defined command name completion
3246func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003247 set wildoptions&
3248 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3249 call assert_equal('"MsFeat', @:)
3250 set wildoptions=fuzzy
3251 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3252 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003253 set wildoptions&
3254endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003255
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003256" " :help tag fuzzy completion - NOT supported
3257" func Test_fuzzy_completion_helptag()
3258" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003259
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003260" highlight group name fuzzy completion
3261func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003262 set wildoptions&
3263 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal('"highlight SKey', @:)
3265 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3266 call assert_equal('"highlight SpecialKey', @:)
3267 set wildoptions=fuzzy
3268 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3269 call assert_equal('"highlight SpecialKey', @:)
3270 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3271 call assert_equal('"highlight Sp*Key', @:)
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" :history suboptions fuzzy completion
3276func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003277 set wildoptions&
3278 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3279 call assert_equal('"history dg', @:)
3280 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3281 call assert_equal('"history search', @:)
3282 set wildoptions=fuzzy
3283 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3284 call assert_equal('"history debug', @:)
3285 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3286 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003287 set wildoptions&
3288endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003289
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003290" :language locale name fuzzy completion
3291func Test_fuzzy_completion_lang()
3292 CheckUnix
3293 set wildoptions&
3294 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3295 call assert_equal('"lang psx', @:)
3296 set wildoptions=fuzzy
3297 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3298 call assert_equal('"lang POSIX', @:)
3299 set wildoptions&
3300endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003301
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003302" :mapclear buffer argument fuzzy completion
3303func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003304 set wildoptions&
3305 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3306 call assert_equal('"mapclear buf', @:)
3307 set wildoptions=fuzzy
3308 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3309 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003310 set wildoptions&
3311endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003312
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003313" map name fuzzy completion
3314func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003315 " test regex completion works
3316 set wildoptions=fuzzy
3317 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3318 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003319 nmap <plug>MyLongMap :p<CR>
3320 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3321 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3322 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3323 call assert_equal("\"nmap MLM \t", @:)
3324 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3325 call assert_equal("\"nmap <F2> one two \t", @:)
3326 " duplicate entries should be removed
3327 vmap <plug>MyLongMap :<C-U>#<CR>
3328 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3329 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3330 nunmap <plug>MyLongMap
3331 vunmap <plug>MyLongMap
3332 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3333 call assert_equal("\"nmap ABC\t", @:)
3334 " results should be sorted by best match
3335 nmap <Plug>format :
3336 nmap <Plug>goformat :
3337 nmap <Plug>TestFOrmat :
3338 nmap <Plug>fendoff :
3339 nmap <Plug>state :
3340 nmap <Plug>FendingOff :
3341 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3342 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3343 nunmap <Plug>format
3344 nunmap <Plug>goformat
3345 nunmap <Plug>TestFOrmat
3346 nunmap <Plug>fendoff
3347 nunmap <Plug>state
3348 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003349 set wildoptions&
3350endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003351
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003352" abbreviation fuzzy completion
3353func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003354 set wildoptions=fuzzy
3355 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3356 call assert_equal("\"iabbr <nowait>", @:)
3357 iabbr WaitForCompletion WFC
3358 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3359 call assert_equal("\"iabbr WaitForCompletion", @:)
3360 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3361 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003362
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003363 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003364 set wildoptions&
3365endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003366
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003367" menu name fuzzy completion
3368func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003369 CheckFeature menu
3370
3371 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003372 set wildoptions&
3373 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3374 call assert_equal('"menu pup', @:)
3375 set wildoptions=fuzzy
3376 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3377 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003378
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003379 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003380 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003381endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003382
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003383" :messages suboptions fuzzy completion
3384func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003385 set wildoptions&
3386 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3387 call assert_equal('"messages clr', @:)
3388 set wildoptions=fuzzy
3389 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3390 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003391 set wildoptions&
3392endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003393
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003394" :set option name fuzzy completion
3395func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003396 set wildoptions&
3397 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3398 call assert_equal('"set brkopt', @:)
3399 set wildoptions=fuzzy
3400 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3401 call assert_equal('"set breakindentopt', @:)
3402 set wildoptions&
3403 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3404 call assert_equal('"set fixendofline', @:)
3405 set wildoptions=fuzzy
3406 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3407 call assert_equal('"set fixendofline', @:)
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" :set <term_option>
3412func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003413 set wildoptions&
3414 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3415 call assert_equal('"set t_EC', @:)
3416 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3417 call assert_equal('"set <t_EC>', @:)
3418 set wildoptions=fuzzy
3419 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3420 call assert_equal('"set t_EC', @:)
3421 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3422 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003423 set wildoptions&
3424endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003425
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003426" " :packadd directory name fuzzy completion - NOT supported
3427" func Test_fuzzy_completion_packadd()
3428" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003429
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003430" " shell command name fuzzy completion - NOT supported
3431" func Test_fuzzy_completion_shellcmd()
3432" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003433
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003434" :sign suboptions fuzzy completion
3435func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003436 set wildoptions&
3437 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3438 call assert_equal('"sign ufe', @:)
3439 set wildoptions=fuzzy
3440 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3441 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003442 set wildoptions&
3443endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003444
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003445" :syntax suboptions fuzzy completion
3446func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003447 set wildoptions&
3448 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3449 call assert_equal('"syntax kwd', @:)
3450 set wildoptions=fuzzy
3451 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3452 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003453 set wildoptions&
3454endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003455
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003456" syntax group name fuzzy completion
3457func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003458 set wildoptions&
3459 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3460 call assert_equal('"syntax list mpar', @:)
3461 set wildoptions=fuzzy
3462 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3463 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003464 set wildoptions&
3465endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003466
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003467" :syntime suboptions fuzzy completion
3468func Test_fuzzy_completion_syntime()
3469 CheckFeature profile
3470 set wildoptions&
3471 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3472 call assert_equal('"syntime clr', @:)
3473 set wildoptions=fuzzy
3474 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3475 call assert_equal('"syntime clear', @:)
3476 set wildoptions&
3477endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003478
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003479" " tag name fuzzy completion - NOT supported
3480" func Test_fuzzy_completion_tagname()
3481" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003482
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003483" " tag name and file fuzzy completion - NOT supported
3484" func Test_fuzzy_completion_tagfile()
3485" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003486
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003487" " user names fuzzy completion - how to test this functionality?
3488" func Test_fuzzy_completion_username()
3489" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003490
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003491" user defined variable name fuzzy completion
3492func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003493 let g:SomeVariable=10
3494 set wildoptions&
3495 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3496 call assert_equal('"let SVar', @:)
3497 set wildoptions=fuzzy
3498 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3499 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003500 set wildoptions&
3501endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003502
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003503" Test for sorting the results by the best match
3504func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003505 %bw!
3506 command T123format :
3507 command T123goformat :
3508 command T123TestFOrmat :
3509 command T123fendoff :
3510 command T123state :
3511 command T123FendingOff :
3512 set wildoptions=fuzzy
3513 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3514 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3515 delcommand T123format
3516 delcommand T123goformat
3517 delcommand T123TestFOrmat
3518 delcommand T123fendoff
3519 delcommand T123state
3520 delcommand T123FendingOff
3521 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003522 set wildoptions&
3523endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003524
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003525" Test for fuzzy completion of a command with lower case letters and a number
3526func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003527 command Foo2Bar :
3528 set wildoptions=fuzzy
3529 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3530 call assert_equal('"Foo2Bar', @:)
3531 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3532 call assert_equal('"Foo2Bar', @:)
3533 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3534 call assert_equal('"Foo2Bar', @:)
3535 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003536 set wildoptions&
3537endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003538
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003539" Test for command completion for a command starting with 'k'
3540func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003541 command KillKillKill :
3542 set wildoptions&
3543 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3544 call assert_equal("\"killkill\<Tab>", @:)
3545 set wildoptions=fuzzy
3546 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3547 call assert_equal('"KillKillKill', @:)
3548 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003549 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003550endfunc
3551
3552" Test for fuzzy completion for user defined custom completion function
3553func Test_fuzzy_completion_custom_func()
3554 func Tcompl(a, c, p)
3555 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3556 endfunc
3557 command -nargs=* -complete=custom,Tcompl Fuzzy :
3558 set wildoptions&
3559 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3560 call assert_equal("\"Fuzzy format", @:)
3561 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3562 call assert_equal("\"Fuzzy xy", @:)
3563 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3564 call assert_equal("\"Fuzzy ttt", @:)
3565 set wildoptions=fuzzy
3566 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3567 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3568 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3569 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3570 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3571 call assert_equal("\"Fuzzy xy", @:)
3572 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3573 call assert_equal("\"Fuzzy TestFOrmat", @:)
3574 delcom Fuzzy
3575 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003576endfunc
3577
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003578" Test for fuzzy completion in the middle of a cmdline instead of at the end
3579func Test_fuzzy_completion_in_middle()
3580 set wildoptions=fuzzy
3581 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3582 call assert_equal("\"set wildchar wildcharm wrap", @:)
3583
3584 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3585 call assert_equal("\"args ++encoding= zz", @:)
3586 set wildoptions&
3587endfunc
3588
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003589" Test for :breakadd argument completion
3590func Test_cmdline_complete_breakadd()
3591 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3592 call assert_equal("\"breakadd expr file func here", @:)
3593 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3594 call assert_equal("\"breakadd expr", @:)
3595 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3596 call assert_equal("\"breakadd expr", @:)
3597 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3598 call assert_equal("\"breakadd here", @:)
3599 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3600 call assert_equal("\"breakadd here", @:)
3601 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3602 call assert_equal("\"breakadd abc", @:)
3603 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3604 let l = getcompletion('not', 'breakpoint')
3605 call assert_equal([], l)
3606
3607 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003608 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003609 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3610 call assert_equal("\"breakadd file Xscript", @:)
3611 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3612 call assert_equal("\"breakadd file Xscript", @:)
3613 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3614 call assert_equal("\"breakadd file 20 Xscript", @:)
3615 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3616 call assert_equal("\"breakadd file 20 Xscript", @:)
3617 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3618 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3619 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3620 call assert_equal("\"breakadd file 20\t", @:)
3621 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3622 call assert_equal("\"breakadd file 20x\t", @:)
3623 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3624 call assert_equal("\"breakadd file Xscript ", @:)
3625 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3626 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003627
3628 " Test for :breakadd func [lnum] <function>
3629 func Xbreak_func()
3630 endfunc
3631 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3632 call assert_equal("\"breakadd func Xbreak_func", @:)
3633 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3634 call assert_equal("\"breakadd func Xbreak_func", @:)
3635 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3636 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3637 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3638 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3639 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3640 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3641 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3642 call assert_equal("\"breakadd func 20\t", @:)
3643 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3644 call assert_equal("\"breakadd func 20x\t", @:)
3645 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3646 call assert_equal("\"breakadd func Xbreak_func ", @:)
3647 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3648 call assert_equal("\"breakadd func X1B2C3", @:)
3649 delfunc Xbreak_func
3650
3651 " Test for :breakadd expr <expression>
3652 let g:Xtest_var = 10
3653 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3654 call assert_equal("\"breakadd expr Xtest_var", @:)
3655 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3656 call assert_equal("\"breakadd expr Xtest_var", @:)
3657 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3658 call assert_equal("\"breakadd expr Xtest_var ", @:)
3659 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3660 call assert_equal("\"breakadd expr X1B2C3", @:)
3661 unlet g:Xtest_var
3662
3663 " Test for :breakadd here
3664 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3665 call assert_equal("\"breakadd here Xtest", @:)
3666 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3667 call assert_equal("\"breakadd here Xtest", @:)
3668 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3669 call assert_equal("\"breakadd here ", @:)
3670endfunc
3671
3672" Test for :breakdel argument completion
3673func Test_cmdline_complete_breakdel()
3674 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3675 call assert_equal("\"breakdel file func here", @:)
3676 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3677 call assert_equal("\"breakdel file", @:)
3678 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3679 call assert_equal("\"breakdel file", @:)
3680 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3681 call assert_equal("\"breakdel here", @:)
3682 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3683 call assert_equal("\"breakdel here", @:)
3684 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3685 call assert_equal("\"breakdel abc", @:)
3686
3687 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003688 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003689 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3690 call assert_equal("\"breakdel file Xscript", @:)
3691 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3692 call assert_equal("\"breakdel file Xscript", @:)
3693 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3694 call assert_equal("\"breakdel file 20 Xscript", @:)
3695 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3696 call assert_equal("\"breakdel file 20 Xscript", @:)
3697 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3698 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3699 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3700 call assert_equal("\"breakdel file 20\t", @:)
3701 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3702 call assert_equal("\"breakdel file 20x\t", @:)
3703 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3704 call assert_equal("\"breakdel file Xscript ", @:)
3705 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3706 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003707
3708 " Test for :breakdel func [lnum] <function>
3709 func Xbreak_func()
3710 endfunc
3711 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3712 call assert_equal("\"breakdel func Xbreak_func", @:)
3713 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3714 call assert_equal("\"breakdel func Xbreak_func", @:)
3715 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3716 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3717 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3718 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3719 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3720 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3721 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3722 call assert_equal("\"breakdel func 20\t", @:)
3723 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3724 call assert_equal("\"breakdel func 20x\t", @:)
3725 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3726 call assert_equal("\"breakdel func Xbreak_func ", @:)
3727 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3728 call assert_equal("\"breakdel func X1B2C3", @:)
3729 delfunc Xbreak_func
3730
3731 " Test for :breakdel here
3732 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3733 call assert_equal("\"breakdel here Xtest", @:)
3734 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3735 call assert_equal("\"breakdel here Xtest", @:)
3736 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3737 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003738endfunc
3739
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003740" Test for :scriptnames argument completion
3741func Test_cmdline_complete_scriptnames()
3742 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003743 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003744 source Xa1b2c3.vim
3745 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3746 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3747 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3748 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3749 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3750 call assert_equal("\"script b2c3", @:)
3751 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3752 call assert_match("\"script 2\<Tab>$", @:)
3753 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3754 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3755 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3756 call assert_equal("\"script ", @:)
3757 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3758 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3759 new
3760 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3761 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3762 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003763 set wildmenu&
3764endfunc
3765
Bram Moolenaard8893442022-05-06 20:38:47 +01003766" this was going over the end of IObuff
3767func Test_report_error_with_composing()
3768 let caught = 'no'
3769 try
3770 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3771 catch /E492:/
3772 let caught = 'yes'
3773 endtry
3774 call assert_equal('yes', caught)
3775endfunc
3776
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003777" Test for expanding 2-letter and 3-letter :substitute command arguments.
3778" These commands don't accept an argument.
3779func Test_cmdline_complete_substitute_short()
3780 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3781 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3782 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3783 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3784 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3785 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3786 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3787 endfor
3788endfunc
3789
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003790" Test for shellcmdline command argument completion
3791func Test_cmdline_complete_shellcmdline_argument()
3792 command -nargs=+ -complete=shellcmdline MyCmd
3793
3794 set wildoptions=fuzzy
3795
3796 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3797 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003798 call assert_equal(['test_cmdline.vim'],
3799 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003800
3801 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3802 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003803 call assert_equal([],
3804 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003805
3806 let compl1 = getcompletion('', 'file')[0]
3807 let compl2 = getcompletion('', 'file')[1]
3808 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3809 call assert_equal('"MyCmd vim ' .. compl1, @:)
3810
3811 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3812 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3813
3814 let compl = getcompletion('', 'file')[1]
3815 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3816 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3817
3818 set wildoptions&
3819 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3820 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003821 call assert_equal(['test_cmdline.vim'],
3822 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003823
3824 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3825 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003826 call assert_equal([],
3827 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003828
3829 let compl1 = getcompletion('', 'file')[0]
3830 let compl2 = getcompletion('', 'file')[1]
3831 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3832 call assert_equal('"MyCmd vim ' .. compl1, @:)
3833
3834 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3835 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3836
3837 let compl = getcompletion('', 'file')[1]
3838 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3839 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3840
3841 delcommand MyCmd
3842endfunc
3843
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003844" Test for :! shell command argument completion
3845func Test_cmdline_complete_bang_cmd_argument()
3846 set wildoptions=fuzzy
3847 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3848 call assert_equal('"!vim test_cmdline.vim', @:)
3849 set wildoptions&
3850 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3851 call assert_equal('"!vim test_cmdline.vim', @:)
3852endfunc
3853
zeertzjq961b2e52023-04-17 15:53:24 +01003854func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003855 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003856endfunc
3857
3858func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003859 call assert_equal(0, getcmdpos())
3860 call assert_equal(0, getcmdscreenpos())
3861 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003862 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01003863
zeertzjqa821b602024-06-18 20:31:08 +02003864 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01003865 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003866 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003867 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003868 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003869 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003870 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02003871
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003872 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
3873 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02003874 let g:results = []
3875 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
3876 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
3877 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003878 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
3879 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
3880 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02003881
3882 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01003883 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003884endfunc
3885
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003886func Test_recursive_register()
3887 let @= = ''
3888 silent! ?e/
3889 let caught = 'no'
3890 try
3891 normal //
3892 catch /E169:/
3893 let caught = 'yes'
3894 endtry
3895 call assert_equal('yes', caught)
3896endfunc
3897
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003898func Test_long_error_message()
3899 " the error should be truncated, not overrun IObuff
3900 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3901endfunc
3902
zeertzjq6791adc2022-07-26 20:42:25 +01003903func Test_cmdline_redraw_tabline()
3904 CheckRunVimInTerminal
3905
3906 let lines =<< trim END
3907 set showtabline=2
3908 autocmd CmdlineEnter * set tabline=foo
3909 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003910 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003911 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3912 call term_sendkeys(buf, ':')
3913 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3914
3915 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003916endfunc
3917
zeertzjqb82a2ab2022-08-21 14:33:57 +01003918func Test_wildmenu_pum_disable_while_shown()
3919 set wildoptions=pum
3920 set wildmenu
3921 cnoremap <F2> <Cmd>set nowildmenu<CR>
3922 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3923 call assert_equal(0, pumvisible())
3924 cunmap <F2>
3925 set wildoptions& wildmenu&
3926endfunc
3927
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003928func Test_setcmdline()
3929 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01003930 call assert_equal(0, setcmdline(test_null_string()))
3931 call assert_equal('', getcmdline())
3932 call assert_equal(1, getcmdpos())
3933
3934 call assert_equal(0, setcmdline(''[: -1]))
3935 call assert_equal('', getcmdline())
3936 call assert_equal(1, getcmdpos())
3937
zeertzjq54acb902022-08-29 16:21:25 +01003938 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003939 call assert_equal(0, setcmdline(a:text))
3940 call assert_equal(a:text, getcmdline())
3941 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003942 call assert_equal(getcmdtype(), g:cmdtype)
3943 unlet g:cmdtype
3944 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003945
3946 call assert_equal(0, setcmdline(a:text, a:pos))
3947 call assert_equal(a:text, getcmdline())
3948 call assert_equal(a:pos, getcmdpos())
3949
3950 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003951 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3952 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003953
3954 return ''
3955 endfunc
3956
3957 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3958 call assert_equal('set rtp?', @:)
3959
zeertzjq54acb902022-08-29 16:21:25 +01003960 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3961 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3962 call assert_equal('foo', g:str)
3963 unlet g:str
3964
3965 delfunc SetText
3966
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003967 " setcmdline() returns 1 when not editing the command line.
3968 call assert_equal(1, 'foo'->setcmdline())
3969
3970 " Called in custom function
3971 func CustomComplete(A, L, P)
3972 call assert_equal(0, setcmdline("DoCmd "))
3973 return "January\nFebruary\nMars\n"
3974 endfunc
3975
3976 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3977 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3978 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003979 delcom DoCmd
3980 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003981
3982 " Called in <expr>
3983 cnoremap <expr>a setcmdline('let foo=')
3984 call feedkeys(":a\<CR>", 'tx')
3985 call assert_equal('let foo=0', @:)
3986 cunmap a
3987endfunc
3988
Sean Dewarfc8a6012023-04-17 16:41:20 +01003989func Test_rulerformat_position()
3990 CheckScreendump
3991
3992 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
3993 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
3994 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
3995 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
3996 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
3997
3998 " clean up
3999 call StopVimInTerminal(buf)
4000endfunc
4001
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01004002" Test for using "%!" in 'rulerformat' to use a function
4003func Test_rulerformat_function()
4004 CheckScreendump
4005
4006 let lines =<< trim END
4007 func TestRulerFn()
4008 return '10,20%=30%%'
4009 endfunc
4010 END
4011 call writefile(lines, 'Xrulerformat_function', 'D')
4012
4013 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
4014 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
4015 call term_sendkeys(buf, ":redraw!\<CR>")
4016 call term_wait(buf)
4017 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
4018
4019 " clean up
4020 call StopVimInTerminal(buf)
4021endfunc
4022
zeertzjqe4c79d32023-08-15 22:41:53 +02004023func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004024 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004025
zeertzjqe4c79d32023-08-15 22:41:53 +02004026 call assert_equal(getcompletion('', 'cmdline'),
4027 \ getcompletion('TestCompletion ', 'cmdline'))
4028 call assert_equal(['<buffer>'],
4029 \ getcompletion('TestCompletion map <bu', 'cmdline'))
4030
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004031 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004032endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02004033
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004034func Test_custom_completion()
4035 func CustomComplete1(lead, line, pos)
4036 return "a\nb\nc"
4037 endfunc
4038 func CustomComplete2(lead, line, pos)
4039 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
4040 endfunc
4041 func Check_custom_completion()
4042 call assert_equal('custom,CustomComplete1', getcmdcompltype())
4043 return ''
4044 endfunc
4045 func Check_customlist_completion()
4046 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
4047 return ''
4048 endfunc
4049
4050 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
4051 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
4052
4053 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
4054 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
4055
4056 call assert_fails("call getcompletion('', 'custom')", 'E475:')
4057 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
4058
zeertzjq757f3212024-04-15 19:01:04 +02004059 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
4060 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
4061 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004062
4063 delcom Test1
4064 delcom Test2
4065
4066 delfunc CustomComplete1
4067 delfunc CustomComplete2
4068 delfunc Check_custom_completion
4069 delfunc Check_customlist_completion
4070endfunc
4071
zeertzjq28a23602023-09-29 19:58:35 +02004072func Test_custom_completion_with_glob()
4073 func TestGlobComplete(A, L, P)
4074 return split(glob('Xglob*'), "\n")
4075 endfunc
4076
4077 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
4078 call writefile([], 'Xglob1', 'D')
4079 call writefile([], 'Xglob2', 'D')
4080
4081 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
4082 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
4083
4084 delcommand TestGlobComplete
4085 delfunc TestGlobComplete
4086endfunc
4087
Christian Brabandt8610f742024-01-12 17:34:40 +01004088func Test_window_size_stays_same_after_changing_cmdheight()
4089 set laststatus=2
4090 let expected = winheight(0)
4091 function! Function_name() abort
4092 call feedkeys(":"..repeat('x', &columns), 'x')
4093 let &cmdheight=2
4094 let &cmdheight=1
4095 redraw
4096 endfunction
4097 call Function_name()
4098 call assert_equal(expected, winheight(0))
4099endfunc
4100
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01004101" verify that buffer-completion finds all buffer names matching a pattern
4102func Test_buffer_completion()
4103 " should return empty list
4104 call assert_equal([], getcompletion('', 'buffer'))
4105
4106 call mkdir('Xbuf_complete', 'R')
4107 e Xbuf_complete/Foobar.c
4108 e Xbuf_complete/MyFoobar.c
4109 e AFoobar.h
4110 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
4111
4112 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
4113 call assert_equal(expected, getcompletion('Foo', 'buffer'))
4114 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
4115 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
4116endfunc
4117
Anton Sharonov49528da2024-04-14 20:02:24 +02004118" :set t_??
4119func Test_term_option()
4120 set wildoptions&
4121 let _cpo = &cpo
4122 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004123 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02004124 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'
4125 \ .. ' 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'
4126 \ .. ' 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'
4127 \ .. ' 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'
4128 \ .. ' 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 +02004129 \ .. ' 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 +02004130 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004131 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004132 let &cpo = _cpo
4133endfunc
4134
Christian Brabandt70a11a62024-07-26 19:13:55 +02004135func Test_ex_command_completion()
4136 " required for :*
4137 set cpo+=*
4138 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
4139 " :++ and :-- are only valid in Vim9 Script context, so they can be ignored
4140 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004141 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004142 call assert_equal(0, exists(':ke'))
4143 call assert_equal(1, exists(':kee'))
4144 call assert_equal(1, exists(':keep'))
4145 call assert_equal(1, exists(':keepm'))
4146 call assert_equal(1, exists(':keepma'))
4147 call assert_equal(1, exists(':keepmar'))
4148 call assert_equal(1, exists(':keepmark'))
4149 call assert_equal(2, exists(':keepmarks'))
4150 call assert_equal(2, exists(':keepalt'))
4151 call assert_equal(2, exists(':keepjumps'))
4152 call assert_equal(2, exists(':keeppatterns'))
4153 set cpo-=*
4154endfunc
4155
zeertzjq5df3cb22024-10-07 21:05:06 +02004156func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004157 CheckMSWindows
4158 let save_shellslash = &shellslash
4159 set noshellslash
4160 call system('mkdir XXXa\_b')
4161 defer delete('XXXa', 'rf')
4162 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4163 call assert_equal('"cd XXXa\_b\', @:)
4164 let &shellslash = save_shellslash
4165endfunc
4166
Bram Moolenaar309976e2019-12-05 18:16:33 +01004167" vim: shiftwidth=2 sts=2 expandtab