Add asserts for set_roof write API

Covers value validation (rejects 2), bounds rejection, and the
basic call paths that set up roof state for the save-roundtrip
test in the next commit.
This commit is contained in:
Axel Meyer
2026-05-24 00:34:18 +02:00
parent 8453b1fc8f
commit e399f6c6f8

View File

@@ -282,6 +282,24 @@ function M.run_tests(ctx)
engine.test.equals(maps.cell_gid("wall", 0, 0), 0, engine.test.equals(maps.cell_gid("wall", 0, 0), 0,
"auto-allocated layer initialised to all-zero except the written cell") "auto-allocated layer initialised to all-zero except the written cell")
-- ---------- v0.4.0: set_roof ----------
-- Roof should be nil before any write. No direct cell_roof reader exists yet
-- (out of scope for v0.4.0). Verify behaviourally via JSON round-trip in Task 3.
-- Happy path: set roof cells, no assertion on read since no public reader
maps.set_roof(1, 1, 1)
maps.set_roof(1, 1, 0) -- toggle back
maps.set_roof(2, 2, 1) -- leave this one set for Task 3's round-trip test
-- Value validation
local ok_v, err_v = pcall(function() maps.set_roof(0, 0, 2) end)
engine.test.assert(not ok_v, "set_roof rejects value=2")
engine.test.assert(err_v and err_v:find("0.*1"), "set_roof error mentions 0 or 1")
-- Bounds rejection
local ok_b = pcall(function() maps.set_roof(4, 0, 1) end)
engine.test.assert(not ok_b, "set_roof rejects x out of bounds")
engine.exit(engine.test.failures()) engine.exit(engine.test.failures())
end end