forked from matthewcheok/JSONCodable
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArrayTests.swift
More file actions
85 lines (76 loc) · 2.42 KB
/
ArrayTests.swift
File metadata and controls
85 lines (76 loc) · 2.42 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// DictionaryTests.swift
// JSONCodable
//
// Created by FoxRichard on 11/5/16.
//
//
import XCTest
class ArrayTests: XCTestCase {
let mixedArrayJSON = [
[
"class": "propertyType",
"rel": "propertyType",
"properties":
[ "name": "John",
"location": [ "coord": [
"lat": 37.790770,
"long": -122.402015
]]]],
["name": "CompanyInc",
"address": "1414 place st Los Angeles, CA"],
[
"class": "propertyType",
"rel": "propertyType",
"properties":
[ "name": "Joe",
"location": [ "coord": [
"lat": 38.790770,
"long": -121.402015
]]]],
["name": "SoftwareInc",
"address": "1313 place st Oakland, CA"]
]
let companiesJSON: [[String: String]] = [
["name": "CompanyInc",
"address": "1414 place st Los Angeles, CA"],
["name": "SoftwareInc",
"address": "1313 place st Oakland, CA"]
]
func testMixedItemsInArray() {
do {
let companies = try [Company](JSONArray: mixedArrayJSON, filtered: true)
guard let companyValues = try? companies.toJSON(),
let companiesEncoded:[[String: String]] = (companyValues as? [[String: String]]) else {
XCTFail()
return
}
XCTAssert(companiesEncoded.count == 2, "encoding invalid")
XCTAssert(companiesJSON.count == 2, "companies mapping invalid")
XCTAssert(companiesEncoded[0] == companiesJSON[0], "companies values incorrect")
XCTAssert(companiesEncoded[1] == companiesJSON[1], "companies values incorrect")
print(companies)
} catch {
print("\(error)")
XCTFail()
}
}
func testMixedItemsInArrayNotFiltered() {
do {
let _ = try [Company](JSONArray: mixedArrayJSON, filtered: false)
XCTFail()
} catch {
print("mapping should fail if not filtered")
}
}
func testCompanyProperties() {
let companyPropertiesJSON = ["companies_properties" : mixedArrayJSON]
do {
let companiesAndProperties = try PropertyCompany(object: companyPropertiesJSON)
print(companiesAndProperties)
} catch {
print(error)
XCTFail()
}
}
}