46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package qmp
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseKeyCombo(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
key string
|
|
mods []string
|
|
wantErr bool
|
|
}{
|
|
{"meta_l+v", "v", []string{"meta_l"}, false},
|
|
{"Ctrl+Shift+V", "v", []string{"ctrl", "shift"}, false},
|
|
{" ctrl + v ", "v", []string{"ctrl"}, false},
|
|
{"f5", "f5", nil, false},
|
|
{"", "", nil, true},
|
|
{"ctrl+", "", nil, true},
|
|
{"+v", "", nil, true},
|
|
{"ctrl+v; calc", "", nil, true},
|
|
{"ctrl+shift+/", "", nil, true},
|
|
}
|
|
for _, tc := range cases {
|
|
key, mods, err := ParseKeyCombo(tc.in)
|
|
if tc.wantErr {
|
|
if err == nil {
|
|
t.Errorf("ParseKeyCombo(%q) accepted", tc.in)
|
|
}
|
|
continue
|
|
}
|
|
if err != nil || key != tc.key || !reflect.DeepEqual(mods, tc.mods) {
|
|
t.Errorf("ParseKeyCombo(%q) = %q %v %v, want %q %v", tc.in, key, mods, err, tc.key, tc.mods)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSendPasteShortcutComboRejectsBadComboBeforeDialing(t *testing.T) {
|
|
err := SendPasteShortcutCombo(t.Context(), t.TempDir(), "ctrl+")
|
|
if err == nil || !strings.Contains(err.Error(), "empty key") {
|
|
t.Fatalf("err = %v", err)
|
|
}
|
|
}
|