tabpage_spec.lua (4243B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 local Screen = require('test.functional.ui.screen') 4 5 local clear = n.clear 6 local command = n.command 7 local eq = t.eq 8 local neq = t.neq 9 local feed = n.feed 10 local eval = n.eval 11 local exec = n.exec 12 local fn = n.fn 13 local api = n.api 14 local curwin = n.api.nvim_get_current_win 15 local assert_alive = n.assert_alive 16 17 describe('tabpage', function() 18 before_each(clear) 19 20 it('advances to the next page via <C-W>gt', function() 21 -- add some tabpages 22 command('tabnew') 23 command('tabnew') 24 command('tabnew') 25 26 eq(4, eval('tabpagenr()')) 27 28 feed('<C-W>gt') 29 30 eq(1, eval('tabpagenr()')) 31 end) 32 33 it('retreats to the previous page via <C-W>gT', function() 34 -- add some tabpages 35 command('tabnew') 36 command('tabnew') 37 command('tabnew') 38 39 eq(4, eval('tabpagenr()')) 40 41 feed('<C-W>gT') 42 43 eq(3, eval('tabpagenr()')) 44 end) 45 46 it('does not crash or loop 999 times if BufWipeout autocommand switches window #17868', function() 47 exec([[ 48 tabedit 49 let s:window_id = win_getid() 50 botright new 51 setlocal bufhidden=wipe 52 let g:win_closed = 0 53 autocmd WinClosed * let g:win_closed += 1 54 autocmd BufWipeout <buffer> call win_gotoid(s:window_id) 55 tabprevious 56 +tabclose 57 ]]) 58 neq(999, eval('g:win_closed')) 59 end) 60 61 it('no segfault with strange WinClosed autocommand #20290', function() 62 pcall( 63 exec, 64 [[ 65 set nohidden 66 edit Xa 67 split Xb 68 tab split 69 new 70 autocmd WinClosed * tabprev | bwipe! 71 close 72 ]] 73 ) 74 assert_alive() 75 end) 76 77 it('nvim_win_close and nvim_win_hide update tabline #20285', function() 78 eq(1, #api.nvim_list_tabpages()) 79 eq({ 1, 1 }, fn.win_screenpos(0)) 80 local win1 = curwin() 81 82 command('tabnew') 83 eq(2, #api.nvim_list_tabpages()) 84 eq({ 2, 1 }, fn.win_screenpos(0)) 85 local win2 = curwin() 86 87 api.nvim_win_close(win1, true) 88 eq(win2, curwin()) 89 eq(1, #api.nvim_list_tabpages()) 90 eq({ 1, 1 }, fn.win_screenpos(0)) 91 92 command('tabnew') 93 eq(2, #api.nvim_list_tabpages()) 94 eq({ 2, 1 }, fn.win_screenpos(0)) 95 local win3 = curwin() 96 97 api.nvim_win_hide(win2) 98 eq(win3, curwin()) 99 eq(1, #api.nvim_list_tabpages()) 100 eq({ 1, 1 }, fn.win_screenpos(0)) 101 end) 102 103 it('switching tabpage after setting laststatus=3 #19591', function() 104 local screen = Screen.new(40, 8) 105 screen:add_extra_attr_ids { 106 [100] = { bold = true, foreground = Screen.colors.Fuchsia }, 107 } 108 109 command('tabnew') 110 command('tabprev') 111 command('set laststatus=3') 112 command('tabnext') 113 feed('<C-G>') 114 screen:expect([[ 115 {24: [No Name] }{5: [No Name] }{2: }{24:X}| 116 ^ | 117 {1:~ }|*4 118 {3:[No Name] }| 119 "[No Name]" --No lines in buffer-- | 120 ]]) 121 command('vnew') 122 screen:expect([[ 123 {24: [No Name] }{5: }{100:2}{5: [No Name] }{2: }{24:X}| 124 ^ │ | 125 {1:~ }│{1:~ }|*4 126 {3:[No Name] }| 127 "[No Name]" --No lines in buffer-- | 128 ]]) 129 end) 130 131 it(':tabmove handles modifiers and addr', function() 132 command('tabnew | tabnew | tabnew') 133 eq(4, fn.nvim_tabpage_get_number(0)) 134 command(' silent :keepalt :: ::: silent! - tabmove') 135 eq(3, fn.nvim_tabpage_get_number(0)) 136 command(' silent :keepalt :: ::: silent! -2 tabmove') 137 eq(1, fn.nvim_tabpage_get_number(0)) 138 end) 139 140 it('0 means current tabpage for gettabvar()', function() 141 command('let t:tabvar = 42') 142 eq(42, fn.gettabvar(0, 'tabvar')) 143 end) 144 145 it(':tabs does not overflow IObuff with long path with comma #20850', function() 146 api.nvim_buf_set_name(0, ('x'):rep(1024) .. ',' .. ('x'):rep(1024)) 147 command('tabs') 148 assert_alive() 149 end) 150 151 it('no crash if autocmd remains in tabpage of closing last window', function() 152 exec([[ 153 tabnew 154 let s:win = win_getid() 155 autocmd TabLeave * ++once tablast | tabonly 156 quit 157 ]]) 158 end) 159 end)