// 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 . // Package input routes Linux key codes without depending on a device backend. package input import ( "os" "testing" "git.stormux.org/storm/fenrir/internal/command" ) func TestPythonProgressBindingsAndNumLockPassThrough(t *testing.T) { for _, layout := range []string{"desktop", "laptop"} { data, err := os.ReadFile("../../config/keyboard/" + layout + ".toml") if err != nil { t.Fatal(err) } bindings, err := Decode_bindings(data) if err != nil { t.Fatal(err) } for _, numLock := range []bool{false, true} { router, err := New_router(bindings) if err != nil { t.Fatal(err) } key := uint16(KeyKPPlus) if layout == "laptop" { router.Key(0, KeyInsert, 1, numLock, false) router.Key(0, KeyShift, 1, numLock, false) key = 25 } got := router.Key(0, key, 1, numLock, false) if layout == "desktop" && numLock { if !got.Forward || got.Command != "" { t.Fatal("keypad Plus no longer types", got) } } else if got.Forward || got.Command != command.ProgressMonitor { t.Fatal(layout, numLock, got) } release := router.Key(0, key, 0, numLock, false) if release.Forward != got.Forward { t.Fatal("release leaked", layout, release) } } } } func TestDeletionMetadataDoesNotChangeKeyRouting(t *testing.T) { for _, key := range []uint16{KeyBackspace, KeyDelete} { router := desktop_router(t) for _, value := range []int32{1, 2} { got := router.Key(0, key, value, false, false) if !got.Forward || !got.Deletion || !got.Interrupt || got.Typing { t.Fatal("deletion metadata", key, value, got) } } if got := router.Key(0, key, 2, false, true); got.Deletion || got.Interrupt { t.Fatal("state sync became deletion", got) } if got := router.Key(0, key, 0, false, false); !got.Forward || got.Deletion { t.Fatal("deletion release changed", got) } } router := desktop_router(t) router.Key(0, KeyInsert, 1, false, false) if got := router.Key(0, KeyBackspace, 1, false, false); got.Deletion || got.Forward || got.Command != command.PassNext { t.Fatal("reader chord became deletion", got) } for _, key := range []uint16{KeyEnter, KeyLeft, KeyKPDot} { router := desktop_router(t) if got := router.Key(0, key, 1, false, false); got.Deletion { t.Fatal("unrelated key became deletion", key, got) } } }