Audit keyboard, focus, veils, motion and clocks across all 500
A cross-cutting pass, each fix with a test that failed first. Veils: MyGo still hands a key to a base that turned off this frame, so every element key now goes through pixel.Shortcut, which an archtest enforces. Input handlers record and the build applies them only while enabled; the editor turns away a veil-frame letter or copy; value bases get a copy and keep only enabled turns. Popups give a held focus back to their opener when the veil lifts. Motion: S5 is enforced at the clock. Every Tick, Since, Step, Toward and Shot runs at 4-15 fps; blinks keep 1 Hz on 4 fps steps, fast animations step at 15, and drawn time is quantized to frames. Clocks stepping back: Since holds at zero without overflow, and k.Elapsed moves a stored start to now, so nothing goes negative, runs backward or indexes out of range. Also: logs count typed text instead of holding it, gallery names use glyphs the font has, removable rows are keyed, components take their own Options (archtest), and sweeps over all 508 demos check veiled keys, clicks, wheels, the clock stepping back and names.
This commit is contained in:
198 files changed
+2708
-422
No files matched your search
@@ -162,6 +162,10 @@ func TestNoBannedCalls(t *testing.T) {
|
||||
if pkg && isUI(sel.X, "", imported) && bannedFuncs[sel.Sel.Name] || !pkg && bannedMethods[sel.Sel.Name] {
|
||||
t.Errorf("%s: banned call %s", f.path, sel.Sel.Name)
|
||||
}
|
||||
// An element's keys go through pixel.Shortcut; c's are the window's.
|
||||
if id, ok := sel.X.(*ast.Ident); sel.Sel.Name == "Shortcut" && !pkg && !(ok && id.Name == "c") {
|
||||
t.Errorf("%s: %s.Shortcut skips the enabled check; use pixel.Shortcut", f.path, receiver(sel.X))
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
@@ -269,3 +273,61 @@ func TestWebScripts(t *testing.T) {
|
||||
t.Fatalf("found %d web scripts; the walk is broken", seen)
|
||||
}
|
||||
}
|
||||
|
||||
// TestComponentsTakeTheirOptions holds PRD 5.1's shape: Name takes NameOptions.
|
||||
func TestComponentsTakeTheirOptions(t *testing.T) {
|
||||
for _, f := range files(t) {
|
||||
tier, ok := tiers[f.pkg]
|
||||
if !ok || tier < 2 || tier > 6 || strings.HasSuffix(f.path, "_test.go") {
|
||||
continue
|
||||
}
|
||||
for _, d := range f.ast.Decls {
|
||||
fn, ok := d.(*ast.FuncDecl)
|
||||
// Undrawn bases, as MyGo's own, are parts, not components.
|
||||
if !ok || fn.Recv != nil || !fn.Name.IsExported() || strings.HasSuffix(fn.Name.Name, "Base") || len(fn.Type.Params.List) == 0 || !isContext(fn.Type.Params.List[0].Type) {
|
||||
continue
|
||||
}
|
||||
want := fn.Name.Name + "Options"
|
||||
if !slices.ContainsFunc(fn.Type.Params.List, func(p *ast.Field) bool { return typeName(p.Type) == want }) {
|
||||
t.Errorf("%s: %s takes no %s", f.path, fn.Name.Name, want)
|
||||
}
|
||||
if r := fn.Type.Results; r != nil && len(r.List) == 1 && strings.HasSuffix(typeName(r.List[0].Type), "Result") && typeName(r.List[0].Type) != fn.Name.Name+"Result" {
|
||||
t.Errorf("%s: %s returns %s", f.path, fn.Name.Name, typeName(r.List[0].Type))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// isContext reports whether x is *ui.Context.
|
||||
func isContext(x ast.Expr) bool {
|
||||
star, ok := x.(*ast.StarExpr)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
sel, ok := star.X.(*ast.SelectorExpr)
|
||||
return ok && sel.Sel.Name == "Context"
|
||||
}
|
||||
|
||||
// typeName is a plain or generic type's name, else "".
|
||||
func typeName(x ast.Expr) string {
|
||||
switch x := x.(type) {
|
||||
case *ast.Ident:
|
||||
return x.Name
|
||||
case *ast.IndexExpr:
|
||||
return typeName(x.X)
|
||||
case *ast.IndexListExpr:
|
||||
return typeName(x.X)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// receiver names a selector's receiver for a message.
|
||||
func receiver(x ast.Expr) string {
|
||||
switch x := x.(type) {
|
||||
case *ast.Ident:
|
||||
return x.Name
|
||||
case *ast.SelectorExpr:
|
||||
return receiver(x.X) + "." + x.Sel.Name
|
||||
}
|
||||
return "an element"
|
||||
}
|
||||
Reference in new issue
Block a user