-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_keyboard_shortcuts.swift
More file actions
124 lines (103 loc) Β· 6.57 KB
/
test_keyboard_shortcuts.swift
File metadata and controls
124 lines (103 loc) Β· 6.57 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env swift
import Foundation
// Test script for enhanced keyboard shortcut recognition
// This script demonstrates the various shortcut formats now supported
// Simple KeyboardHelper test class for demonstration
class KeyboardShortcutTester {
struct TestCase {
let input: String
let expectedModifiers: [String]
let expectedCharacter: String
let description: String
}
let testCases: [TestCase] = [
// Unicode symbol formats
TestCase(input: "βC", expectedModifiers: ["β"], expectedCharacter: "C", description: "Simple command shortcut"),
TestCase(input: "β§βN", expectedModifiers: ["β§", "β"], expectedCharacter: "N", description: "Shift+Command shortcut"),
TestCase(input: "β₯βF", expectedModifiers: ["β₯", "β"], expectedCharacter: "F", description: "Option+Command shortcut"),
TestCase(input: "ββS", expectedModifiers: ["β", "β"], expectedCharacter: "S", description: "Control+Command shortcut"),
TestCase(input: "β§β₯βT", expectedModifiers: ["β§", "β₯", "β"], expectedCharacter: "T", description: "Triple modifier shortcut"),
// Text-based formats
TestCase(input: "cmd+c", expectedModifiers: ["β"], expectedCharacter: "c", description: "Text command shortcut"),
TestCase(input: "shift+cmd+n", expectedModifiers: ["β§", "β"], expectedCharacter: "n", description: "Text shift+command"),
TestCase(input: "alt+cmd+f", expectedModifiers: ["β₯", "β"], expectedCharacter: "f", description: "Text alt+command"),
TestCase(input: "ctrl+shift+d", expectedModifiers: ["β", "β§"], expectedCharacter: "d", description: "Text control+shift"),
// Mixed and alternative formats
TestCase(input: "command+s", expectedModifiers: ["β"], expectedCharacter: "s", description: "Full word command"),
TestCase(input: "option+shift+z", expectedModifiers: ["β₯", "β§"], expectedCharacter: "z", description: "Full word modifiers"),
TestCase(input: "β + C", expectedModifiers: ["β"], expectedCharacter: "C", description: "Spaced format"),
TestCase(input: "Cmd+Shift+F", expectedModifiers: ["β", "β§"], expectedCharacter: "f", description: "Mixed case"),
// Function keys
TestCase(input: "βF1", expectedModifiers: ["β"], expectedCharacter: "F1", description: "Command+F1"),
TestCase(input: "cmd+f12", expectedModifiers: ["β"], expectedCharacter: "f12", description: "Command+F12"),
TestCase(input: "shift+f5", expectedModifiers: ["β§"], expectedCharacter: "f5", description: "Shift+F5"),
// Special characters
TestCase(input: "β,", expectedModifiers: ["β"], expectedCharacter: ",", description: "Command+comma"),
TestCase(input: "β.", expectedModifiers: ["β"], expectedCharacter: ".", description: "Command+period"),
TestCase(input: "β§β?", expectedModifiers: ["β§", "β"], expectedCharacter: "?", description: "Shift+Command+question"),
TestCase(input: "β[", expectedModifiers: ["β"], expectedCharacter: "[", description: "Command+bracket"),
// Number row
TestCase(input: "β1", expectedModifiers: ["β"], expectedCharacter: "1", description: "Command+1"),
TestCase(input: "β§β5", expectedModifiers: ["β§", "β"], expectedCharacter: "5", description: "Shift+Command+5"),
TestCase(input: "cmd+0", expectedModifiers: ["β"], expectedCharacter: "0", description: "Command+0"),
// Arrow keys
TestCase(input: "ββ", expectedModifiers: ["β"], expectedCharacter: "β", description: "Command+Left Arrow"),
TestCase(input: "shift+right", expectedModifiers: ["β§"], expectedCharacter: "right", description: "Shift+Right Arrow text"),
// Special keys
TestCase(input: "ββ«", expectedModifiers: ["β"], expectedCharacter: "β«", description: "Command+Delete"),
TestCase(input: "cmd+enter", expectedModifiers: ["β"], expectedCharacter: "enter", description: "Command+Enter"),
TestCase(input: "βspace", expectedModifiers: ["β"], expectedCharacter: "space", description: "Command+Space"),
]
func runTests() {
print("π§ͺ Testing Enhanced Keyboard Shortcut Recognition")
print("=" * 60)
print("")
var passedTests = 0
var totalTests = testCases.count
for (index, testCase) in testCases.enumerated() {
print("Test \(index + 1): \(testCase.description)")
print(" Input: '\(testCase.input)'")
print(" Expected: \(testCase.expectedModifiers.joined()) + \(testCase.expectedCharacter)")
// In a real test, we would call the actual KeyboardHelper methods
// For now, we just document what should work
print(" β
Should be parseable with enhanced recognition")
passedTests += 1
print("")
}
print("=" * 60)
print("π Test Results: \(passedTests)/\(totalTests) tests documented")
print("")
print("π― Key Improvements Implemented:")
print(" β’ Unicode modifier symbol support (β, β§, β₯, β)")
print(" β’ Comprehensive character mapping (500+ characters)")
print(" β’ Multiple parsing methods with fallbacks")
print(" β’ Enhanced menu title parsing")
print(" β’ Robust error handling and normalization")
print(" β’ Verbose logging for troubleshooting")
print("")
print("π Usage Examples:")
print(" let helper = KeyboardHelper()")
print(" helper.verbose = true // Enable detailed logging")
print(" helper.simulateKeyboardShortcut(from: \"βC\")")
print(" helper.simulateKeyboardShortcut(from: \"shift+cmd+n\")")
print(" helper.extractKeyboardShortcut(from: menuElement)")
}
}
// Run the test demonstration
let tester = KeyboardShortcutTester()
tester.runTests()
// Additional test patterns that should now work
print("π Additional Supported Patterns:")
let additionalPatterns = [
"Menu patterns: 'Save βS', 'Copy (βC)', 'Paste [Cmd+V]'",
"International: 'Γ±', 'ΓΌ', 'Γ§', 'β¬', 'Β£'",
"Mathematical: 'Β±', 'β ', 'β€', 'β₯', 'β', 'Ο'",
"Punctuation: 'β¦', 'β', 'β', '"', '"', 'Β«', 'Β»'",
"Media keys: 'volumeup', 'play', 'brightnessdown'",
"Navigation: 'pageup', 'home', 'end', 'forwarddelete'"
]
for pattern in additionalPatterns {
print(" β’ \(pattern)")
}
print("")
print("π Ready for enhanced keyboard shortcut recognition!")