robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each , setup =t . describe , t . it , t . before_each , t . setup 6local clear , eq , neq =n . clear , t . eq , t . neq 7local command , api , fn =n . command , n . api , n . fn 8local tbl_deep_extend =vim . tbl_deep_extend 9 10-- Set up two overlapping floating windows 11local setup_floating_windows =function () 12local base_opts ={ 13relative ='editor' , 14height =1 , 15width =2 , 16anchor ='NW' , 17style ='minimal' , 18border ='none' , 19} 20 21local bufnr_1 =api . nvim_create_buf ( false , true ) 22api . nvim_buf_set_lines ( bufnr_1 , 0 , - 1 , true , { 'aa' } ) 23local opts_1 =tbl_deep_extend ( 'force' , { row =0 , col =0 , zindex =11 } , base_opts ) 24api . nvim_open_win ( bufnr_1 , false , opts_1 ) 25 26local bufnr_2 =api . nvim_create_buf ( false , true ) 27api . nvim_buf_set_lines ( bufnr_2 , 0 , - 1 , true , { 'bb' } ) 28local opts_2 =tbl_deep_extend ( 'force' , { row =0 , col =1 , zindex =10 } , base_opts ) 29api . nvim_open_win ( bufnr_2 , false , opts_2 ) 30 31command ( 'redraw' ) 32end 33 34describe ( 'screenchar() and family respect floating windows' , function () 35local function with_ext_multigrid ( multigrid ) 36setup ( function () 37clear () 38Screen . new ( 40 , 7 , { ext_multigrid =multigrid } ) 39-- These commands result into visible text `aabc`. 40-- `aab` - from floating windows, `c` - from text in regular window. 41api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { 'cccc' } ) 42setup_floating_windows () 43end ) 44 45it ( 'screenattr()' , function () 46local attr_1 =fn . screenattr ( 1 , 1 ) 47local attr_2 =fn . screenattr ( 1 , 2 ) 48local attr_3 =fn . screenattr ( 1 , 3 ) 49local attr_4 =fn . screenattr ( 1 , 4 ) 50eq ( attr_1 , attr_2 ) 51eq ( attr_1 , attr_3 ) 52neq ( attr_1 , attr_4 ) 53end ) 54 55it ( 'screenchar()' , function () 56eq ( 97 , fn . screenchar ( 1 , 1 )) 57eq ( 97 , fn . screenchar ( 1 , 2 )) 58eq ( 98 , fn . screenchar ( 1 , 3 )) 59eq ( 99 , fn . screenchar ( 1 , 4 )) 60end ) 61 62it ( 'screenchars()' , function () 63eq ( { 97 } , fn . screenchars ( 1 , 1 )) 64eq ( { 97 } , fn . screenchars ( 1 , 2 )) 65eq ( { 98 } , fn . screenchars ( 1 , 3 )) 66eq ( { 99 } , fn . screenchars ( 1 , 4 )) 67end ) 68 69it ( 'screenstring()' , function () 70eq ( 'a' , fn . screenstring ( 1 , 1 )) 71eq ( 'a' , fn . screenstring ( 1 , 2 )) 72eq ( 'b' , fn . screenstring ( 1 , 3 )) 73eq ( 'c' , fn . screenstring ( 1 , 4 )) 74end ) 75end 76 77describe ( 'with ext_multigrid' , function () 78with_ext_multigrid ( true ) 79end ) 80 81describe ( 'without ext_multigrid' , function () 82with_ext_multigrid ( false ) 83end ) 84 85describe ( 'hidden windows' , function () 86before_each ( function () 87clear () 88Screen . new ( 40 , 7 , {} ) 89api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { 'aaa' , 'aaa' } ) 90end ) 91 92local assert_screen_funcs =function () 93eq ( 'a' , fn . screenstring ( 1 , 1 )) 94eq ( 97 , fn . screenchar ( 1 , 1 )) 95eq ( { 97 } , fn . screenchars ( 1 , 1 )) 96eq ( fn . screenattr ( 2 , 1 ), fn . screenattr ( 1 , 1 )) 97end 98 99it ( 'manual' , function () 100local bufnr =api . nvim_create_buf ( false , true ) 101api . nvim_buf_set_lines ( bufnr , 0 , - 1 , true , { 'bb' } ) 102local win_opts ={ relative ='editor' , row =0 , col =0 , height =1 , width =2 , hide =true } 103api . nvim_open_win ( bufnr , false , win_opts ) 104 105assert_screen_funcs () 106end ) 107 108it ( 'from ui2' , function () 109n . exec_lua ( 'require("vim._core.ui2").enable({ enable = true })' ) 110command ( 'echo "foo"' ) 111 112assert_screen_funcs () 113end ) 114end ) 115end )