Files

51 lines
2.0 KiB
Go

// Cthulhu screen reader.
// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
//
// 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 "testing"
func TestDocumentChords(t *testing.T) {
for _, layout := range []KeyboardLayout{DesktopKeyboardLayout, LaptopKeyboardLayout} {
for _, tc := range []struct {
symbol uint32
mask uint16
want Command
}{
{'h', 0, ToggleLearnMode}, {'h', 1, DocumentPreviousHeading},
{'k', controlModifier, DocumentNextLink}, {'k', controlModifier | 1, DocumentPreviousLink},
} {
router := NewCommandRouter([]uint32{0xff63}, DefaultCommandBindings(layout))
if consumed, _ := router.Handle(tc.symbol, 43, tc.mask, true); consumed {
t.Fatal("plain document key consumed")
}
router.Handle(tc.symbol, 43, tc.mask, false)
router.Handle(0xff63, 118, tc.mask, true)
if consumed, command := router.Handle(tc.symbol, 43, tc.mask, true); !consumed || command != tc.want {
t.Fatal("press did not dispatch command")
}
router.Handle(0xff63, 118, tc.mask, false)
if consumed, command := router.Handle(tc.symbol, 43, tc.mask, false); !consumed || command != "" {
t.Fatalf("got %v %v want %v", consumed, command, tc.want)
}
}
}
if got := DefaultCommandBindings(LaptopKeyboardLayout)[CommandChord{Symbol: 'k', CthulhuModifier: true}]; got != ReviewCurrentWord {
t.Fatal("laptop word binding replaced")
}
}