From 68a0932f8b483f58fe2146c49b6a81000b80303d Mon Sep 17 00:00:00 2001 From: Axel Meyer Date: Sun, 14 Jun 2026 11:57:31 +0200 Subject: [PATCH] test: assert template_of getter behavior + bump to v0.3.0 Bump composition dep to 0.3.0 and add 3 assertions covering the new getter: round-trip template-id on composition.create, loud-error on nil arg with message-pattern match, nil on raw entity.create handle. Co-Authored-By: Claude Opus 4.7 (1M context) --- init.lua | 28 +++++++++++++++++++++++++--- manifest.lib | 4 ++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index cc89e53..c36dd37 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,7 @@ --- lib-core.composition-test — Phase A.1 + B.1 --- 23 assertions: 4 define_template + 4 create + 3 list_by_* + 2 destroy + 1 list_templates --- + 8 B.1 (set_tag round-trip + container-block validation) + 1 slots regression. +-- lib-core.composition-test — Phase A.1 + B.1 + C.0 +-- 26 assertions: 4 define_template + 4 create + 3 list_by_* + 2 destroy + 1 list_templates +-- + 8 B.1 (set_tag round-trip + container-block validation) + 1 slots regression +-- + 3 C.0 (template_of getter: round-trip, nil-arg loud-error, raw-entity nil). -- Pattern follows P.2.4 Test-Module-Pattern; TAP output via engine.test.* local composition = require("lib-core.composition") @@ -194,6 +195,27 @@ function M.run_tests(ctx) }) T.assert(not ok_slots_regression, "define_template still loud-errors on 'slots' block (Phase D regression)") + + -- ================================================================ + -- C.0 — template_of getter (3) + -- ================================================================ + + -- 1. composition.create returns entity whose template_of returns its template-id. + local template_of_target = composition.create{ template = "sign" } + T.equals(composition.template_of(template_of_target), "sign", + "template_of returns template-id for composition-created entity") + + -- 2. template_of(nil) loud-errors with message matching "composition.template_of.*entity". + local ok_nil, err_nil = pcall(composition.template_of, nil) + T.assert(not ok_nil and type(err_nil) == "string" + and string.find(err_nil, "composition%.template_of") ~= nil + and string.find(err_nil, "entity") ~= nil, + "template_of(nil) loud-errors with message matching 'composition.template_of.*entity'") + + -- 3. Raw engine.entity.create() entity (no composition) → template_of returns nil (no error). + local raw_alien = entity.create() + T.equals(composition.template_of(raw_alien), nil, + "template_of returns nil for raw entity.create() handle (not composition-managed)") end return M diff --git a/manifest.lib b/manifest.lib index 70f9353..d13d6b2 100644 --- a/manifest.lib +++ b/manifest.lib @@ -1,9 +1,9 @@ { "id": "lib-core.composition-test", "role": "test", - "version": "0.2.0", + "version": "0.3.0", "api_min": "0.1", "deps": [ - {"id": "lib-core.composition", "version": "0.2.0"} + {"id": "lib-core.composition", "version": "0.3.0"} ] }