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 7b62f5c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"identifier": "ExternalLocation.zip",
"url": "https://example.com/ExternalLocation.zip",
"type": "externalLocation"
}
24 changes: 24 additions & 0 deletions Tests/SwiftDocCTests/Rendering/SampleDownloadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,28 @@ 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 referenceUrl = Bundle.module.url(
forResource: "external-location-custom-url", withExtension: "json",
subdirectory: "Rendering Fixtures")!
let originalData = try Data(contentsOf: referenceUrl)

let encoder = JSONEncoder()
encoder.outputFormatting.insert(.sortedKeys)
let decoder = JSONDecoder()

let originalReference = try decoder.decode(ExternalLocationReference.self, from: originalData)
let reencodedReference = try encoder.encode(originalReference)

let roundTripReference = try decoder.decode(ExternalLocationReference.self, from: reencodedReference)
let finalEncodedReference = try encoder.encode(roundTripReference)

let firstJson = String(data: reencodedReference, encoding: .utf8)
let finalJson = String(data: finalEncodedReference, encoding: .utf8)

XCTAssertEqual(firstJson, finalJson)
}
}

0 comments on commit 7b62f5c

Please sign in to comment.