From c3f9c8070d9e156507cfaad6e57f8b43bbe203d4 Mon Sep 17 00:00:00 2001 From: ser-0xff <122270051+ser-0xff@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:03:26 +0300 Subject: [PATCH] Add minimazed test encoding nil optional value to the unkeyed container. --- .../Encoding/JSONEncoderTests.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Tests/ExtrasJSONTests/Encoding/JSONEncoderTests.swift b/Tests/ExtrasJSONTests/Encoding/JSONEncoderTests.swift index 44d1900..1b29629 100644 --- a/Tests/ExtrasJSONTests/Encoding/JSONEncoderTests.swift +++ b/Tests/ExtrasJSONTests/Encoding/JSONEncoderTests.swift @@ -161,4 +161,19 @@ class JSONEncoderTests: XCTestCase { XCTAssertEqual(expected, json) // XCTAss } + + func testEncodeOptionalValueToTheUnkeyedContainer() throws { + struct TestStruct: Encodable { + let value: Int? + + func encode(to encoder: Encoder) throws { + var container = encoder.unkeyedContainer() + try container.encode(value) + } + } + + let s = TestStruct(value: nil) + let encoder = XJSONEncoder() + _ = try encoder.encode(s) + } }