After commit c018f5fd29 Fenrir is being switched over to go. If you do not want to be part of the testing process, please switch to master.

This commit is contained in:
Storm Dragon committed 2026-10-27 20:30:55 -04:00
1 parent c018f5fd29
commit 0e50de4c76
1047 files changed
+58364 -63747

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package input
import (
"testing"
"time"
"git.stormux.org/storm/fenrir/internal/command"
)
func TestBundledSpellingPressesAndHeldActions(t *testing.T) {
for _, layout := range []string{"desktop", "laptop"} {
bindings, _, err := Load_bindings([]string{"../../config/keyboard/" + layout + ".toml"})
if err != nil {
t.Fatal(err)
}
for _, trial := range []struct {
desktop, laptop uint16
actions []command.ID
}{
{KeyKP5, 37, []command.ID{command.CurrentWord, command.SpellWord, command.PhoneticWord, command.CurrentWord}},
{KeyKP8, 23, []command.ID{command.CurrentLine, command.SpellLine, command.PhoneticLine, command.CurrentLine}},
{KeyKP2, 51, []command.ID{command.CurrentChar, command.PhoneticChar, command.CurrentChar}},
} {
router, err := New_router(bindings)
if err != nil {
t.Fatal(err)
}
now := time.Unix(1000, 0)
router.now = func() time.Time { return now }
keyCode := trial.desktop
if layout == "laptop" {
keyCode = trial.laptop
}
for index, want := range trial.actions {
if layout == "laptop" {
router.Key(1, KeyInsert, 1, false, false)
}
if got := router.Key(1, keyCode, 1, false, false); got.Command != want || got.Forward || !got.Interrupt {
t.Fatal(layout, index, got, want)
}
for range 3 {
if got := router.Key(1, keyCode, 2, false, false); got.Command != want || got.Keypress || got.Forward {
t.Fatal("repeat advanced or lost its action", layout, got, want)
}
}
// Exercise both modifier release orders across fresh presses.
if layout == "laptop" && index%2 == 0 {
router.Key(1, KeyInsert, 0, false, false)
}
router.Key(1, keyCode, 0, false, false)
if layout == "laptop" && index%2 != 0 {
router.Key(1, KeyInsert, 0, false, false)
}
now = now.Add(100 * time.Millisecond)
}
now = now.Add(time.Second)
if layout == "laptop" {
router.Key(1, KeyInsert, 1, false, false)
}
if got := router.Key(1, keyCode, 1, false, false); got.Command != trial.actions[0] {
t.Fatal("expired sequence did not restart", got)
}
}
}
}