-
Notifications
You must be signed in to change notification settings - Fork 104
/
RelationshipsTest.swift
66 lines (54 loc) · 1.93 KB
/
RelationshipsTest.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
import XCTest
@testable import XMLCoder
private let xml = """
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship
Id="rId1"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
Target="xl/workbook.xml"/>
<Relationship
Id="rId2"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
Target="docProps/app.xml"/>
<Relationship
Id="rId3"
Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
Target="docProps/core.xml"/>
</Relationships>
""".data(using: .utf8)!
private struct Relationships: Codable {
let items: [Relationship]
enum CodingKeys: String, CodingKey {
case items = "relationship"
}
}
private struct Relationship: Codable {
enum SchemaType: String, Codable {
case officeDocument = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
case extendedProperties = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
case coreProperties = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
}
let id: String
let type: SchemaType
let target: String
enum CodingKeys: CodingKey {
case type
case id
case target
}
}
final class RelationshipsTest: XCTestCase {
func testDecoder() throws {
let decoder = XMLDecoder()
decoder.keyDecodingStrategy = .convertFromCapitalized
let rels = try decoder.decode(Relationships.self, from: xml)
XCTAssertEqual(rels.items.count, 3)
guard let relationship = rels.items.first else {
return
}
XCTAssertEqual(relationship.id, "rId1")
}
static var allTests = [
("testDecoder", testDecoder),
]
}