From 4ec520a7262ff3700888c2c242bc16ae6fc4ec5d Mon Sep 17 00:00:00 2001 From: Ben Rimmington Date: Wed, 15 Jan 2020 03:30:50 +0000 Subject: [PATCH] [BigIntTests] Update the testCodable() method Top-level JSON fragments might fail on Linux, so encode Range instead. --- Tests/BigIntTests/BigIntTests.swift | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Tests/BigIntTests/BigIntTests.swift b/Tests/BigIntTests/BigIntTests.swift index e37be27..19cb9e9 100644 --- a/Tests/BigIntTests/BigIntTests.swift +++ b/Tests/BigIntTests/BigIntTests.swift @@ -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 = lowerBound ..< upperBound + + let encoder = JSONEncoder() + let decoder = JSONDecoder() + let data = try encoder.encode(expectedRange) + let actualRange = try decoder.decode(Range.self, from: data) + + XCTAssertEqual(actualRange, expectedRange) } func testMinMaxDescriptions() {