[BigIntTests] Update the testCodable() method

Top-level JSON fragments might fail on Linux, so encode Range<BigInt> instead.

<https://bugs.swift.org/browse/SR-6163>
This commit is contained in:
Ben Rimmington committed 2020-01-15 03:30:50 +00:00
1 parent 8c378528de
commit 4ec520a726
1 file changed
+11 -12
+11 -12
View File
@@ -111,18 +111,17 @@ final class BigIntTests: XCTestCase {
XCTAssertEqual(baz, bar)
}
func testCodable() {
let foo = BigInt("1234567890123456789012345678901234567890")!
guard let fooData = try? JSONEncoder().encode(foo) else {
XCTFail("Failed to encode \(foo)")
return
}
guard let bar = try? JSONDecoder().decode(BigInt.self, from: fooData) else {
XCTFail("Failed to decode \(String(data: fooData, encoding: .utf8) ?? "")")
return
}
XCTAssertEqual(foo, bar)
func testCodable() throws {
let lowerBound = BigInt("-1234567890123456789012345678901234567890")!
let upperBound = BigInt("+1234567890123456789012345678901234567890")!
let expectedRange: Range<BigInt> = lowerBound ..< upperBound
let encoder = JSONEncoder()
let decoder = JSONDecoder()
let data = try encoder.encode(expectedRange)
let actualRange = try decoder.decode(Range<BigInt>.self, from: data)
XCTAssertEqual(actualRange, expectedRange)
}
func testMinMaxDescriptions() {