Skip to content

Commit e4a6fc4

Browse files
committed
Refactor Row tests to consider all rendered block content
The current tests only look at the `first` RenderBlockContentelement. This is a refactor to support testing `@Small` which can return multiple RenderBlockContent items.
1 parent e56bd43 commit e4a6fc4

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Tests/SwiftDocCTests/Semantics/RowTests.swift renamed to Tests/SwiftDocCTests/Semantics/Reference/RowTests.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ class RowTests: XCTestCase {
2929
["1: warning – org.swift.docc.HasAtLeastOne<Row, Column>"]
3030
)
3131

32+
XCTAssertEqual(renderBlockContent.count, 1)
3233
XCTAssertEqual(
33-
renderBlockContent,
34+
renderBlockContent.first,
3435
.row(.init(numberOfColumns: 0, columns: []))
3536
)
3637
}
@@ -65,8 +66,9 @@ class RowTests: XCTestCase {
6566
]
6667
)
6768

69+
XCTAssertEqual(renderBlockContent.count, 1)
6870
XCTAssertEqual(
69-
renderBlockContent,
71+
renderBlockContent.first,
7072
.row(RenderBlockContent.Row(
7173
numberOfColumns: 6,
7274
columns: [
@@ -129,8 +131,9 @@ class RowTests: XCTestCase {
129131
]
130132
)
131133

134+
XCTAssertEqual(renderBlockContent.count, 1)
132135
XCTAssertEqual(
133-
renderBlockContent,
136+
renderBlockContent.first,
134137
.row(RenderBlockContent.Row(
135138
numberOfColumns: 0,
136139
columns: []
@@ -159,8 +162,9 @@ class RowTests: XCTestCase {
159162
]
160163
)
161164

165+
XCTAssertEqual(renderBlockContent.count, 1)
162166
XCTAssertEqual(
163-
renderBlockContent,
167+
renderBlockContent.first,
164168
.row(RenderBlockContent.Row(
165169
numberOfColumns: 1,
166170
columns: [
@@ -187,8 +191,9 @@ class RowTests: XCTestCase {
187191
]
188192
)
189193

194+
XCTAssertEqual(renderBlockContent.count, 1)
190195
XCTAssertEqual(
191-
renderBlockContent,
196+
renderBlockContent.first,
192197
.row(RenderBlockContent.Row(numberOfColumns: 0, columns: []))
193198
)
194199
}
@@ -212,8 +217,9 @@ class RowTests: XCTestCase {
212217
XCTAssertNotNil(row)
213218
XCTAssertEqual(problems, [])
214219

220+
XCTAssertEqual(renderBlockContent.count, 1)
215221
XCTAssertEqual(
216-
renderBlockContent,
222+
renderBlockContent.first,
217223
.row(RenderBlockContent.Row(
218224
numberOfColumns: 5,
219225
columns: [
@@ -252,8 +258,9 @@ class RowTests: XCTestCase {
252258
XCTAssertNotNil(row)
253259
XCTAssertEqual(problems, [])
254260

261+
XCTAssertEqual(renderBlockContent.count, 1)
255262
XCTAssertEqual(
256-
renderBlockContent,
263+
renderBlockContent.first,
257264
.row(RenderBlockContent.Row(
258265
numberOfColumns: 1,
259266
columns: [

Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ extension XCTestCase {
128128
func parseDirective<Directive: RenderableDirectiveConvertible>(
129129
_ directive: Directive.Type,
130130
source: () -> String
131-
) throws -> (renderBlockContent: RenderBlockContent?, problemIdentifiers: [String], directive: Directive?) {
131+
) throws -> (renderBlockContent: [RenderBlockContent], problemIdentifiers: [String], directive: Directive?) {
132132
let (bundle, context) = try testBundleAndContext()
133133

134134
let document = Document(parsing: source(), options: .parseBlockDirectives)
@@ -145,7 +145,7 @@ extension XCTestCase {
145145
}.sorted()
146146

147147
guard let directive = result as? Directive else {
148-
return (nil, problemIDs, nil)
148+
return ([], problemIDs, nil)
149149
}
150150

151151
var contentCompiler = RenderContentCompiler(
@@ -158,7 +158,9 @@ extension XCTestCase {
158158
)
159159
)
160160

161-
let renderedContent = directive.render(with: &contentCompiler).first as? RenderBlockContent
161+
let renderedContent = try XCTUnwrap(
162+
directive.render(with: &contentCompiler) as? [RenderBlockContent]
163+
)
162164
return (renderedContent, problemIDs, directive)
163165
}
164166
}

0 commit comments

Comments
 (0)