feat: P.3.1 reference test-module — lib-core.maps assertions

This commit is contained in:
Axel Meyer
2026-05-11 02:48:47 +02:00
commit c869196a62
7 changed files with 103 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
build/
*.log

17
README.md Normal file
View File

@@ -0,0 +1,17 @@
# sporel-module-lib-core.maps-test
P.3.1 reference test-module — validates `lib-core.maps` API contracts
via the `engine.test.*` assertion surface.
- Module-ID: `lib-core.maps-test`
- Version: `0.1.0`
- Kind: `test-module` (headless; runs init() once + exits)
- Spec: `meta/docs/superpowers/specs/2026-05-10-test-module-pattern-design.md`
## Run
```bash
Sporel.exe --module=lib-core.maps-test
```
Output is TAP version 13 on stdout; exit-code = failure-count (0 = all pass).

View File

@@ -0,0 +1,8 @@
{
"id": "demo_tilemap",
"tile_size": 32,
"tiles": [
{"id": "grass", "walkable": true, "color": [110, 170, 80]},
{"id": "stone", "walkable": false, "color": [120, 120, 120]}
]
}

37
init.lua Normal file
View File

@@ -0,0 +1,37 @@
-- =====================================================================
-- lib-core.maps-test — Reference test-module (P.3.1)
-- Validates lib-core.maps API contracts via engine.test.* assertions.
-- See: meta/docs/superpowers/specs/2026-05-10-test-module-pattern-design.md
-- =====================================================================
local maps = require("lib-core.maps")
function init(ctx)
-- Setup
local demo_map = maps.load("maps/demo.map.json")
maps.set_current(demo_map)
-- Geometry assertions
local size = maps.size()
engine.test.equals(size.w, 16, "map width = 16")
engine.test.equals(size.h, 16, "map height = 16")
engine.test.equals(maps.tile_size(), 32, "tile_size = 32")
-- Tile lookup + walkability
engine.test.equals(maps.tile_at(0, 0).id, "stone", "tile_at(0,0) is stone")
engine.test.equals(maps.tile_at(5, 5).id, "grass", "tile_at(5,5) is grass")
engine.test.assert(not maps.is_walkable(0, 0), "stone border non-walkable")
engine.test.assert(maps.is_walkable(5, 5), "grass interior walkable")
-- Arity-flex tile_at: 3-arg with nil map_id falls back to current_map (P.2.1)
engine.test.equals(maps.tile_at(nil, 5, 5).id, "grass", "tile_at 3-arg nil-fallback")
-- Out-of-bounds returns nil
engine.test.equals(maps.tile_at(-1, 0), nil, "tile_at OOB negative tx returns nil")
engine.test.equals(maps.tile_at(0, 16), nil, "tile_at OOB ty=size.h returns nil")
-- list() returns registered map-id
local list = maps.list()
engine.test.equals(#list, 1, "maps.list returns 1 registered map")
engine.exit(engine.test.failures())
end

6
manifest.core Normal file
View File

@@ -0,0 +1,6 @@
{
"id": "lib-core.maps-test.core",
"kind": "lib",
"version": "0.1.0",
"license": "Proprietary"
}

10
manifest.module Normal file
View File

@@ -0,0 +1,10 @@
{
"id": "lib-core.maps-test",
"kind": "test-module",
"version": "0.1.0",
"api": "^0.1",
"entry_point": "init.lua",
"deps": [
{"id": "lib-core.maps", "version": "0.1.1"}
]
}

23
maps/demo.map.json Normal file
View File

@@ -0,0 +1,23 @@
{
"id": "demo",
"tilemap": "demo_tilemap",
"size": {"w": 16, "h": 16},
"tiles": [
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
]
}