Files
aego/platform/web/input_fence_order_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

106 lines
3.4 KiB
Go

package web
import (
"fmt"
"reflect"
"testing"
"aego/core/mathx"
"aego/platform"
"aego/platform/input"
)
// The UI sees per-frame input snapshots, so event iteration order alone does
// not prove that editing operations are applied in their original order.
func replayFenceInputFrames(t *testing.T, events []platform.Event) []string {
t.Helper()
f := inspectorFence()
f.delayed = true
f.start = mathx.Vec2{X: 120, Y: 40}
var state input.State
var observed []string
for frame := 0; len(events) != 0 && frame < 32; frame++ {
state.BeginFrame()
n := f.dispatch(events, true, true, func(ev platform.Event) {
switch ev.Kind {
case platform.EvKeyDown:
state.ApplyKeyDown(ev.Key.Scan, ev.Key.Key, ev.Key.Mods, ev.Key.Repeat)
case platform.EvKeyUp:
state.ApplyKeyUp(ev.Key.Scan, ev.Key.Key, ev.Key.Mods)
case platform.EvTextInput:
state.ApplyText(ev.TextBytes())
}
})
if n <= 0 || n > len(events) {
t.Fatalf("frame %d did not make progress: %d", frame, n)
}
events = events[n:]
var actions []string
if len(state.Text()) > 0 {
actions = append(actions, "text:"+string(state.Text()))
}
for _, key := range []input.Scancode{input.KeyBackspace, input.KeyLeft, input.KeyEnter, input.KeyA} {
if state.KeyRepeated(key) {
actions = append(actions, fmt.Sprintf("key:%s:ctrl=%t", key, state.Mods().Has(input.ModCtrl)))
}
}
if len(actions) > 1 {
t.Fatalf("distinct editing actions collapsed in one UI snapshot: %v", actions)
}
observed = append(observed, actions...)
}
if len(events) != 0 {
t.Fatalf("replay did not finish: %d remaining", len(events))
}
return observed
}
func orderedFenceKeyPair(key input.Scancode, text string, mods input.Mods) []platform.Event {
down := fenceKey(platform.EvKeyDown, key, text)
up := fenceKey(platform.EvKeyUp, key, "")
down.Key.Mods, up.Key.Mods = mods, mods
return []platform.Event{down, up}
}
func TestInputFenceOrderedEditingSnapshots(t *testing.T) {
var events []platform.Event
for _, x := range []struct {
key input.Scancode
text string
}{
{input.Key9, "9"}, {input.KeyBackspace, ""}, {input.Key2, "2"}, {input.KeyEnter, ""},
} {
events = append(events, orderedFenceKeyPair(x.key, x.text, 0)...)
}
got := replayFenceInputFrames(t, events)
want := []string{"text:9", "key:Backspace:ctrl=false", "text:2", "key:Enter:ctrl=false"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("edit actions out of order: got %v, want %v", got, want)
}
}
func TestInputFenceOrderedModifierSnapshot(t *testing.T) {
down := fenceKey(platform.EvKeyDown, input.KeyLCtrl, "")
down.Key.Mods = input.ModCtrl
up := fenceKey(platform.EvKeyUp, input.KeyLCtrl, "")
var events []platform.Event
events = append(events, down)
events = append(events, orderedFenceKeyPair(input.KeyA, "", input.ModCtrl)...)
events = append(events, up)
events = append(events, orderedFenceKeyPair(input.Key2, "2", 0)...)
got := replayFenceInputFrames(t, events)
want := []string{"key:A:ctrl=true", "text:2"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("modifier and text out of order: got %v, want %v", got, want)
}
}
func TestInputFenceOrderedRepeatedActions(t *testing.T) {
events := append(orderedFenceKeyPair(input.KeyBackspace, "", 0), orderedFenceKeyPair(input.KeyBackspace, "", 0)...)
got := replayFenceInputFrames(t, events)
want := []string{"key:Backspace:ctrl=false", "key:Backspace:ctrl=false"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("repeated keys collapsed: got %v, want %v", got, want)
}
}