charm/packages/charm-sync/test/utils.test.luau
littensy 73fbfb2685
Some checks are pending
CI / analyze (push) Waiting to run
fix: resolve type errors for new luau version
2026-09-30 18:53:07 -07:00

22 lines
738 B
Text

local Charm = require("../Charm")
local test = require("../../../tests/test")
local utils = require("../src/utils")
test("should flatten functions", function()
local input = {
a = Charm.atom(0),
b = { c = Charm.atom(0) },
d = { e = { f = utils.signalToAtom<<number>>(Charm.signal(0)) } },
}
local result = utils.flatten<<{ [string]: Charm.Atom<number> }>>(input)
assert(result.a == input.a, "should flatten the first level")
assert(result["b/c"] == input.b.c, "should flatten the second level")
assert(result["d/e/f"] == input.d.e.f, "should flatten the third level")
assert(result.b == nil, "should remove the original nested tables")
assert(result.d == nil, "should remove the original nested tables")
end)
return {}