-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathHelperTests.swift
More file actions
49 lines (37 loc) · 1.71 KB
/
HelperTests.swift
File metadata and controls
49 lines (37 loc) · 1.71 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
//
// JSONCodableTests.swift
// JSONCodableTests
//
// Created by Tobias Conradi on 14.10.15.
// Copyright © 2015 matthewcheok. All rights reserved.
//
import XCTest
@testable import JSONCodable
struct NotEncodable {
}
class HelperTests: XCTestCase {
func testArrayElementsAreEncodable() {
let intArray:[Int] = [1,2,3]
XCTAssert(intArray.elementsAreJSONEncodable(), "Array of type [Int] should be encodable")
let encodableArray:[JSONEncodable] = [1,2,3]
XCTAssert(encodableArray.elementsAreJSONEncodable(), "Array of type [JSONEncodable] should be encodable")
let notEncodableArray:[NotEncodable] = [NotEncodable()]
XCTAssert(!notEncodableArray.elementsAreJSONEncodable(), "Array of type [NotEncodable] should not be encodable")
let _ = try? JSONEncoder.create({ (encoder) -> Void in
try encoder.encode(intArray, key: "intArray")
try encoder.encode(encodableArray, key: "encodableArray")
})
}
func testDictionaryIsEncodable() {
let intDict:[String:Int] = ["a":1,"b":2,"c":3]
XCTAssert(intDict.valuesAreJSONEncodable(), "Dictionary of type [String:Int] should be encodable")
let encodableDict:[String:JSONEncodable] = ["a":1,"b":2,"c":3]
XCTAssert(encodableDict.valuesAreJSONEncodable(), "Dictionary of type [String:JSONEncodable] should be encodable")
let notEncodableDict:[String:NotEncodable] = ["a":NotEncodable()]
XCTAssert(!notEncodableDict.valuesAreJSONEncodable(), "Dictionary of type [String:NotEncodable] should not be encodable")
let _ = try? JSONEncoder.create({ (encoder) -> Void in
try encoder.encode(intDict, key: "intArray")
try encoder.encode(encodableDict, key: "encodableArray")
})
}
}