Skip to content

Commit ebea6f3

Browse files
committed
Swift Testing
1 parent 2ca2d58 commit ebea6f3

10 files changed

+444
-367
lines changed

DOM/Tests/DOM.PresentationAttributesTests.swift

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -29,100 +29,97 @@
2929
// 3. This notice may not be removed or altered from any source distribution.
3030
//
3131

32-
import XCTest
32+
import Testing
3333
@testable import SwiftDrawDOM
3434

35-
final class PresentationAttributesTests: XCTestCase {
35+
struct PresentationAttributesTests {
3636

3737
typealias Attributes = DOM.PresentationAttributes
3838
typealias StyleSheet = DOM.StyleSheet
3939

40-
func testOpacityIsApplied() {
41-
XCTAssertNil(
40+
@Test
41+
func opacityIsApplied() {
42+
#expect(
4243
Attributes(opacity: nil)
4344
.applyingAttributes(Attributes(opacity: nil))
44-
.opacity
45+
.opacity == nil
4546
)
4647

47-
XCTAssertEqual(
48+
#expect(
4849
Attributes(opacity: 5)
4950
.applyingAttributes(Attributes(opacity: nil))
50-
.opacity,
51-
5
51+
.opacity == 5
5252
)
5353

54-
XCTAssertEqual(
54+
#expect(
5555
Attributes(opacity: 5)
5656
.applyingAttributes(Attributes(opacity: 10))
57-
.opacity,
58-
10
57+
.opacity == 10
5958
)
6059
}
6160

62-
func testDisplayIsApplied() {
63-
XCTAssertNil(
61+
@Test
62+
func displayIsApplied() {
63+
#expect(
6464
Attributes(display: nil)
6565
.applyingAttributes(Attributes(display: nil))
66-
.display
66+
.display == nil
6767
)
6868

69-
XCTAssertEqual(
69+
#expect(
7070
Attributes(display: DOM.DisplayMode.none)
7171
.applyingAttributes(Attributes(display: nil))
72-
.display,
73-
DOM.DisplayMode.none
72+
.display == DOM.DisplayMode.none
7473
)
7574

76-
XCTAssertEqual(
75+
#expect(
7776
Attributes(display: DOM.DisplayMode.none)
7877
.applyingAttributes(Attributes(display: .inline))
79-
.display,
80-
.inline
78+
.display == .inline
8179
)
8280
}
8381

84-
func testColorIsApplied() {
85-
XCTAssertNil(
82+
@Test
83+
func colorIsApplied() {
84+
#expect(
8685
Attributes(color: nil)
8786
.applyingAttributes(Attributes(color: nil))
88-
.color
87+
.color == nil
8988
)
9089

91-
XCTAssertEqual(
90+
#expect(
9291
Attributes(color: .keyword(.green))
9392
.applyingAttributes(Attributes(color: nil))
94-
.color,
95-
.keyword(.green)
93+
.color == .keyword(.green)
9694
)
9795

98-
XCTAssertEqual(
96+
#expect(
9997
Attributes(color: .keyword(.green))
10098
.applyingAttributes(Attributes(color: .currentColor))
101-
.color,
102-
.currentColor
99+
.color == .currentColor
103100
)
104101
}
105102

106-
func testSelectors() {
107-
XCTAssertEqual(
108-
DOM.makeSelectors(for: .circle()),
109-
[.element("circle")]
103+
@Test
104+
func selectors() {
105+
#expect(
106+
DOM.makeSelectors(for: .circle()) == [.element("circle")]
110107
)
111108

112-
XCTAssertEqual(
113-
DOM.makeSelectors(for: .circle(id: "c1")),
109+
#expect(
110+
DOM.makeSelectors(for: .circle(id: "c1")) ==
114111
[.element("circle"),
115112
.id("c1")]
116113
)
117114

118-
XCTAssertEqual(
119-
DOM.makeSelectors(for: .circle(class: "c")),
115+
#expect(
116+
DOM.makeSelectors(for: .circle(class: "c")) ==
120117
[.element("circle"),
121118
.class("c")]
122119
)
123120

124-
XCTAssertEqual(
125-
DOM.makeSelectors(for: .circle(id: "c1 ", class: "a b c")),
121+
#expect(
122+
DOM.makeSelectors(for: .circle(id: "c1 ", class: "a b c")) ==
126123
[.element("circle"),
127124
.class("a"),
128125
.class("b"),
@@ -131,7 +128,8 @@ final class PresentationAttributesTests: XCTestCase {
131128
)
132129
}
133130

134-
func testLastSheetAttributesAreUsed() {
131+
@Test
132+
func lastSheetAttributesAreUsed() {
135133
var sheet = StyleSheet()
136134
sheet[.id("b")].opacity = 0
137135
sheet[.id("a")].opacity = 1
@@ -140,45 +138,41 @@ final class PresentationAttributesTests: XCTestCase {
140138
another[.id("b")].opacity = 0.1
141139
another[.id("a")].opacity = 0.5
142140

143-
XCTAssertEqual(
141+
#expect(
144142
DOM.makeAttributes(for: .id("a"), styles: [sheet])
145-
.opacity,
146-
1
143+
.opacity == 1
147144
)
148145

149-
XCTAssertEqual(
146+
#expect(
150147
DOM.makeAttributes(for: .id("a"), styles: [sheet, another])
151-
.opacity,
152-
0.5
148+
.opacity == 0.5
153149
)
154150
}
155151

156-
func testSelectorPrecedence() {
152+
@Test
153+
func selectorPrecedence() {
157154
var sheet = StyleSheet()
158155
sheet[.element("circle")].opacity = 1
159156
sheet[.id("c1")].opacity = 0.5
160157
sheet[.class("b")].opacity = 0.1
161158
sheet[.class("c")].opacity = 0.2
162159

163-
XCTAssertEqual(
160+
#expect(
164161
DOM.presentationAttributes(for: .circle(id: "c1", class: "b c"),
165162
styles: [sheet])
166-
.opacity,
167-
0.5
163+
.opacity == 0.5
168164
)
169165

170-
XCTAssertEqual(
166+
#expect(
171167
DOM.presentationAttributes(for: .circle(id: "c2", class: "b c"),
172168
styles: [sheet])
173-
.opacity,
174-
0.2
169+
.opacity == 0.2
175170
)
176171

177-
XCTAssertEqual(
172+
#expect(
178173
DOM.presentationAttributes(for: .circle(id: "c2", class: "z"),
179174
styles: [sheet])
180-
.opacity,
181-
1
175+
.opacity == 1
182176
)
183177
}
184178
}

0 commit comments

Comments
 (0)