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 =n . clear 7local command =n . command 8local eq =t . eq 9local shallowcopy =t . shallowcopy 10local eval =n . eval 11 12describe ( 'UI receives option updates' , function () 13local screen 14 15local function reset ( screen_opts , clear_opts ) 16local defaults ={ 17ambiwidth ='single' , 18arabicshape =true , 19emoji =true , 20guifont ='' , 21guifontwide ='' , 22linespace =0 , 23pumblend =0 , 24mousefocus =false , 25mousehide =true , 26mousemoveevent =false , 27showtabline =1 , 28termguicolors =false , 29termsync =true , 30ttimeout =true , 31ttimeoutlen =50 , 32verbose =0 , 33ext_cmdline =false , 34ext_popupmenu =false , 35ext_tabline =false , 36ext_wildmenu =false , 37ext_linegrid =false , 38ext_hlstate =false , 39ext_multigrid =false , 40ext_messages =false , 41ext_termcolors =false , 42} 43 44clear_opts =shallowcopy ( clear_opts or {} ) 45clear_opts . args_rm =clear_opts . args_rm or {} 46table . insert ( clear_opts . args_rm or {} , '--cmd' ) 47clear ( clear_opts ) 48screen =Screen . new ( 20 , 5 , screen_opts ) 49defaults . guifont =eval ( '&guifont' ) 50-- NB: UI test suite can be run in both "linegrid" and legacy grid mode. 51-- In both cases check that the received value is the one requested. 52defaults . ext_linegrid =screen . _options . ext_linegrid or false 53return defaults 54end 55 56it ( 'for defaults' , function () 57local expected =reset () 58screen : expect ( function () 59eq ( expected , screen . options ) 60end ) 61end ) 62 63it ( 'on attach #11372' , function () 64clear { args_rm ={ '--headless' } } 65local evs ={} 66screen =Screen . new ( 20 , 5 ) 67-- Override mouse_on/mouse_off handlers. 68function screen : _handle_mouse_on () 69table . insert ( evs , 'mouse_on' ) 70end 71function screen : _handle_mouse_off () 72table . insert ( evs , 'mouse_off' ) 73end 74screen : expect ( function () 75eq ( { 'mouse_on' } , evs ) 76end ) 77command ( 'set mouse=' ) 78screen : expect ( function () 79eq ( { 'mouse_on' , 'mouse_off' } , evs ) 80end ) 81command ( 'set mouse&' ) 82screen : expect ( function () 83eq ( { 'mouse_on' , 'mouse_off' , 'mouse_on' } , evs ) 84end ) 85screen : detach () 86eq ( { 'mouse_on' , 'mouse_off' , 'mouse_on' } , evs ) 87screen : attach () 88screen : expect ( function () 89eq ( { 'mouse_on' , 'mouse_off' , 'mouse_on' , 'mouse_on' } , evs ) 90end ) 91end ) 92 93it ( 'when setting options' , function () 94local expected =reset () 95local defaults =shallowcopy ( expected ) 96 97command ( 'set termguicolors' ) 98expected . termguicolors =true 99screen : expect ( function () 100eq ( expected , screen . options ) 101end ) 102 103command ( 'set pumblend=50' ) 104expected . pumblend =50 105screen : expect ( function () 106eq ( expected , screen . options ) 107end ) 108 109-- check handling of out-of-bounds value 110command ( 'set pumblend=-1' ) 111expected . pumblend =0 112screen : expect ( function () 113eq ( expected , screen . options ) 114end ) 115 116command ( 'set guifont=Comic\\ Sans' ) 117expected . guifont ='Comic Sans' 118screen : expect ( function () 119eq ( expected , screen . options ) 120end ) 121 122command ( 'set showtabline=0' ) 123expected . showtabline =0 124screen : expect ( function () 125eq ( expected , screen . options ) 126end ) 127 128command ( 'set linespace=13' ) 129expected . linespace =13 130screen : expect ( function () 131eq ( expected , screen . options ) 132end ) 133 134command ( 'set linespace=-11' ) 135expected . linespace =- 11 136screen : expect ( function () 137eq ( expected , screen . options ) 138end ) 139 140command ( 'set mousefocus' ) 141expected . mousefocus =true 142screen : expect ( function () 143eq ( expected , screen . options ) 144end ) 145 146command ( 'set nomousehide' ) 147expected . mousehide =false 148screen : expect ( function () 149eq ( expected , screen . options ) 150end ) 151 152command ( 'set mousemoveevent' ) 153expected . mousemoveevent =true 154screen : expect ( function () 155eq ( expected , screen . options ) 156end ) 157 158command ( 'set nottimeout' ) 159expected . ttimeout =false 160screen : expect ( function () 161eq ( expected , screen . options ) 162end ) 163 164command ( 'set ttimeoutlen=100' ) 165expected . ttimeoutlen =100 166screen : expect ( function () 167eq ( expected , screen . options ) 168end ) 169 170command ( 'set all&' ) 171screen : expect ( function () 172eq ( defaults , screen . options ) 173end ) 174end ) 175 176it ( "restores statusline and tabline after 'set all&'" , function () 177reset () 178command ( 'tabnew | tabnew' ) 179command ( 'set laststatus=0 showtabline=0' ) 180screen : expect ( { 181unchanged =true , 182condition =function () 183local function row_text ( row ) 184local chunks ={} 185for _ , cell in ipairs ( screen . _grid . rows [ row ]) do 186table . insert ( chunks , cell . text ) 187end 188return table . concat ( chunks ) 189end 190 191eq ( nil , row_text ( 1 ): find ( '%[No Name%]' )) 192eq ( nil , row_text ( screen . _grid . height - 1 ): find ( 'All' , 1 , true )) 193end , 194} ) 195 196command ( 'set all&' ) 197screen : expect ( { 198unchanged =true , 199any ={ '[No Name]' , 'All' } , 200} ) 201end ) 202 203it ( 'with UI extensions' , function () 204local expected =reset ( { ext_cmdline =true , ext_wildmenu =true } ) 205 206expected . ext_cmdline =true 207expected . ext_wildmenu =true 208screen : expect ( function () 209eq ( expected , screen . options ) 210end ) 211 212screen : set_option ( 'ext_popupmenu' , true ) 213expected . ext_popupmenu =true 214screen : expect ( function () 215eq ( expected , screen . options ) 216end ) 217 218screen : set_option ( 'ext_wildmenu' , false ) 219expected . ext_wildmenu =false 220screen : expect ( function () 221eq ( expected , screen . options ) 222end ) 223end ) 224 225local function startup_test ( headless ) 226local expected =reset ( nil , { 227args_rm =( headless and {} or { '--headless' } ), 228args ={ '--cmd' , 'set guifont=Comic\\ Sans\\ 12' } , 229} ) 230expected . guifont ='Comic Sans 12' 231screen : expect ( function () 232eq ( expected , screen . options ) 233end ) 234end 235 236it ( 'from startup options with --headless' , function () 237startup_test ( true ) 238end ) 239it ( 'from startup options with --embed' , function () 240startup_test ( false ) 241end ) 242end ) 243 244describe ( 'UI can set terminal option' , function () 245before_each ( function () 246-- by default we implicitly "--cmd 'set bg=light'" which ruins everything 247clear { args_rm ={ '--cmd' } } 248end ) 249 250it ( 'term_name' , function () 251eq ( 'nvim' , eval '&term' ) 252 253local _ =Screen . new ( 20 , 5 , { term_name ='xterm' } ) 254eq ( 'xterm' , eval '&term' ) 255end ) 256 257it ( 'term_colors' , function () 258eq ( '256' , eval '&t_Co' ) 259 260local screen =Screen . new ( 20 , 5 , { term_colors =8 } ) 261eq ( '8' , eval '&t_Co' ) 262screen : detach () 263 264screen =Screen . new ( 20 , 5 , { term_colors =16777216 } ) 265eq ( '16777216' , eval '&t_Co' ) 266screen : detach () 267end ) 268end )