Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.10] Fix symbol link parsing bug for disambiguated subtraction operators #750

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1326,6 +1326,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 @@ -1616,6 +1624,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