// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later package input import "testing" func TestMessagingBindingsAndExplicitAssignments(t *testing.T) { for _, layout := range []KeyboardLayout{DesktopKeyboardLayout, LaptopKeyboardLayout} { for _, browse := range []bool{false, true} { bindings, err := ResolveCommandBindings(layout, browse, nil) if err != nil { t.Fatal(err) } if bindings[CommandChord{Symbol: 'h', CthulhuModifier: true}] != ToggleLearnMode { t.Fatal("learn mode shortcut changed") } for index := 0; index < 9; index++ { for _, copyMessage := range []bool{false, true} { modifiers := uint16(0) if copyMessage { modifiers = 1 } command := bindings[CommandChord{Symbol: 0xffbe + uint32(index), Modifiers: modifiers, CthulhuModifier: true}] gotIndex, gotCopy, ok := MessageCommandIndex(command) if !ok || gotIndex != index || gotCopy != copyMessage { t.Fatalf("chat chord = %s", command) } } } overrides := []BindingOverride{{Layout: layout, Scope: "global", Command: Preferences, Keys: []string{"Cthulhu+F8"}}} custom, err := ResolveCommandBindings(layout, browse, overrides) if err != nil || custom[CommandChord{Symbol: 0xffc5, CthulhuModifier: true}] != Preferences { t.Fatalf("explicit assignment lost: %v", err) } for _, row := range BindingRows(layout, overrides) { if row.Command == MessageCommand(7, false) && row.Keys != "" { t.Fatal("shortcut list shows a displaced chat binding") } } overrides = append(overrides, BindingOverride{Layout: layout, Scope: "global", Command: MessageCommand(0, false), Keys: []string{"Cthulhu+F8"}}) if ValidateBindingOverrides(overrides) == nil { t.Fatal("two explicit assignments were accepted") } } } for _, command := range []Command{"review-chat-message-0", "review-chat-message-10", "copy-chat-message-01", ToggleLearnMode} { if _, _, ok := MessageCommandIndex(command); ok { t.Fatalf("accepted %q", command) } } }