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// DecodeMultipleTests.swift
3// CBOR
4//
5// Created by Khan Winter on 9/10/25.
6//
7
8import Testing
9#if canImport(FoundationEssentials)
10import FoundationEssentials
11#else
12import Foundation
13#endif
14@testable import CBOR
15
16@Suite
17struct DecodeMultipleTests {
18 @Test
19 func decodeMultipleInts() throws {
20 var value: [UInt8] = try CBORDecoder().decodeMultiple(UInt8.self, from: [0])
21 #expect(value == [0])
22 value = try CBORDecoder().decodeMultiple(UInt8.self, from: [1, 1])
23 #expect(value == [1, 1])
24 // Just below max arg size
25 value = try CBORDecoder().decodeMultiple(UInt8.self, from: [23, 23])
26 #expect(value == [23, 23])
27 // Just above max arg size
28// value = try CBORDecoder().decodeMultiple(UInt8.self, from: [24, 24, 24, 24])
29// #expect(value == [24, 24])
30 // Max Int
31 value = try CBORDecoder().decodeMultiple(UInt8.self, from: [24, UInt8.max])
32 #expect(value == [UInt8.max])
33
34 #expect(throws: DecodingError.self) { try CBORDecoder().decodeMultiple(UInt8.self, from: [128, 128]) }
35 #expect(throws: DecodingError.self) { try CBORDecoder().decodeMultiple(UInt8.self, from: [23, 128]) }
36 }
37
38 @Test
39 func mutlipleMaps() throws {
40 let data = "A262414201614102A262414201614102".asHexData()
41 let dictionary = try CBORDecoder().decodeMultiple([String: Int].self, from: data)
42 #expect(dictionary == [["AB": 1, "A": 2], ["AB": 1, "A": 2]])
43 }
44}