-
Notifications
You must be signed in to change notification settings - Fork 104
/
XMLStackParserTests.swift
58 lines (50 loc) · 1.4 KB
/
XMLStackParserTests.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
//
// XMLStackParserTests.swift
// XMLCoderTests
//
// Created by Vincent Esche on 12/21/18.
//
import XCTest
@testable import XMLCoder
class XMLStackParserTests: XCTestCase {
func testParseWith() throws {
let parser = XMLStackParser()
let xmlString =
"""
<container>
<value>42</value>
<data><![CDATA[lorem ipsum]]></data>
</container>
"""
let xmlData = xmlString.data(using: .utf8)!
let root: XMLCoderElement? = try parser.parse(
with: xmlData,
errorContextLength: 0,
shouldProcessNamespaces: false
)
let expected = XMLCoderElement(
key: "container",
elements: [
XMLCoderElement(
key: "value",
stringValue: "42"
),
XMLCoderElement(
key: "data",
cdataValue: "lorem ipsum"
),
]
)
XCTAssertEqual(root, expected)
}
func testParseWithThrow() throws {
let parser = XMLStackParser()
let xmlString = "lorem ipsum"
let xmlData = xmlString.data(using: .utf8)!
XCTAssertThrowsError(try parser.parse(
with: xmlData,
errorContextLength: 0,
shouldProcessNamespaces: false
))
}
}