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 eq =t . eq 7local eval =n . eval 8local api =n . api 9local source =n . source 10local command =n . command 11local feed =n . feed 12 13describe ( 'CursorMoved' , function () 14before_each ( clear ) 15 16it ( 'is triggered after BufEnter when changing or splitting windows #11878 #12031' , function () 17source ( [[ 18call setline(1, 'foo') 19let g:log = [] 20autocmd BufEnter * let g:log += ['BufEnter' .. expand("<abuf>")] 21autocmd CursorMoved * let g:log += ['CursorMoved' .. expand("<abuf>")] 22]] ) 23eq ( {} , eval ( 'g:log' )) 24command ( 'new' ) 25eq ( { 'BufEnter2' , 'CursorMoved2' } , eval ( 'g:log' )) 26command ( 'wincmd w' ) 27eq ( { 'BufEnter2' , 'CursorMoved2' , 'BufEnter1' , 'CursorMoved1' } , eval ( 'g:log' )) 28end ) 29 30it ( 'is not triggered by temporarily switching window' , function () 31source ( [[ 32let g:cursormoved = 0 33vnew 34autocmd CursorMoved * let g:cursormoved += 1 35]] ) 36command ( 'wincmd w | wincmd p' ) 37eq ( 0 , eval ( 'g:cursormoved' )) 38end ) 39 40it ( "is not triggered by functions that don't change the window" , function () 41source ( [[ 42let g:cursormoved = 0 43let g:buf = bufnr('%') 44vsplit foo 45autocmd CursorMoved * let g:cursormoved += 1 46]] ) 47api . nvim_buf_set_lines ( eval ( 'g:buf' ), 0 , - 1 , true , { 'aaa' } ) 48eq ( 0 , eval ( 'g:cursormoved' )) 49eq ( { 'aaa' } , api . nvim_buf_get_lines ( eval ( 'g:buf' ), 0 , - 1 , true )) 50eq ( 0 , eval ( 'g:cursormoved' )) 51end ) 52 53it ( 'is not triggered by cursor movement prior to first CursorMoved instantiation' , function () 54eq ( {} , api . nvim_get_autocmds ( { event ='CursorMoved' } )) 55feed ( 'ifoobar<Esc>' ) 56source ( [[ 57let g:cursormoved = 0 58autocmd CursorMoved * let g:cursormoved += 1 59]] ) 60eq ( 0 , eval ( 'g:cursormoved' )) 61feed ( '<Ignore>' ) 62eq ( 0 , eval ( 'g:cursormoved' )) 63feed ( '0' ) 64eq ( 1 , eval ( 'g:cursormoved' )) 65end ) 66end ) 67 68describe ( 'CursorMovedI' , function () 69before_each ( clear ) 70 71it ( 'is not triggered by cursor movement prior to first CursorMovedI instantiation' , function () 72eq ( {} , api . nvim_get_autocmds ( { event ='CursorMovedI' } )) 73feed ( 'ifoobar' ) 74source ( [[ 75let g:cursormovedi = 0 76autocmd CursorMovedI * let g:cursormovedi += 1 77]] ) 78eq ( 0 , eval ( 'g:cursormovedi' )) 79feed ( '<Ignore>' ) 80eq ( 0 , eval ( 'g:cursormovedi' )) 81feed ( '<Home>' ) 82eq ( 1 , eval ( 'g:cursormovedi' )) 83end ) 84end )