-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.swift
More file actions
63 lines (50 loc) · 1.66 KB
/
Copy pathtests.swift
File metadata and controls
63 lines (50 loc) · 1.66 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
//
// tests.swift
// JSONParserTests
//
// Created by Eric Cote on 2019-12-15.
// Copyright © 2019 Eric Cote. All rights reserved.
//
import Foundation
import JSONParser
import XCTest
class Tests: XCTestCase {
override func setUp() {
}
override func tearDown() {
}
func testBools() throws {
XCTAssertTrue(try JSONParser.parse("true") as! Bool)
XCTAssertFalse(try JSONParser.parse("false") as! Bool)
}
func testNull() throws {
XCTAssertNil(try JSONParser.parse("null"))
}
func testNumber() throws {
let container = try JSONParser.parse("-12345.12345") as! Double
XCTAssertEqual(container, -12345.12345)
}
func testStringOnly() throws {
let s = "\"json parsing 👌 \\\" \""
let container = try JSONParser.parse(s) as! String
XCTAssertEqual(container, "json parsing 👌 \" ")
}
func testSimpleJSON() throws {
let jsonPath = Bundle(for: type(of: self)).path(forResource: "test", ofType: "json")!
let json = try String(contentsOfFile: jsonPath)
let container = try JSONParser.parse(json) as! Array<Any?>
let firstObject = container[0] as! Dictionary<String, Any?>
XCTAssertEqual(firstObject["_id"] as! String, "5df6e4c2689b2ad6546b9b66")
}
func testPerformanceExample() throws {
let jsonPath = Bundle(for: type(of: self)).path(forResource: "test", ofType: "json")!
let json = try String(contentsOfFile: jsonPath)
measure {
do {
_ = try JSONParser.parse(json)
} catch {
print(error)
}
}
}
}