forked from JohnSundell/Plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodeTests.swift
74 lines (61 loc) · 2.45 KB
/
NodeTests.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
/**
* Plot
* Copyright (c) John Sundell 2019
* MIT license, see LICENSE file for details
*/
import XCTest
import Plot
final class NodeTests: XCTestCase {
func testEscapingText() {
let node = Node<Any>.text("Hello & welcome to <Plot>!")
XCTAssertEqual(node.render(), "Hello & welcome to <Plot>!")
}
func testNotEscapingRawString() {
let node = Node<Any>.raw("Hello & welcome to <Plot>!")
XCTAssertEqual(node.render(), "Hello & welcome to <Plot>!")
}
func testGroup() {
let node = Node<Any>.group(.text("Hello"), .text("World"))
XCTAssertEqual(node.render(), "HelloWorld")
}
func testCustomElement() {
let node = Node<Any>.element(named: "custom")
XCTAssertEqual(node.render(), "<custom></custom>")
}
func testCustomAttribute() {
let node = Node<Any>.attribute(named: "key", value: "value")
XCTAssertEqual(node.render(), #"key="value""#)
}
func testCustomElementWithCustomAttribute() {
let node = Node<Any>.element(named: "custom", attributes: [
Attribute(name: "key", value: "value")
])
XCTAssertEqual(node.render(), #"<custom key="value"></custom>"#)
}
func testCustomElementWithCustomAttributeWithSpecificContext() {
let node = Node<Any>.element(named: "custom", attributes: [
Attribute<String>(name: "key", value: "value")
])
XCTAssertEqual(node.render(), #"<custom key="value"></custom>"#)
}
func testCustomSelfClosedElementWithCustomAttribute() {
let node = Node<Any>.selfClosedElement(named: "custom", attributes: [
Attribute(name: "key", value: "value")
])
XCTAssertEqual(node.render(), #"<custom key="value"/>"#)
}
}
extension NodeTests {
static var allTests: Linux.TestList<NodeTests> {
[
("testEscapingText", testEscapingText),
("testNotEscapingRawString", testNotEscapingRawString),
("testGroup", testGroup),
("testCustomElement", testCustomElement),
("testCustomAttribute", testCustomAttribute),
("testCustomElementWithCustomAttribute", testCustomElementWithCustomAttribute),
("testCustomElementWithCustomAttributeWithSpecificContext", testCustomElementWithCustomAttributeWithSpecificContext),
("testCustomSelfClosedElementWithCustomAttribute", testCustomSelfClosedElementWithCustomAttribute)
]
}
}