Skip to content

Commit 1d9681b

Browse files
ExternalReferenceWalker processes possible value documentation for property list sections (#1061)
* ExternalReferenceWalker processes markdown content inside of PropertyListPossibleValuesSection's * Update Tests/SwiftDocCTests/Infrastructure/ExternalReferenceResolverTests.swift Simplify unit test Co-authored-by: Sofía Rodríguez <[email protected]> --------- Co-authored-by: Sofía Rodríguez <[email protected]>
1 parent e27866d commit 1d9681b

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Sources/SwiftDocC/Semantics/ExternalLinks/ExternalReferenceWalker.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ struct ExternalReferenceWalker: SemanticVisitor {
229229
for markup in parameter.contents { visitMarkup(markup) }
230230
}
231231
}
232+
233+
for possibleValuesSection in symbol.possibleValuesSectionVariants.allValues.map(\.variant) {
234+
for possibleValue in possibleValuesSection.possibleValues {
235+
for markup in possibleValue.contents { visitMarkup(markup) }
236+
}
237+
}
232238
}
233239

234240
mutating func visitDeprecationSummary(_ summary: DeprecationSummary) {

Tests/SwiftDocCTests/Infrastructure/ExternalReferenceResolverTests.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,4 +1434,50 @@ class ExternalReferenceResolverTests: XCTestCase {
14341434
}
14351435
XCTAssertEqual(externalLinkCount, 2, "Did not resolve the 2 expected external links.")
14361436
}
1437+
1438+
func testPossibleValuesWithExternalLink() throws {
1439+
1440+
// Create some example documentation using the symbol graph file located under
1441+
// Tests/SwiftDocCTests/Test Bundles/DictionaryData.docc, and the following
1442+
// documentation extension markup.
1443+
let documentationExtension = TextFile(
1444+
name: "Genre.md",
1445+
utf8Content: """
1446+
# ``DictionaryData/Genre``
1447+
1448+
Genre object.
1449+
1450+
The artist's genre.
1451+
1452+
- PossibleValues:
1453+
- Classic Rock: Something about classic rock with a link: <doc://com.external.testbundle/something/related/to/this/allowed/value>.
1454+
- Folk: Something about folk music with a link: <doc://com.external.testbundle/something/related/to/this/allowed/value>.
1455+
""")
1456+
let symbol = try exampleDocumentation(
1457+
copying: "DictionaryData",
1458+
documentationExtension: documentationExtension,
1459+
path: "/documentation/DictionaryData/Genre"
1460+
)
1461+
1462+
let section = try XCTUnwrap(symbol.possibleValuesSectionVariants.firstValue)
1463+
XCTAssertEqual(section.possibleValues.count, 3)
1464+
1465+
// Check that the two keys with external links in the markup above were found
1466+
// and processed by the test external reference resolver.
1467+
var externalLinkCount = 0
1468+
for possibleValue in section.possibleValues {
1469+
let value = possibleValue.contents.first?.format().trimmingCharacters(in: .whitespaces)
1470+
if possibleValue.value == "Classic Rock" {
1471+
let stringValue = try XCTUnwrap(value)
1472+
XCTAssertEqual(stringValue, "Something about classic rock with a link: <doc://com.external.testbundle/externally/resolved/path>.")
1473+
externalLinkCount += 1
1474+
} else if possibleValue.value == "Folk" {
1475+
let stringValue = try XCTUnwrap(value)
1476+
XCTAssertEqual(stringValue, "Something about folk music with a link: <doc://com.external.testbundle/externally/resolved/path>.")
1477+
externalLinkCount += 1
1478+
}
1479+
}
1480+
XCTAssertEqual(externalLinkCount, 2, "Did not resolve the 2 expected external links.")
1481+
}
1482+
14371483
}

0 commit comments

Comments
 (0)