@@ -314,44 +314,115 @@ class RESTSymbolsTests: XCTestCase {
314
314
315
315
func testReferenceOfEntitlementWithKeyName( ) throws {
316
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
- ] )
317
+ func createDocumentationTopicRenderReferenceForSymbol( keyCustomName: String ? , extraFiles : [ TextFile ] = [ ] ) throws -> TopicRenderReference {
318
+ let someSymbol = makeSymbol (
319
+ id : " plist-key-symbolname " ,
320
+ kind : . init ( rawValue : " enum " ) ,
321
+ pathComponents : [ " plist-key-symbolname " ] ,
322
+ otherMixins : [ SymbolGraph . Symbol. PlistDetails ( rawKey : " plist-key-symbolname " , customTitle : keyCustomName ) ]
323
+ )
324
+ let symbols : [ SymbolGraph . Symbol ] = [ someSymbol ]
325
+ let exampleDocumentation = Folder (
326
+ name : " unit-test.docc " ,
327
+ content : [
328
+ JSONFile ( name : " ModuleName.symbols.json " , content : makeSymbolGraph (
329
+ moduleName : " ModuleName " ,
330
+ symbols : symbols
331
+ ) ) ,
332
+ ] + extraFiles
333
+ )
334
334
let ( _, bundle, context) = try loadBundle ( from: ( try createTempFolder ( content: [ exampleDocumentation] ) ) )
335
335
let moduleReference = ResolvedTopicReference ( bundleIdentifier: bundle. identifier, path: " /documentation/ModuleName " , sourceLanguage: . swift)
336
336
let moduleSymbol = try XCTUnwrap ( ( try context. entity ( with: moduleReference) ) . semantic as? Symbol )
337
337
var translator = RenderNodeTranslator ( context: context, bundle: bundle, identifier: moduleReference)
338
338
let renderNode = translator. visit ( moduleSymbol) as! RenderNode
339
- return try XCTUnwrap ( ( renderNode. references [ " doc://unit-test/documentation/ModuleName/Symbol_Name " ] as? TopicRenderReference ) ? . propertyListKeyNames )
339
+ return try XCTUnwrap ( ( renderNode. references [ " doc://unit-test/documentation/ModuleName/plist-key-symbolname " ] as? TopicRenderReference ) )
340
340
}
341
341
342
342
// The symbol has a custom title.
343
- var propertyListKeyNames = try createDocumentationTopicRenderReferenceForSymbol ( keyCustomName: " Symbol Custom Title " )
343
+ var propertyListKeyNames = try XCTUnwrap ( createDocumentationTopicRenderReferenceForSymbol ( keyCustomName: " Symbol Custom Title " ) . propertyListKeyNames )
344
344
// Check that the reference contains the key symbol name.
345
- XCTAssertEqual ( propertyListKeyNames. titleStyle, . useDisplayName )
345
+ XCTAssertEqual ( propertyListKeyNames. titleStyle, . useRawKey )
346
346
XCTAssertEqual ( propertyListKeyNames. rawKey, " plist-key-symbolname " )
347
347
XCTAssertEqual ( propertyListKeyNames. displayName, " Symbol Custom Title " )
348
348
349
349
// The symbol does not have a custom title.
350
- propertyListKeyNames = try createDocumentationTopicRenderReferenceForSymbol ( keyCustomName: nil )
350
+ propertyListKeyNames = try XCTUnwrap ( createDocumentationTopicRenderReferenceForSymbol ( keyCustomName: nil ) . propertyListKeyNames )
351
351
// Check that the reference does not contain the key symbol name.
352
352
XCTAssertEqual ( propertyListKeyNames. titleStyle, . useRawKey)
353
353
XCTAssertEqual ( propertyListKeyNames. rawKey, " plist-key-symbolname " )
354
354
XCTAssertNil ( propertyListKeyNames. displayName)
355
+
356
+ // The symbol has a custom title and is extended via markdown.
357
+ var referenceNode = try XCTUnwrap ( createDocumentationTopicRenderReferenceForSymbol (
358
+ keyCustomName: " Symbol Custom Title " ,
359
+ extraFiles: [
360
+ TextFile ( name: " plist-key-symbolname.md " , utf8Content:
361
+ """
362
+ # ``ModuleName/plist-key-symbolname``
363
+
364
+ A documentation extension for my plist-key-symbolname.
365
+ """
366
+ )
367
+ ]
368
+ ) )
369
+ propertyListKeyNames = try XCTUnwrap ( referenceNode. propertyListKeyNames)
370
+ // Check that the reference contains the raw key and title matches the
371
+ // key name.
372
+ XCTAssertEqual ( referenceNode. title, " plist-key-symbolname " )
373
+ XCTAssertEqual ( propertyListKeyNames. titleStyle, . useRawKey)
374
+ XCTAssertEqual ( propertyListKeyNames. rawKey, " plist-key-symbolname " )
375
+ XCTAssertEqual ( propertyListKeyNames. displayName, " Symbol Custom Title " )
376
+
377
+ // The symbol has a custom title and is the markdown defines a `Display Name` directive.
378
+ referenceNode = try XCTUnwrap ( createDocumentationTopicRenderReferenceForSymbol (
379
+ keyCustomName: " Symbol Custom Title " ,
380
+ extraFiles: [
381
+ TextFile ( name: " plist-key-symbolname.md " , utf8Content:
382
+ """
383
+ # ``ModuleName/plist-key-symbolname``
384
+
385
+ @Metadata {
386
+ @DisplayName( " Custom Title " )
387
+ }
388
+
389
+ A documentation extension for my plist-key-symbolname.
390
+ """
391
+ )
392
+ ]
393
+ ) )
394
+ propertyListKeyNames = try XCTUnwrap ( referenceNode. propertyListKeyNames)
395
+ // Check that the reference contains the raw key and the title matches the
396
+ // markdown display name.
397
+ XCTAssertEqual ( referenceNode. title, " Custom Title " )
398
+ XCTAssertEqual ( propertyListKeyNames. titleStyle, . useDisplayName)
399
+ XCTAssertEqual ( propertyListKeyNames. rawKey, " plist-key-symbolname " )
400
+ XCTAssertEqual ( propertyListKeyNames. displayName, " Symbol Custom Title " )
401
+
402
+ // The symbol does not have a custom title and is extended via markdown using a `Display Name` directive.
403
+ referenceNode = try createDocumentationTopicRenderReferenceForSymbol (
404
+ keyCustomName: nil ,
405
+ extraFiles: [
406
+ TextFile ( name: " plist-key-symbolname.md " , utf8Content:
407
+ """
408
+ # ``ModuleName/plist-key-symbolname``
409
+
410
+ @Metadata {
411
+ @DisplayName( " Custom Name " )
412
+ }
413
+
414
+ A documentation extension for my plist-key-symbolname.
415
+ """
416
+ )
417
+ ]
418
+ )
419
+ propertyListKeyNames = try XCTUnwrap ( referenceNode. propertyListKeyNames)
420
+ // Check that the custom display name is the same as the markdown even that the
421
+ // property list didn't define a custom title.
422
+ XCTAssertEqual ( referenceNode. title, " Custom Name " )
423
+ XCTAssertEqual ( propertyListKeyNames. titleStyle, . useDisplayName)
424
+ XCTAssertEqual ( propertyListKeyNames. rawKey, " plist-key-symbolname " )
425
+ XCTAssertEqual ( propertyListKeyNames. displayName, nil )
355
426
}
356
427
357
428
0 commit comments