1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
/*
This source file is part of the Swift.org open source project
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
import XCTest
import Foundation
@testable import SwiftDocC
@testable import SwiftDocCUtilities
class ConvertActionIndexerTests: XCTestCase {
// Tests the standalone indexer
func testConvertActionIndexer() throws {
let (bundle, dataProvider) = try DocumentationContext.InputsProvider()
.inputsAndDataProvider(startingPoint: testCatalogURL(named: "TestBundle"), options: .init())
let context = try DocumentationContext(bundle: bundle, dataProvider: dataProvider)
let converter = DocumentationNodeConverter(bundle: bundle, context: context)
// Add /documentation/MyKit to the index, verify the tree dump
do {
let reference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", sourceLanguage: .swift)
let renderNode = try converter.convert(context.entity(with: reference))
let tempIndexURL = try createTemporaryDirectory(named: "index")
let indexer = try ConvertAction.Indexer(outputURL: tempIndexURL, bundleID: bundle.id)
indexer.index(renderNode)
XCTAssertTrue(indexer.finalize(emitJSON: false, emitLMDB: false).isEmpty)
let treeDump = try XCTUnwrap(indexer.dumpTree())
XCTAssertEqual(treeDump, """
[Root]
┗╸Swift
┗╸MyKit
┣╸Basics
┣╸MyKit in Practice
┣╸Global symbols
┗╸Extensions to other frameworks
""")
}
// Add two nodes /documentation/MyKit and /documentation/Test-Bundle/Default-Code-Listing-Syntax to the index
// and verify the tree.
do {
let reference1 = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", sourceLanguage: .swift)
let renderNode1 = try converter.convert(context.entity(with: reference1))
let reference2 = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/Test-Bundle/Default-Code-Listing-Syntax", sourceLanguage: .swift)
let renderNode2 = try converter.convert(context.entity(with: reference2))
let tempIndexURL = try createTemporaryDirectory(named: "index")
let indexer = try ConvertAction.Indexer(outputURL: tempIndexURL, bundleID: bundle.id)
indexer.index(renderNode1)
indexer.index(renderNode2)
XCTAssertTrue(indexer.finalize(emitJSON: false, emitLMDB: false).isEmpty)
let treeDump = try XCTUnwrap(indexer.dumpTree())
XCTAssertEqual(treeDump, """
[Root]
┗╸Swift
┗╸MyKit
┣╸Basics
┣╸MyKit in Practice
┣╸Default Code Listing Syntax
┣╸Global symbols
┗╸Extensions to other frameworks
""")
}
}
}
|