Skip to content

Commit 0245c1f

Browse files
committed
Replace force-unwrapped Range lookups with XCTUnwrap in ExporterTests
Addresses a Copilot review on #202. A missing key in the palette JSON now reports a clean test failure instead of crashing the XCTest runner. https://claude.ai/code/session_01JcvsVeuayd5NE72hbntxbK
1 parent df8e263 commit 0245c1f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

PikaTests/ExporterTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,17 @@ final class ExporterTests: XCTestCase {
8787
XCTAssertTrue(colors.isEmpty)
8888
}
8989

90-
func test_paletteToJSON_outputIsPrettyPrintedAndSorted() {
90+
func test_paletteToJSON_outputIsPrettyPrintedAndSorted() throws {
9191
// The implementation asks JSONSerialization for both `.prettyPrinted`
9292
// and `.sortedKeys`. Preserve that contract so CLI diffs of exported
9393
// palettes stay stable.
9494
let pair = makePair(fg: "#ff0000", bg: "#00ff00", date: Date(timeIntervalSince1970: 0))
9595
let json = Exporter.paletteToJSON(pairs: [pair], name: "Brand")
9696
XCTAssertTrue(json.contains("\n"), "Output should be pretty-printed across multiple lines")
9797
// `colors` sorts alphabetically before `name` when sortedKeys is on.
98-
let colorsIndex = json.range(of: "\"colors\"")!.lowerBound
99-
let nameIndex = json.range(of: "\"name\"")!.lowerBound
100-
XCTAssertLessThan(colorsIndex, nameIndex, "Keys should be alphabetically sorted")
98+
let colorsRange = try XCTUnwrap(json.range(of: "\"colors\""))
99+
let nameRange = try XCTUnwrap(json.range(of: "\"name\""))
100+
XCTAssertLessThan(colorsRange.lowerBound, nameRange.lowerBound,
101+
"Keys should be alphabetically sorted")
101102
}
102103
}

0 commit comments

Comments
 (0)