robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 9a29622b3b00ddb601

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