robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- To run this test: 2-- make functionaltest TEST_FILE=test/functional/example_spec.lua 3 4local t =require ( 'test.testutil' ) 5local n =require ( 'test.functional.testnvim' )() 6local Screen =require ( 'test.functional.ui.screen' ) 7local describe , it , before_each =t . describe , t . it , t . before_each 8local clear =n . clear 9local command =n . command 10local eq =t . eq 11local feed =n . feed 12 13describe ( 'example' , function () 14local screen 15before_each ( function () 16clear () 17screen =Screen . new ( 20 , 5 ) 18end ) 19 20it ( 'screen test' , function () 21-- Do some stuff. 22feed ( 'iline1<cr>line2<esc>' ) 23 24-- For debugging only: prints the current screen. 25-- screen:snapshot_util() 26 27-- Assert the expected state. 28screen : expect ( [[ 29line1 | 30line^2 | 31{1:~ }|*2 32| 33]] ) 34end ) 35 36it ( 'override UI event-handler' , function () 37-- Example: override the "tabline_update" UI event handler. 38-- 39-- screen.lua defines default handlers for UI events, but tests 40-- may sometimes want to override a handler. 41 42-- The UI must declare that it wants to handle the UI events. 43-- For this example, we enable `ext_tabline`: 44screen : detach () 45screen =Screen . new ( 25 , 5 , { rgb =true , ext_tabline =true } ) 46 47-- From ":help ui" we find that `tabline_update` receives `curtab` and 48-- `tabs` objects. So we declare the UI handler like this: 49local event_tabs , event_curtab 50function screen : _handle_tabline_update ( curtab , tabs ) 51event_curtab , event_tabs =curtab , tabs 52end 53 54-- Create a tabpage... 55command ( 'tabedit foo' ) 56 57-- Use screen:expect{condition=…} to check the result. 58screen : expect { 59condition =function () 60eq ( 2 , event_curtab ) 61eq ( { 62{ tab =1 , name ='[No Name]' } , 63{ tab =2 , name ='foo' } , 64} , event_tabs ) 65end , 66} 67end ) 68end )