blob: 3cfdd7648070b942bb14d84b34c15486c2b00159 [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 Moolenaard4cf9fc2022-08-11 14:13:37 +0100277 " reducing window size and then setting cmdheight
278 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 Moolenaarcf5fdf72017-03-02 23:05:51 +0100290func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100291 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
292 call assert_equal('"map <unique> <silent>', getreg(':'))
293 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
294 call assert_equal('"map <script> <unique>', getreg(':'))
295 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
296 call assert_equal('"map <expr> <script>', getreg(':'))
297 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
298 call assert_equal('"map <buffer> <expr>', getreg(':'))
299 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
300 call assert_equal('"map <nowait> <buffer>', getreg(':'))
301 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
302 call assert_equal('"map <special> <nowait>', getreg(':'))
303 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
304 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200305
Bram Moolenaar1776a282019-05-03 16:05:41 +0200306 map <Middle>x middle
307
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200308 map ,f commaf
309 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200310 map <Left> left
311 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200312 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
313 call assert_equal('"map ,f', getreg(':'))
314 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
315 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200316 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
317 call assert_equal('"map <Left>', getreg(':'))
318 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200319 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200320 unmap ,f
321 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200322 unmap <Left>
323 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200324
325 set cpo-=< cpo-=B cpo-=k
326 map <Left> left
327 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
328 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200329 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200330 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200331 unmap <Left>
332
333 set cpo+=<
334 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200335 exe "set t_k6=\<Esc>[17~"
336 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200337 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
338 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200339 if !has('gui_running')
340 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
341 call assert_equal("\"map <F6>x", getreg(':'))
342 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200343 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200344 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200345 set cpo-=<
346
347 set cpo+=B
348 map <Left> left
349 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
350 call assert_equal('"map <Left>', getreg(':'))
351 unmap <Left>
352 set cpo-=B
353
354 set cpo+=k
355 map <Left> left
356 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
357 call assert_equal('"map <Left>', getreg(':'))
358 unmap <Left>
359 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200360
Bram Moolenaar531be472020-09-23 22:38:05 +0200361 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
362
Bram Moolenaar1776a282019-05-03 16:05:41 +0200363 unmap <Middle>x
364 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100365endfunc
366
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100367func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100368 hi Aardig ctermfg=green
369 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000370 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100371 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000372 call assert_equal('"match none', @:)
373 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
374 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100375endfunc
376
377func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100378 hi Aardig ctermfg=green
379 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
380 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200381 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
382 call assert_equal('"hi default Aardig', getreg(':'))
383 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
384 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100385 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
386 call assert_equal('"hi link', getreg(':'))
387 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
388 call assert_equal('"hi default', getreg(':'))
389 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
390 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200391 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
392 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
393 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
394 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200395
396 " A cleared group does not show up in completions.
397 hi Anders ctermfg=green
398 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
399 hi clear Aardig
400 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
401 hi clear Anders
402 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100403endfunc
404
Bram Moolenaar75e15672020-06-28 13:10:22 +0200405" Test for command-line expansion of "hi Ni " (easter egg)
406func Test_highlight_easter_egg()
407 call test_override('ui_delay', 1)
408 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
409 call assert_equal("\"hi Ni \<Tab>", @:)
410 call test_override('ALL', 0)
411endfunc
412
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200413func Test_getcompletion()
414 let groupcount = len(getcompletion('', 'event'))
415 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200416 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200417 call assert_true(matchcount > 0)
418 call assert_true(groupcount > matchcount)
419
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200420 if has('menu')
421 source $VIMRUNTIME/menu.vim
422 let matchcount = len(getcompletion('', 'menu'))
423 call assert_true(matchcount > 0)
424 call assert_equal(['File.'], getcompletion('File', 'menu'))
425 call assert_true(matchcount > 0)
426 let matchcount = len(getcompletion('File.', 'menu'))
427 call assert_true(matchcount > 0)
428 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200429
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200430 let l = getcompletion('v:n', 'var')
431 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200432 let l = getcompletion('v:notexists', 'var')
433 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200434
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200435 args a.c b.c
436 let l = getcompletion('', 'arglist')
437 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000438 let l = getcompletion('a.', 'buffer')
439 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200440 %argdelete
441
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200442 let l = getcompletion('', 'augroup')
443 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200444 let l = getcompletion('blahblah', 'augroup')
445 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200446
447 let l = getcompletion('', 'behave')
448 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200449 let l = getcompletion('not', 'behave')
450 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200451
452 let l = getcompletion('', 'color')
453 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200454 let l = getcompletion('dirty', 'color')
455 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200456
457 let l = getcompletion('', 'command')
458 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200459 let l = getcompletion('awake', 'command')
460 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200461
462 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200463 call assert_true(index(l, 'samples/') >= 0)
464 let l = getcompletion('NoMatch', 'dir')
465 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200466
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100467 if glob('~/*') !=# ''
468 let l = getcompletion('~/', 'dir')
469 call assert_true(l[0][0] ==# '~')
470 endif
471
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200472 let l = getcompletion('exe', 'expression')
473 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200474 let l = getcompletion('kill', 'expression')
475 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200476
477 let l = getcompletion('tag', 'function')
478 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200479 let l = getcompletion('paint', 'function')
480 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200481
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200482 let Flambda = {-> 'hello'}
483 let l = getcompletion('', 'function')
484 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200485 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200486
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200487 let l = getcompletion('run', 'file')
488 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200489 let l = getcompletion('walk', 'file')
490 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200491 set wildignore=*.vim
492 let l = getcompletion('run', 'file', 1)
493 call assert_true(index(l, 'runtest.vim') < 0)
494 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000495 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100496 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000497 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
498 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200499
500 let l = getcompletion('ha', 'filetype')
501 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200502 let l = getcompletion('horse', 'filetype')
503 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200504
505 let l = getcompletion('z', 'syntax')
506 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200507 let l = getcompletion('emacs', 'syntax')
508 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200509
510 let l = getcompletion('jikes', 'compiler')
511 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200512 let l = getcompletion('break', 'compiler')
513 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200514
515 let l = getcompletion('last', 'help')
516 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200517 let l = getcompletion('giveup', 'help')
518 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200519
520 let l = getcompletion('time', 'option')
521 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200522 let l = getcompletion('space', 'option')
523 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200524
525 let l = getcompletion('er', 'highlight')
526 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200527 let l = getcompletion('dark', 'highlight')
528 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200529
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200530 let l = getcompletion('', 'messages')
531 call assert_true(index(l, 'clear') >= 0)
532 let l = getcompletion('not', 'messages')
533 call assert_equal([], l)
534
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200535 let l = getcompletion('', 'mapclear')
536 call assert_true(index(l, '<buffer>') >= 0)
537 let l = getcompletion('not', 'mapclear')
538 call assert_equal([], l)
539
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200540 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200541 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200542 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
543 let root = has('win32') ? 'C:\\' : '/'
544 let l = getcompletion(root, 'shellcmd')
545 let expected = map(filter(glob(root . '*', 0, 1),
546 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
547 call assert_equal(expected, l)
548
Bram Moolenaarb650b982016-08-05 20:35:13 +0200549 if has('cscope')
550 let l = getcompletion('', 'cscope')
551 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
552 call assert_equal(cmds, l)
553 " using cmdline completion must not change the result
554 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
555 let l = getcompletion('', 'cscope')
556 call assert_equal(cmds, l)
557 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
558 let l = getcompletion('find ', 'cscope')
559 call assert_equal(keys, l)
560 endif
561
Bram Moolenaar7522f692016-08-06 14:12:50 +0200562 if has('signs')
563 sign define Testing linehl=Comment
564 let l = getcompletion('', 'sign')
565 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
566 call assert_equal(cmds, l)
567 " using cmdline completion must not change the result
568 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
569 let l = getcompletion('', 'sign')
570 call assert_equal(cmds, l)
571 let l = getcompletion('list ', 'sign')
572 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000573 let l = getcompletion('de*', 'sign')
574 call assert_equal(['define'], l)
575 let l = getcompletion('p?', 'sign')
576 call assert_equal(['place'], l)
577 let l = getcompletion('j.', 'sign')
578 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200579 endif
580
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200581 " Command line completion tests
582 let l = getcompletion('cd ', 'cmdline')
583 call assert_true(index(l, 'samples/') >= 0)
584 let l = getcompletion('cd NoMatch', 'cmdline')
585 call assert_equal([], l)
586 let l = getcompletion('let v:n', 'cmdline')
587 call assert_true(index(l, 'v:null') >= 0)
588 let l = getcompletion('let v:notexists', 'cmdline')
589 call assert_equal([], l)
590 let l = getcompletion('call tag', 'cmdline')
591 call assert_true(index(l, 'taglist(') >= 0)
592 let l = getcompletion('call paint', 'cmdline')
593 call assert_equal([], l)
594
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100595 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000596 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100597 return "oneA\noneB\noneC"
598 endfunc
599 command -nargs=1 -complete=custom,T MyCmd
600 let l = getcompletion('MyCmd ', 'cmdline')
601 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000602 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100603
604 delcommand MyCmd
605 delfunc T
ii144785fe02021-11-21 12:13:56 +0000606 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100607
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200608 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200609 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200610 if has('cmdline_hist')
611 call add(names, 'history')
612 endif
613 if has('gettext')
614 call add(names, 'locale')
615 endif
616 if has('profile')
617 call add(names, 'syntime')
618 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200619
620 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100621 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200622
623 for name in names
624 let matchcount = len(getcompletion('', name))
625 call assert_true(matchcount >= 0, 'No matches for ' . name)
626 endfor
627
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200628 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200629
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000630 edit a~b
631 enew
632 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
633 bw a~b
634
635 if has('unix')
636 edit Xtest\
637 enew
638 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
639 bw Xtest\
640 endif
641
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200642 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200643 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100644 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200645endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200646
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000647" Test for getcompletion() with "fuzzy" in 'wildoptions'
648func Test_getcompletion_wildoptions()
649 let save_wildoptions = &wildoptions
650 set wildoptions&
651 let l = getcompletion('space', 'option')
652 call assert_equal([], l)
653 let l = getcompletion('ier', 'command')
654 call assert_equal([], l)
655 set wildoptions=fuzzy
656 let l = getcompletion('space', 'option')
657 call assert_true(index(l, 'backspace') >= 0)
658 let l = getcompletion('ier', 'command')
659 call assert_true(index(l, 'compiler') >= 0)
660 let &wildoptions = save_wildoptions
661endfunc
662
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000663func Test_complete_autoload_error()
664 let save_rtp = &rtp
665 let lines =<< trim END
666 vim9script
667 export def Complete(..._): string
668 return 'match'
669 enddef
670 echo this will cause an error
671 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100672 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000673 call writefile(lines, 'Xdir/autoload/script.vim')
674 exe 'set rtp+=' .. getcwd() .. '/Xdir'
675
676 let lines =<< trim END
677 vim9script
678 import autoload 'script.vim'
679 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
680 &wildcharm = char2nr("\<Tab>")
681 feedkeys(":Cmd \<Tab>", 'xt')
682 END
683 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
684
685 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000686endfunc
687
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100688func Test_fullcommand()
689 let tests = {
690 \ '': '',
691 \ ':': '',
692 \ ':::': '',
693 \ ':::5': '',
694 \ 'not_a_cmd': '',
695 \ 'Check': '',
696 \ 'syntax': 'syntax',
697 \ ':syntax': 'syntax',
698 \ '::::syntax': 'syntax',
699 \ 'sy': 'syntax',
700 \ 'syn': 'syntax',
701 \ 'synt': 'syntax',
702 \ ':sy': 'syntax',
703 \ '::::sy': 'syntax',
704 \ 'match': 'match',
705 \ '2match': 'match',
706 \ '3match': 'match',
707 \ 'aboveleft': 'aboveleft',
708 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100709 \ 'en': 'endif',
710 \ 'end': 'endif',
711 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100712 \ 's': 'substitute',
713 \ '5s': 'substitute',
714 \ ':5s': 'substitute',
715 \ "'<,'>s": 'substitute',
716 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100717 \ 'CheckLin': 'CheckLinux',
718 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100719 \ }
720
721 for [in, want] in items(tests)
722 call assert_equal(want, fullcommand(in))
723 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200724 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100725
726 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200727
728 command -buffer BufferLocalCommand :
729 command GlobalCommand :
730 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
731 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
732 delcommand BufferLocalCommand
733 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100734endfunc
735
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200736func Test_shellcmd_completion()
737 let save_path = $PATH
738
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100739 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200740 call writefile([''], 'Xpathdir/Xfile.exe')
741 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
742
743 " Set PATH to example directory without trailing slash.
744 let $PATH = getcwd() . '/Xpathdir'
745
746 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
747 " dirs in the PATH, even though they won't be executed. We check that only
748 " subdirs of the PWD and executables from the PATH are included in the
749 " suggestions.
750 let actual = getcompletion('X', 'shellcmd')
751 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
752 call insert(expected, 'Xfile.exe')
753 call assert_equal(expected, actual)
754
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200755 let $PATH = save_path
756endfunc
757
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200758func Test_expand_star_star()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100759 call mkdir('a/b', 'pR')
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200760 call writefile(['asdfasdf'], 'a/b/fileXname')
761 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000762 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200763 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200764endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100765
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100766func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100767 let @a = "def"
768 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
769 call assert_equal('"abc def ghi', @:)
770
771 new
772 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
773
774 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
775 call assert_equal('"aaa asdf bbb', @:)
776
777 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
778 call assert_equal('"aaa /tmp/some bbb', @:)
779
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200780 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
781 call assert_equal('"aaa '.getline(1).' bbb', @:)
782
Bram Moolenaar21efc362016-12-03 14:05:49 +0100783 set incsearch
784 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
785 call assert_equal('"aaa verylongword bbb', @:)
786
787 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
788 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100789
790 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
791 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100792 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200793
794 " Error while typing a command used to cause that it was not executed
795 " in the end.
796 new
797 try
798 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
799 catch /^Vim\%((\a\+)\)\=:E32/
800 " ignore error E32
801 endtry
802 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100803
Bram Moolenaar578fe942020-02-27 21:32:51 +0100804 " Try to paste an invalid register using <C-R>
805 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
806 call assert_equal('"onetwo', @:)
807
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100808 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100809 let @a = "xy\<C-H>z"
810 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
811 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100812 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
813 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100814 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
815 call assert_equal("\"xy\<C-H>z", @:)
816
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100817 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
818 let @a = "xy\<C-V>z"
819 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
820 call assert_equal('"xyz', @:)
821 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
822 call assert_equal("\"xy\<C-V>z", @:)
823
Bram Moolenaar578fe942020-02-27 21:32:51 +0100824 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
825
Bram Moolenaar72532d32018-04-07 19:09:09 +0200826 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100827endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100828
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100829func Test_cmdline_remove_char()
830 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100831
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100832 for e in ['utf8', 'latin1']
833 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100834
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100835 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
836 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100837
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100838 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
839 call assert_equal('"abcdef', @:)
840
841 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
842 call assert_equal('"abc ghi', @:, e)
843
844 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
845 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100846
847 " This was going before the start in latin1.
848 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100849 endfor
850
851 let &encoding = encoding_save
852endfunc
853
854func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200855 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100856
857 set keymap=esperanto
858 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
859 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
860 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100861endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100862
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100863func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100864 new
865 2;'(
866 2;')
867 quit
868endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100869
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100870func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100871 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100872 new
873 source Xtest.vim
874 " Trigger calling validate_cursor()
875 diffsp Xtest.vim
876 quit!
877 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100878endfunc
879
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100880func Test_mark_from_line_zero()
881 " this was reading past the end of the first (empty) line
882 new
883 norm oxxxx
884 call assert_fails("0;'(", 'E20:')
885 bwipe!
886endfunc
887
Bram Moolenaarba47b512017-01-24 21:18:19 +0100888func Test_cmdline_complete_wildoptions()
889 help
890 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
891 let a = join(sort(split(@:)),' ')
892 set wildoptions=tagfile
893 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
894 let b = join(sort(split(@:)),' ')
895 call assert_equal(a, b)
896 bw!
897endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100898
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200899func Test_cmdline_complete_user_cmd()
900 command! -complete=color -nargs=1 Foo :
901 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
902 call assert_equal('"Foo blue', @:)
903 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
904 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000905 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
906 call assert_equal('"Foo a blue', @:)
907 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
908 call assert_equal('"Foo b\', @:)
909 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
910 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200911 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100912
913 redraw
914 call assert_equal('~', Screenline(&lines - 1))
915 command! FooOne :
916 command! FooTwo :
917
918 set nowildmenu
919 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
920 call assert_equal('"FooOne', @:)
921 call assert_equal('~', Screenline(&lines - 1))
922
923 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
924 call assert_equal('"FooTwo', @:)
925 call assert_equal('~', Screenline(&lines - 1))
926
927 delcommand FooOne
928 delcommand FooTwo
929 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200930endfunc
931
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100932func Test_complete_user_cmd()
933 command FooBar echo 'global'
934 command -buffer FooBar echo 'local'
935 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
936 call assert_equal('"FooBar', @:)
937
938 delcommand -buffer FooBar
939 delcommand FooBar
940endfunc
941
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100942func s:ScriptLocalFunction()
943 echo 'yes'
944endfunc
945
946func Test_cmdline_complete_user_func()
947 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200948 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100949 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
950 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100951
952 " g: prefix also works
953 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
954 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200955
956 " using g: prefix does not result in just "g:" matches from a lambda
957 let Fx = { a -> a }
958 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
959 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200960
961 " existence of script-local dict function does not break user function name
962 " completion
963 function s:a_dict_func() dict
964 endfunction
965 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
966 call assert_match('"call Test_cmdline_complete_user_', @:)
967 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100968endfunc
969
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200970func Test_cmdline_complete_user_names()
971 if has('unix') && executable('whoami')
972 let whoami = systemlist('whoami')[0]
973 let first_letter = whoami[0]
974 if len(first_letter) > 0
975 " Trying completion of :e ~x where x is the first letter of
976 " the user name should complete to at least the user name.
977 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
978 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
979 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200980 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200981 " Just in case: check that the system has an Administrator account.
982 let names = system('net user')
983 if names =~ 'Administrator'
984 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100985 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200986 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100987 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200988 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200989 else
990 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200991 endif
992endfunc
993
Bram Moolenaar297610b2019-12-27 17:20:55 +0100994func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200995 CheckExecutable whoami
996 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
997 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100998endfunc
999
Bram Moolenaar8b633132020-03-20 18:20:51 +01001000func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001001 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1002 call assert_equal(lang, v:lc_time)
1003
1004 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1005 call assert_equal(lang, v:ctype)
1006
1007 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1008 call assert_equal(lang, v:collate)
1009
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001010 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001011 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001012
1013 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001014 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001015
Bram Moolenaarec680282020-06-12 19:35:32 +02001016 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001017
Bram Moolenaarec680282020-06-12 19:35:32 +02001018 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1019 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001020
Bram Moolenaarec680282020-06-12 19:35:32 +02001021 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1022 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001023
Bram Moolenaarec680282020-06-12 19:35:32 +02001024 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1025 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001026
1027 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1028 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001029endfunc
1030
Bram Moolenaar297610b2019-12-27 17:20:55 +01001031func Test_cmdline_complete_env_variable()
1032 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001033 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1034 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001035 unlet $X_VIM_TEST_COMPLETE_ENV
1036endfunc
1037
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001038func Test_cmdline_complete_expression()
1039 let g:SomeVar = 'blah'
1040 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1041 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1042 call assert_match('"' .. cmd .. ' SomeVar', @:)
1043 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1044 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1045 endfor
1046 unlet g:SomeVar
1047endfunc
1048
Bram Moolenaar47016f52021-08-26 16:39:58 +02001049" Unique function name for completion below
1050func s:WeirdFunc()
1051 echo 'weird'
1052endfunc
1053
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001054" Test for various command-line completion
1055func Test_cmdline_complete_various()
1056 " completion for a command starting with a comment
1057 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1058 call assert_equal("\" :|\"\<C-A>", @:)
1059
1060 " completion for a range followed by a comment
1061 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1062 call assert_equal("\"1,2\"\<C-A>", @:)
1063
1064 " completion for :k command
1065 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1066 call assert_equal("\"ka\<C-A>", @:)
1067
1068 " completion for short version of the :s command
1069 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1070 call assert_equal("\"sI \<C-A>", @:)
1071
1072 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001073 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001074 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001075 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001076 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001077 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1078 call assert_equal("\"w >> Xfile1", @:)
1079 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001080
1081 " completion for :w ! and :r ! commands
1082 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1083 call assert_equal("\"w !invalid_xyz_cmd", @:)
1084 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1085 call assert_equal("\"r !invalid_xyz_cmd", @:)
1086
1087 " completion for :>> and :<< commands
1088 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1089 call assert_equal("\">>>\<C-A>", @:)
1090 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1091 call assert_equal("\"<<<\<C-A>", @:)
1092
1093 " completion for command with +cmd argument
1094 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1095 call assert_equal("\"buffer +/pat Xabc", @:)
1096 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1097 call assert_equal("\"buffer +/pat\<C-A>", @:)
1098
1099 " completion for a command with a trailing comment
1100 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1101 call assert_equal("\"ls \" comment\<C-A>", @:)
1102
1103 " completion for a command with a trailing command
1104 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1105 call assert_equal("\"ls | ls", @:)
1106
1107 " completion for a command with an CTRL-V escaped argument
1108 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1109 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1110
1111 " completion for a command that doesn't take additional arguments
1112 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1113 call assert_equal("\"all abc\<C-A>", @:)
1114
zeertzjqd3de1782022-09-01 12:58:52 +01001115 " completion for :wincmd with :horizontal modifier
1116 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1117 call assert_equal("\"horizontal wincmd", @:)
1118
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001119 " completion for a command with a command modifier
1120 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1121 call assert_equal("\"topleft new", @:)
1122
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001123 " completion for vim9 and legacy commands
1124 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1125 call assert_equal("\"vim9 call strlen(", @:)
1126 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1127 call assert_equal("\"legac call strlen(", @:)
1128
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001129 " completion for the :disassemble command
1130 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1131 call assert_equal("\"disas debug", @:)
1132 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1133 call assert_equal("\"disas profile", @:)
1134 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1135 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1136 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1137 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001138 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1139 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001140
Bram Moolenaar47016f52021-08-26 16:39:58 +02001141 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001142 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001143
naohiro onodfe04db2021-09-12 15:45:10 +02001144 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1145 call assert_match('"disas <SNR>\d\+_', @:)
1146 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1147 call assert_match('"disas debug <SNR>\d\+_', @:)
1148
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001149 " completion for the :match command
1150 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1151 call assert_equal("\"match Search /pat/\<C-A>", @:)
1152
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001153 " completion for the :doautocmd command
1154 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1155 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1156
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001157 " completion of autocmd group after comma
1158 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1159 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1160
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001161 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001162 call writefile([], 'Xvarfile1', 'D')
1163 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001164 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1165 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001166
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001167 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001168 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001169 augroup END
1170 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001171 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001172
1173 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001174 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1175 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001176 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1177 call assert_equal("\"au XTest.test", @:)
1178
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001179 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001180
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001181 " autocmd pattern completion
1182 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1183 call assert_equal("\"au BufEnter *.py\t", @:)
1184
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001185 " completion for the :unlet command
1186 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1187 call assert_equal("\"unlet one two", @:)
1188
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001189 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001190 " FIXME: what should happen on MS-Windows?
1191 if !has('win32')
1192 edit \{someFile}
1193 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1194 call assert_equal("\"buf {someFile}", @:)
1195 bwipe {someFile}
1196 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001197
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001198 " completion for the :bdelete command
1199 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1200 call assert_equal("\"bdel a b c", @:)
1201
1202 " completion for the :mapclear command
1203 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1204 call assert_equal("\"mapclear <buffer>", @:)
1205
1206 " completion for user defined commands with menu names
1207 menu Test.foo :ls<CR>
1208 com -nargs=* -complete=menu MyCmd
1209 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1210 call assert_equal('"MyCmd Test.', @:)
1211 delcom MyCmd
1212 unmenu Test
1213
1214 " completion for user defined commands with mappings
1215 mapclear
1216 map <F3> :ls<CR>
1217 com -nargs=* -complete=mapping MyCmd
1218 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001219 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001220 mapclear
1221 delcom MyCmd
1222
1223 " completion for :set path= with multiple backslashes
1224 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1225 call assert_equal('"set path=a\\\ b', @:)
1226
1227 " completion for :set dir= with a backslash
1228 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1229 call assert_equal('"set dir=a\ b', @:)
1230
1231 " completion for the :py3 commands
1232 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1233 call assert_equal('"py3 py3do py3file', @:)
1234
Bram Moolenaardf749a22021-03-28 15:29:43 +02001235 " completion for the :vim9 commands
1236 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1237 call assert_equal('"vim9cmd vim9script', @:)
1238
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001239 " redir @" is not the start of a comment. So complete after that
1240 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1241 call assert_equal('"redir @" | cwindow', @:)
1242
1243 " completion after a backtick
1244 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1245 call assert_equal('"e `a1b2c', @:)
1246
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001247 " completion for :language command with an invalid argument
1248 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1249 call assert_equal("\"language dummy \t", @:)
1250
1251 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001252 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1253 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001254
1255 " completion with ambiguous user defined commands
1256 com TCmd1 echo 'TCmd1'
1257 com TCmd2 echo 'TCmd2'
1258 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1259 call assert_equal('"TCmd ', @:)
1260 delcom TCmd1
1261 delcom TCmd2
1262
1263 " completion after a range followed by a pipe (|) character
1264 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1265 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001266
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001267 " completion after a :global command
1268 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1269 call assert_equal('"g/a/chistory', @:)
1270 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1271 call assert_equal("\"g/a\\/chist\t", @:)
1272
Bram Moolenaar9c929712020-09-07 22:05:28 +02001273 " use <Esc> as the 'wildchar' for completion
1274 set wildchar=<Esc>
1275 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1276 call assert_equal('"g/a\xb/clearjumps', @:)
1277 " pressing <esc> twice should cancel the command
1278 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1279 call assert_equal('"g/a\xb/clearjumps', @:)
1280 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001281
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001282 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001283 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001284 call writefile([], '~Xtest')
1285 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1286 call assert_equal('"e \~Xtest', @:)
1287 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001288
1289 " should be able to complete a file name that has a '*'
1290 call writefile([], 'Xx*Yy')
1291 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1292 call assert_equal('"e Xx\*Yy', @:)
1293 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001294
1295 " use a literal star
1296 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1297 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001298 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001299
1300 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1301 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001302endfunc
1303
1304" Test for 'wildignorecase'
1305func Test_cmdline_wildignorecase()
1306 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001307 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001308 set wildignorecase
1309 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1310 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001311 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001312 let g:Sline = ''
1313 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1314 call assert_equal('"e xt', @:)
1315 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001316 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001317endfunc
1318
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001319func Test_cmdline_write_alternatefile()
1320 new
1321 call setline('.', ['one', 'two'])
1322 f foo.txt
1323 new
1324 f #-A
1325 call assert_equal('foo.txt-A', expand('%'))
1326 f #<-B.txt
1327 call assert_equal('foo-B.txt', expand('%'))
1328 f %<
1329 call assert_equal('foo-B', expand('%'))
1330 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001331 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001332 bw!
1333 f foo-B.txt
1334 f %<-A
1335 call assert_equal('foo-B-A', expand('%'))
1336 bw!
1337 bw!
1338endfunc
1339
Bram Moolenaarf5724372022-09-02 19:45:15 +01001340func Test_cmdline_expand_cur_alt_file()
1341 enew
1342 file http://some.com/file.txt
1343 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1344 call assert_equal('"e http://some.com/file.txt', @:)
1345 edit another
1346 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1347 call assert_equal('"e http://some.com/file.txt', @:)
1348 bwipe
1349 bwipe http://some.com/file.txt
1350endfunc
1351
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001352" using a leading backslash here
1353set cpo+=C
1354
1355func Test_cmdline_search_range()
1356 new
1357 call setline(1, ['a', 'b', 'c', 'd'])
1358 /d
1359 1,\/s/b/B/
1360 call assert_equal('B', getline(2))
1361
1362 /a
1363 $
1364 \?,4s/c/C/
1365 call assert_equal('C', getline(3))
1366
1367 call setline(1, ['a', 'b', 'c', 'd'])
1368 %s/c/c/
1369 1,\&s/b/B/
1370 call assert_equal('B', getline(2))
1371
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001372 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001373 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001374
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001375 bwipe!
1376endfunc
1377
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001378" Test for the tick mark (') in an excmd range
1379func Test_tick_mark_in_range()
1380 " If only the tick is passed as a range and no command is specified, there
1381 " should not be an error
1382 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001383 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001384 call assert_fails("',print", 'E78:')
1385endfunc
1386
1387" Test for using a line number followed by a search pattern as range
1388func Test_lnum_and_pattern_as_range()
1389 new
1390 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1391 let @" = ''
1392 2/foo/yank
1393 call assert_equal("foo 3\n", @")
1394 call assert_equal(1, line('.'))
1395 close!
1396endfunc
1397
Bram Moolenaar65189a12017-02-06 22:22:17 +01001398" Tests for getcmdline(), getcmdpos() and getcmdtype()
1399func Check_cmdline(cmdtype)
1400 call assert_equal('MyCmd a', getcmdline())
1401 call assert_equal(8, getcmdpos())
1402 call assert_equal(a:cmdtype, getcmdtype())
1403 return ''
1404endfunc
1405
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001406set cpo&
1407
Bram Moolenaar65189a12017-02-06 22:22:17 +01001408func Test_getcmdtype()
1409 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1410
1411 let cmdtype = ''
1412 debuggreedy
1413 call feedkeys(":debug echo 'test'\<CR>", "t")
1414 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1415 call feedkeys("cont\<CR>", "xt")
1416 0debuggreedy
1417 call assert_equal('>', cmdtype)
1418
1419 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1420 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1421
1422 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001423 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001424
1425 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1426
1427 cnoremap <expr> <F6> Check_cmdline('=')
1428 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1429 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001430
1431 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001432endfunc
1433
Bram Moolenaar52604f22017-04-07 16:17:39 +02001434func Test_verbosefile()
1435 set verbosefile=Xlog
1436 echomsg 'foo'
1437 echomsg 'bar'
1438 set verbosefile=
1439 let log = readfile('Xlog')
1440 call assert_match("foo\nbar", join(log, "\n"))
1441 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001442
1443 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001444 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001445endfunc
1446
Bram Moolenaar4facea32019-10-12 20:17:40 +02001447func Test_verbose_option()
1448 CheckScreendump
1449
1450 let lines =<< trim [SCRIPT]
1451 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1452 call feedkeys("\r", 't') " for the hit-enter prompt
1453 set verbose=20
1454 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001455 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001456
1457 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001458 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001459 call term_sendkeys(buf, ":DoSomething\<CR>")
1460 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1461
1462 " clean up
1463 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001464endfunc
1465
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001466func Test_setcmdpos()
1467 func InsertTextAtPos(text, pos)
1468 call assert_equal(0, setcmdpos(a:pos))
1469 return a:text
1470 endfunc
1471
1472 " setcmdpos() with position in the middle of the command line.
1473 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1474 call assert_equal('"1ab2', @:)
1475
1476 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1477 call assert_equal('"1b2a', @:)
1478
1479 " setcmdpos() with position beyond the end of the command line.
1480 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1481 call assert_equal('"12ab', @:)
1482
1483 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001484 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001485endfunc
1486
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001487func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001488 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001489 let encoding_save = &encoding
1490
1491 for e in encodings
1492 exe 'set encoding=' . e
1493
1494 " Test overstrike in the middle of the command line.
1495 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001496 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001497
1498 " Test overstrike going beyond end of command line.
1499 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001500 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001501
1502 " Test toggling insert/overstrike a few times.
1503 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001504 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001505 endfor
1506
Bram Moolenaar30276f22019-01-24 17:59:39 +01001507 " Test overstrike with multi-byte characters.
1508 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001509 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001510
1511 let &encoding = encoding_save
1512endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001513
Bram Moolenaar52410572019-10-27 05:12:45 +01001514func Test_buffers_lastused()
1515 " check that buffers are sorted by time when wildmode has lastused
1516 call test_settime(1550020000) " middle
1517 edit bufa
1518 enew
1519 call test_settime(1550030000) " newest
1520 edit bufb
1521 enew
1522 call test_settime(1550010000) " oldest
1523 edit bufc
1524 enew
1525 call test_settime(0)
1526 enew
1527
1528 call assert_equal(['bufa', 'bufb', 'bufc'],
1529 \ getcompletion('', 'buffer'))
1530
1531 let save_wildmode = &wildmode
1532 set wildmode=full:lastused
1533
1534 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1535 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1536 call assert_equal('b bufb', X)
1537 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1538 call assert_equal('b bufa', X)
1539 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1540 call assert_equal('b bufc', X)
1541 enew
1542
1543 edit other
1544 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1545 call assert_equal('b bufb', X)
1546 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1547 call assert_equal('b bufa', X)
1548 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1549 call assert_equal('b bufc', X)
1550 enew
1551
1552 let &wildmode = save_wildmode
1553
1554 bwipeout bufa
1555 bwipeout bufb
1556 bwipeout bufc
1557endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001558
Bram Moolenaar479950f2020-01-19 15:45:17 +01001559func Test_cmdlineclear_tabenter()
1560 CheckScreendump
1561
1562 let lines =<< trim [SCRIPT]
1563 call setline(1, range(30))
1564 [SCRIPT]
1565
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001566 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001567 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001568 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001569 " in one tab make the command line higher with CTRL-W -
1570 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1571 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1572
1573 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001574endfunc
1575
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001576" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001577func Test_cmdline_expand_special()
1578 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001579 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001580 call assert_fails('e <afile>', 'E495:')
1581 call assert_fails('e <abuf>', 'E496:')
1582 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001583
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001584 call writefile([], 'Xfile.cpp', 'D')
1585 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001586 new Xfile.cpp
1587 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1588 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1589 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001590endfunc
1591
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001592" Test for backtick expression in the command line
1593func Test_cmd_backtick()
1594 %argd
1595 argadd `=['a', 'b', 'c']`
1596 call assert_equal(['a', 'b', 'c'], argv())
1597 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001598
1599 argadd `echo abc def`
1600 call assert_equal(['abc def'], argv())
1601 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001602endfunc
1603
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001604" Test for the :! command
1605func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001606 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001607
1608 let lines =<< trim [SCRIPT]
1609 " Test for no previous command
1610 call assert_fails('!!', 'E34:')
1611 set nomore
1612 " Test for cmdline expansion with :!
1613 call setline(1, 'foo!')
1614 silent !echo <cWORD> > Xfile.out
1615 call assert_equal(['foo!'], readfile('Xfile.out'))
1616 " Test for using previous command
1617 silent !echo \! !
1618 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1619 call writefile(v:errors, 'Xresult')
1620 call delete('Xfile.out')
1621 qall!
1622 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001623 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001624 if RunVim([], [], '--clean -S Xscript')
1625 call assert_equal([], readfile('Xresult'))
1626 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001627 call delete('Xresult')
1628endfunc
1629
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001630" Test error: "E135: *Filter* Autocommands must not change current buffer"
1631func Test_cmd_bang_E135()
1632 new
1633 call setline(1, ['a', 'b', 'c', 'd'])
1634 augroup test_cmd_filter_E135
1635 au!
1636 autocmd FilterReadPost * help
1637 augroup END
1638 call assert_fails('2,3!echo "x"', 'E135:')
1639
1640 augroup test_cmd_filter_E135
1641 au!
1642 augroup END
1643 %bwipe!
1644endfunc
1645
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001646" Test for using ~ for home directory in cmdline completion matches
1647func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001648 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001649 call writefile([], 'Xexpdir/Xfile1')
1650 call writefile([], 'Xexpdir/Xfile2')
1651 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001652 let save_HOME = $HOME
1653 let $HOME = getcwd()
1654 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1655 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1656 let $HOME = save_HOME
1657 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001658endfunc
1659
Bram Moolenaar578fe942020-02-27 21:32:51 +01001660" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1661" or insert mode (when 'insertmode' is set)
1662func Test_cmdline_ctrl_g()
1663 new
1664 call setline(1, 'abc')
1665 call cursor(1, 3)
1666 " If command line is entered from insert mode, using C-\ C-G should back to
1667 " insert mode
1668 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1669 call assert_equal('abxyc', getline(1))
1670 call assert_equal(4, col('.'))
1671
1672 " If command line is entered in 'insertmode', using C-\ C-G should back to
1673 " 'insertmode'
1674 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1675 call assert_equal('ab12xyc', getline(1))
1676 close!
1677endfunc
1678
Bram Moolenaar578fe942020-02-27 21:32:51 +01001679" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001680func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001681 func T(a, c, p)
1682 return "oneA\noneB\noneC"
1683 endfunc
1684 command -nargs=1 -complete=custom,T MyCmd
1685
Bram Moolenaar578fe942020-02-27 21:32:51 +01001686 set nowildmenu
1687 set wildmode=full,list
1688 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001689 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001690 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001691 call assert_equal('"MyCmd oneA', @:)
1692
1693 set wildmode=longest,full
1694 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1695 call assert_equal('"MyCmd one', @:)
1696 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1697 call assert_equal('"MyCmd oneC', @:)
1698
1699 set wildmode=longest
1700 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1701 call assert_equal('"MyCmd one', @:)
1702
1703 set wildmode=list:longest
1704 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001705 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001706 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001707 call assert_equal('"MyCmd one', @:)
1708
1709 set wildmode=""
1710 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1711 call assert_equal('"MyCmd oneA', @:)
1712
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001713 " Test for wildmode=longest with 'fileignorecase' set
1714 set wildmode=longest
1715 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001716 argadd AAA AAAA AAAAA
1717 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1718 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001719 set fileignorecase&
1720
1721 " Test for listing files with wildmode=list
1722 set wildmode=list
1723 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001724 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001725 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001726 call assert_equal('"b A', @:)
1727
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001728 " when using longest completion match, matches shorter than the argument
1729 " should be ignored (happens with :help)
1730 set wildmode=longest,full
1731 set wildmenu
1732 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1733 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001734 " non existing file
1735 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1736 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001737 set wildmenu&
1738
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001739 " Test for longest file name completion with 'fileignorecase'
1740 " On MS-Windows, file names are case insensitive.
1741 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001742 call writefile([], 'XTESTfoo', 'D')
1743 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001744 set nofileignorecase
1745 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1746 call assert_equal('"e XTESTfoo', @:)
1747 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1748 call assert_equal('"e Xtestbar', @:)
1749 set fileignorecase
1750 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1751 call assert_equal('"e Xtest', @:)
1752 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1753 call assert_equal('"e Xtest', @:)
1754 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001755 endif
1756
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001757 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001758 delcommand MyCmd
1759 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001760 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001761 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001762endfunc
1763
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001764func Test_wildmode()
1765 " Test with utf-8 encoding
1766 call Wildmode_tests()
1767
1768 " Test with latin1 encoding
1769 let save_encoding = &encoding
1770 set encoding=latin1
1771 call Wildmode_tests()
1772 let &encoding = save_encoding
1773endfunc
1774
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001775func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001776 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001777 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001778 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001779 let lines =<< trim END
1780 func vim8#Complete(a, c, p)
1781 return "oneA\noneB\noneC"
1782 endfunc
1783 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001784 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001785
1786 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1787 set nowildmenu
1788 set wildmode=full,list
1789 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1790 call assert_equal('"MyCmd oneA oneB oneC', @:)
1791
1792 let &rtp = save_rtp
1793 set wildmode& wildmenu&
1794 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001795endfunc
1796
Bram Moolenaar578fe942020-02-27 21:32:51 +01001797" Test for interrupting the command-line completion
1798func Test_interrupt_compl()
1799 func F(lead, cmdl, p)
1800 if a:lead =~ 'tw'
1801 call interrupt()
1802 return
1803 endif
1804 return "one\ntwo\nthree"
1805 endfunc
1806 command -nargs=1 -complete=custom,F Tcmd
1807
1808 set nowildmenu
1809 set wildmode=full
1810 let interrupted = 0
1811 try
1812 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1813 catch /^Vim:Interrupt$/
1814 let interrupted = 1
1815 endtry
1816 call assert_equal(1, interrupted)
1817
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001818 let interrupted = 0
1819 try
1820 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1821 catch /^Vim:Interrupt$/
1822 let interrupted = 1
1823 endtry
1824 call assert_equal(1, interrupted)
1825
Bram Moolenaar578fe942020-02-27 21:32:51 +01001826 delcommand Tcmd
1827 delfunc F
1828 set wildmode&
1829endfunc
1830
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001831" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001832func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001833 let str = ":one two\<C-U>"
1834 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001835 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001836 let str ..= "\<Left>five\<Right>"
1837 let str ..= "\<Home>two "
1838 let str ..= "\<C-Left>one "
1839 let str ..= "\<C-Right> three"
1840 let str ..= "\<End>\<S-Left>four "
1841 let str ..= "\<S-Right> six"
1842 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1843 call feedkeys(str, 'xt')
1844 call assert_equal("\"one two three four five six seven", @:)
1845endfunc
1846
1847" Test for moving the cursor on the / command line in 'rightleft' mode
1848func Test_cmdline_edit_rightleft()
1849 CheckFeature rightleft
1850 set rightleft
1851 set rightleftcmd=search
1852 let str = "/one two\<C-U>"
1853 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001854 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001855 let str ..= "\<Right>five\<Left>"
1856 let str ..= "\<Home>two "
1857 let str ..= "\<C-Right>one "
1858 let str ..= "\<C-Left> three"
1859 let str ..= "\<End>\<S-Right>four "
1860 let str ..= "\<S-Left> six"
1861 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1862 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1863 call assert_equal("\"one two three four five six seven", @/)
1864 set rightleftcmd&
1865 set rightleft&
1866endfunc
1867
1868" Test for using <C-\>e in the command line to evaluate an expression
1869func Test_cmdline_expr()
1870 " Evaluate an expression from the beginning of a command line
1871 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1872 call assert_equal('"hello', @:)
1873
1874 " Use an invalid expression for <C-\>e
1875 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1876
1877 " Insert literal <CTRL-\> in the command line
1878 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1879 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001880endfunc
1881
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001882" This was making the insert position negative
1883func Test_cmdline_expr_register()
1884 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1885endfunc
1886
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001887" Test for 'imcmdline' and 'imsearch'
1888" This test doesn't actually test the input method functionality.
1889func Test_cmdline_inputmethod()
1890 new
1891 call setline(1, ['', 'abc', ''])
1892 set imcmdline
1893
1894 call feedkeys(":\"abc\<CR>", 'xt')
1895 call assert_equal("\"abc", @:)
1896 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1897 call assert_equal("\"abc", @:)
1898 call feedkeys("/abc\<CR>", 'xt')
1899 call assert_equal([2, 1], [line('.'), col('.')])
1900 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1901 call assert_equal([2, 1], [line('.'), col('.')])
1902
1903 set imsearch=2
1904 call cursor(1, 1)
1905 call feedkeys("/abc\<CR>", 'xt')
1906 call assert_equal([2, 1], [line('.'), col('.')])
1907 call cursor(1, 1)
1908 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1909 call assert_equal([2, 1], [line('.'), col('.')])
1910 set imdisable
1911 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1912 call assert_equal([2, 1], [line('.'), col('.')])
1913 set imdisable&
1914 set imsearch&
1915
1916 set imcmdline&
1917 %bwipe!
1918endfunc
1919
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001920" Test for using CTRL-_ in the command line with 'allowrevins'
1921func Test_cmdline_revins()
1922 CheckNotMSWindows
1923 CheckFeature rightleft
1924 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1925 call assert_equal("\"abc\<c-_>", @:)
1926 set allowrevins
1927 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1928 call assert_equal('"abcñèæ', @:)
1929 set allowrevins&
1930endfunc
1931
1932" Test for typing UTF-8 composing characters in the command line
1933func Test_cmdline_composing_chars()
1934 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1935 call assert_equal('"ゔ', @:)
1936endfunc
1937
Bram Moolenaar0e717042020-04-27 19:29:01 +02001938" test that ";" works to find a match at the start of the first line
1939func Test_zero_line_search()
1940 new
1941 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1942 call cursor(1,1)
1943 0;/pattern/d
1944 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1945 q!
1946endfunc
1947
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001948func Test_read_shellcmd()
1949 CheckUnix
1950 if executable('ls')
1951 " There should be ls in the $PATH
1952 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1953 call assert_match('^"r! .*\<ls\>', @:)
1954 endif
1955
1956 if executable('rm')
1957 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1958 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
1959 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02001960
1961 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
1962 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
1963 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001964 endif
1965endfunc
1966
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001967" Test for going up and down the directory tree using 'wildmenu'
1968func Test_wildmenu_dirstack()
1969 CheckUnix
1970 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001971 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001972 call writefile([], 'Xwildmenu/file1_1.txt')
1973 call writefile([], 'Xwildmenu/file1_2.txt')
1974 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
1975 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
1976 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
1977 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
1978 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
1979 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001980 set wildmenu
1981
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001982 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001983 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001984 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001985 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001986 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001987 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001988 call assert_equal('"e ../../dir3/', @:)
1989 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
1990 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001991 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001992 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001993 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001994 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001995 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001996 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
1997 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001998
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001999 set wildmenu&
2000endfunc
2001
obcat71c6f7a2021-05-13 20:23:10 +02002002" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002003" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2004" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002005func Test_recalling_cmdline()
2006 CheckFeature cmdline_hist
2007
2008 let g:cmdlines = []
2009 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2010
2011 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002012 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2013 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2014 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2015 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002016 "\ TODO: {'name': 'debug', ...}
2017 \]
2018 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002019 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2020 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2021 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2022 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2023 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002024 \]
2025 let prefix = 'vi'
2026 for h in histories
2027 call histadd(h.name, 'vim')
2028 call histadd(h.name, 'virtue')
2029 call histadd(h.name, 'Virgo')
2030 call histadd(h.name, 'vogue')
2031 call histadd(h.name, 'emacs')
2032 for k in keypairs
2033 let g:cmdlines = []
2034 let keyseqs = h.enter
2035 \ .. prefix
2036 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2037 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2038 \ .. h.exit
2039 call feedkeys(keyseqs, 'xt')
2040 call histdel(h.name, -1) " delete the history added by feedkeys above
2041 let expect = k.prefixmatch
2042 \ ? ['virtue', 'vim', 'virtue', prefix]
2043 \ : ['emacs', 'vogue', 'emacs', prefix]
2044 call assert_equal(expect, g:cmdlines)
2045 endfor
2046 endfor
2047
2048 unlet g:cmdlines
2049 cunmap <Plug>(save-cmdline)
2050endfunc
2051
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002052func Test_cmd_map_cmdlineChanged()
2053 let g:log = []
2054 cnoremap <F1> l<Cmd><CR>s
2055 augroup test
2056 autocmd!
2057 autocmd CmdlineChanged : let g:log += [getcmdline()]
2058 augroup END
2059
2060 call feedkeys(":\<F1>\<CR>", 'xt')
2061 call assert_equal(['l', 'ls'], g:log)
2062
Bram Moolenaar796139a2021-05-18 21:38:45 +02002063 let @b = 'b'
2064 cnoremap <F1> a<C-R>b
2065 let g:log = []
2066 call feedkeys(":\<F1>\<CR>", 'xt')
2067 call assert_equal(['a', 'ab'], g:log)
2068
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002069 unlet g:log
2070 cunmap <F1>
2071 augroup test
2072 autocmd!
2073 augroup END
2074endfunc
2075
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002076" Test for the 'suffixes' option
2077func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002078 call writefile([], 'Xsuffile', 'D')
2079 call writefile([], 'Xsuffile.c', 'D')
2080 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002081 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002082 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2083 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2084 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2085 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002086 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002087 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2088 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2089 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2090 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002091 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002092 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2093 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2094 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2095 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002096 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002097 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002098 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2099 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002100endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002101
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002102" Test for using a popup menu for the command line completion matches
2103" (wildoptions=pum)
2104func Test_wildmenu_pum()
2105 CheckRunVimInTerminal
2106
2107 let commands =<< trim [CODE]
2108 set wildmenu
2109 set wildoptions=pum
2110 set shm+=I
2111 set noruler
2112 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002113
2114 func CmdCompl(a, b, c)
2115 return repeat(['aaaa'], 120)
2116 endfunc
2117 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002118
2119 func MyStatusLine() abort
2120 return 'status'
2121 endfunc
2122 func SetupStatusline()
2123 set statusline=%!MyStatusLine()
2124 set laststatus=2
2125 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002126
2127 func MyTabLine()
2128 return 'my tab line'
2129 endfunc
2130 func SetupTabline()
2131 set statusline=
2132 set tabline=%!MyTabLine()
2133 set showtabline=2
2134 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002135
2136 func DoFeedKeys()
2137 let &wildcharm = char2nr("\t")
2138 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2139 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002140 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002141 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002142
2143 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2144
2145 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002146 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2147
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002148 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002149 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002150 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2151
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002152 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002153 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002154 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2155
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002156 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002157 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002158 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2159
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002160 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002161 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002162 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2163
2164 " pressing <C-E> should end completion and go back to the original match
2165 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002166 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2167
2168 " pressing <C-Y> should select the current match and end completion
2169 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002170 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2171
2172 " With 'wildmode' set to 'longest,full', completing a match should display
2173 " the longest match, the wildmenu should not be displayed.
2174 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2175 call TermWait(buf)
2176 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002177 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2178
2179 " pressing <Tab> should display the wildmenu
2180 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002181 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2182
2183 " pressing <Tab> second time should select the next entry in the menu
2184 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002185 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2186
2187 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002188 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002189 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002190 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2191
2192 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002193 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2194
2195 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002196 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2197
2198 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002199 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002200 call writefile([], 'Xnamedir/XfileA')
2201 call writefile([], 'Xnamedir/XdirA/XfileB')
2202 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002203
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002204 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002205 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2206
2207 " Pressing <Right> on a directory name should go into that directory
2208 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002209 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2210
2211 " Pressing <Left> on a directory name should go to the parent directory
2212 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002213 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2214
2215 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002216 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002217 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002218 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2219
2220 " Pressing <C-D> when the popup menu is displayed should remove the popup
2221 " menu
2222 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002223 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2224
2225 " Pressing <S-Tab> should open the popup menu with the last entry selected
2226 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002227 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2228
2229 " Pressing <Esc> should close the popup menu and cancel the cmd line
2230 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002231 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2232
2233 " Typing a character when the popup is open, should close the popup
2234 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002235 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2236
2237 " When the popup is open, entering the cmdline window should close the popup
2238 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002239 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2240 call term_sendkeys(buf, ":q\<CR>")
2241
2242 " After the last popup menu item, <C-N> should show the original string
2243 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002244 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2245
2246 " Use the popup menu for the command name
2247 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002248 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2249
2250 " Pressing the left arrow should remove the popup menu
2251 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002252 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2253
2254 " Pressing <BS> should remove the popup menu and erase the last character
2255 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002256 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2257
2258 " Pressing <C-W> should remove the popup menu and erase the previous word
2259 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002260 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2261
2262 " Pressing <C-U> should remove the popup menu and erase the entire line
2263 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002264 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2265
2266 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2267 " the cmdline from history
2268 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002269 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2270
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002271 " Check "list" still works
2272 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2273 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002274 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2275 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002276 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2277
rbtnn68cc2b82022-02-09 11:55:47 +00002278 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002279 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002280 call writefile([], 'Xnamedir/あいう/abc')
2281 call writefile([], 'Xnamedir/あいう/xyz')
2282 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002283
2284 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002285 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002286 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2287
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002288 " Pressing <C-A> when the popup menu is displayed should list all the
2289 " matches and pressing a key after that should remove the popup menu
2290 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2291 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2292 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2293
2294 " Pressing <C-A> when the popup menu is displayed should list all the
2295 " matches and pressing <Left> after that should move the cursor
2296 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2297 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2298 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2299
2300 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2301 " should be displayed correctly on the screen.
2302 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2303 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2304
2305 " After using <C-A> to expand all the filename matches, pressing <Up>
2306 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002307 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002308 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2309 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2310 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2311
2312 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2313 " crash Vim
2314 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2315 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2316
Bram Moolenaar414acd32022-02-10 21:09:45 +00002317 " After removing the pum the command line is redrawn
2318 call term_sendkeys(buf, ":edit foo\<CR>")
2319 call term_sendkeys(buf, ":edit bar\<CR>")
2320 call term_sendkeys(buf, ":ls\<CR>")
2321 call term_sendkeys(buf, ":com\<Tab> ")
2322 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002323 call term_sendkeys(buf, "\<C-U>\<CR>")
2324
2325 " Esc still works to abort the command when 'statusline' is set
2326 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2327 call term_sendkeys(buf, ":si\<Tab>")
2328 call term_sendkeys(buf, "\<Esc>")
2329 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002330
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002331 " Esc still works to abort the command when 'tabline' is set
2332 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2333 call term_sendkeys(buf, ":si\<Tab>")
2334 call term_sendkeys(buf, "\<Esc>")
2335 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2336
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002337 " popup is cleared also when 'lazyredraw' is set
2338 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2339 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2340 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2341 call term_sendkeys(buf, "\<Esc>")
2342
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002343 " Pressing <PageDown> should scroll the menu downward
2344 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2345 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2346 call term_sendkeys(buf, "\<PageDown>")
2347 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2348 call term_sendkeys(buf, "\<PageDown>")
2349 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2350 call term_sendkeys(buf, "\<PageDown>")
2351 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2352 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2353 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2354
2355 " Pressing <PageUp> should scroll the menu upward
2356 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2357 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2358 call term_sendkeys(buf, "\<PageUp>")
2359 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2360 call term_sendkeys(buf, "\<PageUp>")
2361 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2362 call term_sendkeys(buf, "\<PageUp>")
2363 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2364
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002365 call term_sendkeys(buf, "\<C-U>\<CR>")
2366 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002367endfunc
2368
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002369" Test for wildmenumode() with the cmdline popup menu
2370func Test_wildmenumode_with_pum()
2371 set wildmenu
2372 set wildoptions=pum
2373 cnoremap <expr> <F2> wildmenumode()
2374 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2375 call assert_equal('"sign define10', @:)
2376 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2377 call assert_equal('"sign define jump list place undefine unplace0', @:)
2378 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2379 call assert_equal('"sign 0', @:)
2380 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2381 call assert_equal('"sign define0', @:)
2382 set nowildmenu wildoptions&
2383 cunmap <F2>
2384endfunc
2385
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002386func Test_wildmenu_with_pum_foldexpr()
2387 CheckRunVimInTerminal
2388
2389 let lines =<< trim END
2390 call setline(1, ['folded one', 'folded two', 'some more text'])
2391 func MyFoldText()
2392 return 'foo'
2393 endfunc
2394 set foldtext=MyFoldText() wildoptions=pum
2395 normal ggzfj
2396 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002397 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002398 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2399 call term_sendkeys(buf, ":set\<Tab>")
2400 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2401
2402 call term_sendkeys(buf, "\<Esc>")
2403 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2404
2405 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002406endfunc
2407
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002408" Test for opening the cmdline completion popup menu from the terminal window.
2409" The popup menu should be positioned correctly over the status line of the
2410" bottom-most window.
2411func Test_wildmenu_pum_from_terminal()
2412 CheckRunVimInTerminal
2413 let python = PythonProg()
2414 call CheckPython(python)
2415
2416 %bw!
2417 let cmds = ['set wildmenu wildoptions=pum']
2418 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2419 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002420 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002421 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2422 call term_sendkeys(buf, "\r\r\r")
2423 call term_wait(buf)
2424 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2425 call term_wait(buf)
2426 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2427 call term_wait(buf)
2428 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002429endfunc
2430
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002431" Test for completion after a :substitute command followed by a pipe (|)
2432" character
2433func Test_cmdline_complete_substitute()
2434 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2435 call assert_equal("\"s | \t", @:)
2436 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2437 call assert_equal("\"s/ | \t", @:)
2438 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2439 call assert_equal("\"s/one | \t", @:)
2440 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2441 call assert_equal("\"s/one/ | \t", @:)
2442 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2443 call assert_equal("\"s/one/two | \t", @:)
2444 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2445 call assert_equal('"s/one/two/ | chistory', @:)
2446 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2447 call assert_equal("\"s/one/two/g \t", @:)
2448 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2449 call assert_equal("\"s/one/two/g | chistory", @:)
2450 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2451 call assert_equal("\"s/one/t\\/ | \t", @:)
2452 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2453 call assert_equal('"s/one/t"o/ | chistory', @:)
2454 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2455 call assert_equal('"s/one/t|o/ | chistory', @:)
2456 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2457 call assert_equal("\"&\t", @:)
2458endfunc
2459
2460" Test for the :dlist command completion
2461func Test_cmdline_complete_dlist()
2462 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2463 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2464 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2465 call assert_equal("\"dlist 10 /pat/ \t", @:)
2466 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2467 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2468 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2469 call assert_equal("\"dlist 10 /pat\\\t", @:)
2470 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2471 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2472endfunc
2473
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002474" argument list (only for :argdel) fuzzy completion
2475func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002476 argadd change.py count.py charge.py
2477 set wildoptions&
2478 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2479 call assert_equal('"argdel cge', @:)
2480 set wildoptions=fuzzy
2481 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2482 call assert_equal('"argdel change.py charge.py', @:)
2483 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002484 set wildoptions&
2485endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002486
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002487" autocmd group name fuzzy completion
2488func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002489 set wildoptions&
2490 augroup MyFuzzyGroup
2491 augroup END
2492 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2493 call assert_equal('"augroup mfg', @:)
2494 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2495 call assert_equal('"augroup MyFuzzyGroup', @:)
2496 set wildoptions=fuzzy
2497 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2498 call assert_equal('"augroup MyFuzzyGroup', @:)
2499 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2500 call assert_equal('"augroup My*p', @:)
2501 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002502 set wildoptions&
2503endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002504
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002505" buffer name fuzzy completion
2506func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002507 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002508 " Use a long name to reduce the risk of matching a random directory name
2509 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002510 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002511 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2512 call assert_equal('"b SRFWL', @:)
2513 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2514 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002515 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002516 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2517 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2518 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2519 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002520 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002521 set wildoptions&
2522endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002523
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002524" buffer name (full path) fuzzy completion
2525func Test_fuzzy_completion_bufname_fullpath()
2526 CheckUnix
2527 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002528 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002529 edit Xcmd/Xstate/Xfile.js
2530 cd Xcmd/Xstate
2531 enew
2532 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2533 call assert_equal('"b CmdStateFile', @:)
2534 set wildoptions=fuzzy
2535 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2536 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2537 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002538 set wildoptions&
2539endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002540
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002541" :behave suboptions fuzzy completion
2542func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002543 set wildoptions&
2544 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2545 call assert_equal('"behave xm', @:)
2546 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2547 call assert_equal('"behave xterm', @:)
2548 set wildoptions=fuzzy
2549 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2550 call assert_equal('"behave xterm', @:)
2551 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2552 call assert_equal('"behave xt*m', @:)
2553 let g:Sline = ''
2554 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2555 call assert_equal('mswin', g:Sline)
2556 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002557 set wildoptions&
2558endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002559
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002560" " colorscheme name fuzzy completion - NOT supported
2561" func Test_fuzzy_completion_colorscheme()
2562" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002563
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002564" built-in command name fuzzy completion
2565func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002566 set wildoptions&
2567 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2568 call assert_equal('"sbwin', @:)
2569 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2570 call assert_equal('"sbrewind', @:)
2571 set wildoptions=fuzzy
2572 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2573 call assert_equal('"sbrewind', @:)
2574 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2575 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002576 set wildoptions&
2577endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002578
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002579" " compiler name fuzzy completion - NOT supported
2580" func Test_fuzzy_completion_compiler()
2581" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002582
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002583" :cscope suboptions fuzzy completion
2584func Test_fuzzy_completion_cscope()
2585 CheckFeature cscope
2586 set wildoptions&
2587 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2588 call assert_equal('"cscope ret', @:)
2589 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2590 call assert_equal('"cscope reset', @:)
2591 set wildoptions=fuzzy
2592 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2593 call assert_equal('"cscope reset', @:)
2594 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2595 call assert_equal('"cscope re*t', @:)
2596 set wildoptions&
2597endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002598
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002599" :diffget/:diffput buffer name fuzzy completion
2600func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002601 new SomeBuffer
2602 diffthis
2603 new OtherBuffer
2604 diffthis
2605 set wildoptions&
2606 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2607 call assert_equal('"diffget sbuf', @:)
2608 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2609 call assert_equal('"diffput sbuf', @:)
2610 set wildoptions=fuzzy
2611 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2612 call assert_equal('"diffget SomeBuffer', @:)
2613 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2614 call assert_equal('"diffput SomeBuffer', @:)
2615 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002616 set wildoptions&
2617endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002618
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002619" " directory name fuzzy completion - NOT supported
2620" func Test_fuzzy_completion_dirname()
2621" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002622
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002623" environment variable name fuzzy completion
2624func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002625 set wildoptions&
2626 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2627 call assert_equal('"echo $VUT', @:)
2628 set wildoptions=fuzzy
2629 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2630 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002631 set wildoptions&
2632endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002633
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002634" autocmd event fuzzy completion
2635func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002636 set wildoptions&
2637 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2638 call assert_equal('"autocmd BWout', @:)
2639 set wildoptions=fuzzy
2640 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2641 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002642 set wildoptions&
2643endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002644
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002645" vim expression fuzzy completion
2646func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002647 let g:PerPlaceCount = 10
2648 set wildoptions&
2649 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2650 call assert_equal('"let c = ppc', @:)
2651 set wildoptions=fuzzy
2652 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2653 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002654 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002655endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002656
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002657" " file name fuzzy completion - NOT supported
2658" func Test_fuzzy_completion_filename()
2659" endfunc
2660
2661" " files in path fuzzy completion - NOT supported
2662" func Test_fuzzy_completion_filesinpath()
2663" endfunc
2664
2665" " filetype name fuzzy completion - NOT supported
2666" func Test_fuzzy_completion_filetype()
2667" endfunc
2668
2669" user defined function name completion
2670func Test_fuzzy_completion_userdefined_func()
2671 set wildoptions&
2672 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2673 call assert_equal('"call Test_f_u_f', @:)
2674 set wildoptions=fuzzy
2675 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2676 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2677 set wildoptions&
2678endfunc
2679
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002680" <SNR> functions should be sorted to the end
2681func Test_fuzzy_completion_userdefined_snr_func()
2682 func s:Sendmail()
2683 endfunc
2684 func SendSomemail()
2685 endfunc
2686 func S1e2n3dmail()
2687 endfunc
2688 set wildoptions=fuzzy
2689 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002690 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002691 set wildoptions&
2692 delfunc s:Sendmail
2693 delfunc SendSomemail
2694 delfunc S1e2n3dmail
2695endfunc
2696
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002697" user defined command name completion
2698func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002699 set wildoptions&
2700 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2701 call assert_equal('"MsFeat', @:)
2702 set wildoptions=fuzzy
2703 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2704 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002705 set wildoptions&
2706endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002707
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002708" " :help tag fuzzy completion - NOT supported
2709" func Test_fuzzy_completion_helptag()
2710" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002711
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002712" highlight group name fuzzy completion
2713func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002714 set wildoptions&
2715 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2716 call assert_equal('"highlight SKey', @:)
2717 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2718 call assert_equal('"highlight SpecialKey', @:)
2719 set wildoptions=fuzzy
2720 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2721 call assert_equal('"highlight SpecialKey', @:)
2722 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2723 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002724 set wildoptions&
2725endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002726
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002727" :history suboptions fuzzy completion
2728func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002729 set wildoptions&
2730 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2731 call assert_equal('"history dg', @:)
2732 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2733 call assert_equal('"history search', @:)
2734 set wildoptions=fuzzy
2735 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2736 call assert_equal('"history debug', @:)
2737 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2738 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002739 set wildoptions&
2740endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002741
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002742" :language locale name fuzzy completion
2743func Test_fuzzy_completion_lang()
2744 CheckUnix
2745 set wildoptions&
2746 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2747 call assert_equal('"lang psx', @:)
2748 set wildoptions=fuzzy
2749 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2750 call assert_equal('"lang POSIX', @:)
2751 set wildoptions&
2752endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002753
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002754" :mapclear buffer argument fuzzy completion
2755func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002756 set wildoptions&
2757 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2758 call assert_equal('"mapclear buf', @:)
2759 set wildoptions=fuzzy
2760 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2761 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002762 set wildoptions&
2763endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002764
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002765" map name fuzzy completion
2766func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002767 " test regex completion works
2768 set wildoptions=fuzzy
2769 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2770 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002771 nmap <plug>MyLongMap :p<CR>
2772 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2773 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2774 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2775 call assert_equal("\"nmap MLM \t", @:)
2776 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2777 call assert_equal("\"nmap <F2> one two \t", @:)
2778 " duplicate entries should be removed
2779 vmap <plug>MyLongMap :<C-U>#<CR>
2780 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2781 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2782 nunmap <plug>MyLongMap
2783 vunmap <plug>MyLongMap
2784 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2785 call assert_equal("\"nmap ABC\t", @:)
2786 " results should be sorted by best match
2787 nmap <Plug>format :
2788 nmap <Plug>goformat :
2789 nmap <Plug>TestFOrmat :
2790 nmap <Plug>fendoff :
2791 nmap <Plug>state :
2792 nmap <Plug>FendingOff :
2793 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2794 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2795 nunmap <Plug>format
2796 nunmap <Plug>goformat
2797 nunmap <Plug>TestFOrmat
2798 nunmap <Plug>fendoff
2799 nunmap <Plug>state
2800 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002801 set wildoptions&
2802endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002803
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002804" abbreviation fuzzy completion
2805func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002806 set wildoptions=fuzzy
2807 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2808 call assert_equal("\"iabbr <nowait>", @:)
2809 iabbr WaitForCompletion WFC
2810 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2811 call assert_equal("\"iabbr WaitForCompletion", @:)
2812 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2813 call assert_equal("\"iabbr a1z\t", @:)
2814 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002815 set wildoptions&
2816endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002817
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002818" menu name fuzzy completion
2819func Test_fuzzy_completion_menu()
2820 CheckGui
2821 set wildoptions&
2822 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2823 call assert_equal('"menu pup', @:)
2824 set wildoptions=fuzzy
2825 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2826 call assert_equal('"menu PopUp.', @:)
2827 set wildoptions&
2828endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002829
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002830" :messages suboptions fuzzy completion
2831func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002832 set wildoptions&
2833 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2834 call assert_equal('"messages clr', @:)
2835 set wildoptions=fuzzy
2836 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2837 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002838 set wildoptions&
2839endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002840
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002841" :set option name fuzzy completion
2842func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002843 set wildoptions&
2844 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2845 call assert_equal('"set brkopt', @:)
2846 set wildoptions=fuzzy
2847 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2848 call assert_equal('"set breakindentopt', @:)
2849 set wildoptions&
2850 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2851 call assert_equal('"set fixendofline', @:)
2852 set wildoptions=fuzzy
2853 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2854 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002855 set wildoptions&
2856endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002857
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002858" :set <term_option>
2859func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002860 set wildoptions&
2861 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2862 call assert_equal('"set t_EC', @:)
2863 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2864 call assert_equal('"set <t_EC>', @:)
2865 set wildoptions=fuzzy
2866 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2867 call assert_equal('"set t_EC', @:)
2868 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2869 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002870 set wildoptions&
2871endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002872
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002873" " :packadd directory name fuzzy completion - NOT supported
2874" func Test_fuzzy_completion_packadd()
2875" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002876
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002877" " shell command name fuzzy completion - NOT supported
2878" func Test_fuzzy_completion_shellcmd()
2879" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002880
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002881" :sign suboptions fuzzy completion
2882func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002883 set wildoptions&
2884 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2885 call assert_equal('"sign ufe', @:)
2886 set wildoptions=fuzzy
2887 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2888 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002889 set wildoptions&
2890endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002891
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002892" :syntax suboptions fuzzy completion
2893func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002894 set wildoptions&
2895 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2896 call assert_equal('"syntax kwd', @:)
2897 set wildoptions=fuzzy
2898 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2899 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002900 set wildoptions&
2901endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002902
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002903" syntax group name fuzzy completion
2904func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002905 set wildoptions&
2906 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2907 call assert_equal('"syntax list mpar', @:)
2908 set wildoptions=fuzzy
2909 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2910 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002911 set wildoptions&
2912endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002913
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002914" :syntime suboptions fuzzy completion
2915func Test_fuzzy_completion_syntime()
2916 CheckFeature profile
2917 set wildoptions&
2918 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2919 call assert_equal('"syntime clr', @:)
2920 set wildoptions=fuzzy
2921 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2922 call assert_equal('"syntime clear', @:)
2923 set wildoptions&
2924endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002925
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002926" " tag name fuzzy completion - NOT supported
2927" func Test_fuzzy_completion_tagname()
2928" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002929
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002930" " tag name and file fuzzy completion - NOT supported
2931" func Test_fuzzy_completion_tagfile()
2932" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002933
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002934" " user names fuzzy completion - how to test this functionality?
2935" func Test_fuzzy_completion_username()
2936" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002937
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002938" user defined variable name fuzzy completion
2939func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002940 let g:SomeVariable=10
2941 set wildoptions&
2942 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2943 call assert_equal('"let SVar', @:)
2944 set wildoptions=fuzzy
2945 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2946 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002947 set wildoptions&
2948endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002949
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002950" Test for sorting the results by the best match
2951func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002952 %bw!
2953 command T123format :
2954 command T123goformat :
2955 command T123TestFOrmat :
2956 command T123fendoff :
2957 command T123state :
2958 command T123FendingOff :
2959 set wildoptions=fuzzy
2960 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
2961 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
2962 delcommand T123format
2963 delcommand T123goformat
2964 delcommand T123TestFOrmat
2965 delcommand T123fendoff
2966 delcommand T123state
2967 delcommand T123FendingOff
2968 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002969 set wildoptions&
2970endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002971
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002972" Test for fuzzy completion of a command with lower case letters and a number
2973func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002974 command Foo2Bar :
2975 set wildoptions=fuzzy
2976 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
2977 call assert_equal('"Foo2Bar', @:)
2978 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
2979 call assert_equal('"Foo2Bar', @:)
2980 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
2981 call assert_equal('"Foo2Bar', @:)
2982 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002983 set wildoptions&
2984endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002985
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002986" Test for command completion for a command starting with 'k'
2987func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002988 command KillKillKill :
2989 set wildoptions&
2990 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2991 call assert_equal("\"killkill\<Tab>", @:)
2992 set wildoptions=fuzzy
2993 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2994 call assert_equal('"KillKillKill', @:)
2995 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002996 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002997endfunc
2998
2999" Test for fuzzy completion for user defined custom completion function
3000func Test_fuzzy_completion_custom_func()
3001 func Tcompl(a, c, p)
3002 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3003 endfunc
3004 command -nargs=* -complete=custom,Tcompl Fuzzy :
3005 set wildoptions&
3006 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3007 call assert_equal("\"Fuzzy format", @:)
3008 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3009 call assert_equal("\"Fuzzy xy", @:)
3010 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3011 call assert_equal("\"Fuzzy ttt", @:)
3012 set wildoptions=fuzzy
3013 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3014 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3015 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3016 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3017 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3018 call assert_equal("\"Fuzzy xy", @:)
3019 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3020 call assert_equal("\"Fuzzy TestFOrmat", @:)
3021 delcom Fuzzy
3022 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003023endfunc
3024
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003025" Test for :breakadd argument completion
3026func Test_cmdline_complete_breakadd()
3027 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3028 call assert_equal("\"breakadd expr file func here", @:)
3029 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3030 call assert_equal("\"breakadd expr", @:)
3031 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3032 call assert_equal("\"breakadd expr", @:)
3033 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3034 call assert_equal("\"breakadd here", @:)
3035 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3036 call assert_equal("\"breakadd here", @:)
3037 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3038 call assert_equal("\"breakadd abc", @:)
3039 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3040 let l = getcompletion('not', 'breakpoint')
3041 call assert_equal([], l)
3042
3043 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003044 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003045 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3046 call assert_equal("\"breakadd file Xscript", @:)
3047 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3048 call assert_equal("\"breakadd file Xscript", @:)
3049 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3050 call assert_equal("\"breakadd file 20 Xscript", @:)
3051 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3052 call assert_equal("\"breakadd file 20 Xscript", @:)
3053 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3054 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3055 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3056 call assert_equal("\"breakadd file 20\t", @:)
3057 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3058 call assert_equal("\"breakadd file 20x\t", @:)
3059 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3060 call assert_equal("\"breakadd file Xscript ", @:)
3061 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3062 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003063
3064 " Test for :breakadd func [lnum] <function>
3065 func Xbreak_func()
3066 endfunc
3067 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3068 call assert_equal("\"breakadd func Xbreak_func", @:)
3069 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3070 call assert_equal("\"breakadd func Xbreak_func", @:)
3071 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3072 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3073 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3074 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3075 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3076 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3077 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3078 call assert_equal("\"breakadd func 20\t", @:)
3079 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3080 call assert_equal("\"breakadd func 20x\t", @:)
3081 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3082 call assert_equal("\"breakadd func Xbreak_func ", @:)
3083 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3084 call assert_equal("\"breakadd func X1B2C3", @:)
3085 delfunc Xbreak_func
3086
3087 " Test for :breakadd expr <expression>
3088 let g:Xtest_var = 10
3089 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3090 call assert_equal("\"breakadd expr Xtest_var", @:)
3091 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3092 call assert_equal("\"breakadd expr Xtest_var", @:)
3093 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3094 call assert_equal("\"breakadd expr Xtest_var ", @:)
3095 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3096 call assert_equal("\"breakadd expr X1B2C3", @:)
3097 unlet g:Xtest_var
3098
3099 " Test for :breakadd here
3100 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3101 call assert_equal("\"breakadd here Xtest", @:)
3102 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3103 call assert_equal("\"breakadd here Xtest", @:)
3104 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3105 call assert_equal("\"breakadd here ", @:)
3106endfunc
3107
3108" Test for :breakdel argument completion
3109func Test_cmdline_complete_breakdel()
3110 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3111 call assert_equal("\"breakdel file func here", @:)
3112 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3113 call assert_equal("\"breakdel file", @:)
3114 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3115 call assert_equal("\"breakdel file", @:)
3116 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3117 call assert_equal("\"breakdel here", @:)
3118 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3119 call assert_equal("\"breakdel here", @:)
3120 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal("\"breakdel abc", @:)
3122
3123 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003124 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003125 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3126 call assert_equal("\"breakdel file Xscript", @:)
3127 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3128 call assert_equal("\"breakdel file Xscript", @:)
3129 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3130 call assert_equal("\"breakdel file 20 Xscript", @:)
3131 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3132 call assert_equal("\"breakdel file 20 Xscript", @:)
3133 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3134 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3135 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3136 call assert_equal("\"breakdel file 20\t", @:)
3137 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal("\"breakdel file 20x\t", @:)
3139 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal("\"breakdel file Xscript ", @:)
3141 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003143
3144 " Test for :breakdel func [lnum] <function>
3145 func Xbreak_func()
3146 endfunc
3147 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3148 call assert_equal("\"breakdel func Xbreak_func", @:)
3149 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3150 call assert_equal("\"breakdel func Xbreak_func", @:)
3151 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3153 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3154 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3155 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3156 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3157 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal("\"breakdel func 20\t", @:)
3159 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3160 call assert_equal("\"breakdel func 20x\t", @:)
3161 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3162 call assert_equal("\"breakdel func Xbreak_func ", @:)
3163 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3164 call assert_equal("\"breakdel func X1B2C3", @:)
3165 delfunc Xbreak_func
3166
3167 " Test for :breakdel here
3168 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3169 call assert_equal("\"breakdel here Xtest", @:)
3170 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3171 call assert_equal("\"breakdel here Xtest", @:)
3172 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3173 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003174endfunc
3175
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003176" Test for :scriptnames argument completion
3177func Test_cmdline_complete_scriptnames()
3178 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003179 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003180 source Xa1b2c3.vim
3181 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3182 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3183 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3184 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3185 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3186 call assert_equal("\"script b2c3", @:)
3187 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3188 call assert_match("\"script 2\<Tab>$", @:)
3189 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3190 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3191 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3192 call assert_equal("\"script ", @:)
3193 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3194 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3195 new
3196 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3197 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3198 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003199 set wildmenu&
3200endfunc
3201
Bram Moolenaard8893442022-05-06 20:38:47 +01003202" this was going over the end of IObuff
3203func Test_report_error_with_composing()
3204 let caught = 'no'
3205 try
3206 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3207 catch /E492:/
3208 let caught = 'yes'
3209 endtry
3210 call assert_equal('yes', caught)
3211endfunc
3212
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003213" Test for expanding 2-letter and 3-letter :substitute command arguments.
3214" These commands don't accept an argument.
3215func Test_cmdline_complete_substitute_short()
3216 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3217 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3218 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3219 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3220 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3221 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3223 endfor
3224endfunc
3225
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003226" Test for :! shell command argument completion
3227func Test_cmdline_complete_bang_cmd_argument()
3228 set wildoptions=fuzzy
3229 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3230 call assert_equal('"!vim test_cmdline.vim', @:)
3231 set wildoptions&
3232 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3233 call assert_equal('"!vim test_cmdline.vim', @:)
3234endfunc
3235
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003236func Check_completion()
3237 call assert_equal('let a', getcmdline())
3238 call assert_equal(6, getcmdpos())
3239 call assert_equal(7, getcmdscreenpos())
3240 call assert_equal('var', getcmdcompltype())
3241 return ''
3242endfunc
3243
3244func Test_screenpos_and_completion()
3245 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3246endfunc
3247
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003248func Test_recursive_register()
3249 let @= = ''
3250 silent! ?e/
3251 let caught = 'no'
3252 try
3253 normal //
3254 catch /E169:/
3255 let caught = 'yes'
3256 endtry
3257 call assert_equal('yes', caught)
3258endfunc
3259
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003260func Test_long_error_message()
3261 " the error should be truncated, not overrun IObuff
3262 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3263endfunc
3264
zeertzjq6791adc2022-07-26 20:42:25 +01003265func Test_cmdline_redraw_tabline()
3266 CheckRunVimInTerminal
3267
3268 let lines =<< trim END
3269 set showtabline=2
3270 autocmd CmdlineEnter * set tabline=foo
3271 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003272 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003273 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3274 call term_sendkeys(buf, ':')
3275 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3276
3277 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003278endfunc
3279
zeertzjqb82a2ab2022-08-21 14:33:57 +01003280func Test_wildmenu_pum_disable_while_shown()
3281 set wildoptions=pum
3282 set wildmenu
3283 cnoremap <F2> <Cmd>set nowildmenu<CR>
3284 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3285 call assert_equal(0, pumvisible())
3286 cunmap <F2>
3287 set wildoptions& wildmenu&
3288endfunc
3289
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003290func Test_setcmdline()
3291 func SetText(text, pos)
zeertzjq54acb902022-08-29 16:21:25 +01003292 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003293 call assert_equal(0, setcmdline(a:text))
3294 call assert_equal(a:text, getcmdline())
3295 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003296 call assert_equal(getcmdtype(), g:cmdtype)
3297 unlet g:cmdtype
3298 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003299
3300 call assert_equal(0, setcmdline(a:text, a:pos))
3301 call assert_equal(a:text, getcmdline())
3302 call assert_equal(a:pos, getcmdpos())
3303
3304 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003305 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3306 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003307
3308 return ''
3309 endfunc
3310
3311 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3312 call assert_equal('set rtp?', @:)
3313
zeertzjq54acb902022-08-29 16:21:25 +01003314 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3315 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3316 call assert_equal('foo', g:str)
3317 unlet g:str
3318
3319 delfunc SetText
3320
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003321 " setcmdline() returns 1 when not editing the command line.
3322 call assert_equal(1, 'foo'->setcmdline())
3323
3324 " Called in custom function
3325 func CustomComplete(A, L, P)
3326 call assert_equal(0, setcmdline("DoCmd "))
3327 return "January\nFebruary\nMars\n"
3328 endfunc
3329
3330 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3331 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3332 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003333 delcom DoCmd
3334 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003335
3336 " Called in <expr>
3337 cnoremap <expr>a setcmdline('let foo=')
3338 call feedkeys(":a\<CR>", 'tx')
3339 call assert_equal('let foo=0', @:)
3340 cunmap a
3341endfunc
3342
Bram Moolenaar309976e2019-12-05 18:16:33 +01003343" vim: shiftwidth=2 sts=2 expandtab