initial json parsing

This commit is contained in:
Serg
2018-04-10 14:13:20 +07:00
parent 65e3d67c32
commit d0efdef8c2
4 changed files with 180 additions and 40 deletions
-36
View File
@@ -1,36 +0,0 @@
//
// MTMRTests.swift
// MTMRTests
//
// Created by Anton Palgunov on 16/03/2018.
// Copyright © 2018 Anton Palgunov. All rights reserved.
//
import XCTest
@testable import MTMR
class MTMRTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
+33
View File
@@ -0,0 +1,33 @@
import XCTest
@testable import MTMR
class ParseConfig: XCTestCase {
func testButtonNoAction() {
let buttonNoActionFixture = """
[ { "type": "staticButton", "title": "Pew" } ]
""".data(using: .utf8)!
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
XCTAssertEqual(result?.first?.type, .staticButton(title: "Pew"))
XCTAssertEqual(result?.first?.action, .some(.none))
}
func testButtonKeyCodeAction() {
let buttonKeycodeFixture = """
[ { "type": "staticButton", "title": "Pew", "action": "hidKey", "keycode": 123} ]
""".data(using: .utf8)!
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
XCTAssertEqual(result?.first?.type, .staticButton(title: "Pew"))
XCTAssertEqual(result?.first?.action, .hidKey(keycode: 123))
}
func testPredefinedItem() {
let buttonKeycodeFixture = """
[ { "type": "brightnessUp" } ]
""".data(using: .utf8)!
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
XCTAssertEqual(result?.first?.type, .staticButton(title: "🔆"))
XCTAssertEqual(result?.first?.action, .keyPress(keycode: 113))
}
}