Skip to content
Open
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
8 changes: 4 additions & 4 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
.package(url: "https://github.com/swiftlang/swift-markdown.git", branch: "main"),
.package(url: "https://github.com/swiftlang/swift-lmdb.git", branch: "main"),
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2"),
.package(url: "https://github.com/swiftlang/swift-docc-symbolkit.git", branch: "main"),
// .package(url: "https://github.com/swiftlang/swift-docc-symbolkit.git", branch: "main"),
.package(url: "https://github.com/QuietMisdreavus/swift-docc-symbolkit.git", branch: "same-shape"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.0.0"),
.package(url: "https://github.com/swiftlang/swift-docc-plugin.git", from: "1.2.0"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extension Constraint.Kind {
case .conformance: return "conforms to"
case .sameType: return "is"
case .superclass: return "inherits"
case .sameShape: return "is the same shape as"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that we this user-facing text. Should this PR also display that somewhere?

}
}
}
Expand Down
34 changes: 34 additions & 0 deletions Tests/SwiftDocCTests/Rendering/ConstraintsRenderSectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import Foundation
import XCTest
@testable import SwiftDocC
import SwiftDocCTestUtilities
import SymbolKit

fileprivate let jsonDecoder = JSONDecoder()
Expand Down Expand Up @@ -273,6 +274,39 @@ class ConstraintsRenderSectionTests: XCTestCase {
// Verify we've removed the "Self." prefix in the type names
XCTAssertEqual(renderReference.conformance?.constraints.map(flattenInlineElements).joined(), "Element conforms to MyProtocol and Index conforms to Equatable.")
}

func testRenderSameShape() async throws {
let symbolGraphFile = Bundle.module.url(
forResource: "SameShapeConstraint",
withExtension: "symbols.json",
subdirectory: "Test Resources"
)!

let catalog = Folder(name: "unit-test.docc", content: [
InfoPlist(displayName: "SameShapeConstraint", identifier: "com.test.example"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: this isn't needed

Suggested change
InfoPlist(displayName: "SameShapeConstraint", identifier: "com.test.example"),

CopyOfFile(original: symbolGraphFile),
])

let (bundle, context) = try await loadBundle(catalog: catalog)

// Compile docs and verify contents
let node = try context.entity(with: ResolvedTopicReference(bundleID: bundle.id, path: "/documentation/SameShapeConstraint/function(_:)", sourceLanguage: .swift))
let symbol = node.semantic as! Symbol
var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference)
let renderNode = translator.visitSymbol(symbol) as! RenderNode

guard let renderReference = renderNode.references.first(where: { (key, value) -> Bool in
return key.hasSuffix("function(_:)")
})?.value as? TopicRenderReference else {
XCTFail("Did not find render reference to function(_:)")
return
}

// The symbol graph only defines constraints on the `swiftGenerics` mixin,
// which docc doesn't load or render.
// However, this test should still run without crashing on decoding the symbol graph.
XCTAssertEqual(renderReference.conformance?.constraints.map(flattenInlineElements).joined(), nil)
}
}

fileprivate func flattenInlineElements(el: RenderInlineContent) -> String {
Expand Down
Loading