-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathArrayTests.swift
64 lines (49 loc) · 1.42 KB
/
ArrayTests.swift
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
//
// Copyright © 2016 Baris Sencan. All rights reserved.
//
import Foundation
import XCTest
import JSONHelper
class ArrayTests: XCTestCase {
// MARK: - Convertable Tests
let urlStrings = ["http://apple.com", "http://google.com", "http://facebook.com"]
let urlHosts = ["apple.com", "google.com", "facebook.com"]
func testArrayToConvertibleArray() {
var urls = [URL]()
urls <-- urlStrings
XCTAssertEqual(urls[0].host, urlHosts[0])
XCTAssertEqual(urls[1].host, urlHosts[1])
XCTAssertEqual(urls[2].host, urlHosts[2])
}
func testArrayAsAnyToConvertibleArray() {
var urls = [URL]()
urls <-- (urlStrings as Any)
XCTAssertEqual(urls[0].host, urlHosts[0])
XCTAssertEqual(urls[1].host, urlHosts[1])
XCTAssertEqual(urls[2].host, urlHosts[2])
}
// MARK: - Deserializable Tests
struct Item: Deserializable {
static let nameKey = "name"
var name: String?
init(dictionary: [String: Any]) {
name <-- dictionary[Item.nameKey]
}
}
let dictionaries = [
[Item.nameKey : "a"],
[Item.nameKey : "b"]
]
func testArrayToDeserializableArray() {
var items = [Item]()
items <-- dictionaries
XCTAssertEqual(items[0].name, "a")
XCTAssertEqual(items[1].name, "b")
}
func testArrayAsAnyToDeserializableArray() {
var items = [Item]()
items <-- (dictionaries as Any)
XCTAssertEqual(items[0].name, "a")
XCTAssertEqual(items[1].name, "b")
}
}