test: normalise nvim bridge functions

- remove helpers.cur*meths
- remove helpers.nvim
This commit is contained in:
Lewis Russell
2024-01-12 13:11:28 +00:00
parent c30f2e3182
commit 4f81f506f9
79 changed files with 1700 additions and 1753 deletions

View File

@@ -1,7 +1,6 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, nvim, tabpage, curtab, eq, ok =
helpers.clear, helpers.nvim, helpers.tabpage, helpers.curtab, helpers.eq, helpers.ok
local curtabmeths = helpers.curtabmeths
local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok
local meths = helpers.meths
local funcs = helpers.funcs
local request = helpers.request
local NIL = vim.NIL
@@ -13,35 +12,35 @@ describe('api/tabpage', function()
describe('list_wins and get_win', function()
it('works', function()
nvim('command', 'tabnew')
nvim('command', 'vsplit')
local tab1, tab2 = unpack(nvim('list_tabpages'))
local win1, win2, win3 = unpack(nvim('list_wins'))
eq({ win1 }, tabpage('list_wins', tab1))
eq({ win2, win3 }, tabpage('list_wins', tab2))
eq(win2, tabpage('get_win', tab2))
nvim('set_current_win', win3)
eq(win3, tabpage('get_win', tab2))
helpers.command('tabnew')
helpers.command('vsplit')
local tab1, tab2 = unpack(meths.nvim_list_tabpages())
local win1, win2, win3 = unpack(meths.nvim_list_wins())
eq({ win1 }, meths.nvim_tabpage_list_wins(tab1))
eq({ win2, win3 }, meths.nvim_tabpage_list_wins(tab2))
eq(win2, meths.nvim_tabpage_get_win(tab2))
meths.nvim_set_current_win(win3)
eq(win3, meths.nvim_tabpage_get_win(tab2))
end)
it('validates args', function()
eq('Invalid tabpage id: 23', pcall_err(tabpage, 'list_wins', 23))
eq('Invalid tabpage id: 23', pcall_err(meths.nvim_tabpage_list_wins, 23))
end)
end)
describe('{get,set,del}_var', function()
it('works', function()
curtab('set_var', 'lua', { 1, 2, { ['3'] = 1 } })
eq({ 1, 2, { ['3'] = 1 } }, curtab('get_var', 'lua'))
eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 't:lua'))
meths.nvim_tabpage_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } })
eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_tabpage_get_var(0, 'lua'))
eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_eval('t:lua'))
eq(1, funcs.exists('t:lua'))
curtabmeths.del_var('lua')
meths.nvim_tabpage_del_var(0, 'lua')
eq(0, funcs.exists('t:lua'))
eq('Key not found: lua', pcall_err(curtabmeths.del_var, 'lua'))
curtabmeths.set_var('lua', 1)
eq('Key not found: lua', pcall_err(meths.nvim_tabpage_del_var, 0, 'lua'))
meths.nvim_tabpage_set_var(0, 'lua', 1)
command('lockvar t:lua')
eq('Key is locked: lua', pcall_err(curtabmeths.del_var, 'lua'))
eq('Key is locked: lua', pcall_err(curtabmeths.set_var, 'lua', 1))
eq('Key is locked: lua', pcall_err(meths.nvim_tabpage_del_var, 0, 'lua'))
eq('Key is locked: lua', pcall_err(meths.nvim_tabpage_set_var, 0, 'lua', 1))
end)
it('tabpage_set_var returns the old value', function()
@@ -62,28 +61,28 @@ describe('api/tabpage', function()
describe('get_number', function()
it('works', function()
local tabs = nvim('list_tabpages')
eq(1, tabpage('get_number', tabs[1]))
local tabs = meths.nvim_list_tabpages()
eq(1, meths.nvim_tabpage_get_number(tabs[1]))
nvim('command', 'tabnew')
local tab1, tab2 = unpack(nvim('list_tabpages'))
eq(1, tabpage('get_number', tab1))
eq(2, tabpage('get_number', tab2))
helpers.command('tabnew')
local tab1, tab2 = unpack(meths.nvim_list_tabpages())
eq(1, meths.nvim_tabpage_get_number(tab1))
eq(2, meths.nvim_tabpage_get_number(tab2))
nvim('command', '-tabmove')
eq(2, tabpage('get_number', tab1))
eq(1, tabpage('get_number', tab2))
helpers.command('-tabmove')
eq(2, meths.nvim_tabpage_get_number(tab1))
eq(1, meths.nvim_tabpage_get_number(tab2))
end)
end)
describe('is_valid', function()
it('works', function()
nvim('command', 'tabnew')
local tab = nvim('list_tabpages')[2]
nvim('set_current_tabpage', tab)
ok(tabpage('is_valid', tab))
nvim('command', 'tabclose')
ok(not tabpage('is_valid', tab))
helpers.command('tabnew')
local tab = meths.nvim_list_tabpages()[2]
meths.nvim_set_current_tabpage(tab)
ok(meths.nvim_tabpage_is_valid(tab))
helpers.command('tabclose')
ok(not meths.nvim_tabpage_is_valid(tab))
end)
end)
end)