Skip to content

Commit

Permalink
Add CBOR tests for encoding/decoding Empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kdubb committed May 16, 2024
1 parent 569e6ac commit e11b302
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Tests/CBORDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])))
}
Expand Down
5 changes: 5 additions & 0 deletions Tests/CBOREncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down

0 comments on commit e11b302

Please sign in to comment.