Skip to content

Commit 6b4d5a3

Browse files
Add a precondition for declaring a node as beta. (#1055)
Added a precondition for declaring a node as beta. For a node to be declared as beta it has to contain at least a single availability item that contains all the already defined characteristics. This code adds a precondition where at least the node needs to have one availability item to be considered as potentially in beta. Before this change, if at somewhere in the code, the availability items got removed from the node, the node would be considered as beta. rdar://137762221 Co-authored-by: David Rönnqvist <[email protected]> --------- Co-authored-by: David Rönnqvist <[email protected]>
1 parent 167424a commit 6b4d5a3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,12 @@ public class DocumentationContentRenderer {
211211
guard let symbol = node.semantic as? Symbol,
212212
let currentPlatforms = documentationContext.configuration.externalMetadata.currentPlatforms,
213213
!currentPlatforms.isEmpty,
214-
let symbolAvailability = symbol.availability
214+
let symbolAvailability = symbol.availability?.availability,
215+
!symbolAvailability.isEmpty // A symbol without availability items can't be in beta.
215216
else { return false }
216217

217218
// Verify that if current platforms are in beta, they match the introduced version of the symbol
218-
for availability in symbolAvailability.availability {
219+
for availability in symbolAvailability {
219220
// If not available on this platform, skip to next platform.
220221
guard !availability.isUnconditionallyUnavailable, let introduced = availability.introducedVersion else {
221222
continue

Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,21 @@ Document
19221922
XCTAssertEqual(renderNode.metadata.platforms?.first?.isBeta, false)
19231923
}
19241924

1925+
// Symbol with an empty set of availbility items.
1926+
1927+
do {
1928+
1929+
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: [
1930+
"Custom Name": PlatformVersion(VersionTriplet(100, 0, 0), beta: true)
1931+
])
1932+
let node = try context.entity(with: reference)
1933+
(node.semantic as? Symbol)?.availability = SymbolGraph.Symbol.Availability(availability: [])
1934+
let documentationContentRendered = DocumentationContentRenderer(documentationContext: context, bundle: bundle)
1935+
let isBeta = documentationContentRendered.isBeta(node)
1936+
// Verify that the symbol is not beta since it does not contains availability info.
1937+
XCTAssertFalse(isBeta)
1938+
}
1939+
19251940
// Different platform is beta
19261941
do {
19271942
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: [

0 commit comments

Comments
 (0)