blob: 6b2850a0273960d20e08774c41bb839e800237a3 [file] [log] [blame]
Bram Moolenaar2d295012022-07-02 16:29:34 +01001" Tests for editing the command line.
2
Christian Brabandteb380b92025-07-07 20:53:55 +02003source util/screendump.vim
Bram Moolenaar2d295012022-07-02 16:29:34 +01004
5func Test_getcmdwintype()
6 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
7 call assert_equal('/', a)
8
9 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
10 call assert_equal('?', a)
11
12 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
13 call assert_equal(':', a)
14
15 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
16 call assert_equal(':', a)
17
18 call assert_equal('', getcmdwintype())
19endfunc
20
21func Test_getcmdwin_autocmd()
22 let s:seq = []
23 augroup CmdWin
24 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
25 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
26 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
27 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
28 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
29 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
30
31 let org_winid = win_getid()
32 let org_bufnr = bufnr()
33 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
34 call assert_equal(':', a)
35 call assert_equal([
36 \ 'WinLeave ' .. org_winid,
37 \ 'WinEnter ' .. s:cmd_winid,
38 \ 'BufLeave ' .. org_bufnr,
39 \ 'BufEnter ' .. s:cmd_bufnr,
40 \ 'CmdWinEnter ' .. s:cmd_winid,
41 \ 'CmdWinLeave ' .. s:cmd_winid,
42 \ 'BufLeave ' .. s:cmd_bufnr,
43 \ 'WinLeave ' .. s:cmd_winid,
44 \ 'WinEnter ' .. org_winid,
45 \ 'BufEnter ' .. org_bufnr,
46 \ ], s:seq)
47
48 au!
49 augroup END
50endfunc
51
52func Test_cmdwin_bug()
53 let winid = win_getid()
54 sp
55 try
56 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
57 catch /^Vim\%((\a\+)\)\=:E11/
58 endtry
59 bw!
60endfunc
61
62func Test_cmdwin_restore()
63 CheckScreendump
64
65 let lines =<< trim [SCRIPT]
66 augroup vimHints | au! | augroup END
67 call setline(1, range(30))
68 2split
69 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010070 call writefile(lines, 'XTest_restore', 'D')
Bram Moolenaar2d295012022-07-02 16:29:34 +010071
72 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar2d295012022-07-02 16:29:34 +010073 call term_sendkeys(buf, "q:")
74 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
75
76 " normal restore
77 call term_sendkeys(buf, ":q\<CR>")
78 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
79
80 " restore after setting 'lines' with one window
81 call term_sendkeys(buf, ":close\<CR>")
82 call term_sendkeys(buf, "q:")
83 call term_sendkeys(buf, ":set lines=18\<CR>")
84 call term_sendkeys(buf, ":q\<CR>")
85 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
86
87 " clean up
88 call StopVimInTerminal(buf)
Bram Moolenaar2d295012022-07-02 16:29:34 +010089endfunc
90
91func Test_cmdwin_no_terminal()
Bram Moolenaarb2f0ca82022-09-18 15:08:19 +010092 CheckScreendump
Bram Moolenaar2d295012022-07-02 16:29:34 +010093
94 let buf = RunVimInTerminal('', {'rows': 12})
Bram Moolenaar2d295012022-07-02 16:29:34 +010095 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
96 call term_sendkeys(buf, "q:")
97 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
98 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
99 call term_sendkeys(buf, ":q\<CR>")
100 call StopVimInTerminal(buf)
101endfunc
102
Bram Moolenaarb2f0ca82022-09-18 15:08:19 +0100103func Test_cmdwin_wrong_command()
104 CheckScreendump
105
106 let buf = RunVimInTerminal('', {'rows': 12})
107 call term_sendkeys(buf, "q:")
108 call term_sendkeys(buf, "als\<Esc>")
109 call term_sendkeys(buf, "\<C-W>k")
110 call VerifyScreenDump(buf, 'Test_cmdwin_wrong_command_1', {})
111
112 call term_sendkeys(buf, "\<C-C>")
113 call VerifyScreenDump(buf, 'Test_cmdwin_wrong_command_2', {})
114
115 call term_sendkeys(buf, ":q\<CR>")
116 call StopVimInTerminal(buf)
117endfunc
118
Bram Moolenaar2d295012022-07-02 16:29:34 +0100119func Test_cmdwin_feedkeys()
120 " This should not generate E488
121 call feedkeys("q:\<CR>", 'x')
122 " Using feedkeys with q: only should automatically close the cmd window
123 call feedkeys('q:', 'xt')
124 call assert_equal(1, winnr('$'))
125 call assert_equal('', getcmdwintype())
126endfunc
127
128" Tests for the issues fixed in 7.4.441.
129" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
130func Test_cmdwin_cedit()
131 exe "set cedit=\<C-c>"
132 normal! :
133 call assert_equal(1, winnr('$'))
134
135 let g:cmd_wintype = ''
136 func CmdWinType()
137 let g:cmd_wintype = getcmdwintype()
138 let g:wintype = win_gettype()
139 return ''
140 endfunc
141
142 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
143 echo input('')
144 call assert_equal('@', g:cmd_wintype)
145 call assert_equal('command', g:wintype)
146
147 set cedit&vim
148 delfunc CmdWinType
149endfunc
150
151" Test for CmdwinEnter autocmd
152func Test_cmdwin_autocmd()
153 augroup CmdWin
154 au!
155 autocmd BufLeave * if &buftype == '' | update | endif
156 autocmd CmdwinEnter * startinsert
157 augroup END
158
159 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
160 call assert_equal('xyz', @:)
161
162 augroup CmdWin
163 au!
164 augroup END
165 augroup! CmdWin
166endfunc
167
168func Test_cmdwin_jump_to_win()
169 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
170 new
171 set modified
172 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
173 close!
174 call feedkeys("q/:close\<CR>", "xt")
175 call assert_equal(1, winnr('$'))
176 call feedkeys("q/:exit\<CR>", "xt")
177 call assert_equal(1, winnr('$'))
178
179 " opening command window twice should fail
180 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
181 call assert_equal(1, winnr('$'))
182endfunc
183
184func Test_cmdwin_tabpage()
185 tabedit
186 call assert_fails("silent norm q/g :I\<Esc>", 'E11:')
187 tabclose!
188endfunc
189
Sean Dewar43b395e2023-08-16 16:17:31 +0100190func Test_cmdwin_interrupted_more_prompt()
Bram Moolenaar2d295012022-07-02 16:29:34 +0100191 CheckScreendump
192
193 " aborting the :smile output caused the cmdline window to use the current
194 " buffer.
195 let lines =<< trim [SCRIPT]
196 au WinNew * smile
197 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100198 call writefile(lines, 'XTest_cmdwin', 'D')
Bram Moolenaar2d295012022-07-02 16:29:34 +0100199
200 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
201 " open cmdwin
202 call term_sendkeys(buf, "q:")
203 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
204 " quit more prompt for :smile command
205 call term_sendkeys(buf, "q")
206 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
207 " execute a simple command
208 call term_sendkeys(buf, "aecho 'done'\<CR>")
209 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
210
211 " clean up
212 call StopVimInTerminal(buf)
Bram Moolenaar2d295012022-07-02 16:29:34 +0100213endfunc
214
215" Test for recursively getting multiple command line inputs
216func Test_cmdwin_multi_input()
217 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
218 call assert_equal('"cyan', @:)
219endfunc
220
221" Test for normal mode commands not supported in the cmd window
222func Test_cmdwin_blocked_commands()
223 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
224 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
225 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
226 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
227 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
228 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
229 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
230 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
231 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
232 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
233 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
234 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
235 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
236 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
237 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
238 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
239 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
240 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
241 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
242 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
243 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
244 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
245 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
246 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
247 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
248 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
249 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
250endfunc
251
252" Close the Cmd-line window in insert mode using CTRL-C
253func Test_cmdwin_insert_mode_close()
254 %bw!
255 let s = ''
256 exe "normal q:a\<C-C>let s='Hello'\<CR>"
257 call assert_equal('Hello', s)
258 call assert_equal(1, winnr('$'))
259endfunc
260
261func Test_cmdwin_ex_mode_with_modifier()
262 " this was accessing memory after allocated text in Ex mode
263 new
264 call setline(1, ['some', 'text', 'lines'])
265 silent! call feedkeys("gQnormal vq:atopleft\<C-V>\<CR>\<CR>", 'xt')
266 bwipe!
267endfunc
268
269func s:ComplInCmdwin_GlobalCompletion(a, l, p)
270 return 'global'
271endfunc
272
273func s:ComplInCmdwin_LocalCompletion(a, l, p)
274 return 'local'
275endfunc
276
277func Test_compl_in_cmdwin()
278 set wildmenu wildchar=<Tab>
279 com! -nargs=1 -complete=command GetInput let input = <q-args>
280 com! -buffer TestCommand echo 'TestCommand'
281 let w:test_winvar = 'winvar'
282 let b:test_bufvar = 'bufvar'
283
284 " User-defined commands
285 let input = ''
286 call feedkeys("q:iGetInput T\<C-x>\<C-v>\<CR>", 'tx!')
287 call assert_equal('TestCommand', input)
288
289 let input = ''
290 call feedkeys("q::GetInput T\<Tab>\<CR>:q\<CR>", 'tx!')
291 call assert_equal('T', input)
292
293
294 com! -nargs=1 -complete=var GetInput let input = <q-args>
295 " Window-local variables
296 let input = ''
297 call feedkeys("q:iGetInput w:test_\<C-x>\<C-v>\<CR>", 'tx!')
298 call assert_equal('w:test_winvar', input)
299
300 let input = ''
301 call feedkeys("q::GetInput w:test_\<Tab>\<CR>:q\<CR>", 'tx!')
302 call assert_equal('w:test_', input)
303
304 " Buffer-local variables
305 let input = ''
306 call feedkeys("q:iGetInput b:test_\<C-x>\<C-v>\<CR>", 'tx!')
307 call assert_equal('b:test_bufvar', input)
308
309 let input = ''
310 call feedkeys("q::GetInput b:test_\<Tab>\<CR>:q\<CR>", 'tx!')
311 call assert_equal('b:test_', input)
312
313
314 " Argument completion of buffer-local command
315 func s:ComplInCmdwin_GlobalCompletionList(a, l, p)
316 return ['global']
317 endfunc
318
319 func s:ComplInCmdwin_LocalCompletionList(a, l, p)
320 return ['local']
321 endfunc
322
323 func s:ComplInCmdwin_CheckCompletion(arg)
324 call assert_equal('local', a:arg)
325 endfunc
326
327 com! -nargs=1 -complete=custom,<SID>ComplInCmdwin_GlobalCompletion
328 \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
329 com! -buffer -nargs=1 -complete=custom,<SID>ComplInCmdwin_LocalCompletion
330 \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
331 call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
332
333 com! -nargs=1 -complete=customlist,<SID>ComplInCmdwin_GlobalCompletionList
334 \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
335 com! -buffer -nargs=1 -complete=customlist,<SID>ComplInCmdwin_LocalCompletionList
336 \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
337
338 call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
339
340 func! s:ComplInCmdwin_CheckCompletion(arg)
341 call assert_equal('global', a:arg)
342 endfunc
343 new
344 call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
345 quit
346
347 delfunc s:ComplInCmdwin_GlobalCompletion
348 delfunc s:ComplInCmdwin_LocalCompletion
349 delfunc s:ComplInCmdwin_GlobalCompletionList
350 delfunc s:ComplInCmdwin_LocalCompletionList
351 delfunc s:ComplInCmdwin_CheckCompletion
352
353 delcom -buffer TestCommand
354 delcom TestCommand
355 delcom GetInput
356 unlet w:test_winvar
357 unlet b:test_bufvar
358 set wildmenu& wildchar&
359endfunc
360
Bram Moolenaar81f277f2023-05-13 13:55:09 +0100361func Test_cmdwin_cmd_completion()
362 set wildmenu wildchar=<Tab>
363 com! -nargs=* -complete=command SomeOne echo 'one'
364 com! -nargs=* -complete=command SomeTwo echo 'two'
365 call feedkeys("q:aSome\<Tab>\<Home>\"\<CR>", 'tx')
366 call assert_equal('"SomeOne', @:)
367 call feedkeys("q:aSome\<Tab>\<Tab>\<Home>\"\<CR>", 'tx')
368 call assert_equal('"SomeTwo', @:)
369 call feedkeys("q:aSome\<Tab>\<Tab>\<S-Tab>\<Home>\"\<CR>", 'tx')
370 call assert_equal('"SomeOne', @:)
371
372 delcom SomeOne
373 delcom SomeTwo
374 set wildmenu& wildchar&
375endfunc
376
Bram Moolenaar2d295012022-07-02 16:29:34 +0100377func Test_cmdwin_ctrl_bsl()
378 " Using CTRL-\ CTRL-N in cmd window should close the window
379 call feedkeys("q:\<C-\>\<C-N>", 'xt')
380 call assert_equal('', getcmdwintype())
381endfunc
382
Bram Moolenaarc963ec32022-07-24 20:08:01 +0100383func Test_cant_open_cmdwin_in_cmdwin()
384 try
385 call feedkeys("q:q::q\<CR>", "x!")
386 catch
387 let caught = v:exception
388 endtry
389 call assert_match('E1292:', caught)
390endfunc
391
Bram Moolenaare98c88c2022-08-16 14:51:53 +0100392func Test_cmdwin_virtual_edit()
393 enew!
394 set ve=all cpo+=$
395 silent normal q/s
396
397 set ve= cpo-=$
398endfunc
399
Bram Moolenaar3a7ad902022-08-23 19:54:27 +0100400" Check that a :normal command can be used to stop Visual mode without side
401" effects.
402func Test_normal_escape()
403 call feedkeys("q:i\" foo\<Esc>:normal! \<C-V>\<Esc>\<CR>:\" bar\<CR>", 'ntx')
404 call assert_equal('" bar', @:)
405endfunc
406
Bram Moolenaar1c3dd8d2022-09-17 19:43:23 +0100407" This was using a pointer to a freed buffer
408func Test_cmdwin_freed_buffer_ptr()
Bram Moolenaar312af652022-09-17 21:20:42 +0100409 " this does not work on MS-Windows because renaming an open file fails
410 CheckNotMSWindows
411
Bram Moolenaar1c3dd8d2022-09-17 19:43:23 +0100412 au BufEnter * next 0| file
413 edit 0
414 silent! norm q/
415
416 au! BufEnter
417 bwipe!
418endfunc
419
Bram Moolenaar8279af52022-09-26 23:08:22 +0100420" This was resulting in a window with negative width.
421" The test doesn't reproduce the illegal memory access though...
422func Test_cmdwin_split_often()
423 let lines = &lines
424 let columns = &columns
425 set t_WS=
426
427 try
428 set encoding=iso8859
429 set ruler
430 winsize 0 0
431 noremap 0 H
432 sil norm 0000000q:
433 catch /E36:/
434 endtry
435
436 bwipe!
437 set encoding=utf8
438 let &lines = lines
439 let &columns = columns
440endfunc
441
Sean Dewar876f5fb2023-08-17 22:40:05 +0200442func Test_cmdwin_restore_heights()
443 set showtabline=0 cmdheight=2 laststatus=0
444 call feedkeys("q::set cmdheight=1\<CR>:q\<CR>", 'ntx')
445 call assert_equal(&lines - 1, winheight(0))
446
447 set showtabline=2 cmdheight=3
448 call feedkeys("q::set showtabline=0\<CR>:q\<CR>", 'ntx')
449 call assert_equal(&lines - 3, winheight(0))
450
451 set cmdheight=1 laststatus=2
452 call feedkeys("q::set laststatus=0\<CR>:q\<CR>", 'ntx')
453 call assert_equal(&lines - 1, winheight(0))
454
455 set laststatus=2
456 call feedkeys("q::set laststatus=1\<CR>:q\<CR>", 'ntx')
457 call assert_equal(&lines - 1, winheight(0))
458
459 set laststatus=2
460 belowright vsplit
461 wincmd _
462 let restcmds = winrestcmd()
463 call feedkeys("q::set laststatus=1\<CR>:q\<CR>", 'ntx')
464 " As we have 2 windows, &ls = 1 should still have a statusline on the last
465 " window. As such, the number of available rows hasn't changed and the window
466 " sizes should be restored.
467 call assert_equal(restcmds, winrestcmd())
468
469 set cmdheight& showtabline& laststatus&
470endfunc
Bram Moolenaar2d295012022-07-02 16:29:34 +0100471
Sean Dewar988f7432023-08-16 14:17:36 +0100472func Test_cmdwin_temp_curwin()
473 func CheckWraps(expect_wrap)
474 setlocal textwidth=0 wrapmargin=1
475
476 call deletebufline('', 1, '$')
477 let as = repeat('a', winwidth(0) - 2 - &wrapmargin)
478 call setline(1, as .. ' b')
479 normal! gww
480
481 setlocal textwidth& wrapmargin&
482 call assert_equal(a:expect_wrap ? [as, 'b'] : [as .. ' b'], getline(1, '$'))
483 endfunc
484
485 func CheckCmdWin()
486 call assert_equal('command', win_gettype())
487 " textoff and &wrapmargin formatting considers the cmdwin_type char.
488 call assert_equal(1, getwininfo(win_getid())[0].textoff)
489 call CheckWraps(1)
490 endfunc
491
492 func CheckOtherWin()
493 call assert_equal('', win_gettype())
494 call assert_equal(0, getwininfo(win_getid())[0].textoff)
495 call CheckWraps(0)
496 endfunc
497
498 call feedkeys("q::call CheckCmdWin()\<CR>:call win_execute(win_getid(winnr('#')), 'call CheckOtherWin()')\<CR>:q<CR>", 'ntx')
499
Sean Dewar43b395e2023-08-16 16:17:31 +0100500 %bwipe!
Sean Dewar988f7432023-08-16 14:17:36 +0100501 delfunc CheckWraps
502 delfunc CheckCmdWin
503 delfunc CheckOtherWin
504endfunc
505
Sean Dewar43b395e2023-08-16 16:17:31 +0100506func Test_cmdwin_interrupted()
507 func CheckInterrupted()
508 call feedkeys("q::call assert_equal('', getcmdwintype())\<CR>:call assert_equal('', getcmdtype())\<CR>:q<CR>", 'ntx')
509 endfunc
510
511 augroup CmdWin
512
513 " While opening the cmdwin's split:
514 " Close the cmdwin's window.
515 au WinEnter * ++once quit
516 call CheckInterrupted()
517
518 " Close the old window.
519 au WinEnter * ++once execute winnr('#') 'quit'
520 call CheckInterrupted()
521
522 " Switch back to the old window.
523 au WinEnter * ++once wincmd p
524 call CheckInterrupted()
525
526 " Change the old window's buffer.
527 au WinEnter * ++once call win_execute(win_getid(winnr('#')), 'enew')
528 call CheckInterrupted()
529
530 " Using BufLeave autocmds as cmdwin restrictions do not apply to them when
531 " fired from opening the cmdwin...
532 " After opening the cmdwin's split, while creating the cmdwin's buffer:
533 " Delete the cmdwin's buffer.
534 au BufLeave * ++once bwipe
535 call CheckInterrupted()
536
537 " Close the cmdwin's window.
538 au BufLeave * ++once quit
539 call CheckInterrupted()
540
541 " Close the old window.
542 au BufLeave * ++once execute winnr('#') 'quit'
543 call CheckInterrupted()
544
545 " Switch to a different window.
546 au BufLeave * ++once split
547 call CheckInterrupted()
548
549 " Change the old window's buffer.
550 au BufLeave * ++once call win_execute(win_getid(winnr('#')), 'enew')
551 call CheckInterrupted()
552
553 " However, changing the current buffer is OK and does not interrupt.
554 au BufLeave * ++once edit other
555 call feedkeys("q::let t=getcmdwintype()\<CR>:let b=bufnr()\<CR>:clo<CR>", 'ntx')
556 call assert_equal(':', t)
557 call assert_equal(1, bufloaded('other'))
558 call assert_notequal(b, bufnr('other'))
559
560 augroup END
561
562 " No autocmds should remain, but clear the augroup to be sure.
563 augroup CmdWin
564 au!
565 augroup END
566
567 %bwipe!
568 delfunc CheckInterrupted
569endfunc
570
Sean Dewar1fb41032023-08-16 17:15:05 +0100571func Test_cmdwin_existing_bufname()
572 func CheckName()
573 call assert_equal(1, getbufinfo('')[0].command)
574 call assert_equal(0, getbufinfo('[Command Line]')[0].command)
575 call assert_match('#a\s*"\[Command Line\]"', execute('ls'))
576 call assert_match('%a\s*"\[Command Line\]"', execute('ls'))
577 endfunc
578
579 file [Command Line]
580 call feedkeys("q::call CheckName()\<CR>:q\<CR>", 'ntx')
581 0file
582 delfunc CheckName
583endfunc
584
Bram Moolenaar2d295012022-07-02 16:29:34 +0100585" vim: shiftwidth=2 sts=2 expandtab