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:
18
init.lua
18
init.lua
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user