Skip to content

Commit 10edeec

Browse files
review: add a test that loads from a render fixture
1 parent 57a8a12 commit 10edeec

File tree

3 files changed

+144
-1
lines changed

3 files changed

+144
-1
lines changed

Sources/SwiftDocC/Model/Rendering/References/ExternalLocationReference.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct ExternalLocationReference: RenderReference, URLReference {
2626

2727
public let identifier: RenderReferenceIdentifier
2828

29-
private let url: String
29+
let url: String
3030

3131
enum CodingKeys: String, CodingKey {
3232
case type
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"schemaVersion" : {
3+
"major" : 1,
4+
"minor" : 0,
5+
"patch" : 0
6+
},
7+
"seeAlsoSections" : [ ],
8+
"metadata" : {
9+
"platforms" : [
10+
{
11+
"name" : "macOS",
12+
"introducedAt" : "10.15"
13+
}
14+
],
15+
"modules" : [
16+
{ "name" : "MyKit" }
17+
],
18+
"title" : "Wifi Access",
19+
"roleHeading" : "Plist Key"
20+
},
21+
"abstract" : [
22+
{
23+
"type" : "text",
24+
"text" : "A "
25+
},
26+
{
27+
"type" : "codeVoice",
28+
"code" : "WiFi access"
29+
},
30+
{
31+
"type" : "text",
32+
"text" : " abstract description."
33+
}
34+
],
35+
"sections" : [
36+
],
37+
"identifier" : {
38+
"url" : "doc:\/\/org.swift.docc.example\/plist\/wifiaccess",
39+
"interfaceLanguage": "swift"
40+
},
41+
"hierarchy" : {
42+
"paths" : [["doc:\/\/org.swift.docc.example\/plist\/wifiaccess"]]
43+
},
44+
"topicSections" : [
45+
],
46+
"kind" : "symbol",
47+
"references" : {
48+
"doc:\/\/org.swift.docc.example\/downloads\/sample.zip": {
49+
"identifier": "ExternalLocation.zip",
50+
"url": "https://example.com/ExternalLocation.zip",
51+
"type": "externalLocation"
52+
},
53+
"doc:\/\/org.swift.docc.example\/plist\/wifiaccess": {
54+
"abstract" : [
55+
{
56+
"text" : "WiFi access",
57+
"type" : "text"
58+
}
59+
],
60+
"identifier" : "doc:\/\/org.swift.docc.example\/plist\/wifiaccess",
61+
"kind" : "symbol",
62+
"title" : "WiFi Access",
63+
"type" : "topic",
64+
"url" : "\/documentation\/mykit"
65+
}
66+
},
67+
"sampleCodeDownload": {
68+
"action": {
69+
"identifier": "doc:\/\/org.swift.docc.example\/downloads\/sample.zip",
70+
"isActive": true,
71+
"overridingTitle": "Download",
72+
"type": "reference"
73+
}
74+
},
75+
"primaryContentSections" : [
76+
{
77+
"kind" : "content",
78+
"content" : [
79+
{
80+
"anchor" : "discussion",
81+
"level" : 2,
82+
"type" : "heading",
83+
"text" : "Discussion"
84+
},
85+
{
86+
"type" : "paragraph",
87+
"inlineContent" : [
88+
{
89+
"type" : "text",
90+
"text" : "Use "
91+
},
92+
{
93+
"type" : "codeVoice",
94+
"code" : "Wifi access"
95+
},
96+
{
97+
"type" : "text",
98+
"text" : " to secure wifi access for your app."
99+
}
100+
]
101+
}
102+
]
103+
}
104+
],
105+
"variants": [{
106+
"paths" : ["\/plist\/wifiaccess"],
107+
"traits" : []
108+
}]
109+
}
110+

Tests/SwiftDocCTests/Rendering/SampleDownloadTests.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,37 @@ class SampleDownloadTests: XCTestCase {
258258

259259
XCTAssertEqual(baseReference, roundTripReference)
260260
}
261+
262+
/// Ensure that an ExternalLocationReference loaded from JSON continues to encode the same
263+
/// information after being decoded and re-encoded.
264+
func testRoundTripExternalLocationFromFixture() throws {
265+
let downloadSymbolURL = Bundle.module.url(
266+
forResource: "external-location-custom-url", withExtension: "json",
267+
subdirectory: "Rendering Fixtures")!
268+
269+
let originalData = try Data(contentsOf: downloadSymbolURL)
270+
let originalRenderNode = try RenderNode.decode(fromJSON: originalData)
271+
272+
let encodedRenderNode = try JSONEncoder().encode(originalRenderNode)
273+
let symbol = try RenderNode.decode(fromJSON: encodedRenderNode)
274+
275+
//
276+
// Sample Download Details
277+
//
278+
279+
guard let section = symbol.sampleDownload else {
280+
XCTFail("Download section not decoded")
281+
return
282+
}
283+
284+
guard case RenderInlineContent.reference(let identifier, _, _, _) = section.action else {
285+
XCTFail("Could not decode action reference")
286+
return
287+
}
288+
289+
XCTAssertEqual(identifier.identifier, "doc://org.swift.docc.example/downloads/sample.zip")
290+
291+
let externalReference = try XCTUnwrap(symbol.references[identifier.identifier] as? ExternalLocationReference)
292+
XCTAssertEqual(externalReference.url, "https://example.com/ExternalLocation.zip")
293+
}
261294
}

0 commit comments

Comments
 (0)