diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2024-01-28 13:03:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-28 13:03:56 +0000 |
commit | a757195a602bf502fcdb702887bf72f50d6e1717 (patch) | |
tree | 41f77c24ddfb88b82eaf1c6a5748036276eea2f9 /test | |
parent | 74e695d22715e52f5561a185583b8c23d4fa0dd6 (diff) | |
parent | d85f180f26c0570c2510c899a0bf0023ec55a692 (diff) | |
download | rneovim-a757195a602bf502fcdb702887bf72f50d6e1717.tar.gz rneovim-a757195a602bf502fcdb702887bf72f50d6e1717.tar.bz2 rneovim-a757195a602bf502fcdb702887bf72f50d6e1717.zip |
Merge pull request #24704 from seandewar/cmdwin-madness
vim-patch:9.1.{0047,0048,0049}: fun cmdwin fixes
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/api/window_spec.lua | 133 | ||||
-rw-r--r-- | test/functional/vimscript/api_functions_spec.lua | 14 | ||||
-rw-r--r-- | test/old/testdir/test_cmdline.vim | 2 | ||||
-rw-r--r-- | test/old/testdir/test_cmdwin.vim | 112 | ||||
-rw-r--r-- | test/old/testdir/test_normal.vim | 13 |
5 files changed, 266 insertions, 8 deletions
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 4e71e4ab85..aadf59eb5a 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -1,18 +1,20 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, curbuf, curbuf_contents, curwin, eq, neq, ok, feed, insert, eval = +local clear, curbuf, curbuf_contents, curwin, eq, neq, matches, ok, feed, insert, eval = helpers.clear, helpers.api.nvim_get_current_buf, helpers.curbuf_contents, helpers.api.nvim_get_current_win, helpers.eq, helpers.neq, + helpers.matches, helpers.ok, helpers.feed, helpers.insert, helpers.eval local poke_eventloop = helpers.poke_eventloop local exec = helpers.exec +local exec_lua = helpers.exec_lua local fn = helpers.fn local request = helpers.request local NIL = vim.NIL @@ -51,7 +53,7 @@ describe('API/win', function() eq('Invalid window id: 23', pcall_err(api.nvim_win_set_buf, 23, api.nvim_get_current_buf())) end) - it('disallowed in cmdwin if win={old_}curwin or buf=curbuf', function() + it('disallowed in cmdwin if win=cmdwin_{old_cur}win or buf=cmdwin_buf', function() local new_buf = api.nvim_create_buf(true, true) local old_win = api.nvim_get_current_win() local new_win = api.nvim_open_win(new_buf, false, { @@ -74,6 +76,36 @@ describe('API/win', function() 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', pcall_err(api.nvim_win_set_buf, new_win, 0) ) + matches( + 'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$', + pcall_err( + exec_lua, + [[ + local cmdwin_buf = vim.api.nvim_get_current_buf() + local new_win, new_buf = ... + vim.api.nvim_buf_call(new_buf, function() + vim.api.nvim_win_set_buf(new_win, cmdwin_buf) + end) + ]], + new_win, + new_buf + ) + ) + matches( + 'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$', + pcall_err( + exec_lua, + [[ + local cmdwin_win = vim.api.nvim_get_current_win() + local new_win, new_buf = ... + vim.api.nvim_win_call(new_win, function() + vim.api.nvim_win_set_buf(cmdwin_win, new_buf) + end) + ]], + new_win, + new_buf + ) + ) local next_buf = api.nvim_create_buf(true, true) api.nvim_win_set_buf(new_win, next_buf) @@ -546,6 +578,7 @@ describe('API/win', function() it('in cmdline-window #9767', function() command('split') eq(2, #api.nvim_list_wins()) + local oldbuf = api.nvim_get_current_buf() local oldwin = api.nvim_get_current_win() local otherwin = api.nvim_open_win(0, false, { relative = 'editor', @@ -570,6 +603,46 @@ describe('API/win', function() api.nvim_win_close(0, true) eq(2, #api.nvim_list_wins()) eq('', fn.getcmdwintype()) + + -- Closing curwin in context of a different window shouldn't close cmdwin. + otherwin = api.nvim_open_win(0, false, { + relative = 'editor', + row = 10, + col = 10, + width = 10, + height = 10, + }) + feed('q:') + exec_lua( + [[ + vim.api.nvim_win_call(..., function() + vim.api.nvim_win_close(0, true) + end) + ]], + otherwin + ) + eq(false, api.nvim_win_is_valid(otherwin)) + eq(':', fn.getcmdwintype()) + -- Closing cmdwin in context of a non-previous window is still OK. + otherwin = api.nvim_open_win(oldbuf, false, { + relative = 'editor', + row = 10, + col = 10, + width = 10, + height = 10, + }) + exec_lua( + [[ + local otherwin, cmdwin = ... + vim.api.nvim_win_call(otherwin, function() + vim.api.nvim_win_close(cmdwin, true) + end) + ]], + otherwin, + api.nvim_get_current_win() + ) + eq('', fn.getcmdwintype()) + eq(true, api.nvim_win_is_valid(otherwin)) end) it('closing current (float) window of another tabpage #15313', function() @@ -646,6 +719,7 @@ describe('API/win', function() api.nvim_win_hide(0) eq('', fn.getcmdwintype()) + local old_buf = api.nvim_get_current_buf() local old_win = api.nvim_get_current_win() local other_win = api.nvim_open_win(0, false, { relative = 'win', @@ -663,6 +737,45 @@ describe('API/win', function() -- Can close other windows. api.nvim_win_hide(other_win) eq(false, api.nvim_win_is_valid(other_win)) + + -- Closing curwin in context of a different window shouldn't close cmdwin. + other_win = api.nvim_open_win(old_buf, false, { + relative = 'editor', + row = 10, + col = 10, + width = 10, + height = 10, + }) + exec_lua( + [[ + vim.api.nvim_win_call(..., function() + vim.api.nvim_win_hide(0) + end) + ]], + other_win + ) + eq(false, api.nvim_win_is_valid(other_win)) + eq(':', fn.getcmdwintype()) + -- Closing cmdwin in context of a non-previous window is still OK. + other_win = api.nvim_open_win(old_buf, false, { + relative = 'editor', + row = 10, + col = 10, + width = 10, + height = 10, + }) + exec_lua( + [[ + local otherwin, cmdwin = ... + vim.api.nvim_win_call(otherwin, function() + vim.api.nvim_win_hide(cmdwin) + end) + ]], + other_win, + api.nvim_get_current_win() + ) + eq('', fn.getcmdwintype()) + eq(true, api.nvim_win_is_valid(other_win)) end) end) @@ -1055,7 +1168,7 @@ describe('API/win', function() eq(1, fn.exists('g:fired')) end) - it('disallowed in cmdwin if enter=true or buf=curbuf', function() + it('disallowed in cmdwin if enter=true or buf=cmdwin_buf', function() local new_buf = api.nvim_create_buf(true, true) feed('q:') eq( @@ -1078,6 +1191,20 @@ describe('API/win', function() height = 5, }) ) + matches( + 'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$', + pcall_err( + exec_lua, + [[ + local cmdwin_buf = vim.api.nvim_get_current_buf() + vim.api.nvim_buf_call(vim.api.nvim_create_buf(false, true), function() + vim.api.nvim_open_win(cmdwin_buf, false, { + relative='editor', row=5, col=5, width=5, height=5, + }) + end) + ]] + ) + ) eq( new_buf, diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 200ad40c3a..4985768bb0 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local neq, eq, command = helpers.neq, helpers.eq, helpers.command local clear = helpers.clear local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval +local exec_lua = helpers.exec_lua local insert, pcall_err = helpers.insert, helpers.pcall_err local matches = helpers.matches local api = helpers.api @@ -106,6 +107,19 @@ describe('eval-API', function() pcall_err(api.nvim_open_term, 0, {}) ) + matches( + 'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$', + pcall_err( + exec_lua, + [[ + local cmdwin_buf = vim.api.nvim_get_current_buf() + vim.api.nvim_buf_call(vim.api.nvim_create_buf(false, true), function() + vim.api.nvim_open_term(cmdwin_buf, {}) + end) + ]] + ) + ) + -- But turning a different buffer into a terminal from the cmdwin is OK. local term_buf = api.nvim_create_buf(false, true) api.nvim_open_term(term_buf, {}) diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim index 8210fc2310..f62a89aec8 100644 --- a/test/old/testdir/test_cmdline.vim +++ b/test/old/testdir/test_cmdline.vim @@ -1885,7 +1885,7 @@ func Test_cmdwin_tabpage() tabclose! endfunc -func Test_cmdwin_interrupted() +func Test_cmdwin_interrupted_more_prompt() CheckScreendump " aborting the :smile output caused the cmdline window to use the current diff --git a/test/old/testdir/test_cmdwin.vim b/test/old/testdir/test_cmdwin.vim index f07fd99f8a..9b1a45708e 100644 --- a/test/old/testdir/test_cmdwin.vim +++ b/test/old/testdir/test_cmdwin.vim @@ -93,4 +93,116 @@ func Test_cmdwin_restore_heights() set cmdheight& showtabline& laststatus& endfunc +func Test_cmdwin_temp_curwin() + func CheckWraps(expect_wrap) + setlocal textwidth=0 wrapmargin=1 + + call deletebufline('', 1, '$') + let as = repeat('a', winwidth(0) - 2 - &wrapmargin) + call setline(1, as .. ' b') + normal! gww + + setlocal textwidth& wrapmargin& + call assert_equal(a:expect_wrap ? [as, 'b'] : [as .. ' b'], getline(1, '$')) + endfunc + + func CheckCmdWin() + call assert_equal('command', win_gettype()) + " textoff and &wrapmargin formatting considers the cmdwin_type char. + call assert_equal(1, getwininfo(win_getid())[0].textoff) + call CheckWraps(1) + endfunc + + func CheckOtherWin() + call assert_equal('', win_gettype()) + call assert_equal(0, getwininfo(win_getid())[0].textoff) + call CheckWraps(0) + endfunc + + call feedkeys("q::call CheckCmdWin()\<CR>:call win_execute(win_getid(winnr('#')), 'call CheckOtherWin()')\<CR>:q<CR>", 'ntx') + + %bwipe! + delfunc CheckWraps + delfunc CheckCmdWin + delfunc CheckOtherWin +endfunc + +func Test_cmdwin_interrupted() + func CheckInterrupted() + call feedkeys("q::call assert_equal('', getcmdwintype())\<CR>:call assert_equal('', getcmdtype())\<CR>:q<CR>", 'ntx') + endfunc + + augroup CmdWin + + " While opening the cmdwin's split: + " Close the cmdwin's window. + au WinEnter * ++once quit + call CheckInterrupted() + + " Close the old window. + au WinEnter * ++once execute winnr('#') 'quit' + call CheckInterrupted() + + " Switch back to the old window. + au WinEnter * ++once wincmd p + call CheckInterrupted() + + " Change the old window's buffer. + au WinEnter * ++once call win_execute(win_getid(winnr('#')), 'enew') + call CheckInterrupted() + + " Using BufLeave autocmds as cmdwin restrictions do not apply to them when + " fired from opening the cmdwin... + " After opening the cmdwin's split, while creating the cmdwin's buffer: + " Delete the cmdwin's buffer. + au BufLeave * ++once bwipe + call CheckInterrupted() + + " Close the cmdwin's window. + au BufLeave * ++once quit + call CheckInterrupted() + + " Close the old window. + au BufLeave * ++once execute winnr('#') 'quit' + call CheckInterrupted() + + " Switch to a different window. + au BufLeave * ++once split + call CheckInterrupted() + + " Change the old window's buffer. + au BufLeave * ++once call win_execute(win_getid(winnr('#')), 'enew') + call CheckInterrupted() + + " However, changing the current buffer is OK and does not interrupt. + au BufLeave * ++once edit other + call feedkeys("q::let t=getcmdwintype()\<CR>:let b=bufnr()\<CR>:clo<CR>", 'ntx') + call assert_equal(':', t) + call assert_equal(1, bufloaded('other')) + call assert_notequal(b, bufnr('other')) + + augroup END + + " No autocmds should remain, but clear the augroup to be sure. + augroup CmdWin + au! + augroup END + + %bwipe! + delfunc CheckInterrupted +endfunc + +func Test_cmdwin_existing_bufname() + func CheckName() + call assert_equal(1, getbufinfo('')[0].command) + call assert_equal(0, getbufinfo('[Command Line]')[0].command) + call assert_match('#a\s*"\[Command Line\]"', execute('ls')) + call assert_match('%a\s*"\[Command Line\]"', execute('ls')) + endfunc + file [Command Line] + call feedkeys("q::call CheckName()\<CR>:q\<CR>", 'ntx') + 0file + delfunc CheckName +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index c72d83fa52..b98547061e 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -3167,15 +3167,18 @@ endfunc func Test_normal50_commandline() CheckFeature timers CheckFeature cmdline_hist + func! DoTimerWork(id) - call assert_equal('[Command Line]', bufname('')) + call assert_equal(1, getbufinfo('')[0].command) + " should fail, with E11, but does fail with E23? "call feedkeys("\<c-^>", 'tm') - " should also fail with E11 + " should fail with E11 - "Invalid in command-line window" call assert_fails(":wincmd p", 'E11') - " return from commandline window - call feedkeys("\<cr>") + + " Return from commandline window. + call feedkeys("\<CR>", 't') endfunc let oldlang=v:lang @@ -3188,7 +3191,9 @@ func Test_normal50_commandline() catch /E23/ " no-op endtry + " clean up + delfunc DoTimerWork set updatetime=4000 exe "lang" oldlang bw! |