forked from JohnSundell/Plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeTests.swift
More file actions
88 lines (70 loc) · 2.63 KB
/
Copy pathNodeTests.swift
File metadata and controls
88 lines (70 loc) · 2.63 KB
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
88
/**
* 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 testEscapingDoubleAmpersands() {
let node = Node<Any>.text("&&")
XCTAssertEqual(node.render(), "&&")
}
func testEscapingAmpersandFollowedByComparisonSymbols() {
let node = Node<Any>.text("&< &>")
XCTAssertEqual(node.render(), "&< &>")
}
func testNotDoubleEscapingText() {
let node = Node<Any>.text("Hello & welcome to <Plot>!&text")
XCTAssertEqual(node.render(), "Hello & welcome to <Plot>!&text")
}
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"/>"#)
}
func testComponents() {
let node = Node<Any>.components {
Paragraph("One")
Paragraph("Two")
}
XCTAssertEqual(node.render(), "<p>One</p><p>Two</p>")
}
func testNodeComponentBodyIsEqualToSelf() {
let node = Node.p("Text")
XCTAssertEqual(node.render(), node.body.render())
}
}