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