Files
aego/project/project_test.go
T
sanspie 69d19e501f Stage 7: documentation, help, playground; templates, aego new/bootstrap/icons, launcher
Documentation: engine/docs assembles one registry from the script
bindings, the schema, module docs and module-owned script paths; problems
are reported as warnings at build time. Module registries record doc
sources and script module owners; diag.Codes lists every diagnostic code.

Project bootstrap: project.defaultSpace ("2d"/"3d"), EnsureDirs creates
the default folders when the editor opens a project (reported in the
console), prefabs/ is a pipeline root. Native builds drop -trimpath so
binding locations resolve inside native/.

Editor files: create scene/prefab/script from menus, move/rename/duplicate
/delete with undo, script package retargeting on move, open scenes and
script panels follow renames, Save As / Rename Scene prompts, scene
picker, startup scene. Scoped shortcuts fall back to the global command
when disabled; Save As is Ctrl+Shift+S, Save All Ctrl+Alt+S.

Script editor: Go to Implementation (stub → native/ source), host
definitions always resolve to stubs, bracket match/mismatch states,
rainbow brackets (persisted), mono code font (ui-mono atlases, per-command
fonts in draw.List, PushFont/PopFont restored by Mark/Restore).

Tests: langsvc definition/implementation, bracket states, dispatch
fallback, script renames, font stack, editor file-op integration, golden
mono glyph and bracket references; depcheck rule for engine/docs.

Docs pipeline: engine, render2d and script/engine ship their own res/docs;
keyword hover text comes from the registry through manifest.Keywords;
project script symbols join the registry; aego docs export|check|build|
serve, --tool docs in native binaries, aego check --explain; app/docstool
and the tools/gendocs module (goldmark) build the static site.

Playground: app/playground + cmd/aego-playground (js/wasm, 3.3 MB gzip)
compile, highlight and run scripts in the browser; run blocks in the
language docs become examples. engine/builtin/headless is the module set
without render3d; workspace.Config.FS; StubFor/StubPaths; backends and the
script importer drop out of js builds.

VM: one frame pointer in the interpreter loop, direct host calls, panic
recovery once per run instead of per host call (Update2k -19%,
Schedule10k -24% against the previous head). bench-build/compare/profile
run pre-built, pinned, interleaved binaries.

Editor: structural bracket levels and current-block highlight, indent
guides, occurrence highlighting with write marks, multi-format clipboard
(copy/cut/paste assets, paste images as sprites or textures). gl33 probes
a renderable depth format and reports framebuffer failures by stage.

7 E:
- project templates empty/2d/2.5d/3d, app/projects as the single creation path (D148)
- launcher and recent projects (D149)
- orthographic Camera3D and Scene View (D150)
- reference states in the Inspector, ids.Short (D151)
- sceneio remaps node references when loading without KeepIDs (D152)
- exported ComponentRef<T> (D153)
- aego icons via module.Audit (D146)
2026-10-13 01:08:56 +03:00

118 lines
2.8 KiB
Go

package project
import (
"os"
"path/filepath"
"testing"
"aego/core/errs"
"aego/core/ids"
)
func TestCreateAndLoad(t *testing.T) {
root := t.TempDir()
p, err := Create(root, "My Game", true)
if err != nil {
t.Fatal(err)
}
if p.Module != "my-game" {
t.Fatalf("module = %q", p.Module)
}
for _, dir := range []string{p.AssetsDir(), p.ScenesDir(), p.CacheDir(), p.NativeDir()} {
if _, err := os.Stat(dir); err != nil {
t.Fatalf("missing directory %s", dir)
}
}
p.MainScene = ids.NewAssetID()
if err := p.Save(); err != nil {
t.Fatal(err)
}
back, err := Load(root)
if err != nil {
t.Fatal(err)
}
if back.Name != "My Game" || back.MainScene != p.MainScene || !back.Native {
t.Fatalf("loaded = %+v", back)
}
if back.Window.Width != 1280 || back.Window.Title != "My Game" {
t.Fatalf("window = %+v", back.Window)
}
}
func TestCreateRefusesToOverwrite(t *testing.T) {
root := t.TempDir()
if _, err := Create(root, "A", false); err != nil {
t.Fatal(err)
}
if _, err := Create(root, "B", false); !errs.Has(err, errs.ProjectExists) {
t.Fatalf("err = %v", err)
}
}
func TestFind(t *testing.T) {
root := t.TempDir()
if _, err := Create(root, "A", false); err != nil {
t.Fatal(err)
}
deep := filepath.Join(root, "assets", "sub")
os.MkdirAll(deep, 0o755)
found, err := Find(deep)
if err != nil {
t.Fatal(err)
}
if found != root {
t.Fatalf("found %q, want %q", found, root)
}
if _, err := Find(t.TempDir()); !errs.Has(err, errs.ProjectNotFound) {
t.Fatalf("err = %v", err)
}
}
func TestLoadRejectsNewerVersion(t *testing.T) {
root := t.TempDir()
os.WriteFile(filepath.Join(root, FileName), []byte("project version=99 {\n name=\"x\"\n}\n"), 0o644)
if _, err := Load(root); !errs.Has(err, errs.ProjectBadFile) {
t.Fatalf("err = %v", err)
}
}
func TestSaveIsCanonical(t *testing.T) {
root := t.TempDir()
p, _ := Create(root, "Game", false)
first, _ := os.ReadFile(p.FilePath())
back, _ := Load(root)
back.Save()
second, _ := os.ReadFile(p.FilePath())
if string(first) != string(second) {
t.Fatalf("save is not stable:\n%s\n---\n%s", first, second)
}
}
func TestLoadKeepsLayoutEnsureDirsCreates(t *testing.T) {
root := t.TempDir()
if err := os.WriteFile(filepath.Join(root, FileName), []byte("project version=1 {\n name=\"T\"\n}\n"), 0o644); err != nil {
t.Fatal(err)
}
p, err := Load(root)
if err != nil {
t.Fatal(err)
}
for _, d := range DefaultDirs {
if _, err := os.Stat(filepath.Join(root, d)); !os.IsNotExist(err) {
t.Fatalf("Load created %s", d)
}
}
made, err := p.EnsureDirs()
if err != nil {
t.Fatal(err)
}
if len(made) != len(DefaultDirs) {
t.Fatalf("created %v, want %v", made, DefaultDirs)
}
again, err := p.EnsureDirs()
if err != nil || len(again) != 0 {
t.Fatalf("second EnsureDirs created %v, err %v", again, err)
}
}