fix(util): Util.merge now skips nil args

This commit is contained in:
Folke Lemaitre 2023-10-13 11:37:52 +02:00
parent 3769461194
commit 70f764bf73
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 25 additions and 8 deletions

View file

@ -101,6 +101,22 @@ describe("util", function()
input = { { a = 1 }, { b = 2 } },
output = { a = 1, b = 2 },
},
{
input = { nil, { a = 1 }, { b = 2 } },
output = { a = 1, b = 2 },
},
{
input = { { a = 1 }, { b = 2 }, nil },
output = { a = 1, b = 2 },
},
{
input = { { a = 1 }, nil, { b = 2 } },
output = { a = 1, b = 2 },
},
{
input = { nil, { a = 1 }, nil, { b = 2 }, nil },
output = { a = 1, b = 2 },
},
{
input = { { a = 1 }, { a = 2 } },
output = { a = 2 },
@ -120,7 +136,11 @@ describe("util", function()
}
for _, test in ipairs(tests) do
assert.same(test.output, Util.merge(unpack(test.input)))
local n = 0
for i in pairs(test.input) do
n = math.max(n, i)
end
assert.same(test.output, Util.merge(unpack(test.input, 1, n)))
end
end)
end)