From e399f6c6f81aa4bb18bb6c7bfd38f1c6a62388b8 Mon Sep 17 00:00:00 2001 From: Axel Meyer Date: Sun, 24 May 2026 00:34:18 +0200 Subject: [PATCH] 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. --- init.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/init.lua b/init.lua index 20c948b..19ec30b 100644 --- a/init.lua +++ b/init.lua @@ -282,6 +282,24 @@ function M.run_tests(ctx) engine.test.equals(maps.cell_gid("wall", 0, 0), 0, "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()) end