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 , eq , api =n . clear , t . eq , n . api 6local command , fn =n . command , n . fn 7local feed =n . feed 8 9before_each ( clear ) 10 11describe ( 'screenpos() function' , function () 12it ( 'works in floating window with border' , function () 13local opts ={ 14relative ='editor' , 15height =8 , 16width =12 , 17row =6 , 18col =8 , 19anchor ='NW' , 20style ='minimal' , 21border ='none' , 22focusable =1 , 23} 24local float =api . nvim_open_win ( api . nvim_create_buf ( false , true ), false , opts ) 25command ( 'redraw' ) 26eq ( { row =7 , col =9 , endcol =9 , curscol =9 } , fn . screenpos ( float , 1 , 1 )) 27 28-- only left border 29opts . border ={ '' , '' , '' , '' , '' , '' , '' , '|' } 30api . nvim_win_set_config ( float , opts ) 31command ( 'redraw' ) 32eq ( { row =7 , col =10 , endcol =10 , curscol =10 } , fn . screenpos ( float , 1 , 1 )) 33 34-- only top border 35opts . border ={ '' , '_' , '' , '' , '' , '' , '' , '' } 36api . nvim_win_set_config ( float , opts ) 37command ( 'redraw' ) 38eq ( { row =8 , col =9 , endcol =9 , curscol =9 } , fn . screenpos ( float , 1 , 1 )) 39 40-- both left and top border 41opts . border ='single' 42api . nvim_win_set_config ( float , opts ) 43command ( 'redraw' ) 44eq ( { row =8 , col =10 , endcol =10 , curscol =10 } , fn . screenpos ( float , 1 , 1 )) 45end ) 46 47it ( 'works for folded line with virt_lines attached to line above' , function () 48api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { 'aaa' , 'bbb' , 'ccc' , 'ddd' } ) 49local ns =api . nvim_create_namespace ( '' ) 50api . nvim_buf_set_extmark ( 510 , 52ns , 530 , 540 , 55{ virt_lines ={ { { 'abb' } } , { { 'acc' } } , { { 'add' } } } } 56) 57command ( '2,3fold' ) 58eq ( { row =5 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 2 , 1 )) 59eq ( { row =5 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 3 , 1 )) 60eq ( { row =6 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 4 , 1 )) 61 62feed ( '<C-E>' ) 63eq ( { row =4 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 2 , 1 )) 64eq ( { row =4 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 3 , 1 )) 65eq ( { row =5 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 4 , 1 )) 66 67feed ( '<C-E>' ) 68eq ( { row =3 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 2 , 1 )) 69eq ( { row =3 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 3 , 1 )) 70eq ( { row =4 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 4 , 1 )) 71 72feed ( '<C-E>' ) 73eq ( { row =2 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 2 , 1 )) 74eq ( { row =2 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 3 , 1 )) 75eq ( { row =3 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 4 , 1 )) 76 77feed ( '<C-E>' ) 78eq ( { row =1 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 2 , 1 )) 79eq ( { row =1 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 3 , 1 )) 80eq ( { row =2 , col =1 , endcol =1 , curscol =1 } , fn . screenpos ( 0 , 4 , 1 )) 81end ) 82end )