From e11b3025a6589cd5e449f65d174b5004000c917a Mon Sep 17 00:00:00 2001 From: Kevin Wooten Date: Wed, 15 May 2024 22:08:45 -0700 Subject: [PATCH] Add CBOR tests for encoding/decoding `Empty` --- Tests/CBORDecoderTests.swift | 5 +++++ Tests/CBOREncoderTests.swift | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Tests/CBORDecoderTests.swift b/Tests/CBORDecoderTests.swift index 89b82d98c..0281f6e40 100644 --- a/Tests/CBORDecoderTests.swift +++ b/Tests/CBORDecoderTests.swift @@ -16,6 +16,11 @@ import XCTest class CBORDecoderTests: XCTestCase { + func testDecodeEmpty() { + struct Empty: Equatable, Codable {} + XCTAssertEqual(try CBORDecoder.default.decode(Empty.self, from: Data([0xA0])), Empty()) + } + func testDecodeNull() { XCTAssertNil(try CBORDecoder.default.decodeIfPresent(String.self, from: Data([0xF6]))) } diff --git a/Tests/CBOREncoderTests.swift b/Tests/CBOREncoderTests.swift index d7391858a..b97f39ea6 100644 --- a/Tests/CBOREncoderTests.swift +++ b/Tests/CBOREncoderTests.swift @@ -20,6 +20,11 @@ class CBOREncoderTests: XCTestCase { return Array(try CBOREncoder().encode(value)) } + func testEncodeEmpty() { + struct Empty: Codable {} + XCTAssertEqual(try encode(Empty()), [0xA0]) + } + func testEncodeNull() { XCTAssertEqual(try encode(String?(nil)), [0xF6]) }