A fast, safe, and efficient CBOR serialization library for Swift on any platform.
swiftpackageindex.com/thecoolwinter/CBOR/1.1.1/documentation/cbor
atproto
swift
cbor
1//
2// DAGCBORDecoderTests.swift
3// CBOR
4//
5// Created by Khan Winter on 10/21/25.
6//
7
8import Testing
9@testable import CBOR
10
11@Suite
12struct DAGCBORDecoderTests {
13 @Test
14 func shortMap() throws {
15 let data = "a1616100".asHexData()
16 let decoded = try DAGCBORDecoder().decode([String: Int].self, from: data)
17 #expect(decoded == ["a": 0])
18 }
19
20 @Test
21 func rejectUnorderedMaps() throws {
22 let data = "a361610162616103616202".asHexData()
23 #expect(throws: DecodingError.self) {
24 return try DAGCBORDecoder().decode([String: Int].self, from: data)
25 }
26 }
27
28 @Test
29 func rejectOtherUnorderedMaps() throws {
30 let data = "a2616201616100".asHexData()
31 #expect(throws: DecodingError.self) {
32 return try DAGCBORDecoder().decode([String: Int].self, from: data)
33 }
34 }
35
36 @Test
37 func rejectConcatenatedItems() throws {
38 var data = "0000".asHexData()
39 #expect(throws: DecodingError.self) {
40 return try DAGCBORDecoder().decode(Int.self, from: data)
41 }
42
43 data = "0000AA".asHexData()
44 #expect(throws: DecodingError.self) {
45 return try DAGCBORDecoder().decode(Int.self, from: data)
46 }
47 }
48}