33 lines
1.3 KiB
Swift
33 lines
1.3 KiB
Swift
import AppKit
|
|
import ConjureKit
|
|
import Testing
|
|
|
|
@Test
|
|
func shortcutRequiresAnActivationModifierAndNormalizesEventFlags() {
|
|
#expect(KeyboardShortcut(keyCode: 0, modifiers: []) == nil)
|
|
#expect(KeyboardShortcut(keyCode: 0, modifiers: .shift) == nil)
|
|
#expect(KeyboardShortcut(keyCode: 0, modifiers: [.shift, .function, .capsLock]) == nil)
|
|
let activationModifiers: [NSEvent.ModifierFlags] = [.command, .option, .control]
|
|
for modifier in activationModifiers {
|
|
let shortcut = KeyboardShortcut(
|
|
keyCode: 0, modifiers: [modifier, .shift, .capsLock, .function, .numericPad]
|
|
)
|
|
#expect(shortcut?.modifiers == [modifier, .shift])
|
|
#expect(shortcut?.keyCode == 0)
|
|
}
|
|
#expect(KeyboardShortcut.commandSpace == KeyboardShortcut(keyCode: 49, modifiers: .command))
|
|
}
|
|
|
|
@Test
|
|
func shortcutRejectsModifierOnlyMediaAndUndefinedKeyCodes() {
|
|
let rejected: [UInt16] = [52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 66, 68, 70, 72, 73, 74, 77, 89, 108, 112, 127, .max]
|
|
for code in rejected {
|
|
#expect(KeyboardShortcut(keyCode: code, modifiers: .command) == nil)
|
|
}
|
|
let accepted: [UInt16] = [0, 10, 36, 49, 53, 64, 65, 67, 69, 71, 75, 76, 78, 88, 90, 95, 96, 102, 104, 107, 110, 126]
|
|
for code in accepted {
|
|
#expect(KeyboardShortcut(keyCode: code, modifiers: [.control, .option]) != nil)
|
|
}
|
|
}
|
|
|