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) <noreply@anthropic.com>
This commit is contained in:
28
init.lua
28
init.lua
@@ -1,6 +1,7 @@
|
|||||||
-- lib-core.composition-test — Phase A.1 + B.1
|
-- lib-core.composition-test — Phase A.1 + B.1 + C.0
|
||||||
-- 23 assertions: 4 define_template + 4 create + 3 list_by_* + 2 destroy + 1 list_templates
|
-- 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.
|
-- + 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.*
|
-- Pattern follows P.2.4 Test-Module-Pattern; TAP output via engine.test.*
|
||||||
|
|
||||||
local composition = require("lib-core.composition")
|
local composition = require("lib-core.composition")
|
||||||
@@ -194,6 +195,27 @@ function M.run_tests(ctx)
|
|||||||
})
|
})
|
||||||
T.assert(not ok_slots_regression,
|
T.assert(not ok_slots_regression,
|
||||||
"define_template still loud-errors on 'slots' block (Phase D 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
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"id": "lib-core.composition-test",
|
"id": "lib-core.composition-test",
|
||||||
"role": "test",
|
"role": "test",
|
||||||
"version": "0.2.0",
|
"version": "0.3.0",
|
||||||
"api_min": "0.1",
|
"api_min": "0.1",
|
||||||
"deps": [
|
"deps": [
|
||||||
{"id": "lib-core.composition", "version": "0.2.0"}
|
{"id": "lib-core.composition", "version": "0.3.0"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user