diff options
Diffstat (limited to 'test/functional/autocmd/autocmd_spec.lua')
-rw-r--r-- | test/functional/autocmd/autocmd_spec.lua | 101 |
1 files changed, 81 insertions, 20 deletions
diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index 805db9dd78..e62d3bb66b 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') +local assert_visible = helpers.assert_visible local dedent = helpers.dedent local eq = helpers.eq local eval = helpers.eval @@ -18,26 +19,86 @@ local source = helpers.source describe('autocmd', function() before_each(clear) - it(':tabnew triggers events in the correct order', function() + it(':tabnew, :split, :close events order, <afile>', function() local expected = { - 'WinLeave', - 'TabLeave', - 'WinEnter', - 'TabNew', - 'TabEnter', - 'BufLeave', - 'BufEnter' + {'WinLeave', ''}, + {'TabLeave', ''}, + {'WinEnter', ''}, + {'TabNew', 'testfile1'}, -- :tabnew + {'TabEnter', ''}, + {'BufLeave', ''}, + {'BufEnter', 'testfile1'}, -- :split + {'WinLeave', 'testfile1'}, + {'WinEnter', 'testfile1'}, + {'WinLeave', 'testfile1'}, + {'WinClosed', '1002'}, -- :close, WinClosed <afile> = window-id + {'WinEnter', 'testfile1'}, + {'WinLeave', 'testfile1'}, -- :bdelete + {'WinEnter', 'testfile1'}, + {'BufLeave', 'testfile1'}, + {'BufEnter', 'testfile2'}, + {'WinClosed', '1000'}, } - command('let g:foo = []') - command('autocmd BufEnter * :call add(g:foo, "BufEnter")') - command('autocmd BufLeave * :call add(g:foo, "BufLeave")') - command('autocmd TabEnter * :call add(g:foo, "TabEnter")') - command('autocmd TabLeave * :call add(g:foo, "TabLeave")') - command('autocmd TabNew * :call add(g:foo, "TabNew")') - command('autocmd WinEnter * :call add(g:foo, "WinEnter")') - command('autocmd WinLeave * :call add(g:foo, "WinLeave")') - command('tabnew') - assert.same(expected, eval('g:foo')) + command('let g:evs = []') + command('autocmd BufEnter * :call add(g:evs, ["BufEnter", expand("<afile>")])') + command('autocmd BufLeave * :call add(g:evs, ["BufLeave", expand("<afile>")])') + command('autocmd TabEnter * :call add(g:evs, ["TabEnter", expand("<afile>")])') + command('autocmd TabLeave * :call add(g:evs, ["TabLeave", expand("<afile>")])') + command('autocmd TabNew * :call add(g:evs, ["TabNew", expand("<afile>")])') + command('autocmd WinEnter * :call add(g:evs, ["WinEnter", expand("<afile>")])') + command('autocmd WinLeave * :call add(g:evs, ["WinLeave", expand("<afile>")])') + command('autocmd WinClosed * :call add(g:evs, ["WinClosed", expand("<afile>")])') + command('tabnew testfile1') + command('split') + command('close') + command('new testfile2') + command('bdelete 1') + eq(expected, eval('g:evs')) + end) + + it('WinClosed is non-recursive', function() + command('let g:triggered = 0') + command('autocmd WinClosed * :let g:triggered+=1 | :bdelete 2') + command('new testfile2') + command('new testfile3') + + -- All 3 buffers are visible. + assert_visible(1, true) + assert_visible(2, true) + assert_visible(3, true) + + -- Trigger WinClosed, which also deletes buffer/window 2. + command('bdelete 1') + + -- Buffers 1 and 2 were closed but WinClosed was triggered only once. + eq(1, eval('g:triggered')) + assert_visible(1, false) + assert_visible(2, false) + assert_visible(3, true) + end) + + it('WinClosed from a different tabpage', function() + command('let g:evs = []') + command('edit tesfile1') + command('autocmd WinClosed <buffer> :call add(g:evs, ["WinClosed", expand("<abuf>")])') + local buf1 = eval("bufnr('%')") + command('new') + local buf2 = eval("bufnr('%')") + command('autocmd WinClosed <buffer> :call add(g:evs, ["WinClosed", expand("<abuf>")])' + -- Attempt recursion. + ..' | bdelete '..buf2) + command('tabedit testfile2') + command('tabedit testfile3') + command('bdelete '..buf2) + -- Non-recursive: only triggered once. + eq({ + {'WinClosed', '2'}, + }, eval('g:evs')) + command('bdelete '..buf1) + eq({ + {'WinClosed', '2'}, + {'WinClosed', '1'}, + }, eval('g:evs')) end) it('v:vim_did_enter is 1 after VimEnter', function() @@ -219,7 +280,7 @@ describe('autocmd', function() eq(7, eval('g:test')) -- API calls are blocked when aucmd_win is not in scope - eq('Vim(call):E5555: API call: Invalid window id', + eq('Vim(call):E5555: API call: Invalid window id: 1001', pcall_err(command, "call nvim_set_current_win(g:winid)")) -- second time aucmd_win is needed, a different code path is invoked @@ -257,7 +318,7 @@ describe('autocmd', function() eq(0, eval('g:had_value')) eq(7, eval('g:test')) - eq('Vim(call):E5555: API call: Invalid window id', + eq('Vim(call):E5555: API call: Invalid window id: 1001', pcall_err(command, "call nvim_set_current_win(g:winid)")) end) |