forked from CoreOffice/XMLCoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmptyElementEmptyStringTests.swift
66 lines (59 loc) · 1.86 KB
/
EmptyElementEmptyStringTests.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
//
// EmptyElementEmptyStringTests.swift
// XMLCoderTests
//
// Created by James Bean on 9/29/19.
//
import XCTest
import XMLCoder
class EmptyElementEmptyStringTests: XCTestCase {
struct Parent: Equatable, Codable {
let thing: Thing
}
struct Thing: Equatable, Codable {
let attribute: String?
let value: String
}
func testEmptyElementEmptyStringDecoding() throws {
let xml = """
<thing></thing>
"""
let expected = Thing(attribute: nil, value: "")
let result = try XMLDecoder().decode(Thing.self, from: xml.data(using: .utf8)!)
XCTAssertEqual(expected, result)
}
func testEmptyElementEmptyStringWithAttributeDecoding() throws {
let xml = """
<thing attribute="x"></thing>
"""
let expected = Thing(attribute: "x", value: "")
let result = try XMLDecoder().decode(Thing.self, from: xml.data(using: .utf8)!)
XCTAssertEqual(expected, result)
}
func testArrayOfEmptyElementStringDecoding() throws {
let xml = """
<container>
<thing></thing>
<thing attribute="x"></thing>
<thing></thing>
</container>
"""
let expected = [
Thing(attribute: nil, value: ""),
Thing(attribute: "x", value: ""),
Thing(attribute: nil, value: ""),
]
let result = try XMLDecoder().decode([Thing].self, from: xml.data(using: .utf8)!)
XCTAssertEqual(expected, result)
}
func testNestedEmptyElementEmptyStringDecoding() throws {
let xml = """
<parent>
<thing/>
</parent>
"""
let expected = Parent(thing: Thing(attribute: nil, value: ""))
let result = try XMLDecoder().decode(Parent.self, from: xml.data(using: .utf8)!)
XCTAssertEqual(expected, result)
}
}