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 =t . describe , t . it , t . before_each 6local clear , command , eq =n . clear , n . command , t . eq 7local insert =n . insert 8local api =n . api 9local assert_alive =n . assert_alive 10 11describe ( 'ui/ext_tabline' , function () 12local screen 13local event_tabs , event_curtab , event_curbuf , event_buffers 14 15before_each ( function () 16clear () 17screen =Screen . new ( 25 , 5 , { rgb =true , ext_tabline =true } ) 18function screen : _handle_tabline_update ( curtab , tabs , curbuf , buffers ) 19event_curtab =curtab 20event_tabs =tabs 21event_curbuf =curbuf 22event_buffers =buffers 23end 24end ) 25 26it ( 'publishes UI events' , function () 27command ( 'tabedit another-tab' ) 28 29local expected_tabs ={ 30{ tab =1 , name ='[No Name]' } , 31{ tab =2 , name ='another-tab' } , 32} 33screen : expect { 34grid =[[ 35^ | 36{1:~ }|*3 37| 38]] , 39condition =function () 40eq ( 2 , event_curtab ) 41eq ( expected_tabs , event_tabs ) 42end , 43} 44 45command ( 'tabNext' ) 46screen : expect { 47grid =[[ 48^ | 49{1:~ }|*3 50| 51]] , 52condition =function () 53eq ( 1 , event_curtab ) 54eq ( expected_tabs , event_tabs ) 55end , 56} 57end ) 58 59it ( 'buffer UI events' , function () 60local expected_buffers_initial ={ 61{ buffer =1 , name ='[No Name]' } , 62} 63 64screen : expect { 65grid =[[ 66^ | 67{1:~ }|*3 68| 69]] , 70condition =function () 71eq ( 1 , event_curbuf ) 72eq ( expected_buffers_initial , event_buffers ) 73end , 74} 75 76command ( 'badd another-buffer' ) 77command ( 'bnext' ) 78 79local expected_buffers ={ 80{ buffer =1 , name ='[No Name]' } , 81{ buffer =2 , name ='another-buffer' } , 82} 83screen : expect { 84grid =[[ 85^ | 86{1:~ }|*3 87| 88]] , 89condition =function () 90eq ( 2 , event_curbuf ) 91eq ( expected_buffers , event_buffers ) 92end , 93} 94end ) 95end ) 96 97describe ( 'tabline' , function () 98local screen 99 100before_each ( function () 101clear () 102screen =Screen . new ( 42 , 5 ) 103end ) 104 105it ( 'redraws when tabline option is set' , function () 106command ( 'set tabline=asdf' ) 107command ( 'set showtabline=2' ) 108screen : expect { 109grid =[[ 110{2:asdf }| 111^ | 112{1:~ }|*2 113| 114]] , 115} 116command ( 'set tabline=jkl' ) 117screen : expect { 118grid =[[ 119{2:jkl }| 120^ | 121{1:~ }|*2 122| 123]] , 124} 125end ) 126 127it ( 'combines highlight attributes' , function () 128screen : set_default_attr_ids ( { 129[ 1 ] ={ foreground =Screen . colors . Blue1 , bold =true } , -- StatusLine 130[ 2 ] ={ bold =true , italic =true } , -- StatusLine 131[ 3 ] ={ bold =true , italic =true , foreground =Screen . colors . Red } , -- NonText combined with StatusLine 132} ) 133command ( 'hi TabLineFill gui=bold,italic' ) 134command ( 'hi Identifier guifg=red' ) 135command ( 'set tabline=Test%#Identifier#here' ) 136command ( 'set showtabline=2' ) 137screen : expect { 138grid =[[ 139{2:Test}{3:here }| 140^ | 141{1:~ }|*2 142| 143]] , 144} 145end ) 146 147it ( 'click definitions do not leak memory #21765' , function () 148command ( 'set tabline=%@MyClickFunc@MyClickText%T' ) 149command ( 'set showtabline=2' ) 150command ( 'redrawtabline' ) 151end ) 152 153it ( 'clicks work with truncated double-width label #24187' , function () 154insert ( 'tab1' ) 155command ( 'tabnew' ) 156insert ( 'tab2' ) 157command ( 'tabprev' ) 158api . nvim_set_option_value ( 'tabline' , '%1T口口%2Ta' .. ( 'b' ): rep ( 38 ) .. '%999Xc' , {} ) 159screen : expect { 160grid =[[ 161{2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }| 162tab^1 | 163{1:~ }|*2 164| 165]] , 166} 167assert_alive () 168api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 1 ) 169screen : expect { 170grid =[[ 171{2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }| 172tab^2 | 173{1:~ }|*2 174| 175]] , 176} 177api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 0 ) 178screen : expect { 179grid =[[ 180{2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }| 181tab^1 | 182{1:~ }|*2 183| 184]] , 185} 186api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 39 ) 187screen : expect { 188grid =[[ 189{2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }| 190tab^2 | 191{1:~ }|*2 192| 193]] , 194} 195api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 40 ) 196screen : expect { 197grid =[[ 198tab^1 | 199{1:~ }|*3 200| 201]] , 202} 203end ) 204 205it ( 'middle-click closes tab' , function () 206command ( 'tabnew' ) 207command ( 'tabnew' ) 208command ( 'tabnew' ) 209command ( 'tabprev' ) 210eq ( { 3 , 4 } , api . nvim_eval ( '[tabpagenr(), tabpagenr("$")]' )) 211api . nvim_input_mouse ( 'middle' , 'press' , '' , 0 , 0 , 1 ) 212eq ( { 2 , 3 } , api . nvim_eval ( '[tabpagenr(), tabpagenr("$")]' )) 213api . nvim_input_mouse ( 'middle' , 'press' , '' , 0 , 0 , 20 ) 214eq ( { 2 , 2 } , api . nvim_eval ( '[tabpagenr(), tabpagenr("$")]' )) 215api . nvim_input_mouse ( 'middle' , 'press' , '' , 0 , 0 , 1 ) 216eq ( { 1 , 1 } , api . nvim_eval ( '[tabpagenr(), tabpagenr("$")]' )) 217end ) 218 219it ( 'does not show floats with focusable=false' , function () 220screen : set_default_attr_ids ( { 221[ 1 ] ={ background =Screen . colors . Plum1 } , 222[ 2 ] ={ underline =true , background =Screen . colors . LightGrey } , 223[ 3 ] ={ bold =true } , 224[ 4 ] ={ reverse =true } , 225[ 5 ] ={ bold =true , foreground =Screen . colors . Blue1 } , 226[ 6 ] ={ foreground =Screen . colors . Fuchsia , bold =true } , 227[ 7 ] ={ foreground =Screen . colors . SeaGreen , bold =true } , 228} ) 229command ( 'tabnew' ) 230api . nvim_open_win ( 0 , false , { 231focusable =false , 232relative ='editor' , 233height =1 , 234width =1 , 235row =0 , 236col =0 , 237} ) 238screen : expect { 239grid =[[ 240{1: }{2:[No Name] }{3: [No Name] }{4: }{2:X}| 241^ | 242{5:~ }|*2 243| 244]] , 245} 246command ( 'tabs' ) 247screen : expect { 248grid =[[ 249{6:Tab page 1} | 250# [No Name] | 251{6:Tab page 2} | 252> [No Name] | 253{7:Press ENTER or type command to continue}^ | 254]] , 255} 256end ) 257end )