test(tabclose): remove deprecated calls, use testnvim helpers

This commit is contained in:
Sean Dewar
2025-07-19 18:18:15 +01:00
parent 05a83265f9
commit 1d2d6e31a7

View File

@@ -2,10 +2,10 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')() local n = require('test.functional.testnvim')()
local clear, eq = n.clear, t.eq local clear, eq = n.clear, t.eq
local api = n.api
local command = n.command local command = n.command
local eval = n.eval local eval = n.eval
local exec = n.exec local exec = n.exec
local exec_capture = n.exec_capture
describe('TabClosed', function() describe('TabClosed', function()
before_each(clear) before_each(clear)
@@ -18,11 +18,11 @@ describe('TabClosed', function()
) )
repeat repeat
command('tabnew') command('tabnew')
until api.nvim_eval('tabpagenr()') == 6 -- current tab is now 6 until 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:6:6:5', exec_capture('tabclose')) -- 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:5:5:4', exec_capture('close')) -- 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:2:2:3', exec_capture('2tabclose')) -- 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 eq('tabclosed:1:1:2\ntabclosed:1:1:1', exec_capture('tabonly')) -- close tabs 1 and 2
end) end)
it('is triggered when closing a window via bdelete from another tab', function() it('is triggered when closing a window via bdelete from another tab', function()
@@ -32,9 +32,9 @@ describe('TabClosed', function()
command('1tabedit Xtestfile') command('1tabedit Xtestfile')
command('1tabedit Xtestfile') command('1tabedit Xtestfile')
command('normal! 1gt') command('normal! 1gt')
eq({ 1, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) eq({ 1, 3 }, eval('[tabpagenr(), tabpagenr("$")]'))
eq('tabclosed:2:2:1\ntabclosed:2:2:1', api.nvim_exec('bdelete Xtestfile', true)) eq('tabclosed:2:2:1\ntabclosed:2:2:1', exec_capture('bdelete Xtestfile'))
eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) eq({ 1, 1 }, eval('[tabpagenr(), tabpagenr("$")]'))
end) end)
it('is triggered when closing a window via bdelete from current tab', function() it('is triggered when closing a window via bdelete from current tab', function()
@@ -46,9 +46,9 @@ describe('TabClosed', function()
command('1tabedit Xtestfile2') command('1tabedit Xtestfile2')
-- Only one tab is closed, and the alternate file is used for the other. -- Only one tab is closed, and the alternate file is used for the other.
eq({ 2, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) eq({ 2, 3 }, eval('[tabpagenr(), tabpagenr("$")]'))
eq('tabclosed:2:2:2', api.nvim_exec('bdelete Xtestfile2', true)) eq('tabclosed:2:2:2', exec_capture('bdelete Xtestfile2'))
eq('Xtestfile1', api.nvim_eval('bufname("")')) eq('Xtestfile1', eval('bufname("")'))
end) end)
it('triggers after tab page is properly freed', function() it('triggers after tab page is properly freed', function()
@@ -90,11 +90,11 @@ describe('TabClosed', function()
command('au! TabClosed 2 echom "tabclosed:match"') command('au! TabClosed 2 echom "tabclosed:match"')
repeat repeat
command('tabnew') command('tabnew')
until api.nvim_eval('tabpagenr()') == 7 -- current tab is now 7 until eval('tabpagenr()') == 7 -- current tab is now 7
-- sanity check, we shouldn't match on tabs with numbers other than 2 -- sanity check, we shouldn't match on tabs with numbers other than 2
eq('tabclosed:7:7:6', api.nvim_exec('tabclose', true)) eq('tabclosed:7:7:6', exec_capture('tabclose'))
-- close tab page 2, current tab is now 5 -- close tab page 2, current tab is now 5
eq('tabclosed:2:2:5\ntabclosed:match', api.nvim_exec('2tabclose', true)) eq('tabclosed:2:2:5\ntabclosed:match', exec_capture('2tabclose'))
end) end)
end) end)
@@ -104,9 +104,9 @@ describe('TabClosed', function()
'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
) )
command('tabedit Xtestfile') command('tabedit Xtestfile')
eq({ 2, 2 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) eq({ 2, 2 }, eval('[tabpagenr(), tabpagenr("$")]'))
eq('tabclosed:2:2:1', api.nvim_exec('close', true)) eq('tabclosed:2:2:1', exec_capture('close'))
eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) eq({ 1, 1 }, eval('[tabpagenr(), tabpagenr("$")]'))
end) end)
end) end)
end) end)