Files
fenrir/internal/input/additional_review_test.go

80 lines
2.5 KiB
Go

// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package input
import (
"testing"
"git.stormux.org/storm/fenrir/internal/command"
)
func TestAdditionalReviewChordsConsumeHoldsAndBalanceReleases(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
shift bool
want command.ID
}{
{KeyKP7, 22, true, command.CursorLine},
{KeyKP9, 24, true, command.CursorColumn},
{KeyKP4, 36, true, command.LineToCursor},
{KeyKP6, 38, true, command.LineFromCursor},
{KeyKP1, 50, false, command.ScreenFirstChar},
{KeyKP3, 52, false, command.ScreenLastChar},
} {
for _, controlKey := range []uint16{KeyCtrl, KeyRightCtrl} {
for _, modifierFirst := range []bool{false, true} {
for _, numLock := range []bool{false, true} {
router, err := New_router(bindings)
if err != nil {
t.Fatal(err)
}
keyCode := trial.desktop
modifierCodes := []uint16{KeyInsert, controlKey}
if layout == "laptop" {
keyCode = trial.laptop
if trial.shift {
modifierCodes = append(modifierCodes, KeyRightShift)
}
}
forwarded := map[uint16]bool{}
for _, code := range modifierCodes {
forwarded[code] = router.Key(1, code, 1, numLock, false).Forward
}
if got := router.Key(0, keyCode, 1, numLock, false); got.Command != trial.want || got.Forward || !got.Interrupt {
t.Fatal(layout, trial.want, got)
}
if got := router.Key(0, keyCode, 2, numLock, false); got.Command != "" || got.Forward || got.Interrupt {
t.Fatal("hold repeated command", trial.want, got)
}
releases := append([]uint16{keyCode}, modifierCodes...)
if modifierFirst {
releases = append(modifierCodes, keyCode)
}
for _, code := range releases {
device := 1
if code == keyCode {
device = 0
}
if got := router.Key(device, code, 0, numLock, false); got.Command != "" || got.Forward != forwarded[code] {
t.Fatal("unbalanced release", layout, trial.want, code, got)
}
}
if router.Held(0) || router.Held(1) {
t.Fatal("stuck additional-review chord")
}
if got := router.Key(0, 30, 1, numLock, false); !got.Forward || got.Command != "" {
t.Fatal("typing after report", got)
}
}
}
}
}
}
}