Skip to content

Commit

Permalink
review: add a test that loads from a render fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
QuietMisdreavus committed Jun 9, 2023
1 parent 57a8a12 commit 10edeec
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct ExternalLocationReference: RenderReference, URLReference {

public let identifier: RenderReferenceIdentifier

private let url: String
let url: String

enum CodingKeys: String, CodingKey {
case type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"schemaVersion" : {
"major" : 1,
"minor" : 0,
"patch" : 0
},
"seeAlsoSections" : [ ],
"metadata" : {
"platforms" : [
{
"name" : "macOS",
"introducedAt" : "10.15"
}
],
"modules" : [
{ "name" : "MyKit" }
],
"title" : "Wifi Access",
"roleHeading" : "Plist Key"
},
"abstract" : [
{
"type" : "text",
"text" : "A "
},
{
"type" : "codeVoice",
"code" : "WiFi access"
},
{
"type" : "text",
"text" : " abstract description."
}
],
"sections" : [
],
"identifier" : {
"url" : "doc:\/\/org.swift.docc.example\/plist\/wifiaccess",
"interfaceLanguage": "swift"
},
"hierarchy" : {
"paths" : [["doc:\/\/org.swift.docc.example\/plist\/wifiaccess"]]
},
"topicSections" : [
],
"kind" : "symbol",
"references" : {
"doc:\/\/org.swift.docc.example\/downloads\/sample.zip": {
"identifier": "ExternalLocation.zip",
"url": "https://example.com/ExternalLocation.zip",
"type": "externalLocation"
},
"doc:\/\/org.swift.docc.example\/plist\/wifiaccess": {
"abstract" : [
{
"text" : "WiFi access",
"type" : "text"
}
],
"identifier" : "doc:\/\/org.swift.docc.example\/plist\/wifiaccess",
"kind" : "symbol",
"title" : "WiFi Access",
"type" : "topic",
"url" : "\/documentation\/mykit"
}
},
"sampleCodeDownload": {
"action": {
"identifier": "doc:\/\/org.swift.docc.example\/downloads\/sample.zip",
"isActive": true,
"overridingTitle": "Download",
"type": "reference"
}
},
"primaryContentSections" : [
{
"kind" : "content",
"content" : [
{
"anchor" : "discussion",
"level" : 2,
"type" : "heading",
"text" : "Discussion"
},
{
"type" : "paragraph",
"inlineContent" : [
{
"type" : "text",
"text" : "Use "
},
{
"type" : "codeVoice",
"code" : "Wifi access"
},
{
"type" : "text",
"text" : " to secure wifi access for your app."
}
]
}
]
}
],
"variants": [{
"paths" : ["\/plist\/wifiaccess"],
"traits" : []
}]
}

33 changes: 33 additions & 0 deletions Tests/SwiftDocCTests/Rendering/SampleDownloadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,37 @@ class SampleDownloadTests: XCTestCase {

XCTAssertEqual(baseReference, roundTripReference)
}

/// Ensure that an ExternalLocationReference loaded from JSON continues to encode the same
/// information after being decoded and re-encoded.
func testRoundTripExternalLocationFromFixture() throws {
let downloadSymbolURL = Bundle.module.url(
forResource: "external-location-custom-url", withExtension: "json",
subdirectory: "Rendering Fixtures")!

let originalData = try Data(contentsOf: downloadSymbolURL)
let originalRenderNode = try RenderNode.decode(fromJSON: originalData)

let encodedRenderNode = try JSONEncoder().encode(originalRenderNode)
let symbol = try RenderNode.decode(fromJSON: encodedRenderNode)

//
// Sample Download Details
//

guard let section = symbol.sampleDownload else {
XCTFail("Download section not decoded")
return
}

guard case RenderInlineContent.reference(let identifier, _, _, _) = section.action else {
XCTFail("Could not decode action reference")
return
}

XCTAssertEqual(identifier.identifier, "doc://org.swift.docc.example/downloads/sample.zip")

let externalReference = try XCTUnwrap(symbol.references[identifier.identifier] as? ExternalLocationReference)
XCTAssertEqual(externalReference.url, "https://example.com/ExternalLocation.zip")
}
}

0 comments on commit 10edeec

Please sign in to comment.