Files
aego/ui/theme/theme_test.go
sanspie 50be5c04bc
ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Stage 12.5: Art Workspace and asset authoring
Add dockable Art tools, animation and previews, guarded asset workflows,
and the Web Asset Studio built on the shared Art Core. Expand English and
Russian documentation, interactive Try scenes, examples and editor icons.

Add audio waveform navigation, source analysis, guarded previews and a
browser Worker mixer. Preserve source changes and recovery with bounded
checks, and strengthen native, browser and interoperability CI.

Prepare version 0.12.5 and manually built native artifact candidates.
Fix the production site image demo build dependency.
Reuse immutable scene indices when capturing keyframes.
Wait for real Persist save/load completion in component tests.
Stabilize browser Game View captures outside pointer hover.
Aseprite interchange and persistent Audio EDL recovery remain limited;
the artifact workflow does not publish releases or change stable.
2026-11-15 10:37:50 +03:00

151 lines
5.2 KiB
Go

package theme
import (
"reflect"
"testing"
"aego/core/mathx"
)
func TestCodeThemeComplete(t *testing.T) {
colorT := reflect.TypeOf(mathx.Color{})
for name, th := range map[string]Theme{"default": Default(), "editor": Editor(), "light": Light()} {
v := reflect.ValueOf(th.Code)
for i := 0; i < v.NumField(); i++ {
f, field := v.Field(i), v.Type().Field(i)
switch {
case f.Type() == colorT:
if f.Interface().(mathx.Color).A == 0 {
t.Errorf("%s: Code.%s is empty", name, field.Name)
}
case f.Kind() == reflect.Array && f.Type().Elem() == colorT:
for j := 0; j < f.Len(); j++ {
if f.Index(j).Interface().(mathx.Color).A == 0 {
t.Errorf("%s: Code.%s[%d] is empty", name, field.Name, j)
}
}
case f.Kind() == reflect.Float32:
if f.Float() == 0 {
t.Errorf("%s: Code.%s is zero", name, field.Name)
}
}
}
}
}
type pair struct {
name string
fg, bg mathx.Color
min float32
}
func pairs(t Theme) []pair {
c := t.Code
out := []pair{
{"Text/Panel", t.Text, t.Panel, 7},
{"Text/PanelAlt", t.Text, t.PanelAlt, 7},
{"Text/CardBg", t.Text, t.CardBg, 7},
{"Text/Background", t.Text, t.Background, 7},
{"Text/Selection", t.Text, t.Selection, 4.5},
{"Text/ButtonActive", t.Text, t.ButtonActive, 4.5},
{"Text/Widget", t.Text, t.Widget, 4.5},
{"TextDim/Panel", t.TextDim, t.Panel, 4.5},
{"TextDim/Header", t.TextDim, t.Header, 4.5},
{"TextDim/CardBg", t.TextDim, t.CardBg, 4.5},
{"TextDisabled/Panel", t.TextDisabled, t.Panel, 2},
{"Unit/CardBg", t.Unit, t.CardBg, 3},
{"Accent/Panel", t.Accent, t.Panel, 3},
{"Error/Panel", t.Error, t.Panel, 3},
{"Warn/Panel", t.Warn, t.Panel, 3},
{"Ok/Panel", t.Ok, t.Panel, 3},
{"Border/Panel", t.Border, t.Panel, 1.1},
{"LineNoActive/Gutter", c.LineNoActive, c.GutterBg, 4.5},
{"LineNo/Gutter", c.LineNo, c.GutterBg, 2},
{"Comment/Code", c.Comment, c.Background, 3},
}
for _, x := range []struct {
name string
col mathx.Color
}{
{"Plain", c.Plain}, {"Keyword", c.Keyword}, {"Type", c.Type}, {"Function", c.Function},
{"Field", c.Field}, {"Param", c.Param}, {"Const", c.Const}, {"String", c.String},
{"Number", c.Number}, {"Attribute", c.Attribute}, {"Namespace", c.Namespace},
{"Signal", c.Signal}, {"Coroutine", c.Coroutine}, {"Builtin", c.Builtin},
{"Operator", c.Operator}, {"Punctuation", c.Punctuation}, {"Error", c.Error},
} {
out = append(out, pair{x.name + "/Code", x.col, c.Background, 4.5})
}
for i, s := range t.Series {
out = append(out, pair{"Series" + string(rune('0'+i)) + "/Panel", s, t.Panel, 2.5})
}
return out
}
// Both themes keep text and syntax colours readable by WCAG ratios.
func TestThemeContrast(t *testing.T) {
for _, tc := range []struct {
name string
th Theme
}{{"dark", Editor()}, {"light", Light()}} {
for _, p := range pairs(tc.th) {
if got := Contrast(p.fg, p.bg); got < p.min {
t.Errorf("%s %s: contrast %.2f, want at least %.1f", tc.name, p.name, got, p.min)
}
}
}
}
func TestDestructiveButtonUsesReadableThemeColors(t *testing.T) {
for name, th := range map[string]Theme{"dark": Editor(), "light": Light()} {
normal := th.DestructiveButton(false, false)
hot := th.DestructiveButton(true, false)
active := th.DestructiveButton(false, true)
for state, bg := range map[string]mathx.Color{"normal": normal, "hot": hot, "active": active} {
if bg.A != 1 || bg.R <= bg.G || bg.R <= bg.B || Contrast(mathx.White, bg) < 4.5 {
t.Errorf("%s %s destructive action is not legible red: %+v, contrast %.2f", name, state, bg, Contrast(mathx.White, bg))
}
}
if !(Luminance(active) < Luminance(normal) && Luminance(normal) < Luminance(hot)) || th.DestructiveButton(true, true) != active {
t.Errorf("%s destructive button states do not preserve active priority", name)
}
}
}
func TestModeRoundTrip(t *testing.T) {
for _, m := range []Mode{ModeSystem, ModeDark, ModeLight} {
if ParseMode(m.String()) != m {
t.Fatalf("%v does not round-trip", m)
}
}
if !For(ModeSystem, true).Dark || For(ModeSystem, false).Dark || !For(ModeDark, false).Dark || For(ModeLight, true).Dark {
t.Fatal("For picks the wrong theme")
}
}
func TestSceneColorsFollowEditorTheme(t *testing.T) {
dark, light := Editor(), Light()
if dark.SceneBg != mathx.ColorRGB8(0x15, 0x17, 0x1B) {
t.Fatal("dark scene background changed")
}
if Luminance(light.SceneBg) < 0.5 || Luminance(light.SceneBg) <= Luminance(dark.SceneBg) {
t.Fatal("light scene background must be light")
}
if light.ViewportBg != dark.ViewportBg || light.ViewportText != dark.ViewportText {
t.Fatal("changing the scene must not change the game viewport frame")
}
for _, tc := range []struct {
name string
th Theme
}{{"dark", dark}, {"light", light}} {
if Contrast(tc.th.SceneText, tc.th.SceneBg) < 2 || Contrast(tc.th.SceneLine, tc.th.SceneBg) < 3 {
t.Errorf("%s scene overlays are not readable", tc.name)
}
if Contrast(tc.th.GridMajor, tc.th.SceneBg) <= Contrast(tc.th.GridMinor, tc.th.SceneBg) {
t.Errorf("%s major grid must be more visible than minor grid", tc.name)
}
}
if For(ModeSystem, false).SceneBg != light.SceneBg || For(ModeSystem, true).SceneBg != dark.SceneBg {
t.Fatal("system scene theme must follow the system appearance")
}
}