github.com/Seikaijyu/gio@v0.0.1/io/key/key_test.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package key
     4  
     5  import (
     6  	"testing"
     7  )
     8  
     9  func TestKeySet(t *testing.T) {
    10  	const allMods = ModAlt | ModShift | ModSuper | ModCtrl | ModCommand
    11  	tests := []struct {
    12  		Set        Set
    13  		Matches    []Event
    14  		Mismatches []Event
    15  	}{
    16  		{"A", []Event{{Name: "A"}}, []Event{{Name: "A", Modifiers: ModShift}}},
    17  		{"[A,B,C]", []Event{{Name: "A"}, {Name: "B"}}, []Event{}},
    18  		{"Short-A", []Event{{Name: "A", Modifiers: ModShortcut}}, []Event{{Name: "A", Modifiers: ModShift}}},
    19  		{"(Ctrl)-A", []Event{{Name: "A", Modifiers: ModCtrl}, {Name: "A"}}, []Event{{Name: "A", Modifiers: ModShift}}},
    20  		{"Shift-[A,B,C]", []Event{{Name: "A", Modifiers: ModShift}}, []Event{{Name: "B", Modifiers: ModShift | ModCtrl}}},
    21  		{Set(allMods.String() + "-A"), []Event{{Name: "A", Modifiers: allMods}}, []Event{}},
    22  	}
    23  	for _, tst := range tests {
    24  		for _, e := range tst.Matches {
    25  			if !tst.Set.Contains(e.Name, e.Modifiers) {
    26  				t.Errorf("key set %q didn't contain %+v", tst.Set, e)
    27  			}
    28  		}
    29  		for _, e := range tst.Mismatches {
    30  			if tst.Set.Contains(e.Name, e.Modifiers) {
    31  				t.Errorf("key set %q contains %+v", tst.Set, e)
    32  			}
    33  		}
    34  	}
    35  }