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 feed =n . feed 8local retry =t . retry 9local exec =n . source 10local sleep =vim . uv . sleep 11local api =n . api 12 13before_each ( clear ) 14 15describe ( 'CursorHold' , function () 16before_each ( function () 17exec ( [[ 18let g:cursorhold = 0 19augroup test 20au CursorHold * let g:cursorhold += 1 21augroup END 22]] ) 23end ) 24 25it ( 'is triggered correctly #12587' , function () 26local function test_cursorhold ( fn , early ) 27local ut =2 28-- if testing with small 'updatetime' fails, double its value and test again 29retry ( 10 , nil , function () 30ut =ut * 2 31api . nvim_set_option_value ( 'updatetime' , ut , {} ) 32feed ( '0' ) -- reset did_cursorhold 33api . nvim_set_var ( 'cursorhold' , 0 ) 34sleep ( ut / 4 ) 35fn () 36eq ( 0 , api . nvim_get_var ( 'cursorhold' )) 37sleep ( ut / 2 ) 38fn () 39eq ( 0 , api . nvim_get_var ( 'cursorhold' )) 40sleep ( ut / 2 ) 41eq ( early , api . nvim_get_var ( 'cursorhold' )) 42sleep ( ut / 4 * 3 ) 43eq ( 1 , api . nvim_get_var ( 'cursorhold' )) 44end ) 45end 46 47local ignore_key =api . nvim_replace_termcodes ( '<Ignore>' , true , true , true ) 48test_cursorhold ( function () end , 1 ) 49test_cursorhold ( function () 50feed ( '' ) 51end , 1 ) 52test_cursorhold ( function () 53api . nvim_feedkeys ( '' , 'n' , true ) 54end , 1 ) 55test_cursorhold ( function () 56feed ( '<Ignore>' ) 57end , 0 ) 58test_cursorhold ( function () 59api . nvim_feedkeys ( ignore_key , 'n' , true ) 60end , 0 ) 61end ) 62 63it ( "reducing 'updatetime' while waiting for CursorHold #20241" , function () 64api . nvim_set_option_value ( 'updatetime' , 10000 , {} ) 65feed ( '0' ) -- reset did_cursorhold 66api . nvim_set_var ( 'cursorhold' , 0 ) 67sleep ( 50 ) 68eq ( 0 , api . nvim_get_var ( 'cursorhold' )) 69api . nvim_set_option_value ( 'updatetime' , 20 , {} ) 70sleep ( 10 ) 71eq ( 1 , api . nvim_get_var ( 'cursorhold' )) 72end ) 73 74it ( 'is not triggered after only K_EVENT on startup' , function () 75api . nvim_set_option_value ( 'updatetime' , 20 , {} ) 76sleep ( 50 ) 77eq ( 0 , api . nvim_get_var ( 'cursorhold' )) 78feed ( '0' ) 79-- Poll: CursorHold may take longer than one 'updatetime' to fire. 80retry ( nil , 1000 , function () 81eq ( 1 , api . nvim_get_var ( 'cursorhold' )) 82end ) 83end ) 84end ) 85 86describe ( 'CursorHoldI' , function () 87-- NOTE: since this test uses RPC it is not necessary to trigger the initial 88-- issue (#3757) via timer's or RPC callbacks in the first place. 89it ( 'is triggered after input' , function () 90exec ( [[ 91set updatetime=1 92 93let g:cursorhold = 0 94augroup test 95au CursorHoldI * let g:cursorhold += 1 96augroup END 97]] ) 98feed ( 'ifoo' ) 99retry ( 5 , nil , function () 100sleep ( 1 ) 101eq ( 1 , api . nvim_get_var ( 'cursorhold' )) 102end ) 103end ) 104end )