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 exec =n . exec 8local exec_lua =n . exec_lua 9local feed =n . feed 10local api =n . api 11local poke_eventloop =n . poke_eventloop 12 13before_each ( clear ) 14 15describe ( 'state() function' , function () 16-- oldtest: Test_state() 17it ( 'works' , function () 18api . nvim_ui_attach ( 80 , 24 , {} ) -- Allow hit-enter-prompt 19 20exec_lua ( [[ 21function _G.Get_state_mode() 22_G.res = { vim.fn.state(), vim.api.nvim_get_mode().mode:sub(1, 1) } 23end 24function _G.Run_timer() 25local timer = vim.uv.new_timer() 26timer:start(0, 0, function() 27_G.Get_state_mode() 28timer:close() 29end) 30end 31]] ) 32exec ( [[ 33call setline(1, ['one', 'two', 'three']) 34map ;; gg 35set complete=. 36func RunTimer() 37call timer_start(0, {id -> v:lua.Get_state_mode()}) 38endfunc 39au Filetype foobar call v:lua.Get_state_mode() 40]] ) 41 42-- Using a ":" command Vim is busy, thus "S" is returned 43feed ( [[:call v:lua.Get_state_mode()<CR>]] ) 44eq ( { 'S' , 'n' } , exec_lua ( 'return _G.res' )) 45 46-- Using a timer callback 47feed ( [[:call RunTimer()<CR>]] ) 48poke_eventloop () -- Process pending input 49poke_eventloop () -- Process time_event 50eq ( { 'c' , 'n' } , exec_lua ( 'return _G.res' )) 51 52-- Halfway a mapping 53feed ( [[:call v:lua.Run_timer()<CR>;]] ) 54api . nvim_get_mode () -- Process pending input and luv timer callback 55feed ( ';' ) 56eq ( { 'mS' , 'n' } , exec_lua ( 'return _G.res' )) 57 58-- An operator is pending 59feed ( [[:call RunTimer()<CR>y]] ) 60poke_eventloop () -- Process pending input 61poke_eventloop () -- Process time_event 62feed ( 'y' ) 63eq ( { 'oSc' , 'n' } , exec_lua ( 'return _G.res' )) 64 65-- A register was specified 66feed ( [[:call RunTimer()<CR>"r]] ) 67poke_eventloop () -- Process pending input 68poke_eventloop () -- Process time_event 69feed ( 'yy' ) 70eq ( { 'oSc' , 'n' } , exec_lua ( 'return _G.res' )) 71 72-- Insert mode completion 73feed ( [[:call RunTimer()<CR>Got<C-N>]] ) 74poke_eventloop () -- Process pending input 75poke_eventloop () -- Process time_event 76feed ( '<Esc>' ) 77eq ( { 'aSc' , 'i' } , exec_lua ( 'return _G.res' )) 78 79-- Autocommand executing 80feed ( [[:set filetype=foobar<CR>]] ) 81eq ( { 'xS' , 'n' } , exec_lua ( 'return _G.res' )) 82 83-- messages scrolled 84feed ( [[:call v:lua.Run_timer() | echo "one\ntwo\nthree"<CR>]] ) 85api . nvim_get_mode () -- Process pending input and luv timer callback 86feed ( '<CR>' ) 87eq ( { 'Ss' , 'r' } , exec_lua ( 'return _G.res' )) 88end ) 89end )