bufenter_spec.lua (1528B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 4 local clear = n.clear 5 local command = n.command 6 local eq = t.eq 7 local eval = n.eval 8 local request = n.request 9 local source = n.source 10 11 describe('autocmd BufEnter', function() 12 before_each(clear) 13 14 it("triggered by nvim_command('edit <dir>')", function() 15 command("autocmd BufEnter * if isdirectory(expand('<afile>')) | let g:dir_bufenter = 1 | endif") 16 request('nvim_command', 'split .') 17 eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. 18 eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. 19 end) 20 21 it('triggered by "try|:split <dir>|endtry" in a function', function() 22 command("autocmd BufEnter * if isdirectory(expand('<afile>')) | let g:dir_bufenter = 1 | endif") 23 source([[ 24 function! Test() 25 try 26 exe 'split .' 27 catch 28 endtry 29 endfunction 30 ]]) 31 command('call Test()') 32 eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. 33 eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. 34 end) 35 36 it('triggered by ":split normal|:help|:bw"', function() 37 n.add_builddir_to_rtp() 38 command('split normal') 39 command('wincmd j') 40 command('help') 41 command('wincmd L') 42 command('autocmd BufEnter normal let g:bufentered = 1') 43 command('bw') 44 eq(1, eval('bufnr("%")')) -- The cursor is back to the bottom window 45 eq(0, eval("exists('g:bufentered')")) -- The autocmd hasn't been triggered 46 end) 47 end)