test(pack): simplify tests for data field

This commit is contained in:
Evgeni Chasnovski
2025-08-22 13:32:11 +03:00
parent 92e7d5eaf2
commit 7acfad226d

View File

@@ -311,32 +311,20 @@ describe('vim.pack', function()
eq(exec_lua('return #_G.event_log'), 0)
end)
it('passes data field through to opts.load', function()
eq(
2,
exec_lua(function()
local successes = 0
vim.pack.add({
{ name = 'tabletest', src = repos_src.basic, data = { test = 'value' } },
{ name = 'stringtest', src = repos_src.basic, data = 'value' },
}, {
confirm = false,
load = function(p)
if p.spec.name == 'tabletest' then
if p.spec.data.test == 'value' then
successes = successes + 1
end
end
if p.spec.name == 'stringtest' then
if p.spec.data == 'value' then
successes = successes + 1
end
end
end,
})
return successes
end)
)
it('passes `data` field through to `opts.load`', function()
local out = exec_lua(function()
local map = {} ---@type table<string,boolean>
local load = function(p)
local name = p.spec.name ---@type string
map[name] = name == 'basic' and (p.spec.data.test == 'value') or (p.spec.data == 'value')
end
vim.pack.add({
{ src = repos_src.basic, data = { test = 'value' } },
{ src = repos_src.defbranch, data = 'value' },
}, { load = load })
return map
end)
eq({ basic = true, defbranch = true }, out)
end)
it('asks for installation confirmation', function()
@@ -1207,21 +1195,17 @@ describe('vim.pack', function()
}, exec_lua('return vim.pack.get()'))
end)
it('respects data field', function()
eq(
true,
exec_lua(function()
vim.pack.add {
{ src = repos_src.basic, data = { test = 'value' } },
}
for _, p in ipairs(vim.pack.get()) do
if p.spec.name == 'basic' and p.spec.data.test == 'value' then
return true
end
end
return false
end)
)
it('respects `data` field', function()
local out = exec_lua(function()
vim.pack.add({
{ src = repos_src.basic, data = { test = 'value' } },
{ src = repos_src.defbranch, data = 'value' },
})
local plugs = vim.pack.get()
---@type table<string,string>
return { basic = plugs[1].spec.data.test, defbranch = plugs[2].spec.data }
end)
eq({ basic = 'value', defbranch = 'value' }, out)
end)
it('works with `del()`', function()