From 4556cfb81b417cd2722a7d412eb89d8f37b687f0 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Tue, 29 Jan 2019 12:03:53 +0900 Subject: [PATCH] Add `test_null_yml()` to `EncoderTests` from #157 --- Tests/YamsTests/EncoderTests.swift | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Tests/YamsTests/EncoderTests.swift b/Tests/YamsTests/EncoderTests.swift index 49cd9f9..24715b4 100644 --- a/Tests/YamsTests/EncoderTests.swift +++ b/Tests/YamsTests/EncoderTests.swift @@ -316,6 +316,29 @@ class EncoderTests: XCTestCase { // swiftlint:disable:this type_body_length expectEqual(type(of: decoded), Employee.self, "Expected decoded value to be of type Employee; got \(type(of: decoded)) instead.") } + func test_null_yml() throws { + let s = """ + n1: ~ + n2: null + n3: NULL + n4: Null + n5: + """ + struct Test: Decodable { + let n1: String? + let n2: String? + let n3: String? + let n4: String? + let n5: String? + } + let t = try YAMLDecoder().decode(Test.self, from: s) + XCTAssertNil(t.n1) + XCTAssertNil(t.n2) + XCTAssertNil(t.n3) + XCTAssertNil(t.n4) + XCTAssertNil(t.n5) + } + // MARK: - Helper Functions private func _testRoundTrip(of value: T, @@ -1089,7 +1112,8 @@ extension EncoderTests { ("testValuesInUnkeyedContainer", testValuesInUnkeyedContainer), ("testDictionary", testDictionary), ("testNodeTypeMismatch", testNodeTypeMismatch), - ("testDecodingConcreteTypeParameter", testDecodingConcreteTypeParameter) + ("testDecodingConcreteTypeParameter", testDecodingConcreteTypeParameter), + ("test_null_yml", test_null_yml) ] } }