119 lines
3.9 KiB
Go
119 lines
3.9 KiB
Go
// Fenrir console screen reader.
|
|
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify it
|
|
// under the terms of the GNU General Public License as published by the Free
|
|
// Software Foundation, either version 3 of the License, or (at your option)
|
|
// any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
// more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
|
|
|
|
package input
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.stormux.org/storm/fenrir/internal/command"
|
|
)
|
|
|
|
func TestMenuChordAndCaptureSwallowEveryKey(t *testing.T) {
|
|
router := desktop_router(t)
|
|
router.Key(1, KeyInsert, 1, false, false)
|
|
if got := router.Key(1, KeyF, 1, false, false); got.Command != command.FenrirMenu || got.Forward {
|
|
t.Fatal(got)
|
|
}
|
|
router.Capture(true)
|
|
router.Key(1, KeyF, 0, false, false)
|
|
router.Key(1, KeyInsert, 0, false, false)
|
|
for _, numLock := range []bool{false, true} {
|
|
for code := uint16(1); code <= 767; code++ {
|
|
for _, value := range []int32{1, 2, 0} {
|
|
got := router.Key(2, code, value, numLock, false)
|
|
if got.Forward || got.Command != "" {
|
|
t.Fatalf("key %d value %d leaked: %+v", code, value, got)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCaptureClearsPassNextAndDrainsHeldKeys(t *testing.T) {
|
|
router := desktop_router(t)
|
|
if !router.Key(1, KeyCtrl, 1, false, false).Forward {
|
|
t.Fatal("fixture modifier not forwarded")
|
|
}
|
|
router.Pass_next()
|
|
router.Capture(true)
|
|
if len(router.Forwarded(1)) != 0 {
|
|
t.Fatal("forwarded state survived capture")
|
|
}
|
|
if router.Key(1, KeyCtrl, 0, false, false).Forward {
|
|
t.Fatal("modifier release leaked")
|
|
}
|
|
router.Key(1, KeyDown, 1, false, false)
|
|
router.Capture(false)
|
|
for _, value := range []int32{2, 0} {
|
|
got := router.Key(1, KeyDown, value, false, false)
|
|
if got.Forward || got.UI != nil || got.Command != "" {
|
|
t.Fatal("held key leaked after close", got)
|
|
}
|
|
}
|
|
if got := router.Key(1, KeyKP8, 1, false, false); got.Command != command.CurrentLine {
|
|
t.Fatal("pass-next survived", got)
|
|
}
|
|
router.Reset()
|
|
if got := router.Key(1, KeyF, 1, false, false); !got.Forward {
|
|
t.Fatal("ordinary input did not recover", got)
|
|
}
|
|
}
|
|
|
|
func TestCapturedModifiersRepeatAndSync(t *testing.T) {
|
|
router := desktop_router(t)
|
|
router.Capture(true)
|
|
if got := router.Key(3, KeyCtrl, 1, false, false); !got.Interrupt || got.Forward || got.UI != nil {
|
|
t.Fatal("captured Control did not stop speech", got)
|
|
}
|
|
router.Key(3, KeyCtrl, 0, false, false)
|
|
router.Key(1, KeyShift, 1, false, false)
|
|
got := router.Key(2, KeyTab, 1, false, false)
|
|
if got.UI == nil || !got.UI.Shift || got.UI.Name != "tab" {
|
|
t.Fatal(got)
|
|
}
|
|
got = router.Key(2, KeyTab, 2, false, false)
|
|
if got.UI == nil {
|
|
t.Fatal("navigation did not repeat")
|
|
}
|
|
for _, key := range []uint16{KeyEnter, KeySpace, KeyEsc} {
|
|
router.Key(1, key, 1, false, false)
|
|
if got := router.Key(1, key, 2, false, false); got.UI != nil {
|
|
t.Fatal("activation repeated", got)
|
|
}
|
|
}
|
|
if got := router.Key(1, KeyDown, 1, false, true); got.UI != nil || got.Forward {
|
|
t.Fatal("sync navigated", got)
|
|
}
|
|
}
|
|
|
|
func TestDesktopTOMLValidated(t *testing.T) {
|
|
bindings, err := Decode_bindings(desktop_data(t))
|
|
if err != nil || len(bindings.Bindings) == 0 {
|
|
t.Fatal(bindings, err)
|
|
}
|
|
for _, replacement := range []struct{ old, new string }{
|
|
{"version = 1", "version = 2"}, {"fenrir_menu", "unknown"},
|
|
{"\"FENRIR\", \"F\"", "\"FENRIR\", \"UNKNOWN\""},
|
|
} {
|
|
if _, err := Decode_bindings([]byte(strings.Replace(string(desktop_data(t)), replacement.old, replacement.new, 1))); err == nil {
|
|
t.Fatal("invalid layout accepted", replacement)
|
|
}
|
|
}
|
|
}
|