63 lines
2.3 KiB
Go
63 lines
2.3 KiB
Go
package input
|
|
|
|
import "testing"
|
|
|
|
func TestTentacleWormholeShortcutAvailableOnBothLayouts(t *testing.T) {
|
|
chord, err := ParseCommandChord("Cthulhu+Ctrl+Shift+W")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, layout := range []KeyboardLayout{DesktopKeyboardLayout, LaptopKeyboardLayout} {
|
|
suggestions := []BindingOverride{{Layout: layout, Scope: "global", Command: "tentacle/wormhole/menu", Keys: []string{"Cthulhu+Ctrl+Shift+W"}}}
|
|
merged := MergeTentacleBindings(nil, suggestions)
|
|
bindings, err := ResolveCommandBindings(layout, true, merged)
|
|
if err != nil || bindings[chord] != "tentacle/wormhole/menu" {
|
|
t.Fatalf("layout %v: shortcut %v, error %v", layout, bindings[chord], err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTentacleBindingsCoreWinsAcrossScopesAndRemapping(t *testing.T) {
|
|
suggestions := []BindingOverride{
|
|
{DesktopKeyboardLayout, "global", "tentacle/a/one", []string{"F9"}},
|
|
{DesktopKeyboardLayout, "browse", "tentacle/b/two", []string{"F9"}},
|
|
{DesktopKeyboardLayout, "global", "tentacle/a/quit", []string{"Cthulhu+q"}},
|
|
{LaptopKeyboardLayout, "global", "tentacle/b/two", []string{"F9"}},
|
|
}
|
|
if err := ValidateTentacleBindings(suggestions); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, core := range [][]BindingOverride{nil, {{DesktopKeyboardLayout, "browse", DocumentNextHeading, []string{"F9"}}}} {
|
|
merged := MergeTentacleBindings(core, suggestions)
|
|
bindings, err := ResolveCommandBindings(DesktopKeyboardLayout, true, merged)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
f9, _ := ParseCommandChord("F9")
|
|
want := Command("tentacle/a/one")
|
|
if core != nil {
|
|
want = DocumentNextHeading
|
|
}
|
|
if bindings[f9] != want {
|
|
t.Fatalf("F9 = %s want %s", bindings[f9], want)
|
|
}
|
|
quit, _ := ParseCommandChord("Cthulhu+q")
|
|
if bindings[quit] != Quit {
|
|
t.Fatal("tentacle replaced Quit")
|
|
}
|
|
laptop, _ := ResolveCommandBindings(LaptopKeyboardLayout, true, merged)
|
|
if laptop[f9] != "tentacle/b/two" {
|
|
t.Fatal("layouts share reservations")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTentacleBindingsRejectCoreIdentity(t *testing.T) {
|
|
if ValidateTentacleBindings([]BindingOverride{{DesktopKeyboardLayout, "global", Quit, []string{"F9"}}}) == nil {
|
|
t.Fatal("accepted core identity")
|
|
}
|
|
if ValidateBindingOverrides([]BindingOverride{{DesktopKeyboardLayout, "global", "tentacle/a/one", []string{"F9"}}}) == nil {
|
|
t.Fatal("persisted runtime registration")
|
|
}
|
|
}
|