blob: ff38b69c6e3d236a6fcf986cf64f173b8821c948 [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Bram Moolenaar4facea32019-10-12 20:17:40 +02003source check.vim
4source screendump.vim
Bram Moolenaar24ebd832020-03-16 21:25:24 +01005source view_util.vim
Bram Moolenaarc82dd862020-06-07 17:30:33 +02006source shared.vim
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00007import './vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02008
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00009func SetUp()
10 func SaveLastScreenLine()
11 let g:Sline = Screenline(&lines - 1)
12 return ''
13 endfunc
14 cnoremap <expr> <F4> SaveLastScreenLine()
15endfunc
16
17func TearDown()
18 delfunc SaveLastScreenLine
19 cunmap <F4>
20endfunc
21
Bram Moolenaarae3150e2016-06-11 23:22:36 +020022func Test_complete_tab()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010023 call writefile(['testfile'], 'Xtestfile', 'D')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020024 call feedkeys(":e Xtest\t\r", "tx")
25 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020026
27 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
28 call feedkeys(":e %\t\r", "tx")
29 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020030endfunc
31
32func Test_complete_list()
33 " We can't see the output, but at least we check the code runs properly.
34 call feedkeys(":e test\<C-D>\r", "tx")
35 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010036
37 " If a command doesn't support completion, then CTRL-D should be literally
38 " used.
39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000041
42 " Test for displaying the tail of the completion matches
43 set wildmode=longest,full
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010044 call mkdir('Xtest', 'R')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000045 call writefile([], 'Xtest/a.c')
46 call writefile([], 'Xtest/a.h')
47 let g:Sline = ''
48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49 call assert_equal('a.c a.h', g:Sline)
50 call assert_equal('"e Xtest/', @:)
51 if has('win32')
52 " Test for 'completeslash'
53 set completeslash=backslash
54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000056 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000058 set completeslash=slash
59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000061 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000063 set completeslash&
64 endif
65
66 " Test for displaying the tail with wildcards
67 let g:Sline = ''
68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
70 call assert_equal('"e Xtes?/', @:)
71 let g:Sline = ''
72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
74 call assert_equal('"e Xtes*/', @:)
75 let g:Sline = ''
76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77 call assert_equal(':e Xtes[/', g:Sline)
78 call assert_equal('"e Xtes[/', @:)
79
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000080 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020081endfunc
82
83func Test_complete_wildmenu()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010084 call mkdir('Xwilddir1/Xdir2', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010085 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
86 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
87 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
88 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020089 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010090
91 " Pressing <Tab> completes, and moves to next files when pressing again.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010092 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010093 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010094 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020095 call assert_equal('testfile2', getline(1))
96
Bram Moolenaar37db6422019-03-28 21:26:23 +010097 " <S-Tab> is like <Tab> but begin with the last match and then go to
98 " previous.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010099 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100100 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100101 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100102 call assert_equal('testfile1', getline(1))
103
104 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100105 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100106 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100107 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100108 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100109 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100110 call assert_equal('testfile1', getline(1))
111
112 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100113 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100114 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100115 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100116 call assert_equal('testfile1', getline(1))
117
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100118 " this fails in some Unix GUIs, not sure why
119 if !has('unix') || !has('gui_running')
120 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
121 " different than 'wildchar'.
122 set wildcharm=<C-Z>
123 cnoremap <C-J> <Down><C-Z>
124 cnoremap <C-K> <Up><C-Z>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100125 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100126 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100127 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100128 call assert_equal('testfile1', getline(1))
129 set wildcharm=0
130 cunmap <C-J>
131 cunmap <C-K>
132 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100133
Bram Moolenaar578fe942020-02-27 21:32:51 +0100134 " Test for canceling the wild menu by adding a character
135 redrawstatus
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100136 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
137 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100138
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100139 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100140 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
142 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
143 cd -
144
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000145 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100146 cnoremap <expr> <F2> wildmenumode()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100147 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
148 call assert_equal('"cd Xwilddir1/0', @:)
149 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
150 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100151 cunmap <F2>
152
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000153 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
154 " After this pressing <Left> or <Right> should not change the selection.
155 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
156 call assert_equal('"sign define', @:)
157 call histadd('cmd', 'TestWildMenu')
158 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
159 call assert_equal('"TestWildMenu', @:)
160
Bram Moolenaar37db6422019-03-28 21:26:23 +0100161 " cleanup
162 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200163 set nowildmenu
164endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100165
Bram Moolenaara60053b2020-09-03 16:50:13 +0200166func Test_wildmenu_screendump()
167 CheckScreendump
168
169 let lines =<< trim [SCRIPT]
170 set wildmenu hlsearch
171 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100172 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173
174 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
175 call term_sendkeys(buf, ":vim\<Tab>")
176 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
177
178 call term_sendkeys(buf, "\<Tab>")
179 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
180
181 call term_sendkeys(buf, "\<Tab>")
182 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
183
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100184 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200185 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
186 call term_sendkeys(buf, "\<Esc>")
187
188 " clean up
189 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200190endfunc
191
Bram Moolenaara653e532022-04-19 11:38:24 +0100192func Test_redraw_in_autocmd()
193 CheckScreendump
194
195 let lines =<< trim END
196 set cmdheight=2
197 autocmd CmdlineChanged * redraw
198 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100199 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100200
201 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
202 call term_sendkeys(buf, ":for i in range(3)\<CR>")
203 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
204
205 call term_sendkeys(buf, "let i =")
206 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
207
208 " clean up
209 call term_sendkeys(buf, "\<CR>")
210 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100211endfunc
212
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100213func Test_redrawstatus_in_autocmd()
214 CheckScreendump
215
216 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100217 set laststatus=2
218 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100219 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100220 END
221 call writefile(lines, 'XTest_redrawstatus', 'D')
222
223 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100224 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100225 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
226 call term_sendkeys(buf, ":foobar")
227 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100228 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100229 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100230 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100231 " with cmdheight=1 messages have scrolled when typing :endfor
232 call term_sendkeys(buf, "\<CR>:endfor")
233 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
234 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
235 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
236 call term_sendkeys(buf, ":for in in range(3)")
237 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
238 call term_sendkeys(buf, "\<CR>:endfor")
239 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100240
241 " clean up
242 call term_sendkeys(buf, "\<CR>")
243 call StopVimInTerminal(buf)
244endfunc
245
Bram Moolenaarf797e302022-08-11 13:17:30 +0100246func Test_changing_cmdheight()
247 CheckScreendump
248
249 let lines =<< trim END
250 set cmdheight=1 laststatus=2
Bram Moolenaar0816f472022-10-05 15:42:32 +0100251 func EchoTwo()
252 set laststatus=2
253 set cmdheight=5
254 echo 'foo'
255 echo 'bar'
256 set cmdheight=1
257 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100258 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100259 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100260
261 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
262 call term_sendkeys(buf, ":resize -3\<CR>")
263 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
264
265 " using the space available doesn't change the status line
266 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
267 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
268
269 " using more space moves the status line up
270 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
271 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
272
273 " reducing cmdheight moves status line down
274 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
275 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
276
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000277 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100278 call term_sendkeys(buf, ":resize -1\<CR>")
279 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
280 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
281
Bram Moolenaar0816f472022-10-05 15:42:32 +0100282 " setting 'cmdheight' works after outputting two messages
283 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
284 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
285
Bram Moolenaarf797e302022-08-11 13:17:30 +0100286 " clean up
287 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100288endfunc
289
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100290func Test_cmdheight_tabline()
291 CheckScreendump
292
293 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
294 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
295
296 " clean up
297 call StopVimInTerminal(buf)
298endfunc
299
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100300func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100301 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
302 call assert_equal('"map <unique> <silent>', getreg(':'))
303 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
304 call assert_equal('"map <script> <unique>', getreg(':'))
305 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
306 call assert_equal('"map <expr> <script>', getreg(':'))
307 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
308 call assert_equal('"map <buffer> <expr>', getreg(':'))
309 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
310 call assert_equal('"map <nowait> <buffer>', getreg(':'))
311 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
312 call assert_equal('"map <special> <nowait>', getreg(':'))
313 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
314 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200315
Bram Moolenaar1776a282019-05-03 16:05:41 +0200316 map <Middle>x middle
317
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200318 map ,f commaf
319 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200320 map <Left> left
321 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200322 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
323 call assert_equal('"map ,f', getreg(':'))
324 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
325 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200326 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
327 call assert_equal('"map <Left>', getreg(':'))
328 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200329 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000330 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
331 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200332 unmap ,f
333 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200334 unmap <Left>
335 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200336
zeertzjqc3a26c62023-02-17 16:40:20 +0000337 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200338 map <Left> left
339 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
340 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200341 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200342 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000343 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
344 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200345 unmap <Left>
346
347 set cpo+=<
348 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200349 exe "set t_k6=\<Esc>[17~"
350 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200351 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
352 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200353 if !has('gui_running')
354 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
355 call assert_equal("\"map <F6>x", getreg(':'))
356 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200357 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200358 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200359 set cpo-=<
360
361 set cpo+=B
362 map <Left> left
363 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
364 call assert_equal('"map <Left>', getreg(':'))
365 unmap <Left>
366 set cpo-=B
367
368 set cpo+=k
369 map <Left> left
370 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
371 call assert_equal('"map <Left>', getreg(':'))
372 unmap <Left>
373 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200374
Bram Moolenaar531be472020-09-23 22:38:05 +0200375 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
376
Bram Moolenaar1776a282019-05-03 16:05:41 +0200377 unmap <Middle>x
378 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100379endfunc
380
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100381func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100382 hi Aardig ctermfg=green
383 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000384 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100385 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000386 call assert_equal('"match none', @:)
387 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
388 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100389endfunc
390
391func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100392 hi Aardig ctermfg=green
393 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
394 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200395 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
396 call assert_equal('"hi default Aardig', getreg(':'))
397 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
398 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100399 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
400 call assert_equal('"hi link', getreg(':'))
401 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
402 call assert_equal('"hi default', getreg(':'))
403 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
404 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200405 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
406 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
407 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
408 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200409
410 " A cleared group does not show up in completions.
411 hi Anders ctermfg=green
412 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
413 hi clear Aardig
414 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
415 hi clear Anders
416 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100417endfunc
418
Bram Moolenaar75e15672020-06-28 13:10:22 +0200419" Test for command-line expansion of "hi Ni " (easter egg)
420func Test_highlight_easter_egg()
421 call test_override('ui_delay', 1)
422 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
423 call assert_equal("\"hi Ni \<Tab>", @:)
424 call test_override('ALL', 0)
425endfunc
426
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200427func Test_getcompletion()
428 let groupcount = len(getcompletion('', 'event'))
429 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200430 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200431 call assert_true(matchcount > 0)
432 call assert_true(groupcount > matchcount)
433
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200434 if has('menu')
435 source $VIMRUNTIME/menu.vim
436 let matchcount = len(getcompletion('', 'menu'))
437 call assert_true(matchcount > 0)
438 call assert_equal(['File.'], getcompletion('File', 'menu'))
439 call assert_true(matchcount > 0)
440 let matchcount = len(getcompletion('File.', 'menu'))
441 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000442 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200443 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200444
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200445 let l = getcompletion('v:n', 'var')
446 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200447 let l = getcompletion('v:notexists', 'var')
448 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200449
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200450 args a.c b.c
451 let l = getcompletion('', 'arglist')
452 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000453 let l = getcompletion('a.', 'buffer')
454 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200455 %argdelete
456
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200457 let l = getcompletion('', 'augroup')
458 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200459 let l = getcompletion('blahblah', 'augroup')
460 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200461
462 let l = getcompletion('', 'behave')
463 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200464 let l = getcompletion('not', 'behave')
465 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200466
467 let l = getcompletion('', 'color')
468 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200469 let l = getcompletion('dirty', 'color')
470 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200471
472 let l = getcompletion('', 'command')
473 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200474 let l = getcompletion('awake', 'command')
475 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200476
477 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200478 call assert_true(index(l, 'samples/') >= 0)
479 let l = getcompletion('NoMatch', 'dir')
480 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200481
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100482 if glob('~/*') !=# ''
483 let l = getcompletion('~/', 'dir')
484 call assert_true(l[0][0] ==# '~')
485 endif
486
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200487 let l = getcompletion('exe', 'expression')
488 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200489 let l = getcompletion('kill', 'expression')
490 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200491
492 let l = getcompletion('tag', 'function')
493 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200494 let l = getcompletion('paint', 'function')
495 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200496
Kota Kato90c23532023-01-18 15:27:38 +0000497 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000498 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000499 let l = getcompletion('ruby', 'function')
500 call assert_equal([], l)
501 endif
502
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200503 let Flambda = {-> 'hello'}
504 let l = getcompletion('', 'function')
505 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200506 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200507
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200508 let l = getcompletion('run', 'file')
509 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200510 let l = getcompletion('walk', 'file')
511 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200512 set wildignore=*.vim
513 let l = getcompletion('run', 'file', 1)
514 call assert_true(index(l, 'runtest.vim') < 0)
515 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000516 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100517 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000518 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
519 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200520
521 let l = getcompletion('ha', 'filetype')
522 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200523 let l = getcompletion('horse', 'filetype')
524 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200525
526 let l = getcompletion('z', 'syntax')
527 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200528 let l = getcompletion('emacs', 'syntax')
529 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200530
531 let l = getcompletion('jikes', 'compiler')
532 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200533 let l = getcompletion('break', 'compiler')
534 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200535
536 let l = getcompletion('last', 'help')
537 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200538 let l = getcompletion('giveup', 'help')
539 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200540
541 let l = getcompletion('time', 'option')
542 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200543 let l = getcompletion('space', 'option')
544 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200545
546 let l = getcompletion('er', 'highlight')
547 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200548 let l = getcompletion('dark', 'highlight')
549 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200550
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200551 let l = getcompletion('', 'messages')
552 call assert_true(index(l, 'clear') >= 0)
553 let l = getcompletion('not', 'messages')
554 call assert_equal([], l)
555
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200556 let l = getcompletion('', 'mapclear')
557 call assert_true(index(l, '<buffer>') >= 0)
558 let l = getcompletion('not', 'mapclear')
559 call assert_equal([], l)
560
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200561 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200562 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200563 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
564 let root = has('win32') ? 'C:\\' : '/'
565 let l = getcompletion(root, 'shellcmd')
566 let expected = map(filter(glob(root . '*', 0, 1),
567 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
568 call assert_equal(expected, l)
569
Bram Moolenaarb650b982016-08-05 20:35:13 +0200570 if has('cscope')
571 let l = getcompletion('', 'cscope')
572 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
573 call assert_equal(cmds, l)
574 " using cmdline completion must not change the result
575 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
576 let l = getcompletion('', 'cscope')
577 call assert_equal(cmds, l)
578 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
579 let l = getcompletion('find ', 'cscope')
580 call assert_equal(keys, l)
581 endif
582
Bram Moolenaar7522f692016-08-06 14:12:50 +0200583 if has('signs')
584 sign define Testing linehl=Comment
585 let l = getcompletion('', 'sign')
586 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
587 call assert_equal(cmds, l)
588 " using cmdline completion must not change the result
589 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
590 let l = getcompletion('', 'sign')
591 call assert_equal(cmds, l)
592 let l = getcompletion('list ', 'sign')
593 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000594 let l = getcompletion('de*', 'sign')
595 call assert_equal(['define'], l)
596 let l = getcompletion('p?', 'sign')
597 call assert_equal(['place'], l)
598 let l = getcompletion('j.', 'sign')
599 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200600 endif
601
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200602 " Command line completion tests
603 let l = getcompletion('cd ', 'cmdline')
604 call assert_true(index(l, 'samples/') >= 0)
605 let l = getcompletion('cd NoMatch', 'cmdline')
606 call assert_equal([], l)
607 let l = getcompletion('let v:n', 'cmdline')
608 call assert_true(index(l, 'v:null') >= 0)
609 let l = getcompletion('let v:notexists', 'cmdline')
610 call assert_equal([], l)
611 let l = getcompletion('call tag', 'cmdline')
612 call assert_true(index(l, 'taglist(') >= 0)
613 let l = getcompletion('call paint', 'cmdline')
614 call assert_equal([], l)
615
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100616 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000617 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100618 return "oneA\noneB\noneC"
619 endfunc
620 command -nargs=1 -complete=custom,T MyCmd
621 let l = getcompletion('MyCmd ', 'cmdline')
622 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000623 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100624
625 delcommand MyCmd
626 delfunc T
ii144785fe02021-11-21 12:13:56 +0000627 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100628
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200629 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200630 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200631 if has('cmdline_hist')
632 call add(names, 'history')
633 endif
634 if has('gettext')
635 call add(names, 'locale')
636 endif
637 if has('profile')
638 call add(names, 'syntime')
639 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200640
641 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100642 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200643
644 for name in names
645 let matchcount = len(getcompletion('', name))
646 call assert_true(matchcount >= 0, 'No matches for ' . name)
647 endfor
648
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200649 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200650
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000651 edit a~b
652 enew
653 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
654 bw a~b
655
656 if has('unix')
657 edit Xtest\
658 enew
659 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
660 bw Xtest\
661 endif
662
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200663 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200664 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100665 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200666endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200667
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000668func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000669 " Get a dialog in the GUI
670 CheckNotGui
671
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000672 " This was using uninitialized memory.
673 let lines =<< trim END
674 set verbose=6
675 norm @=ٷ
676 qall!
677 END
678 call writefile(lines, 'XmultiScript', 'D')
679 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
680endfunc
681
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000682" Test for getcompletion() with "fuzzy" in 'wildoptions'
683func Test_getcompletion_wildoptions()
684 let save_wildoptions = &wildoptions
685 set wildoptions&
686 let l = getcompletion('space', 'option')
687 call assert_equal([], l)
688 let l = getcompletion('ier', 'command')
689 call assert_equal([], l)
690 set wildoptions=fuzzy
691 let l = getcompletion('space', 'option')
692 call assert_true(index(l, 'backspace') >= 0)
693 let l = getcompletion('ier', 'command')
694 call assert_true(index(l, 'compiler') >= 0)
695 let &wildoptions = save_wildoptions
696endfunc
697
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000698func Test_complete_autoload_error()
699 let save_rtp = &rtp
700 let lines =<< trim END
701 vim9script
702 export def Complete(..._): string
703 return 'match'
704 enddef
705 echo this will cause an error
706 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100707 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000708 call writefile(lines, 'Xdir/autoload/script.vim')
709 exe 'set rtp+=' .. getcwd() .. '/Xdir'
710
711 let lines =<< trim END
712 vim9script
713 import autoload 'script.vim'
714 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
715 &wildcharm = char2nr("\<Tab>")
716 feedkeys(":Cmd \<Tab>", 'xt')
717 END
718 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
719
720 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000721endfunc
722
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100723func Test_fullcommand()
724 let tests = {
725 \ '': '',
726 \ ':': '',
727 \ ':::': '',
728 \ ':::5': '',
729 \ 'not_a_cmd': '',
730 \ 'Check': '',
731 \ 'syntax': 'syntax',
732 \ ':syntax': 'syntax',
733 \ '::::syntax': 'syntax',
734 \ 'sy': 'syntax',
735 \ 'syn': 'syntax',
736 \ 'synt': 'syntax',
737 \ ':sy': 'syntax',
738 \ '::::sy': 'syntax',
739 \ 'match': 'match',
740 \ '2match': 'match',
741 \ '3match': 'match',
742 \ 'aboveleft': 'aboveleft',
743 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100744 \ 'en': 'endif',
745 \ 'end': 'endif',
746 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100747 \ 's': 'substitute',
748 \ '5s': 'substitute',
749 \ ':5s': 'substitute',
750 \ "'<,'>s": 'substitute',
751 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100752 \ 'CheckLin': 'CheckLinux',
753 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100754 \ }
755
756 for [in, want] in items(tests)
757 call assert_equal(want, fullcommand(in))
758 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200759 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100760
761 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200762
763 command -buffer BufferLocalCommand :
764 command GlobalCommand :
765 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
766 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
767 delcommand BufferLocalCommand
768 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100769endfunc
770
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200771func Test_shellcmd_completion()
772 let save_path = $PATH
773
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100774 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200775 call writefile([''], 'Xpathdir/Xfile.exe')
776 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
777
778 " Set PATH to example directory without trailing slash.
779 let $PATH = getcwd() . '/Xpathdir'
780
781 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
782 " dirs in the PATH, even though they won't be executed. We check that only
783 " subdirs of the PWD and executables from the PATH are included in the
784 " suggestions.
785 let actual = getcompletion('X', 'shellcmd')
786 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
787 call insert(expected, 'Xfile.exe')
788 call assert_equal(expected, actual)
789
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200790 let $PATH = save_path
791endfunc
792
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200793func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100794 call mkdir('a/b/c', 'pR')
795 call writefile(['asdfasdf'], 'a/b/c/fileXname')
796 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
797 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200798 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200799endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100800
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100801func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100802 let @a = "def"
803 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
804 call assert_equal('"abc def ghi', @:)
805
806 new
807 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
808
809 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
810 call assert_equal('"aaa asdf bbb', @:)
811
812 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
813 call assert_equal('"aaa /tmp/some bbb', @:)
814
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200815 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
816 call assert_equal('"aaa '.getline(1).' bbb', @:)
817
Bram Moolenaar21efc362016-12-03 14:05:49 +0100818 set incsearch
819 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
820 call assert_equal('"aaa verylongword bbb', @:)
821
822 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
823 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100824
825 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
826 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100827 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200828
829 " Error while typing a command used to cause that it was not executed
830 " in the end.
831 new
832 try
833 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
834 catch /^Vim\%((\a\+)\)\=:E32/
835 " ignore error E32
836 endtry
837 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100838
Bram Moolenaar578fe942020-02-27 21:32:51 +0100839 " Try to paste an invalid register using <C-R>
840 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
841 call assert_equal('"onetwo', @:)
842
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100843 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100844 let @a = "xy\<C-H>z"
845 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
846 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100847 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
848 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100849 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
850 call assert_equal("\"xy\<C-H>z", @:)
851
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100852 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
853 let @a = "xy\<C-V>z"
854 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
855 call assert_equal('"xyz', @:)
856 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
857 call assert_equal("\"xy\<C-V>z", @:)
858
Bram Moolenaar578fe942020-02-27 21:32:51 +0100859 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
860
Bram Moolenaar72532d32018-04-07 19:09:09 +0200861 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100862endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100863
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100864func Test_cmdline_remove_char()
865 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100866
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100867 for e in ['utf8', 'latin1']
868 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100869
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100870 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
871 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100872
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100873 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
874 call assert_equal('"abcdef', @:)
875
876 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
877 call assert_equal('"abc ghi', @:, e)
878
879 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
880 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100881
882 " This was going before the start in latin1.
883 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100884 endfor
885
886 let &encoding = encoding_save
887endfunc
888
889func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200890 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100891
892 set keymap=esperanto
893 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
894 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
895 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100896endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100897
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100898func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100899 new
900 2;'(
901 2;')
902 quit
903endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100904
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100905func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100906 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100907 new
908 source Xtest.vim
909 " Trigger calling validate_cursor()
910 diffsp Xtest.vim
911 quit!
912 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100913endfunc
914
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100915func Test_mark_from_line_zero()
916 " this was reading past the end of the first (empty) line
917 new
918 norm oxxxx
919 call assert_fails("0;'(", 'E20:')
920 bwipe!
921endfunc
922
Bram Moolenaarba47b512017-01-24 21:18:19 +0100923func Test_cmdline_complete_wildoptions()
924 help
925 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
926 let a = join(sort(split(@:)),' ')
927 set wildoptions=tagfile
928 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
929 let b = join(sort(split(@:)),' ')
930 call assert_equal(a, b)
931 bw!
932endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100933
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200934func Test_cmdline_complete_user_cmd()
935 command! -complete=color -nargs=1 Foo :
936 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
937 call assert_equal('"Foo blue', @:)
938 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
939 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000940 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
941 call assert_equal('"Foo a blue', @:)
942 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
943 call assert_equal('"Foo b\', @:)
944 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
945 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200946 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100947
948 redraw
949 call assert_equal('~', Screenline(&lines - 1))
950 command! FooOne :
951 command! FooTwo :
952
953 set nowildmenu
954 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
955 call assert_equal('"FooOne', @:)
956 call assert_equal('~', Screenline(&lines - 1))
957
958 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
959 call assert_equal('"FooTwo', @:)
960 call assert_equal('~', Screenline(&lines - 1))
961
962 delcommand FooOne
963 delcommand FooTwo
964 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200965endfunc
966
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100967func Test_complete_user_cmd()
968 command FooBar echo 'global'
969 command -buffer FooBar echo 'local'
970 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
971 call assert_equal('"FooBar', @:)
972
973 delcommand -buffer FooBar
974 delcommand FooBar
975endfunc
976
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100977func s:ScriptLocalFunction()
978 echo 'yes'
979endfunc
980
981func Test_cmdline_complete_user_func()
982 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200983 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100984 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
985 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100986
987 " g: prefix also works
988 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
989 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200990
991 " using g: prefix does not result in just "g:" matches from a lambda
992 let Fx = { a -> a }
993 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
994 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200995
996 " existence of script-local dict function does not break user function name
997 " completion
998 function s:a_dict_func() dict
999 endfunction
1000 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1001 call assert_match('"call Test_cmdline_complete_user_', @:)
1002 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001003endfunc
1004
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001005func Test_cmdline_complete_user_names()
1006 if has('unix') && executable('whoami')
1007 let whoami = systemlist('whoami')[0]
1008 let first_letter = whoami[0]
1009 if len(first_letter) > 0
1010 " Trying completion of :e ~x where x is the first letter of
1011 " the user name should complete to at least the user name.
1012 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1013 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1014 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001015 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001016 " Just in case: check that the system has an Administrator account.
1017 let names = system('net user')
1018 if names =~ 'Administrator'
1019 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001020 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001021 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001022 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001023 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001024 else
1025 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001026 endif
1027endfunc
1028
Bram Moolenaar297610b2019-12-27 17:20:55 +01001029func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001030 CheckExecutable whoami
1031 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1032 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001033endfunc
1034
Bram Moolenaar8b633132020-03-20 18:20:51 +01001035func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001036 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1037 call assert_equal(lang, v:lc_time)
1038
1039 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1040 call assert_equal(lang, v:ctype)
1041
1042 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1043 call assert_equal(lang, v:collate)
1044
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001045 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001046 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001047
1048 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001049 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001050
Bram Moolenaarec680282020-06-12 19:35:32 +02001051 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001052
Bram Moolenaarec680282020-06-12 19:35:32 +02001053 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1054 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001055
Bram Moolenaarec680282020-06-12 19:35:32 +02001056 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1057 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001058
Bram Moolenaarec680282020-06-12 19:35:32 +02001059 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1060 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001061
1062 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1063 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001064endfunc
1065
Bram Moolenaar297610b2019-12-27 17:20:55 +01001066func Test_cmdline_complete_env_variable()
1067 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001068 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1069 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001070 unlet $X_VIM_TEST_COMPLETE_ENV
1071endfunc
1072
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001073func Test_cmdline_complete_expression()
1074 let g:SomeVar = 'blah'
1075 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1076 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1077 call assert_match('"' .. cmd .. ' SomeVar', @:)
1078 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1079 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1080 endfor
1081 unlet g:SomeVar
1082endfunc
1083
Bram Moolenaar47016f52021-08-26 16:39:58 +02001084" Unique function name for completion below
1085func s:WeirdFunc()
1086 echo 'weird'
1087endfunc
1088
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001089" Test for various command-line completion
1090func Test_cmdline_complete_various()
1091 " completion for a command starting with a comment
1092 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1093 call assert_equal("\" :|\"\<C-A>", @:)
1094
1095 " completion for a range followed by a comment
1096 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1097 call assert_equal("\"1,2\"\<C-A>", @:)
1098
1099 " completion for :k command
1100 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1101 call assert_equal("\"ka\<C-A>", @:)
1102
1103 " completion for short version of the :s command
1104 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1105 call assert_equal("\"sI \<C-A>", @:)
1106
1107 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001108 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001109 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001110 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001111 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001112 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1113 call assert_equal("\"w >> Xfile1", @:)
1114 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001115
1116 " completion for :w ! and :r ! commands
1117 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1118 call assert_equal("\"w !invalid_xyz_cmd", @:)
1119 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1120 call assert_equal("\"r !invalid_xyz_cmd", @:)
1121
1122 " completion for :>> and :<< commands
1123 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1124 call assert_equal("\">>>\<C-A>", @:)
1125 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1126 call assert_equal("\"<<<\<C-A>", @:)
1127
1128 " completion for command with +cmd argument
1129 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1130 call assert_equal("\"buffer +/pat Xabc", @:)
1131 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1132 call assert_equal("\"buffer +/pat\<C-A>", @:)
1133
1134 " completion for a command with a trailing comment
1135 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1136 call assert_equal("\"ls \" comment\<C-A>", @:)
1137
1138 " completion for a command with a trailing command
1139 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1140 call assert_equal("\"ls | ls", @:)
1141
1142 " completion for a command with an CTRL-V escaped argument
1143 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1144 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1145
1146 " completion for a command that doesn't take additional arguments
1147 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1148 call assert_equal("\"all abc\<C-A>", @:)
1149
zeertzjqd3de1782022-09-01 12:58:52 +01001150 " completion for :wincmd with :horizontal modifier
1151 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1152 call assert_equal("\"horizontal wincmd", @:)
1153
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001154 " completion for a command with a command modifier
1155 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1156 call assert_equal("\"topleft new", @:)
1157
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001158 " completion for vim9 and legacy commands
1159 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1160 call assert_equal("\"vim9 call strlen(", @:)
1161 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1162 call assert_equal("\"legac call strlen(", @:)
1163
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001164 " completion for the :disassemble command
1165 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1166 call assert_equal("\"disas debug", @:)
1167 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1168 call assert_equal("\"disas profile", @:)
1169 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1170 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1171 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1172 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001173 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1174 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001175
Bram Moolenaar47016f52021-08-26 16:39:58 +02001176 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001177 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001178
naohiro onodfe04db2021-09-12 15:45:10 +02001179 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1180 call assert_match('"disas <SNR>\d\+_', @:)
1181 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1182 call assert_match('"disas debug <SNR>\d\+_', @:)
1183
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001184 " completion for the :match command
1185 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1186 call assert_equal("\"match Search /pat/\<C-A>", @:)
1187
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001188 " completion for the :doautocmd command
1189 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1190 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1191
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001192 " completion of autocmd group after comma
1193 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1194 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1195
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001196 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001197 call writefile([], 'Xvarfile1', 'D')
1198 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001199 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1200 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001201
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001202 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001203 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001204 augroup END
1205 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001206 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001207
1208 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001209 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1210 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001211 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1212 call assert_equal("\"au XTest.test", @:)
1213
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001214 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001215
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001216 " autocmd pattern completion
1217 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1218 call assert_equal("\"au BufEnter *.py\t", @:)
1219
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001220 " completion for the :unlet command
1221 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1222 call assert_equal("\"unlet one two", @:)
1223
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001224 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001225 " FIXME: what should happen on MS-Windows?
1226 if !has('win32')
1227 edit \{someFile}
1228 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1229 call assert_equal("\"buf {someFile}", @:)
1230 bwipe {someFile}
1231 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001232
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001233 " completion for the :bdelete command
1234 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1235 call assert_equal("\"bdel a b c", @:)
1236
1237 " completion for the :mapclear command
1238 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1239 call assert_equal("\"mapclear <buffer>", @:)
1240
1241 " completion for user defined commands with menu names
1242 menu Test.foo :ls<CR>
1243 com -nargs=* -complete=menu MyCmd
1244 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1245 call assert_equal('"MyCmd Test.', @:)
1246 delcom MyCmd
1247 unmenu Test
1248
1249 " completion for user defined commands with mappings
1250 mapclear
1251 map <F3> :ls<CR>
1252 com -nargs=* -complete=mapping MyCmd
1253 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001254 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001255 mapclear
1256 delcom MyCmd
1257
1258 " completion for :set path= with multiple backslashes
1259 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1260 call assert_equal('"set path=a\\\ b', @:)
1261
1262 " completion for :set dir= with a backslash
1263 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1264 call assert_equal('"set dir=a\ b', @:)
1265
1266 " completion for the :py3 commands
1267 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1268 call assert_equal('"py3 py3do py3file', @:)
1269
Bram Moolenaardf749a22021-03-28 15:29:43 +02001270 " completion for the :vim9 commands
1271 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1272 call assert_equal('"vim9cmd vim9script', @:)
1273
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001274 " redir @" is not the start of a comment. So complete after that
1275 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1276 call assert_equal('"redir @" | cwindow', @:)
1277
1278 " completion after a backtick
1279 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1280 call assert_equal('"e `a1b2c', @:)
1281
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001282 " completion for :language command with an invalid argument
1283 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1284 call assert_equal("\"language dummy \t", @:)
1285
1286 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001287 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1288 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001289
1290 " completion with ambiguous user defined commands
1291 com TCmd1 echo 'TCmd1'
1292 com TCmd2 echo 'TCmd2'
1293 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1294 call assert_equal('"TCmd ', @:)
1295 delcom TCmd1
1296 delcom TCmd2
1297
1298 " completion after a range followed by a pipe (|) character
1299 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1300 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001301
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001302 " completion after a :global command
1303 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1304 call assert_equal('"g/a/chistory', @:)
1305 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1306 call assert_equal("\"g/a\\/chist\t", @:)
1307
Bram Moolenaar9c929712020-09-07 22:05:28 +02001308 " use <Esc> as the 'wildchar' for completion
1309 set wildchar=<Esc>
1310 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1311 call assert_equal('"g/a\xb/clearjumps', @:)
1312 " pressing <esc> twice should cancel the command
1313 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1314 call assert_equal('"g/a\xb/clearjumps', @:)
1315 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001316
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001317 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001318 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001319 call writefile([], '~Xtest')
1320 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1321 call assert_equal('"e \~Xtest', @:)
1322 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001323
1324 " should be able to complete a file name that has a '*'
1325 call writefile([], 'Xx*Yy')
1326 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1327 call assert_equal('"e Xx\*Yy', @:)
1328 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001329
1330 " use a literal star
1331 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1332 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001333 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001334
1335 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1336 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001337endfunc
1338
zeertzjq094dd152023-06-15 22:51:57 +01001339" Test that expanding a pattern doesn't interfere with cmdline completion.
1340func Test_expand_during_cmdline_completion()
1341 func ExpandStuff()
1342 badd <script>:p:h/README.*
1343 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1344 $bwipe
1345 call assert_equal('README.txt', expand('README.*'))
1346 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1347 endfunc
1348 augroup test_CmdlineChanged
1349 autocmd!
1350 autocmd CmdlineChanged * call ExpandStuff()
1351 augroup END
1352
1353 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1354 call assert_equal('"sign place', @:)
1355
1356 augroup test_CmdlineChanged
1357 au!
1358 augroup END
1359 augroup! test_CmdlineChanged
1360 delfunc ExpandStuff
1361endfunc
1362
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001363" Test for 'wildignorecase'
1364func Test_cmdline_wildignorecase()
1365 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001366 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001367 set wildignorecase
1368 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1369 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001370 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001371 let g:Sline = ''
1372 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1373 call assert_equal('"e xt', @:)
1374 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001375 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001376endfunc
1377
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001378func Test_cmdline_write_alternatefile()
1379 new
1380 call setline('.', ['one', 'two'])
1381 f foo.txt
1382 new
1383 f #-A
1384 call assert_equal('foo.txt-A', expand('%'))
1385 f #<-B.txt
1386 call assert_equal('foo-B.txt', expand('%'))
1387 f %<
1388 call assert_equal('foo-B', expand('%'))
1389 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001390 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001391 bw!
1392 f foo-B.txt
1393 f %<-A
1394 call assert_equal('foo-B-A', expand('%'))
1395 bw!
1396 bw!
1397endfunc
1398
Bram Moolenaarf5724372022-09-02 19:45:15 +01001399func Test_cmdline_expand_cur_alt_file()
1400 enew
1401 file http://some.com/file.txt
1402 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1403 call assert_equal('"e http://some.com/file.txt', @:)
1404 edit another
1405 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1406 call assert_equal('"e http://some.com/file.txt', @:)
1407 bwipe
1408 bwipe http://some.com/file.txt
1409endfunc
1410
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001411" using a leading backslash here
1412set cpo+=C
1413
1414func Test_cmdline_search_range()
1415 new
1416 call setline(1, ['a', 'b', 'c', 'd'])
1417 /d
1418 1,\/s/b/B/
1419 call assert_equal('B', getline(2))
1420
1421 /a
1422 $
1423 \?,4s/c/C/
1424 call assert_equal('C', getline(3))
1425
1426 call setline(1, ['a', 'b', 'c', 'd'])
1427 %s/c/c/
1428 1,\&s/b/B/
1429 call assert_equal('B', getline(2))
1430
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001431 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001432 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001433
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001434 bwipe!
1435endfunc
1436
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001437" Test for the tick mark (') in an excmd range
1438func Test_tick_mark_in_range()
1439 " If only the tick is passed as a range and no command is specified, there
1440 " should not be an error
1441 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001442 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001443 call assert_fails("',print", 'E78:')
1444endfunc
1445
1446" Test for using a line number followed by a search pattern as range
1447func Test_lnum_and_pattern_as_range()
1448 new
1449 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1450 let @" = ''
1451 2/foo/yank
1452 call assert_equal("foo 3\n", @")
1453 call assert_equal(1, line('.'))
1454 close!
1455endfunc
1456
Bram Moolenaar65189a12017-02-06 22:22:17 +01001457" Tests for getcmdline(), getcmdpos() and getcmdtype()
1458func Check_cmdline(cmdtype)
1459 call assert_equal('MyCmd a', getcmdline())
1460 call assert_equal(8, getcmdpos())
1461 call assert_equal(a:cmdtype, getcmdtype())
1462 return ''
1463endfunc
1464
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001465set cpo&
1466
Bram Moolenaar65189a12017-02-06 22:22:17 +01001467func Test_getcmdtype()
1468 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1469
1470 let cmdtype = ''
1471 debuggreedy
1472 call feedkeys(":debug echo 'test'\<CR>", "t")
1473 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1474 call feedkeys("cont\<CR>", "xt")
1475 0debuggreedy
1476 call assert_equal('>', cmdtype)
1477
1478 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1479 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1480
1481 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001482 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001483
1484 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1485
1486 cnoremap <expr> <F6> Check_cmdline('=')
1487 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1488 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001489
1490 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001491endfunc
1492
Bram Moolenaar52604f22017-04-07 16:17:39 +02001493func Test_verbosefile()
1494 set verbosefile=Xlog
1495 echomsg 'foo'
1496 echomsg 'bar'
1497 set verbosefile=
1498 let log = readfile('Xlog')
1499 call assert_match("foo\nbar", join(log, "\n"))
1500 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001501
1502 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001503 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001504endfunc
1505
Bram Moolenaar4facea32019-10-12 20:17:40 +02001506func Test_verbose_option()
1507 CheckScreendump
1508
1509 let lines =<< trim [SCRIPT]
1510 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1511 call feedkeys("\r", 't') " for the hit-enter prompt
1512 set verbose=20
1513 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001514 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001515
1516 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001517 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001518 call term_sendkeys(buf, ":DoSomething\<CR>")
1519 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1520
1521 " clean up
1522 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001523endfunc
1524
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001525func Test_setcmdpos()
1526 func InsertTextAtPos(text, pos)
1527 call assert_equal(0, setcmdpos(a:pos))
1528 return a:text
1529 endfunc
1530
1531 " setcmdpos() with position in the middle of the command line.
1532 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1533 call assert_equal('"1ab2', @:)
1534
1535 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1536 call assert_equal('"1b2a', @:)
1537
1538 " setcmdpos() with position beyond the end of the command line.
1539 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1540 call assert_equal('"12ab', @:)
1541
1542 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001543 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001544endfunc
1545
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001546func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001547 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001548 let encoding_save = &encoding
1549
1550 for e in encodings
1551 exe 'set encoding=' . e
1552
1553 " Test overstrike in the middle of the command line.
1554 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001555 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001556
1557 " Test overstrike going beyond end of command line.
1558 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001559 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001560
1561 " Test toggling insert/overstrike a few times.
1562 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001563 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001564 endfor
1565
Bram Moolenaar30276f22019-01-24 17:59:39 +01001566 " Test overstrike with multi-byte characters.
1567 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001568 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001569
1570 let &encoding = encoding_save
1571endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001572
Bram Moolenaar52410572019-10-27 05:12:45 +01001573func Test_buffers_lastused()
1574 " check that buffers are sorted by time when wildmode has lastused
1575 call test_settime(1550020000) " middle
1576 edit bufa
1577 enew
1578 call test_settime(1550030000) " newest
1579 edit bufb
1580 enew
1581 call test_settime(1550010000) " oldest
1582 edit bufc
1583 enew
1584 call test_settime(0)
1585 enew
1586
1587 call assert_equal(['bufa', 'bufb', 'bufc'],
1588 \ getcompletion('', 'buffer'))
1589
1590 let save_wildmode = &wildmode
1591 set wildmode=full:lastused
1592
1593 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1594 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1595 call assert_equal('b bufb', X)
1596 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1597 call assert_equal('b bufa', X)
1598 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1599 call assert_equal('b bufc', X)
1600 enew
1601
1602 edit other
1603 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1604 call assert_equal('b bufb', X)
1605 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1606 call assert_equal('b bufa', X)
1607 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1608 call assert_equal('b bufc', X)
1609 enew
1610
1611 let &wildmode = save_wildmode
1612
1613 bwipeout bufa
1614 bwipeout bufb
1615 bwipeout bufc
1616endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001617
Bram Moolenaar479950f2020-01-19 15:45:17 +01001618func Test_cmdlineclear_tabenter()
1619 CheckScreendump
1620
1621 let lines =<< trim [SCRIPT]
1622 call setline(1, range(30))
1623 [SCRIPT]
1624
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001625 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001626 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001627 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001628 " in one tab make the command line higher with CTRL-W -
1629 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1630 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1631
1632 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001633endfunc
1634
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001635" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001636func Test_cmdline_expand_special()
1637 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001638 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001639 call assert_fails('e <afile>', 'E495:')
1640 call assert_fails('e <abuf>', 'E496:')
1641 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001642
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001643 call writefile([], 'Xfile.cpp', 'D')
1644 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001645 new Xfile.cpp
1646 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1647 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1648 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001649endfunc
1650
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001651" Test for backtick expression in the command line
1652func Test_cmd_backtick()
1653 %argd
1654 argadd `=['a', 'b', 'c']`
1655 call assert_equal(['a', 'b', 'c'], argv())
1656 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001657
1658 argadd `echo abc def`
1659 call assert_equal(['abc def'], argv())
1660 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001661endfunc
1662
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001663" Test for the :! command
1664func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001665 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001666
1667 let lines =<< trim [SCRIPT]
1668 " Test for no previous command
1669 call assert_fails('!!', 'E34:')
1670 set nomore
1671 " Test for cmdline expansion with :!
1672 call setline(1, 'foo!')
1673 silent !echo <cWORD> > Xfile.out
1674 call assert_equal(['foo!'], readfile('Xfile.out'))
1675 " Test for using previous command
1676 silent !echo \! !
1677 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1678 call writefile(v:errors, 'Xresult')
1679 call delete('Xfile.out')
1680 qall!
1681 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001682 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001683 if RunVim([], [], '--clean -S Xscript')
1684 call assert_equal([], readfile('Xresult'))
1685 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001686 call delete('Xresult')
1687endfunc
1688
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001689" Test error: "E135: *Filter* Autocommands must not change current buffer"
1690func Test_cmd_bang_E135()
1691 new
1692 call setline(1, ['a', 'b', 'c', 'd'])
1693 augroup test_cmd_filter_E135
1694 au!
1695 autocmd FilterReadPost * help
1696 augroup END
1697 call assert_fails('2,3!echo "x"', 'E135:')
1698
1699 augroup test_cmd_filter_E135
1700 au!
1701 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01001702 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001703 %bwipe!
1704endfunc
1705
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001706func Test_cmd_bang_args()
1707 new
1708 :.!
1709 call assert_equal(0, v:shell_error)
1710
1711 " Note that below there is one space char after the '!'. This caused a
1712 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1713 :.!
1714 call assert_equal(0, v:shell_error)
1715 bwipe!
1716
1717 CheckUnix
1718 :.!pwd
1719 call assert_equal(0, v:shell_error)
1720 :.! pwd
1721 call assert_equal(0, v:shell_error)
1722
1723 " Note there is one space after 'pwd'.
1724 :.! pwd
1725 call assert_equal(0, v:shell_error)
1726
1727 " Note there are two spaces after 'pwd'.
1728 :.! pwd
1729 call assert_equal(0, v:shell_error)
1730 :.!ls ~
1731 call assert_equal(0, v:shell_error)
1732
1733 " Note there is one space char after '~'.
1734 :.!ls ~
1735 call assert_equal(0, v:shell_error)
1736
1737 " Note there are two spaces after '~'.
1738 :.!ls ~
1739 call assert_equal(0, v:shell_error)
1740
1741 :.!echo "foo"
1742 call assert_equal(getline('.'), "foo")
1743 :.!echo "foo "
1744 call assert_equal(getline('.'), "foo ")
1745 :.!echo " foo "
1746 call assert_equal(getline('.'), " foo ")
1747 :.!echo " foo "
1748 call assert_equal(getline('.'), " foo ")
1749
1750 %bwipe!
1751endfunc
1752
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001753" Test for using ~ for home directory in cmdline completion matches
1754func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001755 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001756 call writefile([], 'Xexpdir/Xfile1')
1757 call writefile([], 'Xexpdir/Xfile2')
1758 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001759 let save_HOME = $HOME
1760 let $HOME = getcwd()
1761 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1762 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1763 let $HOME = save_HOME
1764 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001765endfunc
1766
Bram Moolenaar578fe942020-02-27 21:32:51 +01001767" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1768" or insert mode (when 'insertmode' is set)
1769func Test_cmdline_ctrl_g()
1770 new
1771 call setline(1, 'abc')
1772 call cursor(1, 3)
1773 " If command line is entered from insert mode, using C-\ C-G should back to
1774 " insert mode
1775 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1776 call assert_equal('abxyc', getline(1))
1777 call assert_equal(4, col('.'))
1778
1779 " If command line is entered in 'insertmode', using C-\ C-G should back to
1780 " 'insertmode'
1781 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1782 call assert_equal('ab12xyc', getline(1))
1783 close!
1784endfunc
1785
Bram Moolenaar578fe942020-02-27 21:32:51 +01001786" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001787func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001788 func T(a, c, p)
1789 return "oneA\noneB\noneC"
1790 endfunc
1791 command -nargs=1 -complete=custom,T MyCmd
1792
Bram Moolenaar578fe942020-02-27 21:32:51 +01001793 set nowildmenu
1794 set wildmode=full,list
1795 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001796 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001797 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001798 call assert_equal('"MyCmd oneA', @:)
1799
1800 set wildmode=longest,full
1801 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1802 call assert_equal('"MyCmd one', @:)
1803 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1804 call assert_equal('"MyCmd oneC', @:)
1805
1806 set wildmode=longest
1807 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1808 call assert_equal('"MyCmd one', @:)
1809
1810 set wildmode=list:longest
1811 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001812 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001813 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001814 call assert_equal('"MyCmd one', @:)
1815
1816 set wildmode=""
1817 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1818 call assert_equal('"MyCmd oneA', @:)
1819
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001820 " Test for wildmode=longest with 'fileignorecase' set
1821 set wildmode=longest
1822 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001823 argadd AAA AAAA AAAAA
1824 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1825 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001826 set fileignorecase&
1827
1828 " Test for listing files with wildmode=list
1829 set wildmode=list
1830 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001831 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001832 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001833 call assert_equal('"b A', @:)
1834
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001835 " when using longest completion match, matches shorter than the argument
1836 " should be ignored (happens with :help)
1837 set wildmode=longest,full
1838 set wildmenu
1839 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1840 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001841 " non existing file
1842 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1843 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001844 set wildmenu&
1845
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001846 " Test for longest file name completion with 'fileignorecase'
1847 " On MS-Windows, file names are case insensitive.
1848 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001849 call writefile([], 'XTESTfoo', 'D')
1850 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001851 set nofileignorecase
1852 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1853 call assert_equal('"e XTESTfoo', @:)
1854 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1855 call assert_equal('"e Xtestbar', @:)
1856 set fileignorecase
1857 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1858 call assert_equal('"e Xtest', @:)
1859 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1860 call assert_equal('"e Xtest', @:)
1861 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001862 endif
1863
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001864 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001865 delcommand MyCmd
1866 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001867 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001868 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001869endfunc
1870
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001871func Test_wildmode()
1872 " Test with utf-8 encoding
1873 call Wildmode_tests()
1874
1875 " Test with latin1 encoding
1876 let save_encoding = &encoding
1877 set encoding=latin1
1878 call Wildmode_tests()
1879 let &encoding = save_encoding
1880endfunc
1881
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001882func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001883 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001884 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001885 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001886 let lines =<< trim END
1887 func vim8#Complete(a, c, p)
1888 return "oneA\noneB\noneC"
1889 endfunc
1890 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001891 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001892
1893 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1894 set nowildmenu
1895 set wildmode=full,list
1896 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1897 call assert_equal('"MyCmd oneA oneB oneC', @:)
1898
1899 let &rtp = save_rtp
1900 set wildmode& wildmenu&
1901 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001902endfunc
1903
Bram Moolenaar578fe942020-02-27 21:32:51 +01001904" Test for interrupting the command-line completion
1905func Test_interrupt_compl()
1906 func F(lead, cmdl, p)
1907 if a:lead =~ 'tw'
1908 call interrupt()
1909 return
1910 endif
1911 return "one\ntwo\nthree"
1912 endfunc
1913 command -nargs=1 -complete=custom,F Tcmd
1914
1915 set nowildmenu
1916 set wildmode=full
1917 let interrupted = 0
1918 try
1919 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1920 catch /^Vim:Interrupt$/
1921 let interrupted = 1
1922 endtry
1923 call assert_equal(1, interrupted)
1924
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001925 let interrupted = 0
1926 try
1927 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1928 catch /^Vim:Interrupt$/
1929 let interrupted = 1
1930 endtry
1931 call assert_equal(1, interrupted)
1932
Bram Moolenaar578fe942020-02-27 21:32:51 +01001933 delcommand Tcmd
1934 delfunc F
1935 set wildmode&
1936endfunc
1937
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001938" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001939func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001940 let str = ":one two\<C-U>"
1941 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001942 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001943 let str ..= "\<Left>five\<Right>"
1944 let str ..= "\<Home>two "
1945 let str ..= "\<C-Left>one "
1946 let str ..= "\<C-Right> three"
1947 let str ..= "\<End>\<S-Left>four "
1948 let str ..= "\<S-Right> six"
1949 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1950 call feedkeys(str, 'xt')
1951 call assert_equal("\"one two three four five six seven", @:)
1952endfunc
1953
1954" Test for moving the cursor on the / command line in 'rightleft' mode
1955func Test_cmdline_edit_rightleft()
1956 CheckFeature rightleft
1957 set rightleft
1958 set rightleftcmd=search
1959 let str = "/one two\<C-U>"
1960 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001961 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001962 let str ..= "\<Right>five\<Left>"
1963 let str ..= "\<Home>two "
1964 let str ..= "\<C-Right>one "
1965 let str ..= "\<C-Left> three"
1966 let str ..= "\<End>\<S-Right>four "
1967 let str ..= "\<S-Left> six"
1968 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1969 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1970 call assert_equal("\"one two three four five six seven", @/)
1971 set rightleftcmd&
1972 set rightleft&
1973endfunc
1974
1975" Test for using <C-\>e in the command line to evaluate an expression
1976func Test_cmdline_expr()
1977 " Evaluate an expression from the beginning of a command line
1978 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1979 call assert_equal('"hello', @:)
1980
1981 " Use an invalid expression for <C-\>e
1982 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1983
1984 " Insert literal <CTRL-\> in the command line
1985 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1986 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001987endfunc
1988
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001989" This was making the insert position negative
1990func Test_cmdline_expr_register()
1991 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1992endfunc
1993
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001994" Test for 'imcmdline' and 'imsearch'
1995" This test doesn't actually test the input method functionality.
1996func Test_cmdline_inputmethod()
1997 new
1998 call setline(1, ['', 'abc', ''])
1999 set imcmdline
2000
2001 call feedkeys(":\"abc\<CR>", 'xt')
2002 call assert_equal("\"abc", @:)
2003 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2004 call assert_equal("\"abc", @:)
2005 call feedkeys("/abc\<CR>", 'xt')
2006 call assert_equal([2, 1], [line('.'), col('.')])
2007 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2008 call assert_equal([2, 1], [line('.'), col('.')])
2009
2010 set imsearch=2
2011 call cursor(1, 1)
2012 call feedkeys("/abc\<CR>", 'xt')
2013 call assert_equal([2, 1], [line('.'), col('.')])
2014 call cursor(1, 1)
2015 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2016 call assert_equal([2, 1], [line('.'), col('.')])
2017 set imdisable
2018 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2019 call assert_equal([2, 1], [line('.'), col('.')])
2020 set imdisable&
2021 set imsearch&
2022
2023 set imcmdline&
2024 %bwipe!
2025endfunc
2026
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002027" Test for using CTRL-_ in the command line with 'allowrevins'
2028func Test_cmdline_revins()
2029 CheckNotMSWindows
2030 CheckFeature rightleft
2031 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2032 call assert_equal("\"abc\<c-_>", @:)
2033 set allowrevins
2034 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2035 call assert_equal('"abcñèæ', @:)
2036 set allowrevins&
2037endfunc
2038
2039" Test for typing UTF-8 composing characters in the command line
2040func Test_cmdline_composing_chars()
2041 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2042 call assert_equal('"ゔ', @:)
2043endfunc
2044
Bram Moolenaar0e717042020-04-27 19:29:01 +02002045" test that ";" works to find a match at the start of the first line
2046func Test_zero_line_search()
2047 new
2048 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2049 call cursor(1,1)
2050 0;/pattern/d
2051 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2052 q!
2053endfunc
2054
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002055func Test_read_shellcmd()
2056 CheckUnix
2057 if executable('ls')
2058 " There should be ls in the $PATH
2059 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2060 call assert_match('^"r! .*\<ls\>', @:)
2061 endif
2062
2063 if executable('rm')
2064 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2065 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2066 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002067
2068 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2069 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2070 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002071 endif
2072endfunc
2073
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002074" Test for going up and down the directory tree using 'wildmenu'
2075func Test_wildmenu_dirstack()
2076 CheckUnix
2077 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002078 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002079 call writefile([], 'Xwildmenu/file1_1.txt')
2080 call writefile([], 'Xwildmenu/file1_2.txt')
2081 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2082 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2083 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2084 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2085 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2086 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002087 set wildmenu
2088
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002089 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002090 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002091 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002092 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002093 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002094 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002095 call assert_equal('"e ../../dir3/', @:)
2096 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2097 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002098 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002099 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002100 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002101 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002102 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002103 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2104 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002105
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002106 set wildmenu&
2107endfunc
2108
obcat71c6f7a2021-05-13 20:23:10 +02002109" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002110" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2111" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002112func Test_recalling_cmdline()
2113 CheckFeature cmdline_hist
2114
2115 let g:cmdlines = []
2116 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2117
2118 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002119 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2120 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2121 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2122 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002123 "\ TODO: {'name': 'debug', ...}
2124 \]
2125 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002126 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2127 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2128 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2129 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2130 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002131 \]
2132 let prefix = 'vi'
2133 for h in histories
2134 call histadd(h.name, 'vim')
2135 call histadd(h.name, 'virtue')
2136 call histadd(h.name, 'Virgo')
2137 call histadd(h.name, 'vogue')
2138 call histadd(h.name, 'emacs')
2139 for k in keypairs
2140 let g:cmdlines = []
2141 let keyseqs = h.enter
2142 \ .. prefix
2143 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2144 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2145 \ .. h.exit
2146 call feedkeys(keyseqs, 'xt')
2147 call histdel(h.name, -1) " delete the history added by feedkeys above
2148 let expect = k.prefixmatch
2149 \ ? ['virtue', 'vim', 'virtue', prefix]
2150 \ : ['emacs', 'vogue', 'emacs', prefix]
2151 call assert_equal(expect, g:cmdlines)
2152 endfor
2153 endfor
2154
2155 unlet g:cmdlines
2156 cunmap <Plug>(save-cmdline)
2157endfunc
2158
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002159func Test_cmd_map_cmdlineChanged()
2160 let g:log = []
2161 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002162 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002163 autocmd!
2164 autocmd CmdlineChanged : let g:log += [getcmdline()]
2165 augroup END
2166
2167 call feedkeys(":\<F1>\<CR>", 'xt')
2168 call assert_equal(['l', 'ls'], g:log)
2169
Bram Moolenaar796139a2021-05-18 21:38:45 +02002170 let @b = 'b'
2171 cnoremap <F1> a<C-R>b
2172 let g:log = []
2173 call feedkeys(":\<F1>\<CR>", 'xt')
2174 call assert_equal(['a', 'ab'], g:log)
2175
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002176 unlet g:log
2177 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002178 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002179 autocmd!
2180 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002181 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002182endfunc
2183
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002184" Test for the 'suffixes' option
2185func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002186 call writefile([], 'Xsuffile', 'D')
2187 call writefile([], 'Xsuffile.c', 'D')
2188 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002189 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002190 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2191 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2192 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2193 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002194 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002195 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2196 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2197 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2198 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002199 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002200 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2201 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2202 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2203 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002204 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002205 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002206 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2207 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002208endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002209
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002210" Test for using a popup menu for the command line completion matches
2211" (wildoptions=pum)
2212func Test_wildmenu_pum()
2213 CheckRunVimInTerminal
2214
2215 let commands =<< trim [CODE]
2216 set wildmenu
2217 set wildoptions=pum
2218 set shm+=I
2219 set noruler
2220 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002221
2222 func CmdCompl(a, b, c)
2223 return repeat(['aaaa'], 120)
2224 endfunc
2225 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002226
2227 func MyStatusLine() abort
2228 return 'status'
2229 endfunc
2230 func SetupStatusline()
2231 set statusline=%!MyStatusLine()
2232 set laststatus=2
2233 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002234
2235 func MyTabLine()
2236 return 'my tab line'
2237 endfunc
2238 func SetupTabline()
2239 set statusline=
2240 set tabline=%!MyTabLine()
2241 set showtabline=2
2242 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002243
2244 func DoFeedKeys()
2245 let &wildcharm = char2nr("\t")
2246 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2247 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002248 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002249 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002250
2251 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2252
2253 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002254 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2255
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002256 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002257 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002258 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2259
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002260 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002261 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002262 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2263
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002264 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002265 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002266 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2267
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002268 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002269 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002270 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2271
2272 " pressing <C-E> should end completion and go back to the original match
2273 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002274 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2275
2276 " pressing <C-Y> should select the current match and end completion
2277 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002278 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2279
2280 " With 'wildmode' set to 'longest,full', completing a match should display
2281 " the longest match, the wildmenu should not be displayed.
2282 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2283 call TermWait(buf)
2284 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002285 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2286
2287 " pressing <Tab> should display the wildmenu
2288 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002289 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2290
2291 " pressing <Tab> second time should select the next entry in the menu
2292 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002293 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2294
2295 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002296 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002297 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002298 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2299
2300 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002301 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2302
2303 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002304 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2305
2306 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002307 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002308 call writefile([], 'Xnamedir/XfileA')
2309 call writefile([], 'Xnamedir/XdirA/XfileB')
2310 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002311
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002312 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002313 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2314
2315 " Pressing <Right> on a directory name should go into that directory
2316 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002317 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2318
2319 " Pressing <Left> on a directory name should go to the parent directory
2320 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002321 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2322
2323 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002324 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002325 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002326 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2327
2328 " Pressing <C-D> when the popup menu is displayed should remove the popup
2329 " menu
2330 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002331 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2332
2333 " Pressing <S-Tab> should open the popup menu with the last entry selected
2334 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002335 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2336
2337 " Pressing <Esc> should close the popup menu and cancel the cmd line
2338 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002339 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2340
2341 " Typing a character when the popup is open, should close the popup
2342 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002343 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2344
2345 " When the popup is open, entering the cmdline window should close the popup
2346 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002347 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2348 call term_sendkeys(buf, ":q\<CR>")
2349
2350 " After the last popup menu item, <C-N> should show the original string
2351 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002352 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2353
2354 " Use the popup menu for the command name
2355 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002356 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2357
2358 " Pressing the left arrow should remove the popup menu
2359 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002360 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2361
2362 " Pressing <BS> should remove the popup menu and erase the last character
2363 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002364 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2365
2366 " Pressing <C-W> should remove the popup menu and erase the previous word
2367 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002368 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2369
2370 " Pressing <C-U> should remove the popup menu and erase the entire line
2371 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002372 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2373
2374 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2375 " the cmdline from history
2376 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002377 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2378
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002379 " Check "list" still works
2380 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2381 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002382 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2383 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002384 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2385
rbtnn68cc2b82022-02-09 11:55:47 +00002386 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002387 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002388 call writefile([], 'Xnamedir/あいう/abc')
2389 call writefile([], 'Xnamedir/あいう/xyz')
2390 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002391
2392 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002393 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002394 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2395
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002396 " Pressing <C-A> when the popup menu is displayed should list all the
2397 " matches and pressing a key after that should remove the popup menu
2398 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2399 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2400 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2401
2402 " Pressing <C-A> when the popup menu is displayed should list all the
2403 " matches and pressing <Left> after that should move the cursor
2404 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2405 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2406 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2407
2408 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2409 " should be displayed correctly on the screen.
2410 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2411 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2412
2413 " After using <C-A> to expand all the filename matches, pressing <Up>
2414 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002415 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002416 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2417 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2418 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2419
2420 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2421 " crash Vim
2422 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2423 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2424
Bram Moolenaar414acd32022-02-10 21:09:45 +00002425 " After removing the pum the command line is redrawn
2426 call term_sendkeys(buf, ":edit foo\<CR>")
2427 call term_sendkeys(buf, ":edit bar\<CR>")
2428 call term_sendkeys(buf, ":ls\<CR>")
2429 call term_sendkeys(buf, ":com\<Tab> ")
2430 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002431 call term_sendkeys(buf, "\<C-U>\<CR>")
2432
2433 " Esc still works to abort the command when 'statusline' is set
2434 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2435 call term_sendkeys(buf, ":si\<Tab>")
2436 call term_sendkeys(buf, "\<Esc>")
2437 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002438
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002439 " Esc still works to abort the command when 'tabline' is set
2440 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2441 call term_sendkeys(buf, ":si\<Tab>")
2442 call term_sendkeys(buf, "\<Esc>")
2443 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2444
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002445 " popup is cleared also when 'lazyredraw' is set
2446 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2447 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2448 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2449 call term_sendkeys(buf, "\<Esc>")
2450
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002451 " Pressing <PageDown> should scroll the menu downward
2452 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2453 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2454 call term_sendkeys(buf, "\<PageDown>")
2455 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2456 call term_sendkeys(buf, "\<PageDown>")
2457 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2458 call term_sendkeys(buf, "\<PageDown>")
2459 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2460 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2461 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2462
2463 " Pressing <PageUp> should scroll the menu upward
2464 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2465 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2466 call term_sendkeys(buf, "\<PageUp>")
2467 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2468 call term_sendkeys(buf, "\<PageUp>")
2469 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2470 call term_sendkeys(buf, "\<PageUp>")
2471 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2472
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002473 call term_sendkeys(buf, "\<C-U>\<CR>")
2474 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002475endfunc
2476
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002477" Test for wildmenumode() with the cmdline popup menu
2478func Test_wildmenumode_with_pum()
2479 set wildmenu
2480 set wildoptions=pum
2481 cnoremap <expr> <F2> wildmenumode()
2482 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2483 call assert_equal('"sign define10', @:)
2484 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2485 call assert_equal('"sign define jump list place undefine unplace0', @:)
2486 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2487 call assert_equal('"sign 0', @:)
2488 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2489 call assert_equal('"sign define0', @:)
2490 set nowildmenu wildoptions&
2491 cunmap <F2>
2492endfunc
2493
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002494func Test_wildmenu_with_pum_foldexpr()
2495 CheckRunVimInTerminal
2496
2497 let lines =<< trim END
2498 call setline(1, ['folded one', 'folded two', 'some more text'])
2499 func MyFoldText()
2500 return 'foo'
2501 endfunc
2502 set foldtext=MyFoldText() wildoptions=pum
2503 normal ggzfj
2504 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002505 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002506 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2507 call term_sendkeys(buf, ":set\<Tab>")
2508 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2509
2510 call term_sendkeys(buf, "\<Esc>")
2511 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2512
2513 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002514endfunc
2515
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002516" Test for opening the cmdline completion popup menu from the terminal window.
2517" The popup menu should be positioned correctly over the status line of the
2518" bottom-most window.
2519func Test_wildmenu_pum_from_terminal()
2520 CheckRunVimInTerminal
2521 let python = PythonProg()
2522 call CheckPython(python)
2523
2524 %bw!
2525 let cmds = ['set wildmenu wildoptions=pum']
2526 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2527 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002528 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002529 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2530 call term_sendkeys(buf, "\r\r\r")
2531 call term_wait(buf)
2532 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2533 call term_wait(buf)
2534 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2535 call term_wait(buf)
2536 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002537endfunc
2538
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002539func Test_wildmenu_pum_clear_entries()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002540 CheckRunVimInTerminal
2541
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002542 " This was using freed memory. Run in a terminal to get the pum to update.
2543 let lines =<< trim END
2544 set wildoptions=pum
2545 set wildchar=<C-E>
2546 END
2547 call writefile(lines, 'XwildmenuTest', 'D')
2548 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2549
2550 call term_sendkeys(buf, ":\<C-E>\<C-E>")
2551 call VerifyScreenDump(buf, 'Test_wildmenu_pum_clear_entries_1', {})
2552
2553 set wildoptions& wildchar&
2554endfunc
2555
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002556" Test for completion after a :substitute command followed by a pipe (|)
2557" character
2558func Test_cmdline_complete_substitute()
2559 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2560 call assert_equal("\"s | \t", @:)
2561 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2562 call assert_equal("\"s/ | \t", @:)
2563 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2564 call assert_equal("\"s/one | \t", @:)
2565 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2566 call assert_equal("\"s/one/ | \t", @:)
2567 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2568 call assert_equal("\"s/one/two | \t", @:)
2569 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2570 call assert_equal('"s/one/two/ | chistory', @:)
2571 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2572 call assert_equal("\"s/one/two/g \t", @:)
2573 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2574 call assert_equal("\"s/one/two/g | chistory", @:)
2575 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2576 call assert_equal("\"s/one/t\\/ | \t", @:)
2577 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2578 call assert_equal('"s/one/t"o/ | chistory', @:)
2579 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2580 call assert_equal('"s/one/t|o/ | chistory', @:)
2581 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2582 call assert_equal("\"&\t", @:)
2583endfunc
2584
2585" Test for the :dlist command completion
2586func Test_cmdline_complete_dlist()
2587 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2588 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2589 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2590 call assert_equal("\"dlist 10 /pat/ \t", @:)
2591 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2592 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2593 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2594 call assert_equal("\"dlist 10 /pat\\\t", @:)
2595 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2596 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2597endfunc
2598
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002599" argument list (only for :argdel) fuzzy completion
2600func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002601 argadd change.py count.py charge.py
2602 set wildoptions&
2603 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2604 call assert_equal('"argdel cge', @:)
2605 set wildoptions=fuzzy
2606 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2607 call assert_equal('"argdel change.py charge.py', @:)
2608 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002609 set wildoptions&
2610endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002611
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002612" autocmd group name fuzzy completion
2613func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002614 set wildoptions&
2615 augroup MyFuzzyGroup
2616 augroup END
2617 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2618 call assert_equal('"augroup mfg', @:)
2619 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2620 call assert_equal('"augroup MyFuzzyGroup', @:)
2621 set wildoptions=fuzzy
2622 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2623 call assert_equal('"augroup MyFuzzyGroup', @:)
2624 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2625 call assert_equal('"augroup My*p', @:)
2626 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002627 set wildoptions&
2628endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002629
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002630" buffer name fuzzy completion
2631func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002632 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002633 " Use a long name to reduce the risk of matching a random directory name
2634 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002635 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002636 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2637 call assert_equal('"b SRFWL', @:)
2638 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2639 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002640 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002641 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2642 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2643 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2644 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002645 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002646 set wildoptions&
2647endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002648
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002649" buffer name (full path) fuzzy completion
2650func Test_fuzzy_completion_bufname_fullpath()
2651 CheckUnix
2652 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002653 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002654 edit Xcmd/Xstate/Xfile.js
2655 cd Xcmd/Xstate
2656 enew
2657 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2658 call assert_equal('"b CmdStateFile', @:)
2659 set wildoptions=fuzzy
2660 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2661 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2662 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002663 set wildoptions&
2664endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002665
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002666" :behave suboptions fuzzy completion
2667func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002668 set wildoptions&
2669 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2670 call assert_equal('"behave xm', @:)
2671 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2672 call assert_equal('"behave xterm', @:)
2673 set wildoptions=fuzzy
2674 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2675 call assert_equal('"behave xterm', @:)
2676 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2677 call assert_equal('"behave xt*m', @:)
2678 let g:Sline = ''
2679 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2680 call assert_equal('mswin', g:Sline)
2681 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002682 set wildoptions&
2683endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002684
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002685" " colorscheme name fuzzy completion - NOT supported
2686" func Test_fuzzy_completion_colorscheme()
2687" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002688
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002689" built-in command name fuzzy completion
2690func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002691 set wildoptions&
2692 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2693 call assert_equal('"sbwin', @:)
2694 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2695 call assert_equal('"sbrewind', @:)
2696 set wildoptions=fuzzy
2697 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2698 call assert_equal('"sbrewind', @:)
2699 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2700 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002701 set wildoptions&
2702endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002703
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002704" " compiler name fuzzy completion - NOT supported
2705" func Test_fuzzy_completion_compiler()
2706" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002707
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002708" :cscope suboptions fuzzy completion
2709func Test_fuzzy_completion_cscope()
2710 CheckFeature cscope
2711 set wildoptions&
2712 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2713 call assert_equal('"cscope ret', @:)
2714 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2715 call assert_equal('"cscope reset', @:)
2716 set wildoptions=fuzzy
2717 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2718 call assert_equal('"cscope reset', @:)
2719 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2720 call assert_equal('"cscope re*t', @:)
2721 set wildoptions&
2722endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002723
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002724" :diffget/:diffput buffer name fuzzy completion
2725func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002726 new SomeBuffer
2727 diffthis
2728 new OtherBuffer
2729 diffthis
2730 set wildoptions&
2731 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2732 call assert_equal('"diffget sbuf', @:)
2733 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2734 call assert_equal('"diffput sbuf', @:)
2735 set wildoptions=fuzzy
2736 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2737 call assert_equal('"diffget SomeBuffer', @:)
2738 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2739 call assert_equal('"diffput SomeBuffer', @:)
2740 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002741 set wildoptions&
2742endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002743
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002744" " directory name fuzzy completion - NOT supported
2745" func Test_fuzzy_completion_dirname()
2746" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002747
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002748" environment variable name fuzzy completion
2749func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002750 set wildoptions&
2751 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2752 call assert_equal('"echo $VUT', @:)
2753 set wildoptions=fuzzy
2754 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2755 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002756 set wildoptions&
2757endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002758
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002759" autocmd event fuzzy completion
2760func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002761 set wildoptions&
2762 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2763 call assert_equal('"autocmd BWout', @:)
2764 set wildoptions=fuzzy
2765 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2766 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002767 set wildoptions&
2768endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002769
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002770" vim expression fuzzy completion
2771func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002772 let g:PerPlaceCount = 10
2773 set wildoptions&
2774 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2775 call assert_equal('"let c = ppc', @:)
2776 set wildoptions=fuzzy
2777 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2778 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002779 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002780endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002781
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002782" " file name fuzzy completion - NOT supported
2783" func Test_fuzzy_completion_filename()
2784" endfunc
2785
2786" " files in path fuzzy completion - NOT supported
2787" func Test_fuzzy_completion_filesinpath()
2788" endfunc
2789
2790" " filetype name fuzzy completion - NOT supported
2791" func Test_fuzzy_completion_filetype()
2792" endfunc
2793
2794" user defined function name completion
2795func Test_fuzzy_completion_userdefined_func()
2796 set wildoptions&
2797 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2798 call assert_equal('"call Test_f_u_f', @:)
2799 set wildoptions=fuzzy
2800 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2801 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2802 set wildoptions&
2803endfunc
2804
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002805" <SNR> functions should be sorted to the end
2806func Test_fuzzy_completion_userdefined_snr_func()
2807 func s:Sendmail()
2808 endfunc
2809 func SendSomemail()
2810 endfunc
2811 func S1e2n3dmail()
2812 endfunc
2813 set wildoptions=fuzzy
2814 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002815 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002816 set wildoptions&
2817 delfunc s:Sendmail
2818 delfunc SendSomemail
2819 delfunc S1e2n3dmail
2820endfunc
2821
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002822" user defined command name completion
2823func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002824 set wildoptions&
2825 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2826 call assert_equal('"MsFeat', @:)
2827 set wildoptions=fuzzy
2828 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2829 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002830 set wildoptions&
2831endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002832
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002833" " :help tag fuzzy completion - NOT supported
2834" func Test_fuzzy_completion_helptag()
2835" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002836
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002837" highlight group name fuzzy completion
2838func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002839 set wildoptions&
2840 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2841 call assert_equal('"highlight SKey', @:)
2842 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2843 call assert_equal('"highlight SpecialKey', @:)
2844 set wildoptions=fuzzy
2845 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2846 call assert_equal('"highlight SpecialKey', @:)
2847 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2848 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002849 set wildoptions&
2850endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002851
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002852" :history suboptions fuzzy completion
2853func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002854 set wildoptions&
2855 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2856 call assert_equal('"history dg', @:)
2857 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2858 call assert_equal('"history search', @:)
2859 set wildoptions=fuzzy
2860 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2861 call assert_equal('"history debug', @:)
2862 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2863 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002864 set wildoptions&
2865endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002866
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002867" :language locale name fuzzy completion
2868func Test_fuzzy_completion_lang()
2869 CheckUnix
2870 set wildoptions&
2871 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2872 call assert_equal('"lang psx', @:)
2873 set wildoptions=fuzzy
2874 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2875 call assert_equal('"lang POSIX', @:)
2876 set wildoptions&
2877endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002878
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002879" :mapclear buffer argument fuzzy completion
2880func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002881 set wildoptions&
2882 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2883 call assert_equal('"mapclear buf', @:)
2884 set wildoptions=fuzzy
2885 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2886 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002887 set wildoptions&
2888endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002889
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002890" map name fuzzy completion
2891func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002892 " test regex completion works
2893 set wildoptions=fuzzy
2894 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2895 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002896 nmap <plug>MyLongMap :p<CR>
2897 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2898 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2899 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2900 call assert_equal("\"nmap MLM \t", @:)
2901 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2902 call assert_equal("\"nmap <F2> one two \t", @:)
2903 " duplicate entries should be removed
2904 vmap <plug>MyLongMap :<C-U>#<CR>
2905 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2906 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2907 nunmap <plug>MyLongMap
2908 vunmap <plug>MyLongMap
2909 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2910 call assert_equal("\"nmap ABC\t", @:)
2911 " results should be sorted by best match
2912 nmap <Plug>format :
2913 nmap <Plug>goformat :
2914 nmap <Plug>TestFOrmat :
2915 nmap <Plug>fendoff :
2916 nmap <Plug>state :
2917 nmap <Plug>FendingOff :
2918 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2919 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2920 nunmap <Plug>format
2921 nunmap <Plug>goformat
2922 nunmap <Plug>TestFOrmat
2923 nunmap <Plug>fendoff
2924 nunmap <Plug>state
2925 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002926 set wildoptions&
2927endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002928
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002929" abbreviation fuzzy completion
2930func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002931 set wildoptions=fuzzy
2932 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2933 call assert_equal("\"iabbr <nowait>", @:)
2934 iabbr WaitForCompletion WFC
2935 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2936 call assert_equal("\"iabbr WaitForCompletion", @:)
2937 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2938 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00002939
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002940 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002941 set wildoptions&
2942endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002943
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002944" menu name fuzzy completion
2945func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00002946 CheckFeature menu
2947
2948 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002949 set wildoptions&
2950 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2951 call assert_equal('"menu pup', @:)
2952 set wildoptions=fuzzy
2953 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2954 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00002955
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002956 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00002957 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002958endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002959
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002960" :messages suboptions fuzzy completion
2961func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002962 set wildoptions&
2963 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2964 call assert_equal('"messages clr', @:)
2965 set wildoptions=fuzzy
2966 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2967 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002968 set wildoptions&
2969endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002970
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002971" :set option name fuzzy completion
2972func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002973 set wildoptions&
2974 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2975 call assert_equal('"set brkopt', @:)
2976 set wildoptions=fuzzy
2977 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2978 call assert_equal('"set breakindentopt', @:)
2979 set wildoptions&
2980 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2981 call assert_equal('"set fixendofline', @:)
2982 set wildoptions=fuzzy
2983 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2984 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002985 set wildoptions&
2986endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002987
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002988" :set <term_option>
2989func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002990 set wildoptions&
2991 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2992 call assert_equal('"set t_EC', @:)
2993 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2994 call assert_equal('"set <t_EC>', @:)
2995 set wildoptions=fuzzy
2996 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2997 call assert_equal('"set t_EC', @:)
2998 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2999 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003000 set wildoptions&
3001endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003002
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003003" " :packadd directory name fuzzy completion - NOT supported
3004" func Test_fuzzy_completion_packadd()
3005" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003006
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003007" " shell command name fuzzy completion - NOT supported
3008" func Test_fuzzy_completion_shellcmd()
3009" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003010
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003011" :sign suboptions fuzzy completion
3012func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003013 set wildoptions&
3014 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3015 call assert_equal('"sign ufe', @:)
3016 set wildoptions=fuzzy
3017 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3018 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003019 set wildoptions&
3020endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003021
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003022" :syntax suboptions fuzzy completion
3023func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003024 set wildoptions&
3025 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3026 call assert_equal('"syntax kwd', @:)
3027 set wildoptions=fuzzy
3028 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3029 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003030 set wildoptions&
3031endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003032
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003033" syntax group name fuzzy completion
3034func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003035 set wildoptions&
3036 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3037 call assert_equal('"syntax list mpar', @:)
3038 set wildoptions=fuzzy
3039 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3040 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003041 set wildoptions&
3042endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003043
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003044" :syntime suboptions fuzzy completion
3045func Test_fuzzy_completion_syntime()
3046 CheckFeature profile
3047 set wildoptions&
3048 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3049 call assert_equal('"syntime clr', @:)
3050 set wildoptions=fuzzy
3051 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3052 call assert_equal('"syntime clear', @:)
3053 set wildoptions&
3054endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003055
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003056" " tag name fuzzy completion - NOT supported
3057" func Test_fuzzy_completion_tagname()
3058" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003059
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003060" " tag name and file fuzzy completion - NOT supported
3061" func Test_fuzzy_completion_tagfile()
3062" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003063
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003064" " user names fuzzy completion - how to test this functionality?
3065" func Test_fuzzy_completion_username()
3066" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003067
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003068" user defined variable name fuzzy completion
3069func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003070 let g:SomeVariable=10
3071 set wildoptions&
3072 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3073 call assert_equal('"let SVar', @:)
3074 set wildoptions=fuzzy
3075 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3076 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003077 set wildoptions&
3078endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003079
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003080" Test for sorting the results by the best match
3081func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003082 %bw!
3083 command T123format :
3084 command T123goformat :
3085 command T123TestFOrmat :
3086 command T123fendoff :
3087 command T123state :
3088 command T123FendingOff :
3089 set wildoptions=fuzzy
3090 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3091 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3092 delcommand T123format
3093 delcommand T123goformat
3094 delcommand T123TestFOrmat
3095 delcommand T123fendoff
3096 delcommand T123state
3097 delcommand T123FendingOff
3098 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003099 set wildoptions&
3100endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003101
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003102" Test for fuzzy completion of a command with lower case letters and a number
3103func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003104 command Foo2Bar :
3105 set wildoptions=fuzzy
3106 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3107 call assert_equal('"Foo2Bar', @:)
3108 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3109 call assert_equal('"Foo2Bar', @:)
3110 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3111 call assert_equal('"Foo2Bar', @:)
3112 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003113 set wildoptions&
3114endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003115
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003116" Test for command completion for a command starting with 'k'
3117func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003118 command KillKillKill :
3119 set wildoptions&
3120 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal("\"killkill\<Tab>", @:)
3122 set wildoptions=fuzzy
3123 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3124 call assert_equal('"KillKillKill', @:)
3125 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003126 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003127endfunc
3128
3129" Test for fuzzy completion for user defined custom completion function
3130func Test_fuzzy_completion_custom_func()
3131 func Tcompl(a, c, p)
3132 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3133 endfunc
3134 command -nargs=* -complete=custom,Tcompl Fuzzy :
3135 set wildoptions&
3136 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3137 call assert_equal("\"Fuzzy format", @:)
3138 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3139 call assert_equal("\"Fuzzy xy", @:)
3140 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3141 call assert_equal("\"Fuzzy ttt", @:)
3142 set wildoptions=fuzzy
3143 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3144 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3145 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3146 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3147 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3148 call assert_equal("\"Fuzzy xy", @:)
3149 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3150 call assert_equal("\"Fuzzy TestFOrmat", @:)
3151 delcom Fuzzy
3152 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003153endfunc
3154
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003155" Test for :breakadd argument completion
3156func Test_cmdline_complete_breakadd()
3157 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal("\"breakadd expr file func here", @:)
3159 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3160 call assert_equal("\"breakadd expr", @:)
3161 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3162 call assert_equal("\"breakadd expr", @:)
3163 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3164 call assert_equal("\"breakadd here", @:)
3165 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3166 call assert_equal("\"breakadd here", @:)
3167 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3168 call assert_equal("\"breakadd abc", @:)
3169 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3170 let l = getcompletion('not', 'breakpoint')
3171 call assert_equal([], l)
3172
3173 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003174 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003175 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3176 call assert_equal("\"breakadd file Xscript", @:)
3177 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal("\"breakadd file Xscript", @:)
3179 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3180 call assert_equal("\"breakadd file 20 Xscript", @:)
3181 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3182 call assert_equal("\"breakadd file 20 Xscript", @:)
3183 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3184 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3185 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3186 call assert_equal("\"breakadd file 20\t", @:)
3187 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3188 call assert_equal("\"breakadd file 20x\t", @:)
3189 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3190 call assert_equal("\"breakadd file Xscript ", @:)
3191 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3192 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003193
3194 " Test for :breakadd func [lnum] <function>
3195 func Xbreak_func()
3196 endfunc
3197 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3198 call assert_equal("\"breakadd func Xbreak_func", @:)
3199 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3200 call assert_equal("\"breakadd func Xbreak_func", @:)
3201 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3202 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3203 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3204 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3205 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3206 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3207 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3208 call assert_equal("\"breakadd func 20\t", @:)
3209 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3210 call assert_equal("\"breakadd func 20x\t", @:)
3211 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3212 call assert_equal("\"breakadd func Xbreak_func ", @:)
3213 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3214 call assert_equal("\"breakadd func X1B2C3", @:)
3215 delfunc Xbreak_func
3216
3217 " Test for :breakadd expr <expression>
3218 let g:Xtest_var = 10
3219 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3220 call assert_equal("\"breakadd expr Xtest_var", @:)
3221 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal("\"breakadd expr Xtest_var", @:)
3223 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal("\"breakadd expr Xtest_var ", @:)
3225 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal("\"breakadd expr X1B2C3", @:)
3227 unlet g:Xtest_var
3228
3229 " Test for :breakadd here
3230 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3231 call assert_equal("\"breakadd here Xtest", @:)
3232 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3233 call assert_equal("\"breakadd here Xtest", @:)
3234 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3235 call assert_equal("\"breakadd here ", @:)
3236endfunc
3237
3238" Test for :breakdel argument completion
3239func Test_cmdline_complete_breakdel()
3240 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3241 call assert_equal("\"breakdel file func here", @:)
3242 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3243 call assert_equal("\"breakdel file", @:)
3244 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3245 call assert_equal("\"breakdel file", @:)
3246 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3247 call assert_equal("\"breakdel here", @:)
3248 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3249 call assert_equal("\"breakdel here", @:)
3250 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3251 call assert_equal("\"breakdel abc", @:)
3252
3253 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003254 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003255 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3256 call assert_equal("\"breakdel file Xscript", @:)
3257 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3258 call assert_equal("\"breakdel file Xscript", @:)
3259 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3260 call assert_equal("\"breakdel file 20 Xscript", @:)
3261 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3262 call assert_equal("\"breakdel file 20 Xscript", @:)
3263 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3265 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3266 call assert_equal("\"breakdel file 20\t", @:)
3267 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3268 call assert_equal("\"breakdel file 20x\t", @:)
3269 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3270 call assert_equal("\"breakdel file Xscript ", @:)
3271 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3272 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003273
3274 " Test for :breakdel func [lnum] <function>
3275 func Xbreak_func()
3276 endfunc
3277 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3278 call assert_equal("\"breakdel func Xbreak_func", @:)
3279 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3280 call assert_equal("\"breakdel func Xbreak_func", @:)
3281 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3282 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3283 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3284 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3285 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3286 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3287 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3288 call assert_equal("\"breakdel func 20\t", @:)
3289 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3290 call assert_equal("\"breakdel func 20x\t", @:)
3291 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3292 call assert_equal("\"breakdel func Xbreak_func ", @:)
3293 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3294 call assert_equal("\"breakdel func X1B2C3", @:)
3295 delfunc Xbreak_func
3296
3297 " Test for :breakdel here
3298 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3299 call assert_equal("\"breakdel here Xtest", @:)
3300 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3301 call assert_equal("\"breakdel here Xtest", @:)
3302 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3303 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003304endfunc
3305
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003306" Test for :scriptnames argument completion
3307func Test_cmdline_complete_scriptnames()
3308 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003309 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003310 source Xa1b2c3.vim
3311 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3312 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3313 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3314 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3315 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3316 call assert_equal("\"script b2c3", @:)
3317 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3318 call assert_match("\"script 2\<Tab>$", @:)
3319 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3320 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3321 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3322 call assert_equal("\"script ", @:)
3323 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3324 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3325 new
3326 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3327 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3328 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003329 set wildmenu&
3330endfunc
3331
Bram Moolenaard8893442022-05-06 20:38:47 +01003332" this was going over the end of IObuff
3333func Test_report_error_with_composing()
3334 let caught = 'no'
3335 try
3336 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3337 catch /E492:/
3338 let caught = 'yes'
3339 endtry
3340 call assert_equal('yes', caught)
3341endfunc
3342
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003343" Test for expanding 2-letter and 3-letter :substitute command arguments.
3344" These commands don't accept an argument.
3345func Test_cmdline_complete_substitute_short()
3346 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3347 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3348 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3349 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3350 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3351 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3352 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3353 endfor
3354endfunc
3355
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003356" Test for :! shell command argument completion
3357func Test_cmdline_complete_bang_cmd_argument()
3358 set wildoptions=fuzzy
3359 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3360 call assert_equal('"!vim test_cmdline.vim', @:)
3361 set wildoptions&
3362 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3363 call assert_equal('"!vim test_cmdline.vim', @:)
3364endfunc
3365
zeertzjq961b2e52023-04-17 15:53:24 +01003366func Call_cmd_funcs()
3367 return string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003368endfunc
3369
3370func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003371 call assert_equal(0, getcmdpos())
3372 call assert_equal(0, getcmdscreenpos())
3373 call assert_equal('', getcmdcompltype())
3374
3375 cnoremap <expr> <F2> string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
3376 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
3377 call assert_equal("\"let a[6, 7, 'var']", @:)
3378 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
3379 call assert_equal("\"quit [6, 7, '']", @:)
3380 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
3381 call assert_equal("\"nosuchcommand [15, 16, '']", @:)
3382 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003383endfunc
3384
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003385func Test_recursive_register()
3386 let @= = ''
3387 silent! ?e/
3388 let caught = 'no'
3389 try
3390 normal //
3391 catch /E169:/
3392 let caught = 'yes'
3393 endtry
3394 call assert_equal('yes', caught)
3395endfunc
3396
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003397func Test_long_error_message()
3398 " the error should be truncated, not overrun IObuff
3399 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3400endfunc
3401
zeertzjq6791adc2022-07-26 20:42:25 +01003402func Test_cmdline_redraw_tabline()
3403 CheckRunVimInTerminal
3404
3405 let lines =<< trim END
3406 set showtabline=2
3407 autocmd CmdlineEnter * set tabline=foo
3408 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003409 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003410 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3411 call term_sendkeys(buf, ':')
3412 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3413
3414 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003415endfunc
3416
zeertzjqb82a2ab2022-08-21 14:33:57 +01003417func Test_wildmenu_pum_disable_while_shown()
3418 set wildoptions=pum
3419 set wildmenu
3420 cnoremap <F2> <Cmd>set nowildmenu<CR>
3421 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3422 call assert_equal(0, pumvisible())
3423 cunmap <F2>
3424 set wildoptions& wildmenu&
3425endfunc
3426
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003427func Test_setcmdline()
3428 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01003429 call assert_equal(0, setcmdline(test_null_string()))
3430 call assert_equal('', getcmdline())
3431 call assert_equal(1, getcmdpos())
3432
3433 call assert_equal(0, setcmdline(''[: -1]))
3434 call assert_equal('', getcmdline())
3435 call assert_equal(1, getcmdpos())
3436
zeertzjq54acb902022-08-29 16:21:25 +01003437 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003438 call assert_equal(0, setcmdline(a:text))
3439 call assert_equal(a:text, getcmdline())
3440 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003441 call assert_equal(getcmdtype(), g:cmdtype)
3442 unlet g:cmdtype
3443 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003444
3445 call assert_equal(0, setcmdline(a:text, a:pos))
3446 call assert_equal(a:text, getcmdline())
3447 call assert_equal(a:pos, getcmdpos())
3448
3449 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003450 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3451 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003452
3453 return ''
3454 endfunc
3455
3456 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3457 call assert_equal('set rtp?', @:)
3458
zeertzjq54acb902022-08-29 16:21:25 +01003459 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3460 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3461 call assert_equal('foo', g:str)
3462 unlet g:str
3463
3464 delfunc SetText
3465
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003466 " setcmdline() returns 1 when not editing the command line.
3467 call assert_equal(1, 'foo'->setcmdline())
3468
3469 " Called in custom function
3470 func CustomComplete(A, L, P)
3471 call assert_equal(0, setcmdline("DoCmd "))
3472 return "January\nFebruary\nMars\n"
3473 endfunc
3474
3475 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3476 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3477 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003478 delcom DoCmd
3479 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003480
3481 " Called in <expr>
3482 cnoremap <expr>a setcmdline('let foo=')
3483 call feedkeys(":a\<CR>", 'tx')
3484 call assert_equal('let foo=0', @:)
3485 cunmap a
3486endfunc
3487
Sean Dewarfc8a6012023-04-17 16:41:20 +01003488func Test_rulerformat_position()
3489 CheckScreendump
3490
3491 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
3492 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
3493 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
3494 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
3495 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
3496
3497 " clean up
3498 call StopVimInTerminal(buf)
3499endfunc
3500
Bram Moolenaar309976e2019-12-05 18:16:33 +01003501" vim: shiftwidth=2 sts=2 expandtab