Skip to content

Commit 1aa5c80

Browse files
committed
Do not emit topics section for variants that don't have topics
If the Objective-C version of a symbol doesn't have topics, do not emit a Topics section for it, instead of defaulting to the Swift symbol's topics. This logic was implemented for Topics sections in articles, but not in symbols. rdar://92127060
1 parent 75b536c commit 1aa5c80

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,11 +1279,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
12791279
)
12801280
}
12811281

1282-
if sections.isEmpty {
1283-
return nil
1284-
} else {
1285-
return sections
1286-
}
1282+
return sections
12871283
} ?? .init(defaultValue: [])
12881284

12891285
node.defaultImplementationsSectionsVariants = VariantCollection<[TaskGroupRenderSection]>(

Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase {
701701
)
702702
}
703703

704-
func testEncodesNilTopicsSectionsForVariantIfDefaultIsNonEmpty() throws {
704+
func testEncodesNilTopicsSectionsForArticleVariantIfDefaultIsNonEmpty() throws {
705705
try assertMultiVariantArticle(
706706
configureArticle: { article in
707707
article.automaticTaskGroups = []
@@ -738,6 +738,26 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase {
738738
)
739739
}
740740

741+
func testEncodesNilTopicsSectionsForSymbolVariantIfDefaultIsNonEmpty() throws {
742+
try assertMultiVariantSymbol(
743+
assertOriginalRenderNode: { renderNode in
744+
XCTAssertEqual(renderNode.topicSections.count, 6)
745+
},
746+
assertDataAfterApplyingVariant: { renderNodeData in
747+
// See reasoning for the RenderNodeProxy type in the similar test above.
748+
749+
struct RenderNodeProxy: Codable {
750+
var topicSections: [TaskGroupRenderSection]?
751+
}
752+
753+
XCTAssertNil(
754+
try JSONDecoder().decode(RenderNodeProxy.self, from: renderNodeData).topicSections,
755+
"Expected topicSections to be null in the JSON because the article has no Objective-C topics."
756+
)
757+
}
758+
)
759+
}
760+
741761
func testArticleAutomaticTaskGroupsForArticleOnlyIncludeTopicsAvailableInTheArticleLanguage() throws {
742762
func referenceWithPath(_ path: String) -> ResolvedTopicReference {
743763
ResolvedTopicReference(
@@ -848,7 +868,13 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase {
848868
XCTAssertEqual(renderNode.topicSections.count, 2)
849869
},
850870
assertAfterApplyingVariant: { renderNode in
851-
XCTAssertEqual(renderNode.topicSections.count, 2)
871+
XCTAssert(
872+
renderNode.topicSections.isEmpty,
873+
"""
874+
Expected no topics section for the Objective-C variant, because there are no Objective-C \
875+
relationships.
876+
"""
877+
)
852878
}
853879
)
854880
}
@@ -1040,7 +1066,8 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase {
10401066
configureSymbol: (Symbol) throws -> () = { _ in },
10411067
configureRenderNodeTranslator: (inout RenderNodeTranslator) -> () = { _ in },
10421068
assertOriginalRenderNode: (RenderNode) throws -> (),
1043-
assertAfterApplyingVariant: (RenderNode) throws -> ()
1069+
assertAfterApplyingVariant: (RenderNode) throws -> () = { _ in },
1070+
assertDataAfterApplyingVariant: (Data) throws -> () = { _ in }
10441071
) throws {
10451072
let (_, bundle, context) = try testBundleAndContext(copying: "TestBundle")
10461073

@@ -1066,7 +1093,8 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase {
10661093
identifier: identifier,
10671094
configureRenderNodeTranslator: configureRenderNodeTranslator,
10681095
assertOriginalRenderNode: assertOriginalRenderNode,
1069-
assertAfterApplyingVariant: assertAfterApplyingVariant
1096+
assertAfterApplyingVariant: assertAfterApplyingVariant,
1097+
assertDataAfterApplyingVariant: assertDataAfterApplyingVariant
10701098
)
10711099
}
10721100

0 commit comments

Comments
 (0)