forked from JohnSundell/Plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentTests.swift
87 lines (78 loc) · 2.29 KB
/
DocumentTests.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Plot
* Copyright (c) John Sundell 2019
* MIT license, see LICENSE file for details
*/
import XCTest
import Plot
final class DocumentTests: XCTestCase {
func testEmptyDocument() {
let document = Document<FormatStub>.custom()
XCTAssertEqual(document.render(), "")
}
func testEmptyIndentedDocument() {
let document = Document<FormatStub>.custom()
XCTAssertEqual(document.render(indentedBy: .spaces(4)), "")
}
func testIndentationWithSpaces() {
let document = Document.custom(
withFormat: FormatStub.self,
elements: [
.named("one", nodes: [
.element(named: "two", nodes: [
.selfClosedElement(named: "three")
])
]),
.selfClosed(named: "four", attributes: [
Attribute(name: "key", value: "value")
])
]
)
XCTAssertEqual(document.render(indentedBy: .spaces(4)), """
<one>
<two>
<three/>
</two>
</one>
<four key="value"/>
""")
}
func testIndentationWithTabs() {
let document = Document.custom(
withFormat: FormatStub.self,
elements: [
.named("one", nodes: [
.element(named: "two", nodes: [
.selfClosedElement(named: "three")
])
]),
.selfClosed(named: "four", attributes: [
Attribute(name: "key", value: "value")
])
]
)
XCTAssertEqual(document.render(indentedBy: .tabs(1)), """
<one>
\t<two>
\t\t<three/>
\t</two>
</one>
<four key="value"/>
""")
}
}
private extension DocumentTests {
struct FormatStub: DocumentFormat {
enum RootContext {}
}
}
extension DocumentTests {
static var allTests: Linux.TestList<DocumentTests> {
[
("testEmptyDocument", testEmptyDocument),
("testEmptyIndentedDocument", testEmptyIndentedDocument),
("testIndentationWithSpaces", testIndentationWithSpaces),
("testIndentationWithTabs", testIndentationWithTabs)
]
}
}