Cthulhu is no longer a fork. Now it is a screen reader written in Golang.
This commit is contained in:
1 parent
a998fe67de
commit
069fc674dc
708 files changed
+112482
-532
No files matched your search
@@ -0,0 +1,89 @@
|
||||
package input
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestShouldInterruptSpeechOnKeyPress(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
event Event
|
||||
want bool
|
||||
}{
|
||||
{name: "left control press", event: Event{Keycode: 37, Pressed: true}, want: true},
|
||||
{name: "left shift press", event: Event{Keycode: 50, Pressed: true}, want: true},
|
||||
{name: "right shift press", event: Event{Keycode: 62, Pressed: true}, want: true},
|
||||
{name: "left control release", event: Event{Keycode: 37, Pressed: false}, want: false},
|
||||
{name: "letter press", event: Event{Keycode: 38, Pressed: true}, want: true},
|
||||
{name: "up press at table boundary", event: NewKeyEvent(111, true, "Up"), want: true},
|
||||
{name: "up release", event: NewKeyEvent(111, false, "Up"), want: false},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := ShouldInterruptSpeech(test.event); got != test.want {
|
||||
t.Fatalf("ShouldInterruptSpeech() = %v, want %v", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifierKeycodesSupportsHighX11Keycodes(t *testing.T) {
|
||||
modifiers := NewModifierKeycodes(37, 105)
|
||||
|
||||
if !modifiers.Contains(37) || !modifiers.Contains(105) {
|
||||
t.Fatal("Control keycodes were omitted")
|
||||
}
|
||||
if modifiers.Contains(38) {
|
||||
t.Fatal("unrelated keycode was marked as a modifier")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewKeyEventClassifiesNonPrintableKeys(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
kind KeyKind
|
||||
text string
|
||||
}{
|
||||
{name: "Control_L", kind: KeyModifier, text: "left control"},
|
||||
{name: "ISO_Level3_Shift", kind: KeyModifier, text: "Alt Gr"},
|
||||
{name: "F12", kind: KeyFunction, text: "f12"},
|
||||
{name: "Return", kind: KeyAction, text: "return"},
|
||||
{name: "KP_Page_Down", kind: KeyAction, text: "page down"},
|
||||
{name: "Left", kind: KeyNavigation, text: "left"},
|
||||
{name: "KP_Home", kind: KeyNavigation, text: "home"},
|
||||
{name: "dead_acute", kind: KeyDiacritical, text: "acute"},
|
||||
{name: "dead_abovering", kind: KeyDiacritical, text: "ring"},
|
||||
{name: "a", kind: KeyUnknown, text: ""},
|
||||
{name: "F13", kind: KeyUnknown, text: ""},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
event := NewKeyEvent(42, true, test.name)
|
||||
if event.Kind != test.kind || event.Text != test.text || event.Name != test.name {
|
||||
t.Fatalf("event = %+v, want kind %v and text %q", event, test.kind, test.text)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEchoTextHonorsNonPrintableCategories(t *testing.T) {
|
||||
settings := EchoSettings{EnableKeyEcho: true, EnableModifierKeys: true, EnableFunctionKeys: true,
|
||||
EnableActionKeys: true, EnableNavigationKeys: true, EnableDiacriticalKeys: true}
|
||||
for _, name := range []string{"Control_L", "F1", "Tab", "Right", "dead_acute"} {
|
||||
event := NewKeyEvent(42, true, name)
|
||||
if got := EchoText(event, settings); got == "" {
|
||||
t.Fatalf("EchoText(%q) was empty", name)
|
||||
}
|
||||
}
|
||||
settings.EnableNavigationKeys = false
|
||||
if got := EchoText(NewKeyEvent(42, true, "Right"), settings); got != "" {
|
||||
t.Fatalf("disabled navigation echo = %q", got)
|
||||
}
|
||||
settings.EnableKeyEcho = false
|
||||
if got := EchoText(NewKeyEvent(42, true, "F1"), settings); got != "" {
|
||||
t.Fatalf("disabled key echo = %q", got)
|
||||
}
|
||||
settings.EnableKeyEcho = true
|
||||
if got := EchoText(NewKeyEvent(42, false, "F1"), settings); got != "" {
|
||||
t.Fatalf("release echo = %q", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user