Files
fenrir/internal/input/script_keys_test.go

94 lines
3.3 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 (
"git.stormux.org/storm/fenrir/internal/command"
"testing"
)
func TestScriptChordsModifiersRepeatsAndReleaseOrders(t *testing.T) {
for _, releaseModifierFirst := range []bool{true, false} {
router := new_script_router(t, []string{"KEY_COMPOSE"}, []ScriptBinding{{ID: "script:music", Keys: []string{"KEY_SCRIPT", "KEY_SHIFT", "KEY_U"}}})
compose, _ := Key_code("KEY_COMPOSE")
for _, key := range []uint16{compose, KeyRightShift} {
if result := router.Key(0, key, 1, false, false); result.Forward || result.Command != "" {
t.Fatal(result)
}
}
if result := router.Key(0, 22, 1, false, false); result.Command != "script:music" || result.Forward {
t.Fatal(result)
}
if result := router.Key(0, 22, 2, false, false); result.Command != "" || result.Forward {
t.Fatal("repeat launched script", result)
}
keys := []uint16{22, KeyRightShift, compose}
if releaseModifierFirst {
keys = []uint16{compose, KeyRightShift, 22}
}
for _, key := range keys {
if result := router.Key(0, key, 0, false, false); result.Forward || result.Command != "" {
t.Fatal(result)
}
}
if result := router.Key(0, 22, 1, false, false); !result.Forward || result.Command != "" {
t.Fatal("normal typing lost", result)
}
}
}
func new_script_router(t *testing.T, keys []string, bindings []ScriptBinding) Router {
t.Helper()
router, err := New_router(Layout{Bindings: []Binding{{Name: "Quit", Keys: []string{"FENRIR", "Q"}, Command: command.Quit}}})
if err != nil {
t.Fatal(err)
}
if err := router.Configure_scripts(keys, bindings); err != nil {
t.Fatal(err)
}
return router
}
func TestScriptRoutingHandoffPassNextAndUnbound(t *testing.T) {
router := new_script_router(t, []string{"KEY_F12"}, []ScriptBinding{{ID: "script:a", Keys: []string{"KEY_SCRIPT", "KEY_A"}}})
f12, _ := Key_code("KEY_F12")
router.Pass_next()
if result := router.Key(0, f12, 1, false, false); !result.Forward {
t.Fatal(result)
}
if result := router.Key(0, 30, 1, false, false); !result.Forward {
t.Fatal(result)
}
router.Reset()
router.Key(0, f12, 1, false, false)
if result := router.Key(0, 30, 1, false, true); result.Command != "" {
t.Fatal("sync fired script", result)
}
router.Reset()
router.Key(0, f12, 1, false, false)
if result := router.Key(0, 48, 1, false, false); result.Command != command.Unbound || result.Forward {
t.Fatal(result)
}
router.Reset()
router.Capture(true)
router.Key(0, f12, 1, false, false)
if result := router.Key(0, 30, 1, false, false); result.Command != "" || result.UI == nil {
t.Fatal("script escaped menu capture", result)
}
}