fix(picker.config): better config merging and tests

This commit is contained in:
Folke Lemaitre 2025-01-17 20:36:33 +01:00
parent a194bbc374
commit 9986b47707
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
5 changed files with 99 additions and 35 deletions

46
tests/config_spec.lua Normal file
View file

@ -0,0 +1,46 @@
---@module 'luassert'
local function d(v)
return vim.inspect(v):gsub("%s+", " ")
end
describe("config", function()
local tests = {
{
{ 1, 2 },
{ 3, 4 },
{ 3, 4 },
},
{
{ 1, 2 },
nil,
{ 1, 2 },
},
{
{ a = 1, b = 2 },
{ c = 3 },
{ a = 1, b = 2, c = 3 },
},
{
{ 1, 2, a = 1 },
{ 3, 4, b = 2 },
{ 3, 4, b = 2 },
},
{
{ 3, 4, b = 2 },
{ 1, 2 },
{ 1, 2 },
},
{
{ 1, 2, a = 1 },
{ b = 2 },
{ 1, 2, b = 2, a = 1 },
},
}
for _, t in ipairs(tests) do
it("merges correctly " .. d(t), function()
local ret = Snacks.config.merge(t[1], t[2])
assert.are.same(ret, t[3])
end)
end
end)