From 178d713799cb76af6c74ea683d3e69e59ec3732d Mon Sep 17 00:00:00 2001 From: Oleksii Dykan Date: Mon, 23 Oct 2017 11:50:55 +0200 Subject: [PATCH] cover top level nullable types --- CodableFirebaseTests/TestCodableFirestore.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CodableFirebaseTests/TestCodableFirestore.swift b/CodableFirebaseTests/TestCodableFirestore.swift index 4d5d4ae..0f54e45 100644 --- a/CodableFirebaseTests/TestCodableFirestore.swift +++ b/CodableFirebaseTests/TestCodableFirestore.swift @@ -397,6 +397,17 @@ class TestCodableFirestore: XCTestCase { _testRoundTrip(of: Employee.testValue) } + func testEncodingTopLevelNullableType() { + // EnhancedBool is a type which encodes either as a Bool or as nil. + _testEncodeFailure(of: EnhancedBool.true) + _testEncodeFailure(of: EnhancedBool.false) + _testEncodeFailure(of: EnhancedBool.fileNotFound) + + _testRoundTrip(of: TopLevelWrapper(EnhancedBool.true)) + _testRoundTrip(of: TopLevelWrapper(EnhancedBool.false)) + _testRoundTrip(of: TopLevelWrapper(EnhancedBool.fileNotFound)) + } + func testTypeCoercion() { _testRoundTripTypeCoercionFailure(of: [false, true], as: [Int].self) _testRoundTripTypeCoercionFailure(of: [false, true], as: [Int8].self)