|
11 | 11 | import Foundation
|
12 | 12 | import XCTest
|
13 | 13 | @testable import SwiftDocC
|
| 14 | +import SwiftDocCTestUtilities |
14 | 15 | import Markdown
|
15 | 16 |
|
16 | 17 | class RenderNodeTranslatorTests: XCTestCase {
|
@@ -650,6 +651,120 @@ class RenderNodeTranslatorTests: XCTestCase {
|
650 | 651 |
|
651 | 652 | }
|
652 | 653 |
|
| 654 | + func testAutomaticImplementationsWithExtraDotsFromExternalModule() throws { |
| 655 | + let inheritedDefaultImplementationsFromExternalModuleSGF = Bundle.module.url( |
| 656 | + forResource: "InheritedDefaultImplementationsFromExternalModule.symbols", |
| 657 | + withExtension: "json", |
| 658 | + subdirectory: "Test Resources" |
| 659 | + )! |
| 660 | + |
| 661 | + let testBundle = try Folder( |
| 662 | + name: "unit-test.docc", |
| 663 | + content: [ |
| 664 | + InfoPlist(displayName: "TestBundle", identifier: "com.test.example"), |
| 665 | + CopyOfFile(original: inheritedDefaultImplementationsFromExternalModuleSGF), |
| 666 | + ] |
| 667 | + ).write(inside: createTemporaryDirectory()) |
| 668 | + |
| 669 | + try assertDefaultImplementationCollectionTitles( |
| 670 | + in: try loadRenderNode(at: "/documentation/SecondTarget/FancyProtocolConformer", in: testBundle), |
| 671 | + [ |
| 672 | + "FancyProtocol Implementations", |
| 673 | + ] |
| 674 | + ) |
| 675 | + |
| 676 | + try assertDefaultImplementationCollectionTitles( |
| 677 | + in: try loadRenderNode(at: "/documentation/SecondTarget/OtherFancyProtocolConformer", in: testBundle), |
| 678 | + [ |
| 679 | + "OtherFancyProtocol Implementations", |
| 680 | + ] |
| 681 | + ) |
| 682 | + |
| 683 | + try assertDefaultImplementationCollectionTitles( |
| 684 | + in: try loadRenderNode(at: "/documentation/SecondTarget/FooConformer", in: testBundle), |
| 685 | + [ |
| 686 | + "Foo Implementations", |
| 687 | + ] |
| 688 | + ) |
| 689 | + } |
| 690 | + |
| 691 | + func testAutomaticImplementationsFromCurrentModuleWithMixOfDocCoverage() throws { |
| 692 | + let inheritedDefaultImplementationsSGF = Bundle.module.url( |
| 693 | + forResource: "InheritedDefaultImplementations.symbols", |
| 694 | + withExtension: "json", |
| 695 | + subdirectory: "Test Resources" |
| 696 | + )! |
| 697 | + let inheritedDefaultImplementationsAtSwiftSGF = Bundle.module.url( |
| 698 | + |
| 699 | + withExtension: "json", |
| 700 | + subdirectory: "Test Resources" |
| 701 | + )! |
| 702 | + |
| 703 | + let testBundle = try Folder( |
| 704 | + name: "unit-test.docc", |
| 705 | + content: [ |
| 706 | + InfoPlist(displayName: "TestBundle", identifier: "com.test.example"), |
| 707 | + CopyOfFile(original: inheritedDefaultImplementationsSGF), |
| 708 | + CopyOfFile(original: inheritedDefaultImplementationsAtSwiftSGF), |
| 709 | + ] |
| 710 | + ).write(inside: createTemporaryDirectory()) |
| 711 | + |
| 712 | + try assertDefaultImplementationCollectionTitles( |
| 713 | + in: try loadRenderNode(at: "/documentation/FirstTarget/Bar", in: testBundle), |
| 714 | + [ |
| 715 | + "Foo Implementations", |
| 716 | + ] |
| 717 | + ) |
| 718 | + |
| 719 | + try assertDefaultImplementationCollectionTitles( |
| 720 | + in: try loadRenderNode(at: "/documentation/FirstTarget/OtherStruct", in: testBundle), |
| 721 | + [ |
| 722 | + "Comparable Implementations", |
| 723 | + "Equatable Implementations", |
| 724 | + ] |
| 725 | + ) |
| 726 | + |
| 727 | + try assertDefaultImplementationCollectionTitles( |
| 728 | + in: try loadRenderNode(at: "/documentation/FirstTarget/SomeStruct", in: testBundle), |
| 729 | + [ |
| 730 | + "Comparable Implementations", |
| 731 | + "Equatable Implementations", |
| 732 | + "FancyProtocol Implementations", |
| 733 | + "OtherFancyProtocol Implementations", |
| 734 | + ] |
| 735 | + ) |
| 736 | + } |
| 737 | + |
| 738 | + func assertDefaultImplementationCollectionTitles( |
| 739 | + in renderNode: RenderNode, |
| 740 | + _ expectedTitles: [String], |
| 741 | + file: StaticString = #file, |
| 742 | + line: UInt = #line |
| 743 | + ) throws { |
| 744 | + let defaultImplementationSection = try XCTUnwrap( |
| 745 | + renderNode.topicSections.first(where: { $0.title == "Default Implementations" }), |
| 746 | + "Expected to find default implementations topic section.", |
| 747 | + file: file, |
| 748 | + line: line |
| 749 | + ) |
| 750 | + |
| 751 | + let references = defaultImplementationSection.identifiers.compactMap { identifier in |
| 752 | + renderNode.references[identifier] as? TopicRenderReference |
| 753 | + } |
| 754 | + |
| 755 | + XCTAssertEqual(references.map(\.title), expectedTitles, file: file, line: line) |
| 756 | + } |
| 757 | + |
| 758 | + func loadRenderNode(at path: String, in bundleURL: URL) throws -> RenderNode { |
| 759 | + let (_, bundle, context) = try loadBundle(from: bundleURL) |
| 760 | + |
| 761 | + let reference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: path, sourceLanguage: .swift) |
| 762 | + var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference, source: nil) |
| 763 | + let node = try context.entity(with: reference) |
| 764 | + let symbol = try XCTUnwrap(node.semantic as? Symbol) |
| 765 | + return try XCTUnwrap(translator.visitSymbol(symbol) as? RenderNode) |
| 766 | + } |
| 767 | + |
653 | 768 | func testAutomaticTaskGroupTopicsAreSorted() throws {
|
654 | 769 | let (bundle, context) = try testBundleAndContext(named: "DefaultImplementations")
|
655 | 770 | let structReference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/DefaultImplementations/Foo", sourceLanguage: .swift)
|
|
0 commit comments