robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
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 neq =t . neq 10local feed =n . feed 11local eval =n . eval 12local exec =n . exec 13local exec_lua =n . exec_lua 14local fn =n . fn 15local api =n . api 16local curwin =n . api . nvim_get_current_win 17local assert_alive =n . assert_alive 18 19describe ( 'tabpage' , function () 20before_each ( clear ) 21 22it ( 'advances to the next page via <C-W>gt' , function () 23-- add some tabpages 24command ( 'tabnew' ) 25command ( 'tabnew' ) 26command ( 'tabnew' ) 27 28eq ( 4 , eval ( 'tabpagenr()' )) 29 30feed ( '<C-W>gt' ) 31 32eq ( 1 , eval ( 'tabpagenr()' )) 33end ) 34 35it ( 'retreats to the previous page via <C-W>gT' , function () 36-- add some tabpages 37command ( 'tabnew' ) 38command ( 'tabnew' ) 39command ( 'tabnew' ) 40 41eq ( 4 , eval ( 'tabpagenr()' )) 42 43feed ( '<C-W>gT' ) 44 45eq ( 3 , eval ( 'tabpagenr()' )) 46end ) 47 48it ( 'does not crash or loop 999 times if BufWipeout autocommand switches window #17868' , function () 49exec ( [[ 50tabedit 51let s:window_id = win_getid() 52botright new 53setlocal bufhidden=wipe 54let g:win_closed = 0 55autocmd WinClosed * let g:win_closed += 1 56autocmd BufWipeout <buffer> call win_gotoid(s:window_id) 57tabprevious 58+tabclose 59]] ) 60neq ( 999 , eval ( 'g:win_closed' )) 61end ) 62 63it ( 'no segfault with strange WinClosed autocommand #20290' , function () 64pcall ( 65exec , 66[[ 67set nohidden 68edit Xa 69split Xb 70tab split 71new 72autocmd WinClosed * tabprev | bwipe! 73close 74]] 75) 76assert_alive () 77end ) 78 79it ( 'nvim_win_close and nvim_win_hide update tabline #20285' , function () 80eq ( 1 , # api . nvim_list_tabpages ()) 81eq ( { 1 , 1 } , fn . win_screenpos ( 0 )) 82local win1 =curwin () 83 84command ( 'tabnew' ) 85eq ( 2 , # api . nvim_list_tabpages ()) 86eq ( { 2 , 1 } , fn . win_screenpos ( 0 )) 87local win2 =curwin () 88 89api . nvim_win_close ( win1 , true ) 90eq ( win2 , curwin ()) 91eq ( 1 , # api . nvim_list_tabpages ()) 92eq ( { 1 , 1 } , fn . win_screenpos ( 0 )) 93 94command ( 'tabnew' ) 95eq ( 2 , # api . nvim_list_tabpages ()) 96eq ( { 2 , 1 } , fn . win_screenpos ( 0 )) 97local win3 =curwin () 98 99api . nvim_win_hide ( win2 ) 100eq ( win3 , curwin ()) 101eq ( 1 , # api . nvim_list_tabpages ()) 102eq ( { 1 , 1 } , fn . win_screenpos ( 0 )) 103end ) 104 105it ( 'switching tabpage after setting laststatus=3 #19591' , function () 106local screen =Screen . new ( 40 , 8 ) 107screen : add_extra_attr_ids { 108[ 100 ] ={ bold =true , foreground =Screen . colors . Fuchsia } , 109} 110 111command ( 'tabnew' ) 112command ( 'tabprev' ) 113command ( 'set laststatus=3' ) 114command ( 'tabnext' ) 115feed ( '<C-G>' ) 116screen : expect ( [[ 117{24: [No Name] }{5: [No Name] }{2: }{24:X}| 118^ | 119{1:~ }|*4 120{3:[No Name] }| 121"[No Name]" --No lines in buffer-- | 122]] ) 123command ( 'vnew' ) 124screen : expect ( [[ 125{24: [No Name] }{5: }{100:2}{5: [No Name] }{2: }{24:X}| 126^ │ | 127{1:~ }│{1:~ }|*4 128{3:[No Name] }| 129"[No Name]" --No lines in buffer-- | 130]] ) 131end ) 132 133it ( ':tabmove handles modifiers and addr' , function () 134command ( 'tabnew | tabnew | tabnew' ) 135eq ( 4 , fn . nvim_tabpage_get_number ( 0 )) 136command ( ' silent :keepalt :: ::: silent! - tabmove' ) 137eq ( 3 , fn . nvim_tabpage_get_number ( 0 )) 138command ( ' silent :keepalt :: ::: silent! -2 tabmove' ) 139eq ( 1 , fn . nvim_tabpage_get_number ( 0 )) 140end ) 141 142it ( '0 means current tabpage for gettabvar()' , function () 143command ( 'let t:tabvar = 42' ) 144eq ( 42 , fn . gettabvar ( 0 , 'tabvar' )) 145end ) 146 147it ( "gettabwinvar() returns tab-local 'cmdheight' #31140" , function () 148command ( 'set cmdheight=5' ) 149local tab1 =api . nvim_get_current_tabpage () 150command ( 'tabnew' ) 151command ( 'set cmdheight=2' ) 152local tab2 =api . nvim_get_current_tabpage () 153local tnr1 =fn . nvim_tabpage_get_number ( tab1 ) 154local tnr2 =fn . nvim_tabpage_get_number ( tab2 ) 155 156-- Reading the *other* tab's cmdheight does not change the current tab. 157eq ( 5 , fn . gettabwinvar ( tnr1 , 1 , '&cmdheight' )) 158eq ( 2 , fn . gettabwinvar ( tnr2 , 1 , '&cmdheight' )) 159eq ( tab2 , api . nvim_get_current_tabpage ()) 160eq ( 2 , api . nvim_get_option_value ( 'cmdheight' , {} )) 161end ) 162 163it ( ':tabs does not overflow IObuff with long path with comma #20850' , function () 164api . nvim_buf_set_name ( 0 , ( 'x' ): rep ( 1024 ) .. ',' .. ( 'x' ): rep ( 1024 )) 165command ( 'tabs' ) 166assert_alive () 167end ) 168 169it ( 'no crash if autocmd remains in tabpage of closing last window' , function () 170exec ( [[ 171tabnew 172let s:win = win_getid() 173autocmd TabLeave * ++once tablast | tabonly 174quit 175]] ) 176end ) 177 178it ( 179'no crash when :tabclose/:tabonly and WinClosed autocmd wipes buf and switches to closing tab' , 180function () 181exec_lua ( function () 182local win1 =vim . api . nvim_get_current_win () 183vim . cmd ( 'botright new' ) 184local win2 =vim . api . nvim_get_current_win () 185local buf2 =vim . api . nvim_get_current_buf () 186vim . cmd ( 'tabedit' ) 187vim . api . nvim_create_autocmd ( 'WinClosed' , { 188pattern =tostring ( win2 ), 189callback =function () 190-- Wipe the closing window's buffer and switch back to the original window, 191-- so `curtab == tp` in tabpage_close_other's loop. 192vim . api . nvim_buf_delete ( buf2 , { force =true } ) 193vim . api . nvim_set_current_win ( win1 ) 194end , 195} ) 196vim . cmd ( 'tabonly' ) 197end ) 198assert_alive () 199end 200) 201end )