Skip to content

Commit 76a1f16

Browse files
committed
Add JSONWrapperTests
1 parent 42a3bb6 commit 76a1f16

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import XCTest
2+
import Cache
3+
4+
final class JSONWrapperTests: XCTestCase {
5+
func testJSONDictionary() {
6+
let json: JSONDictionary = [
7+
"name": "John Snow",
8+
"location": "Winterfell"
9+
]
10+
11+
let wrapper = JSONDictionaryWrapper(jsonDictionary: json)
12+
13+
let data = try! JSONEncoder().encode(wrapper)
14+
let decodedWrapper = try! JSONDecoder().decode(JSONDictionaryWrapper.self, from: data)
15+
16+
XCTAssertEqual(
17+
NSDictionary(dictionary: decodedWrapper.jsonDictionary),
18+
NSDictionary(dictionary: json)
19+
)
20+
}
21+
22+
func testJSONArray() {
23+
let json: JSONArray = [
24+
[
25+
"name": "John Snow",
26+
"location": "Winterfell"
27+
],
28+
[
29+
"name": "Daenerys Targaryen",
30+
"location": "Dragonstone"
31+
]
32+
]
33+
34+
let wrapper = JSONArrayWrapper(jsonArray: json)
35+
36+
let data = try! JSONEncoder().encode(wrapper)
37+
let decodedWrapper = try! JSONDecoder().decode(JSONArrayWrapper.self, from: data)
38+
39+
zip(json, decodedWrapper.jsonArray).forEach {
40+
XCTAssertEqual(
41+
NSDictionary(dictionary: $0),
42+
NSDictionary(dictionary: $1)
43+
)
44+
}
45+
}
46+
}
47+

0 commit comments

Comments
 (0)