File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments