Files
cthulhu/internal/input/window_title_test.go

43 lines
1.5 KiB
Go

package input
import "testing"
func TestWindowTitleBindings(t *testing.T) {
for _, layout := range []KeyboardLayout{DesktopKeyboardLayout, LaptopKeyboardLayout} {
for _, modifierFirst := range []bool{false, true} {
symbol, code := keypadEnterKeySymbol, uint16(104)
if layout == LaptopKeyboardLayout {
symbol, code = '/', 61
}
bindings, err := ResolveCommandBindings(layout, true, nil)
if err != nil {
t.Fatal(err)
}
router := NewCommandRouter([]uint32{0xff63}, bindings)
router.Handle(0xff63, 118, 0, true)
if consumed, command := router.Handle(symbol, code, 0, true); !consumed || command != PresentWindowTitle {
t.Fatalf("layout %v title press = %v %q", layout, consumed, command)
}
if consumed, command := router.Handle(symbol, code, 0, true); !consumed || command != "" {
t.Fatalf("title repeat = %v %q", consumed, command)
}
keys := []struct {
symbol uint32
code uint16
}{{symbol, code}, {0xff63, 118}}
if modifierFirst {
keys[0], keys[1] = keys[1], keys[0]
}
for _, key := range keys {
if consumed, command := router.Handle(key.symbol, key.code, 0, false); !consumed || command != "" {
t.Fatalf("title release = %v %q", consumed, command)
}
}
// The command remains available through the preferences binding editor.
if err := ValidateBindingOverrides([]BindingOverride{{Layout: layout, Scope: "global", Command: PresentWindowTitle, Keys: []string{"Cthulhu+Ctrl+t"}}}); err != nil {
t.Fatal(err)
}
}
}
}