2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local clear, eq = n.clear, t.eq
|
|
|
|
local api = n.api
|
|
|
|
local command = n.command
|
2015-01-04 21:03:22 -07:00
|
|
|
|
|
|
|
describe('TabClosed', function()
|
2017-12-30 06:12:25 -07:00
|
|
|
before_each(clear)
|
2017-12-29 12:35:52 -07:00
|
|
|
|
2017-12-30 06:12:25 -07:00
|
|
|
describe('au TabClosed', function()
|
|
|
|
describe('with * as <afile>', function()
|
|
|
|
it('matches when closing any tab', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command(
|
2017-12-30 06:12:25 -07:00
|
|
|
'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
|
|
|
|
)
|
|
|
|
repeat
|
2024-01-12 06:11:28 -07:00
|
|
|
command('tabnew')
|
2024-01-12 10:59:57 -07:00
|
|
|
until api.nvim_eval('tabpagenr()') == 6 -- current tab is now 6
|
|
|
|
eq('tabclosed:6:6:5', api.nvim_exec('tabclose', true)) -- close last 6, current tab is now 5
|
|
|
|
eq('tabclosed:5:5:4', api.nvim_exec('close', true)) -- close last window on tab, closes tab
|
|
|
|
eq('tabclosed:2:2:3', api.nvim_exec('2tabclose', true)) -- close tab 2, current tab is now 3
|
|
|
|
eq('tabclosed:1:1:2\ntabclosed:1:1:1', api.nvim_exec('tabonly', true)) -- close tabs 1 and 2
|
2017-12-30 06:12:25 -07:00
|
|
|
end)
|
2017-12-29 12:35:52 -07:00
|
|
|
|
2017-12-30 06:12:25 -07:00
|
|
|
it('is triggered when closing a window via bdelete from another tab', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command(
|
2017-12-30 06:12:25 -07:00
|
|
|
'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
|
|
|
|
)
|
2024-01-12 06:11:28 -07:00
|
|
|
command('1tabedit Xtestfile')
|
|
|
|
command('1tabedit Xtestfile')
|
|
|
|
command('normal! 1gt')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 1, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
|
|
|
|
eq('tabclosed:2:2:1\ntabclosed:2:2:1', api.nvim_exec('bdelete Xtestfile', true))
|
|
|
|
eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
|
2017-12-30 06:12:25 -07:00
|
|
|
end)
|
2017-12-29 12:35:52 -07:00
|
|
|
|
2017-12-30 06:12:25 -07:00
|
|
|
it('is triggered when closing a window via bdelete from current tab', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command(
|
2017-12-30 06:12:25 -07:00
|
|
|
'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
|
|
|
|
)
|
2024-01-12 06:11:28 -07:00
|
|
|
command('file Xtestfile1')
|
|
|
|
command('1tabedit Xtestfile2')
|
|
|
|
command('1tabedit Xtestfile2')
|
2017-12-29 12:35:52 -07:00
|
|
|
|
2017-12-30 06:12:25 -07:00
|
|
|
-- Only one tab is closed, and the alternate file is used for the other.
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 2, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
|
|
|
|
eq('tabclosed:2:2:2', api.nvim_exec('bdelete Xtestfile2', true))
|
|
|
|
eq('Xtestfile1', api.nvim_eval('bufname("")'))
|
2017-12-30 06:12:25 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('with NR as <afile>', function()
|
|
|
|
it('matches when closing a tab whose index is NR', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command(
|
2017-12-30 06:12:25 -07:00
|
|
|
'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
|
|
|
|
)
|
2024-01-12 06:11:28 -07:00
|
|
|
command('au! TabClosed 2 echom "tabclosed:match"')
|
2017-12-30 06:12:25 -07:00
|
|
|
repeat
|
2024-01-12 06:11:28 -07:00
|
|
|
command('tabnew')
|
2024-01-12 10:59:57 -07:00
|
|
|
until api.nvim_eval('tabpagenr()') == 7 -- current tab is now 7
|
2017-12-30 06:12:25 -07:00
|
|
|
-- sanity check, we shouldn't match on tabs with numbers other than 2
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('tabclosed:7:7:6', api.nvim_exec('tabclose', true))
|
2017-12-30 06:12:25 -07:00
|
|
|
-- close tab page 2, current tab is now 5
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('tabclosed:2:2:5\ntabclosed:match', api.nvim_exec('2tabclose', true))
|
2017-12-30 06:12:25 -07:00
|
|
|
end)
|
|
|
|
end)
|
2017-12-29 12:35:52 -07:00
|
|
|
|
2017-12-30 06:12:25 -07:00
|
|
|
describe('with close', function()
|
|
|
|
it('is triggered', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command(
|
2017-12-30 06:12:25 -07:00
|
|
|
'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
|
|
|
|
)
|
2024-01-12 06:11:28 -07:00
|
|
|
command('tabedit Xtestfile')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 2, 2 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
|
|
|
|
eq('tabclosed:2:2:1', api.nvim_exec('close', true))
|
|
|
|
eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
|
2017-12-30 06:12:25 -07:00
|
|
|
end)
|
2015-01-04 21:03:22 -07:00
|
|
|
end)
|
2017-12-30 06:12:25 -07:00
|
|
|
end)
|
2015-01-04 21:03:22 -07:00
|
|
|
end)
|