From b376eafdf82ac9bf1a6d80489c53206388ff44e1 Mon Sep 17 00:00:00 2001 From: Clay Ellis Date: Wed, 20 Jul 2016 12:19:31 -0600 Subject: [PATCH] Added tests for unboxing at a specified key --- Tests/UnboxTests.swift | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Tests/UnboxTests.swift b/Tests/UnboxTests.swift index 81c9fa8..ebec387 100644 --- a/Tests/UnboxTests.swift +++ b/Tests/UnboxTests.swift @@ -1210,7 +1210,42 @@ class UnboxTests: XCTestCase { XCTFail("Unexpected error thrown: \(error)") } } + + func testUnboxingStartingAtCustomKey() { + let dictionary: UnboxableDictionary = [ + "A": [ + "int": 14 + ] + ] + do { + let unboxed: UnboxTestSimpleMock = try Unbox(dictionary, at: "A") + XCTAssertEqual(unboxed.int, 14) + } catch { + XCTFail("Unexpected error thrown: \(error)") + } + } + + func testUnboxingStartingAtMissingCustomKey() { + let dictionary: UnboxableDictionary = [ + "A": [ + "int": 3 + ] + ] + + do { + let unboxed: UnboxTestSimpleMock = try Unbox(dictionary, at: "B") + XCTAssertEqual(unboxed.int, 3) + } catch { + switch error { + case UnboxValueError.MissingValueForKey(let missingKey): + XCTAssertEqual(missingKey, "B") + default: + XCTFail("Unexpected error thrown: \(error)") + } + } + } + } private func UnboxTestDictionaryWithAllRequiredKeysWithValidValues(nested: Bool) -> UnboxableDictionary {