-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy pathMarkdownContentBuilderTests.swift
135 lines (119 loc) · 2.52 KB
/
MarkdownContentBuilderTests.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import Foundation
import XCTest
@testable import MarkdownUI
final class MarkdownContentBuilderTests: XCTestCase {
func testEmpty() {
// given
@MarkdownContentBuilder func build() -> MarkdownContent {}
// when
let result = build()
// then
XCTAssertEqual(.init(), result)
}
func testExpressions() {
// given
@MarkdownContentBuilder func build() -> MarkdownContent {
"**First** paragraph."
Paragraph {
Strong("Second")
" paragraph."
}
}
// when
let result = build()
// then
XCTAssertEqual(
MarkdownContent(
blocks: [
.paragraph(
content: [
.strong(children: [.text("First")]),
.text(" paragraph."),
]
),
.paragraph(
content: [
.strong(children: [.text("Second")]),
.text(" paragraph."),
]
),
]
),
result
)
}
func testForLoops() {
// given
@MarkdownContentBuilder func build() -> MarkdownContent {
for i in 0...3 {
"\(i)"
}
}
// when
let result = build()
// then
XCTAssertEqual(
MarkdownContent(
blocks: [
.paragraph(content: [.text("0")]),
.paragraph(content: [.text("1")]),
.paragraph(content: [.text("2")]),
.paragraph(content: [.text("3")]),
]
),
result
)
}
func testIf() {
@MarkdownContentBuilder func build() -> MarkdownContent {
"Something is:"
if true {
"true"
}
}
// when
let result = build()
// then
XCTAssertEqual(
MarkdownContent(
blocks: [
.paragraph(content: [.text("Something is:")]),
.paragraph(content: [.text("true")]),
]
),
result
)
}
func testIfElse() {
@MarkdownContentBuilder func build(_ value: Bool) -> MarkdownContent {
"Something is:"
if value {
"true"
} else {
"false"
}
}
// when
let result1 = build(true)
let result2 = build(false)
// then
XCTAssertEqual(
MarkdownContent(
blocks: [
.paragraph(content: [.text("Something is:")]),
.paragraph(content: [.text("true")]),
]
),
result1
)
XCTAssertEqual(
MarkdownContent(
blocks: [
.paragraph(content: [.text("Something is:")]),
.paragraph(content: [.text("false")]),
]
),
result2
)
}
}