Skip to content

Commit 0c8dec1

Browse files
committed
swift-testing
1 parent a519f08 commit 0c8dec1

22 files changed

+1707
-1559
lines changed

DOM/Tests/DOM+Extensions.swift

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -33,59 +33,59 @@
3333
import Foundation
3434

3535
extension DOM {
36-
37-
static func createLine() -> DOM.Line {
38-
return DOM.Line(x1: 0, y1: 1, x2: 3, y2: 4)
39-
}
40-
41-
static func createCircle() -> DOM.Circle {
42-
return DOM.Circle(cx: 0, cy: 1, r: 2)
43-
}
44-
45-
static func createEllipse() -> DOM.Ellipse {
46-
return DOM.Ellipse(cx: 0, cy: 1, rx: 2, ry: 3)
47-
}
48-
49-
static func createRect() -> DOM.Rect {
50-
return DOM.Rect(x: 0, y: 1, width: 2, height: 3)
51-
}
52-
53-
static func createPolygon() -> DOM.Polygon {
54-
return DOM.Polygon(0, 1, 2, 3, 4, 5)
55-
}
56-
57-
static func createPolyline() -> DOM.Polyline {
58-
return DOM.Polyline(0, 1, 2, 3, 4, 5)
59-
}
60-
61-
static func createText() -> DOM.Text {
62-
return DOM.Text(y: 1, value: "The quick brown fox")
63-
}
64-
65-
static func createPath() -> DOM.Path {
66-
let path = DOM.Path(x: 0, y: 1)
67-
path.segments.append(.move(x: 10, y: 10, space: .absolute))
68-
path.segments.append(.horizontal(x: 10, space: .absolute))
69-
return path
70-
}
71-
72-
static func createGroup() -> DOM.Group {
73-
let group = DOM.Group()
74-
group.childElements.append(createLine())
75-
group.childElements.append(createPolygon())
76-
group.childElements.append(createCircle())
77-
group.childElements.append(createPath())
78-
group.childElements.append(createRect())
79-
group.childElements.append(createEllipse())
80-
return group
81-
}
36+
37+
static func createLine() -> DOM.Line {
38+
return DOM.Line(x1: 0, y1: 1, x2: 3, y2: 4)
39+
}
40+
41+
static func createCircle() -> DOM.Circle {
42+
return DOM.Circle(cx: 0, cy: 1, r: 2)
43+
}
44+
45+
static func createEllipse() -> DOM.Ellipse {
46+
return DOM.Ellipse(cx: 0, cy: 1, rx: 2, ry: 3)
47+
}
48+
49+
static func createRect() -> DOM.Rect {
50+
return DOM.Rect(x: 0, y: 1, width: 2, height: 3)
51+
}
52+
53+
static func createPolygon() -> DOM.Polygon {
54+
return DOM.Polygon(0, 1, 2, 3, 4, 5)
55+
}
56+
57+
static func createPolyline() -> DOM.Polyline {
58+
return DOM.Polyline(0, 1, 2, 3, 4, 5)
59+
}
60+
61+
static func createText() -> DOM.Text {
62+
return DOM.Text(y: 1, value: "The quick brown fox")
63+
}
64+
65+
static func createPath() -> DOM.Path {
66+
let path = DOM.Path(x: 0, y: 1)
67+
path.segments.append(.move(x: 10, y: 10, space: .absolute))
68+
path.segments.append(.horizontal(x: 10, space: .absolute))
69+
return path
70+
}
71+
72+
static func createGroup() -> DOM.Group {
73+
let group = DOM.Group()
74+
group.childElements.append(createLine())
75+
group.childElements.append(createPolygon())
76+
group.childElements.append(createCircle())
77+
group.childElements.append(createPath())
78+
group.childElements.append(createRect())
79+
group.childElements.append(createEllipse())
80+
return group
81+
}
8282
}
8383

8484
// Equatable just for tests
8585

8686
extension DOM.GraphicsElement: Swift.Equatable {
87-
static func ==(lhs: DOM.GraphicsElement, rhs: DOM.GraphicsElement) -> Bool {
88-
let toString: (Any) -> String = { var text = ""; dump($0, to: &text); return text }
89-
return toString(lhs) == toString(rhs)
90-
}
87+
static func ==(lhs: DOM.GraphicsElement, rhs: DOM.GraphicsElement) -> Bool {
88+
let toString: (Any) -> String = { var text = ""; dump($0, to: &text); return text }
89+
return toString(lhs) == toString(rhs)
90+
}
9191
}

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)