Ariver
2026-07-12 24f551a39eae849d891da26cc91f90d354e3a2db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//go:build darwin
 
package hotkey
 
import "testing"
 
func TestDarwinModifierDiagnosticsIncludeOptionAndCommand(t *testing.T) {
    tests := []struct {
        name    string
        keyCode int
        want    int
    }{
        {name: "left option", keyCode: 58, want: 0},
        {name: "right option", keyCode: 61, want: 1},
        {name: "left command", keyCode: 55, want: 2},
        {name: "right command", keyCode: 54, want: 3},
        {name: "non diagnostic", keyCode: 49, want: -1},
    }
 
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            if got := modifierDiagnosticIndex(tt.keyCode); got != tt.want {
                t.Fatalf("modifierDiagnosticIndex(%d) = %d, want %d", tt.keyCode, got, tt.want)
            }
        })
    }
}
 
func TestDarwinHotkeySourceNameDocumentsCommandFallback(t *testing.T) {
    tests := []struct {
        source int
        want   string
    }{
        {source: 0, want: "none"},
        {source: 1, want: "physicalHID"},
        {source: 2, want: "physicalCombined"},
        {source: 3, want: "eventTap"},
        {source: 4, want: "recent"},
        {source: 5, want: "aggregateCommandFlag"},
    }
 
    for _, tt := range tests {
        if got := hotkeySourceName(tt.source); got != tt.want {
            t.Fatalf("hotkeySourceName(%d) = %q, want %q", tt.source, got, tt.want)
        }
    }
}
 
func TestDarwinSideModifierSourceAcceptedRejectsAggregateCommandFlag(t *testing.T) {
    tests := []struct {
        name   string
        source int
        want   bool
    }{
        {name: "none", source: 0, want: false},
        {name: "physical HID", source: 1, want: true},
        {name: "physical combined", source: 2, want: true},
        {name: "event tap tracked", source: 3, want: true},
        {name: "recent side-specific event", source: 4, want: true},
        {name: "aggregate command diagnostic only", source: 5, want: false},
    }
 
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            if got := sideModifierSourceAccepted(tt.source); got != tt.want {
                t.Fatalf("sideModifierSourceAccepted(%d) = %t, want %t", tt.source, got, tt.want)
            }
        })
    }
}
 
func TestDarwinModifierGroupIncludesCommandSides(t *testing.T) {
    if got := modifierGroup(0x5B); got != 4 {
        t.Fatalf("modifierGroup(L-Command) = %d, want 4", got)
    }
    if got := modifierGroup(0x5C); got != 4 {
        t.Fatalf("modifierGroup(R-Command) = %d, want 4", got)
    }
}