Files
aego/ui/richtext/layout_test.go
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

81 lines
2.0 KiB
Go

package richtext
import "testing"
type mono7 struct{}
func (mono7) Width(f Face, s string) float32 {
n := float32(0)
for range s {
n++
}
if f == H1 {
return n * 12
}
return n * 7
}
func (mono7) Height(f Face) float32 {
if f == H1 {
return 24
}
return 16
}
func TestWrap(t *testing.T) {
lines := wrap(Inline("aaa bbb `ccc` ddd"), Body, 0, 7*8, mono7{})
if len(lines) != 2 {
t.Fatalf("%d lines: %+v", len(lines), lines)
}
if lines[0][0].Text != "aaa bbb" || lines[1][0].Text != "ccc" || lines[1][0].Face != Mono || lines[1][1].Text != " ddd" {
t.Fatalf("%+v", lines)
}
if lines[1][1].X != 21 {
t.Fatalf("x = %v", lines[1][1].X)
}
}
func TestLayout(t *testing.T) {
md := "# Coroutines\n\nA coroutine pauses with [yield](ref:keyword/yield).\n\n- one\n- two\n\n| Form | Resumes |\n|---|---|\n| `yield` | on the next frame of the game |\n\n```aes run\nyield wait(0.1)\n\treturn\n```\n"
hl := func(lang, line string) []Token {
if lang == "aes" && len(line) >= 5 && line[:5] == "yield" {
return []Token{{Start: 0, End: 5, Kind: "keyword"}}
}
return nil
}
d := Layout(Parse(md), 200, mono7{}, hl)
var kinds []LineKind
link, code, run, header := false, false, false, false
for _, l := range d.Lines {
kinds = append(kinds, l.Kind)
for _, r := range l.Runs {
if r.Target == "ref:keyword/yield" && r.Text == "yield" {
link = true
}
if r.Token == "keyword" && r.Text == "yield" {
code = true
}
}
run = run || l.Run
header = header || l.Header
}
if !link || !code || !run || !header {
t.Fatalf("link %v code %v run %v header %v", link, code, run, header)
}
if kinds[0] != HeadingLine || d.Lines[0].H != 24 {
t.Fatalf("heading line %+v", d.Lines[0])
}
for i := 1; i < len(d.Lines); i++ {
if d.Lines[i].Y < d.Lines[i-1].Y+d.Lines[i-1].H {
t.Fatalf("line %d overlaps the previous one", i)
}
}
for _, l := range d.Lines {
for _, r := range l.Runs {
if l.Kind != CodeLine && r.X+r.W > 200+0.01 && len(l.Runs) > 1 {
t.Fatalf("run %q overflows: %v+%v", r.Text, r.X, r.W)
}
}
}
}