Skip to content

Commit

Permalink
Fix symbol link parsing bug for disambiguated subtraction operators (#…
Browse files Browse the repository at this point in the history
…739)

rdar://113870038

Co-authored-by: Pat Shaughnessy <[email protected]>
  • Loading branch information
d-ronnqvist and patshaughnessy authored Nov 8, 2023
1 parent 4e9d7f8 commit c7dad6b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ extension PathHierarchy {
if let dashIndex = name.lastIndex(of: "-") {
let kind = String(name[dashIndex...].dropFirst())
let name = String(name[..<dashIndex])
if let languagePrefix = knownLanguagePrefixes.first(where: { kind.starts(with: $0) }) {
return PathComponent(full: full, name: name, kind: String(kind.dropFirst(languagePrefix.count)), hash: hash)
} else {
if knownSymbolKinds.contains(kind) {
return PathComponent(full: full, name: name, kind: kind, hash: hash)
} else if let languagePrefix = knownLanguagePrefixes.first(where: { kind.starts(with: $0) }) {
let kindWithoutLanguage = String(kind.dropFirst(languagePrefix.count))
return PathComponent(full: full, name: name, kind: kindWithoutLanguage, hash: hash)
}
}
return PathComponent(full: full, name: name, kind: nil, hash: hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1667,14 +1667,17 @@ let expected = """
try """
# ``Operators/MyNumber``
A documentation extension that curates symbosl with characters not allowed in a resolved reference URL.
A documentation extension that curates symbols with characters not allowed in a resolved reference URL.
## Topics
- ``<(_:_:)``
- ``>(_:_:)``
- ``<=(_:_:)``
- ``>=(_:_:)``
- ``-(_:_:)-22pw2``
- ``-(_:)-9xdx0``
- ``-=(_:_:)-7w3vn``
""".write(to: root.appendingPathComponent("doc-extension.md"), atomically: true, encoding: .utf8)
}

Expand Down
10 changes: 10 additions & 0 deletions Tests/SwiftDocCTests/Infrastructure/PathHierarchyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,14 @@ class PathHierarchyTests: XCTestCase {
XCTAssertEqual(try tree.findSymbol(path: "<=(_:_:)", parent: myNumberID).identifier.precise, "s:SLsE2leoiySbx_xtFZ::SYNTHESIZED::s:9Operators8MyNumberV")
XCTAssertEqual(try tree.findSymbol(path: ">=(_:_:)", parent: myNumberID).identifier.precise, "s:SLsE2geoiySbx_xtFZ::SYNTHESIZED::s:9Operators8MyNumberV")

XCTAssertEqual(try tree.findSymbol(path: "-(_:_:)-22pw2", parent: myNumberID).identifier.precise, "s:9Operators8MyNumberV1soiyA2C_ACtFZ")
XCTAssertEqual(try tree.findSymbol(path: "-(_:)-9xdx0", parent: myNumberID).identifier.precise, "s:s13SignedNumericPsE1sopyxxFZ::SYNTHESIZED::s:9Operators8MyNumberV")
XCTAssertEqual(try tree.findSymbol(path: "-=(_:_:)-7w3vn", parent: myNumberID).identifier.precise, "s:s18AdditiveArithmeticPsE2seoiyyxz_xtFZ::SYNTHESIZED::s:9Operators8MyNumberV")

XCTAssertEqual(try tree.findSymbol(path: "-(_:_:)-func.op", parent: myNumberID).identifier.precise, "s:9Operators8MyNumberV1soiyA2C_ACtFZ")
XCTAssertEqual(try tree.findSymbol(path: "-(_:)-func.op", parent: myNumberID).identifier.precise, "s:s13SignedNumericPsE1sopyxxFZ::SYNTHESIZED::s:9Operators8MyNumberV")
XCTAssertEqual(try tree.findSymbol(path: "-=(_:_:)-func.op", parent: myNumberID).identifier.precise, "s:s18AdditiveArithmeticPsE2seoiyyxz_xtFZ::SYNTHESIZED::s:9Operators8MyNumberV")

let paths = tree.caseInsensitiveDisambiguatedPaths()

// Unmodified operator name in URL
Expand Down Expand Up @@ -1622,6 +1630,8 @@ class PathHierarchyTests: XCTestCase {
assertParsedPathComponents("path-swift.type.property-hash", [("path", "type.property", "hash")])
assertParsedPathComponents("path-type.property", [("path", "type.property", nil)])
assertParsedPathComponents("path-swift.type.property", [("path", "type.property", nil)])

assertParsedPathComponents("-(_:_:)-hash", [("-(_:_:)", nil, "hash")])
}

// MARK: Test helpers
Expand Down

0 comments on commit c7dad6b

Please sign in to comment.