mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 17:08:39 +00:00
68 lines
2.2 KiB
Swift
68 lines
2.2 KiB
Swift
import XCTest
|
|
|
|
class ParseConfig: XCTestCase {
|
|
func testButtonNoAction() {
|
|
let buttonNoActionFixture = """
|
|
[ { "type": "staticButton", "title": "Pew" } ]
|
|
""".data(using: .utf8)!
|
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
|
guard case .staticButton("Pew")? = result?.first?.type else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard case .none? = result?.first?.action else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
}
|
|
|
|
func testButtonKeyCodeAction() {
|
|
let buttonKeycodeFixture = """
|
|
[ { "type": "staticButton", "title": "Pew", "action": "hidKey", "keycode": 123} ]
|
|
""".data(using: .utf8)!
|
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
|
guard case .staticButton("Pew")? = result?.first?.type else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard case .hidKey(keycode: 123)? = result?.first?.action else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
}
|
|
|
|
func testPredefinedItem() {
|
|
let buttonKeycodeFixture = """
|
|
[ { "type": "escape" } ]
|
|
""".data(using: .utf8)!
|
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
|
guard case .staticButton("esc")? = result?.first?.type else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard case .keyPress(keycode: 53)? = result?.first?.action else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
}
|
|
|
|
func testExtendedWidthForPredefinedItem() {
|
|
let buttonKeycodeFixture = """
|
|
[ { "type": "escape", "width": 110}, ]
|
|
""".data(using: .utf8)!
|
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
|
guard case .staticButton("esc")? = result?.first?.type else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard case .keyPress(keycode: 53)? = result?.first?.action else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
guard case .width(110)? = result?.first?.additionalParameters[.width] else {
|
|
XCTFail()
|
|
return
|
|
}
|
|
}
|
|
}
|