Files
aego/scene/sceneio/registries_test.go
sanspie 17cb5e4291 Stage 2-5: assets, scene/ECS, editor, 3D, and Aego Script
Stage 2: render pipeline and UI toolkit over gpu/platform.
Stage 3: schema registry, asset pipeline + runtime loader, scene graph and ECS.
Stage 4: editor — docking, inspector, scene/game views, play mode, asset browser, console, profiler; 4.5 adds the 3D foundation (mixed 2D/3D spaces, meshes, depth).
Stage 5: Aego Script — compiler (lexer/parser/types/resolver/checker/asm/compiler), bytecode with verifier and register VM, instance runtime, stdlib, native bindings, and editor/CLI integration (aego run/edit/check/test/dump).
2026-10-08 13:17:28 +03:00

56 lines
1.2 KiB
Go

package sceneio
import (
"testing"
"aego/scene"
"aego/schema"
)
type twin struct {
V float32 `aego:"v"`
}
func twinTypes(t *testing.T) *scene.Types {
t.Helper()
ty := scene.NewTypes(schema.NewRegistry())
if err := scene.RegisterComponent[twin](ty, schema.Name("test.Twin")); err != nil {
t.Fatal(err)
}
if err := RegisterUnknown(ty); err != nil {
t.Fatal(err)
}
if err := ty.Schema().Freeze(); err != nil {
t.Fatal(err)
}
return ty
}
func queryCount(t *testing.T, src *scene.Types, dst *scene.Types) int {
t.Helper()
s := scene.New(src, nil, scene.Options{})
h := s.Create(s.Root(), "N")
scene.Add[twin](s, h).V = 1
s.Flush()
loaded, _, err := Load(Save(s), "t.aescene", dst, nil, LoadOptions{KeepIDs: true})
if err != nil {
t.Fatal(err)
}
n := 0
scene.Query1[twin](loaded).Each(func(scene.NodeHandle, *twin) { n++ })
return n
}
func TestQuerySameRegistry(t *testing.T) {
ty := twinTypes(t)
if n := queryCount(t, ty, ty); n != 1 {
t.Fatalf("query sees %d nodes", n)
}
}
func TestQueryAcrossRegistries(t *testing.T) {
if n := queryCount(t, twinTypes(t), twinTypes(t)); n != 1 {
t.Fatalf("query sees %d nodes when the scene is loaded into a second registry", n)
}
}