|
11 | 11 | import Foundation
|
12 | 12 | import XCTest
|
13 | 13 | @testable import SwiftDocC
|
| 14 | +import SwiftDocCTestUtilities |
| 15 | +import SymbolKit |
14 | 16 |
|
15 | 17 | fileprivate extension [RenderBlockContent] {
|
16 | 18 | var firstParagraphText: String? {
|
@@ -309,4 +311,48 @@ class RESTSymbolsTests: XCTestCase {
|
309 | 311 |
|
310 | 312 | AssertRoundtrip(for: object)
|
311 | 313 | }
|
| 314 | + |
| 315 | + func testReferenceOfEntitlementWithKeyName() throws { |
| 316 | + |
| 317 | + func createDocumentationTopicRenderReferenceForSymbol(keyCustomName: String?) throws -> TopicRenderReference.PropertyListKeyNames { |
| 318 | + let exampleDocumentation = Folder(name: "unit-test.docc", content: [ |
| 319 | + JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph( |
| 320 | + moduleName: "ModuleName", |
| 321 | + symbols: [ |
| 322 | + SymbolGraph.Symbol( |
| 323 | + identifier: .init(precise: "symbol-id", interfaceLanguage: "swift"), |
| 324 | + names: .init(title: "Symbol Name", navigator: nil, subHeading: nil, prose: nil), |
| 325 | + pathComponents: ["Symbol Name"], |
| 326 | + docComment: nil, |
| 327 | + accessLevel: .public, |
| 328 | + kind: .init(parsedIdentifier: .typeProperty, displayName: "Type Property"), |
| 329 | + mixins: [SymbolGraph.Symbol.PlistDetails.mixinKey:SymbolGraph.Symbol.PlistDetails(rawKey: "plist-key-symbolname", customTitle: keyCustomName)] |
| 330 | + ) |
| 331 | + ] |
| 332 | + )) |
| 333 | + ]) |
| 334 | + let (_, bundle, context) = try loadBundle(from: (try createTempFolder(content: [exampleDocumentation]))) |
| 335 | + let moduleReference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/ModuleName", sourceLanguage: .swift) |
| 336 | + let moduleSymbol = try XCTUnwrap((try context.entity(with: moduleReference)).semantic as? Symbol) |
| 337 | + var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: moduleReference) |
| 338 | + let renderNode = translator.visit(moduleSymbol) as! RenderNode |
| 339 | + return try XCTUnwrap((renderNode.references["doc://unit-test/documentation/ModuleName/Symbol_Name"] as? TopicRenderReference)?.propertyListKeyNames) |
| 340 | + } |
| 341 | + |
| 342 | + // The symbol has a custom title. |
| 343 | + var propertyListKeyNames = try createDocumentationTopicRenderReferenceForSymbol(keyCustomName: "Symbol Custom Title") |
| 344 | + // Check that the reference contains the key symbol name. |
| 345 | + XCTAssertEqual(propertyListKeyNames.titleStyle, .useDisplayName) |
| 346 | + XCTAssertEqual(propertyListKeyNames.rawKey, "plist-key-symbolname") |
| 347 | + XCTAssertEqual(propertyListKeyNames.displayName, "Symbol Custom Title") |
| 348 | + |
| 349 | + // The symbol does not have a custom title. |
| 350 | + propertyListKeyNames = try createDocumentationTopicRenderReferenceForSymbol(keyCustomName: nil) |
| 351 | + // Check that the reference does not contain the key symbol name. |
| 352 | + XCTAssertEqual(propertyListKeyNames.titleStyle, .useRawKey) |
| 353 | + XCTAssertEqual(propertyListKeyNames.rawKey, "plist-key-symbolname") |
| 354 | + XCTAssertNil(propertyListKeyNames.displayName) |
| 355 | + } |
| 356 | + |
| 357 | + |
312 | 358 | }
|
0 commit comments