-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy pathTextStyleBuilderTests.swift
121 lines (106 loc) · 2.82 KB
/
TextStyleBuilderTests.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
import MarkdownUI
import SwiftUI
import XCTest
final class TextStyleBuilderTests: XCTestCase {
func testBuildEmpty() {
// given
@TextStyleBuilder func build() -> some TextStyle {}
let textStyle = build()
// when
var attributes = AttributeContainer()
textStyle._collectAttributes(in: &attributes)
// then
XCTAssertEqual(AttributeContainer(), attributes)
}
func testBuildOne() {
// given
@TextStyleBuilder func build() -> some TextStyle {
ForegroundColor(.primary)
}
let textStyle = build()
// when
var attributes = AttributeContainer()
textStyle._collectAttributes(in: &attributes)
// then
XCTAssertEqual(AttributeContainer().foregroundColor(.primary), attributes)
}
func testBuildMany() {
// given
@TextStyleBuilder func build() -> some TextStyle {
ForegroundColor(.primary)
BackgroundColor(.cyan)
UnderlineStyle(.single)
}
let textStyle = build()
// when
var attributes = AttributeContainer()
textStyle._collectAttributes(in: &attributes)
// then
XCTAssertEqual(
AttributeContainer()
.foregroundColor(.primary)
.backgroundColor(.cyan)
.underlineStyle(.single),
attributes
)
}
func testBuildOptional() {
// given
@TextStyleBuilder func makeTextStyle(_ condition: Bool) -> some TextStyle {
ForegroundColor(.primary)
if condition {
BackgroundColor(.cyan)
}
}
let textStyle1 = makeTextStyle(true)
let textStyle2 = makeTextStyle(false)
// when
var attributes1 = AttributeContainer()
textStyle1._collectAttributes(in: &attributes1)
var attributes2 = AttributeContainer()
textStyle2._collectAttributes(in: &attributes2)
// then
XCTAssertEqual(
AttributeContainer()
.foregroundColor(.primary)
.backgroundColor(.cyan),
attributes1
)
XCTAssertEqual(
AttributeContainer()
.foregroundColor(.primary),
attributes2
)
}
func testBuildEither() {
// given
@TextStyleBuilder func makeTextStyle(_ condition: Bool) -> some TextStyle {
ForegroundColor(.primary)
if condition {
BackgroundColor(.cyan)
} else {
UnderlineStyle(.single)
}
}
let textStyle1 = makeTextStyle(true)
let textStyle2 = makeTextStyle(false)
// when
var attributes1 = AttributeContainer()
textStyle1._collectAttributes(in: &attributes1)
var attributes2 = AttributeContainer()
textStyle2._collectAttributes(in: &attributes2)
// then
XCTAssertEqual(
AttributeContainer()
.foregroundColor(.primary)
.backgroundColor(.cyan),
attributes1
)
XCTAssertEqual(
AttributeContainer()
.foregroundColor(.primary)
.underlineStyle(.single),
attributes2
)
}
}