-
Notifications
You must be signed in to change notification settings - Fork 104
/
EmptyArrayTest.swift
68 lines (56 loc) · 1.62 KB
/
EmptyArrayTest.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
65
66
67
68
//
// EmptyArrayTest.swift
// XMLCoderTests
//
// Created by Benjamin Wetherfield on 10/1/19.
//
import XCTest
@testable import XMLCoder
struct Empty: Equatable, Codable {}
struct EmptyArray: Equatable, Codable {
enum CodingKeys: String, CodingKey { case empties = "empty" }
let empties: [Empty]
}
struct EmptyWrapper: Equatable, Codable {
let empty: Empty
}
struct OptionalEmptyWrapper: Equatable, Codable {
let empty: Empty?
}
private let xml = """
<container>
<empty/>
<empty/>
<empty/>
</container>
"""
private let xmlArray = """
<container>
<empty/>
<empty/>
<empty/>
</container>
"""
private let xmlContainsEmpty = """
<container>
<empty/>
</container>
"""
class EmptyArrayTest: XCTestCase {
func testEmptyArrayDecode() throws {
let decoded = try XMLDecoder().decode([Empty].self, from: xml.data(using: .utf8)!)
XCTAssertEqual(decoded, [Empty(), Empty(), Empty()])
}
func testWrappedEmptyArrayDecode() throws {
let decoded = try XMLDecoder().decode(EmptyArray.self, from: xmlArray.data(using: .utf8)!)
XCTAssertEqual(decoded, EmptyArray(empties: [Empty(), Empty(), Empty()]))
}
func testWrappedEmptyDecode() throws {
let decoded = try XMLDecoder().decode(EmptyWrapper.self, from: xmlContainsEmpty.data(using: .utf8)!)
XCTAssertEqual(decoded, EmptyWrapper(empty: Empty()))
}
func testWrappedOptionalEmptyDecode() throws {
let decoded = try XMLDecoder().decode(OptionalEmptyWrapper.self, from: xmlContainsEmpty.data(using: .utf8)!)
XCTAssertEqual(decoded, OptionalEmptyWrapper(empty: Empty()))
}
}