@marcuspuchalla/nachos 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +674 -0
  3. package/README.md +345 -0
  4. package/dist/chunk-2FUTHZQQ.cjs +755 -0
  5. package/dist/chunk-2FUTHZQQ.cjs.map +1 -0
  6. package/dist/chunk-2HBCILJS.cjs +2034 -0
  7. package/dist/chunk-2HBCILJS.cjs.map +1 -0
  8. package/dist/chunk-7CFYWHS6.js +742 -0
  9. package/dist/chunk-7CFYWHS6.js.map +1 -0
  10. package/dist/chunk-PD72MVTX.cjs +160 -0
  11. package/dist/chunk-PD72MVTX.cjs.map +1 -0
  12. package/dist/chunk-ZDZ2B5PE.js +149 -0
  13. package/dist/chunk-ZDZ2B5PE.js.map +1 -0
  14. package/dist/chunk-ZRPJUEIZ.js +2020 -0
  15. package/dist/chunk-ZRPJUEIZ.js.map +1 -0
  16. package/dist/encoder/index.cjs +57 -0
  17. package/dist/encoder/index.cjs.map +1 -0
  18. package/dist/encoder/index.d.cts +72 -0
  19. package/dist/encoder/index.d.ts +72 -0
  20. package/dist/encoder/index.js +4 -0
  21. package/dist/encoder/index.js.map +1 -0
  22. package/dist/index.cjs +606 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.cts +494 -0
  25. package/dist/index.d.ts +494 -0
  26. package/dist/index.js +523 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/metafile-cjs.json +1 -0
  29. package/dist/metafile-esm.json +1 -0
  30. package/dist/parser/index.cjs +85 -0
  31. package/dist/parser/index.cjs.map +1 -0
  32. package/dist/parser/index.d.cts +72 -0
  33. package/dist/parser/index.d.ts +72 -0
  34. package/dist/parser/index.js +4 -0
  35. package/dist/parser/index.js.map +1 -0
  36. package/dist/types-DvNlfbKB.d.cts +301 -0
  37. package/dist/types-DvNlfbKB.d.ts +301 -0
  38. package/dist/useCborSimpleEncoder-ButVU988.d.cts +268 -0
  39. package/dist/useCborSimpleEncoder-TVxzNJ_9.d.ts +268 -0
  40. package/dist/useCborTag-B_iaShG6.d.ts +142 -0
  41. package/dist/useCborTag-BfTIV8HM.d.cts +142 -0
  42. package/package.json +102 -0
  43. package/src/__tests__/public-api.test.ts +326 -0
  44. package/src/encoder/__tests__/cbor-collection-encoder.test.ts +331 -0
  45. package/src/encoder/__tests__/cbor-integer-encoder.test.ts +283 -0
  46. package/src/encoder/__tests__/cbor-simple-encoder.test.ts +224 -0
  47. package/src/encoder/__tests__/cbor-string-encoder.test.ts +345 -0
  48. package/src/encoder/__tests__/cbor-tag-encoder.test.ts +565 -0
  49. package/src/encoder/composables/#useCborTagEncoder.ts# +158 -0
  50. package/src/encoder/composables/useCborCollectionEncoder.ts +424 -0
  51. package/src/encoder/composables/useCborEncoder.ts +203 -0
  52. package/src/encoder/composables/useCborIntegerEncoder.ts +188 -0
  53. package/src/encoder/composables/useCborSimpleEncoder.ts +266 -0
  54. package/src/encoder/composables/useCborStringEncoder.ts +266 -0
  55. package/src/encoder/composables/useCborTagEncoder.ts +158 -0
  56. package/src/encoder/index.ts +35 -0
  57. package/src/encoder/types.ts +88 -0
  58. package/src/encoder/utils.ts +80 -0
  59. package/src/index.ts +434 -0
  60. package/src/parser/__tests__/ast-tree-structure.test.ts +311 -0
  61. package/src/parser/__tests__/cbor-collection-errors.test.ts +296 -0
  62. package/src/parser/__tests__/cbor-collection.test.ts +369 -0
  63. package/src/parser/__tests__/cbor-deterministic-encoding.test.ts +432 -0
  64. package/src/parser/__tests__/cbor-diagnostic.test.ts +333 -0
  65. package/src/parser/__tests__/cbor-duplicate-keys.test.ts +235 -0
  66. package/src/parser/__tests__/cbor-float-errors.test.ts +222 -0
  67. package/src/parser/__tests__/cbor-float.test.ts +502 -0
  68. package/src/parser/__tests__/cbor-integer-errors.test.ts +139 -0
  69. package/src/parser/__tests__/cbor-integer.test.ts +200 -0
  70. package/src/parser/__tests__/cbor-map-duplicate-keys.test.ts +403 -0
  71. package/src/parser/__tests__/cbor-parser-errors.test.ts +126 -0
  72. package/src/parser/__tests__/cbor-security-dos-protection.test.ts +503 -0
  73. package/src/parser/__tests__/cbor-sequences.test.ts +150 -0
  74. package/src/parser/__tests__/cbor-source-map.test.ts +321 -0
  75. package/src/parser/__tests__/cbor-standard-tags.test.ts +340 -0
  76. package/src/parser/__tests__/cbor-string-errors.test.ts +227 -0
  77. package/src/parser/__tests__/cbor-string.test.ts +224 -0
  78. package/src/parser/__tests__/cbor-tag-advanced.test.ts +500 -0
  79. package/src/parser/__tests__/cbor-tag-errors.test.ts +447 -0
  80. package/src/parser/__tests__/cbor-tag-source-map.test.ts +360 -0
  81. package/src/parser/__tests__/cbor-tag.test.ts +684 -0
  82. package/src/parser/__tests__/extreme-edge-cases.test.ts +146 -0
  83. package/src/parser/__tests__/pathBuilder.test.ts +256 -0
  84. package/src/parser/__tests__/rfc-test-vectors.test.ts +607 -0
  85. package/src/parser/__tests__/security-limits.test.ts +248 -0
  86. package/src/parser/__tests__/utils-errors.test.ts +127 -0
  87. package/src/parser/composables/useCborCollection.ts +509 -0
  88. package/src/parser/composables/useCborDiagnostic.ts +381 -0
  89. package/src/parser/composables/useCborFloat.ts +256 -0
  90. package/src/parser/composables/useCborInteger.ts +114 -0
  91. package/src/parser/composables/useCborParser.ts +951 -0
  92. package/src/parser/composables/useCborString.ts +330 -0
  93. package/src/parser/composables/useCborStringTypes.ts +129 -0
  94. package/src/parser/composables/useCborTag.ts +739 -0
  95. package/src/parser/index.ts +56 -0
  96. package/src/parser/types.ts +371 -0
  97. package/src/parser/utils/pathBuilder.ts +259 -0
  98. package/src/parser/utils.ts +398 -0
  99. package/src/utils/__tests__/logger.test.ts +186 -0
  100. package/src/utils/logger.ts +96 -0
@@ -0,0 +1,607 @@
1
+ /**
2
+ * RFC 8949 Test Vectors
3
+ * All examples from RFC 8949 Appendix A: Examples of Encoded CBOR Data Items
4
+ * https://www.rfc-editor.org/rfc/rfc8949.html#name-examples-of-encoded-cbor-da
5
+ *
6
+ * This test suite validates 100% compliance with the CBOR specification
7
+ */
8
+
9
+ import { describe, it, expect } from 'vitest'
10
+ import { useCborParser } from '../composables/useCborParser'
11
+
12
+ describe('RFC 8949 Appendix A Test Vectors', () => {
13
+ describe('Integers', () => {
14
+ it('should parse 0', () => {
15
+ const { parse } = useCborParser()
16
+ const result = parse('00')
17
+ expect(result.value).toBe(0)
18
+ })
19
+
20
+ it('should parse 1', () => {
21
+ const { parse } = useCborParser()
22
+ const result = parse('01')
23
+ expect(result.value).toBe(1)
24
+ })
25
+
26
+ it('should parse 10', () => {
27
+ const { parse } = useCborParser()
28
+ const result = parse('0a')
29
+ expect(result.value).toBe(10)
30
+ })
31
+
32
+ it('should parse 23', () => {
33
+ const { parse } = useCborParser()
34
+ const result = parse('17')
35
+ expect(result.value).toBe(23)
36
+ })
37
+
38
+ it('should parse 24', () => {
39
+ const { parse } = useCborParser()
40
+ const result = parse('1818')
41
+ expect(result.value).toBe(24)
42
+ })
43
+
44
+ it('should parse 25', () => {
45
+ const { parse } = useCborParser()
46
+ const result = parse('1819')
47
+ expect(result.value).toBe(25)
48
+ })
49
+
50
+ it('should parse 100', () => {
51
+ const { parse } = useCborParser()
52
+ const result = parse('1864')
53
+ expect(result.value).toBe(100)
54
+ })
55
+
56
+ it('should parse 1000', () => {
57
+ const { parse } = useCborParser()
58
+ const result = parse('1903e8')
59
+ expect(result.value).toBe(1000)
60
+ })
61
+
62
+ it('should parse 1000000', () => {
63
+ const { parse } = useCborParser()
64
+ const result = parse('1a000f4240')
65
+ expect(result.value).toBe(1000000)
66
+ })
67
+
68
+ it('should parse 1000000000000', () => {
69
+ const { parse } = useCborParser()
70
+ const result = parse('1b000000e8d4a51000')
71
+ expect(result.value).toBe(1000000000000)
72
+ })
73
+
74
+ it('should parse 18446744073709551615 (max uint64)', () => {
75
+ const { parse } = useCborParser()
76
+ const result = parse('1bffffffffffffffff')
77
+ expect(result.value).toBe(18446744073709551615n)
78
+ })
79
+
80
+ it('should parse 18446744073709551616 (bignum tag)', () => {
81
+ const { parse } = useCborParser()
82
+ const result = parse('c249010000000000000000')
83
+ // Parser converts bignum to BigInt value
84
+ expect(result.value).toEqual({
85
+ tag: 2,
86
+ value: 18446744073709551616n
87
+ })
88
+ })
89
+
90
+ it('should parse -18446744073709551616 (negative bignum tag)', () => {
91
+ const { parse } = useCborParser()
92
+ const result = parse('3bffffffffffffffff')
93
+ expect(result.value).toBe(-18446744073709551616n)
94
+ })
95
+
96
+ it('should parse -18446744073709551617 (negative bignum tag)', () => {
97
+ const { parse } = useCborParser()
98
+ const result = parse('c349010000000000000000')
99
+ // Parser converts bignum to BigInt value
100
+ expect(result.value).toEqual({
101
+ tag: 3,
102
+ value: -18446744073709551617n
103
+ })
104
+ })
105
+
106
+ it('should parse -1', () => {
107
+ const { parse } = useCborParser()
108
+ const result = parse('20')
109
+ expect(result.value).toBe(-1)
110
+ })
111
+
112
+ it('should parse -10', () => {
113
+ const { parse } = useCborParser()
114
+ const result = parse('29')
115
+ expect(result.value).toBe(-10)
116
+ })
117
+
118
+ it('should parse -100', () => {
119
+ const { parse } = useCborParser()
120
+ const result = parse('3863')
121
+ expect(result.value).toBe(-100)
122
+ })
123
+
124
+ it('should parse -1000', () => {
125
+ const { parse } = useCborParser()
126
+ const result = parse('3903e7')
127
+ expect(result.value).toBe(-1000)
128
+ })
129
+ })
130
+
131
+ describe('Floating-Point Numbers', () => {
132
+ it('should parse 0.0', () => {
133
+ const { parse } = useCborParser()
134
+ const result = parse('f90000')
135
+ expect(result.value).toBe(0.0)
136
+ })
137
+
138
+ it('should parse -0.0', () => {
139
+ const { parse } = useCborParser()
140
+ const result = parse('f98000')
141
+ expect(result.value).toBe(-0.0)
142
+ expect(Object.is(result.value, -0.0)).toBe(true)
143
+ })
144
+
145
+ it('should parse 1.0', () => {
146
+ const { parse } = useCborParser()
147
+ const result = parse('f93c00')
148
+ expect(result.value).toBe(1.0)
149
+ })
150
+
151
+ it('should parse 1.1', () => {
152
+ const { parse } = useCborParser()
153
+ const result = parse('fb3ff199999999999a')
154
+ expect(result.value).toBe(1.1)
155
+ })
156
+
157
+ it('should parse 1.5', () => {
158
+ const { parse } = useCborParser()
159
+ const result = parse('f93e00')
160
+ expect(result.value).toBe(1.5)
161
+ })
162
+
163
+ it('should parse 65504.0 (max normal float16)', () => {
164
+ const { parse } = useCborParser()
165
+ const result = parse('f97bff')
166
+ expect(result.value).toBe(65504.0)
167
+ })
168
+
169
+ it('should parse 100000.0', () => {
170
+ const { parse } = useCborParser()
171
+ const result = parse('fa47c35000')
172
+ expect(result.value).toBe(100000.0)
173
+ })
174
+
175
+ it('should parse 3.4028234663852886e+38 (max float32)', () => {
176
+ const { parse } = useCborParser()
177
+ const result = parse('fa7f7fffff')
178
+ expect(result.value).toBeCloseTo(3.4028234663852886e+38, -30)
179
+ })
180
+
181
+ it('should parse 1.0e+300', () => {
182
+ const { parse } = useCborParser()
183
+ const result = parse('fb7e37e43c8800759c')
184
+ expect(result.value).toBe(1.0e+300)
185
+ })
186
+
187
+ it('should parse 5.960464477539063e-8 (min positive subnormal float16)', () => {
188
+ const { parse } = useCborParser()
189
+ const result = parse('f90001')
190
+ expect(result.value).toBeCloseTo(5.960464477539063e-8, 15)
191
+ })
192
+
193
+ it('should parse 0.00006103515625 (min positive normal float16)', () => {
194
+ const { parse } = useCborParser()
195
+ const result = parse('f90400')
196
+ expect(result.value).toBeCloseTo(0.00006103515625, 15)
197
+ })
198
+
199
+ it('should parse -4.0', () => {
200
+ const { parse } = useCborParser()
201
+ const result = parse('f9c400')
202
+ expect(result.value).toBe(-4.0)
203
+ })
204
+
205
+ it('should parse -4.1', () => {
206
+ const { parse } = useCborParser()
207
+ const result = parse('fbc010666666666666')
208
+ expect(result.value).toBe(-4.1)
209
+ })
210
+
211
+ it('should parse Infinity', () => {
212
+ const { parse } = useCborParser()
213
+ const result = parse('f97c00')
214
+ expect(result.value).toBe(Infinity)
215
+ })
216
+
217
+ it('should parse NaN', () => {
218
+ const { parse } = useCborParser()
219
+ const result = parse('f97e00')
220
+ expect(Number.isNaN(result.value)).toBe(true)
221
+ })
222
+
223
+ it('should parse -Infinity', () => {
224
+ const { parse } = useCborParser()
225
+ const result = parse('f9fc00')
226
+ expect(result.value).toBe(-Infinity)
227
+ })
228
+
229
+ it('should parse Infinity (float32)', () => {
230
+ const { parse } = useCborParser()
231
+ const result = parse('fa7f800000')
232
+ expect(result.value).toBe(Infinity)
233
+ })
234
+
235
+ it('should parse NaN (float32)', () => {
236
+ const { parse } = useCborParser()
237
+ const result = parse('fa7fc00000')
238
+ expect(Number.isNaN(result.value)).toBe(true)
239
+ })
240
+
241
+ it('should parse -Infinity (float32)', () => {
242
+ const { parse } = useCborParser()
243
+ const result = parse('faff800000')
244
+ expect(result.value).toBe(-Infinity)
245
+ })
246
+
247
+ it('should parse Infinity (float64)', () => {
248
+ const { parse } = useCborParser()
249
+ const result = parse('fb7ff0000000000000')
250
+ expect(result.value).toBe(Infinity)
251
+ })
252
+
253
+ it('should parse NaN (float64)', () => {
254
+ const { parse } = useCborParser()
255
+ const result = parse('fb7ff8000000000000')
256
+ expect(Number.isNaN(result.value)).toBe(true)
257
+ })
258
+
259
+ it('should parse -Infinity (float64)', () => {
260
+ const { parse } = useCborParser()
261
+ const result = parse('fbfff0000000000000')
262
+ expect(result.value).toBe(-Infinity)
263
+ })
264
+ })
265
+
266
+ describe('Simple Values', () => {
267
+ it('should parse false', () => {
268
+ const { parse } = useCborParser()
269
+ const result = parse('f4')
270
+ expect(result.value).toBe(false)
271
+ })
272
+
273
+ it('should parse true', () => {
274
+ const { parse } = useCborParser()
275
+ const result = parse('f5')
276
+ expect(result.value).toBe(true)
277
+ })
278
+
279
+ it('should parse null', () => {
280
+ const { parse } = useCborParser()
281
+ const result = parse('f6')
282
+ expect(result.value).toBe(null)
283
+ })
284
+
285
+ it('should parse undefined', () => {
286
+ const { parse } = useCborParser()
287
+ const result = parse('f7')
288
+ expect(result.value).toBe(undefined)
289
+ })
290
+
291
+ it('should parse simple(16)', () => {
292
+ const { parse } = useCborParser()
293
+ const result = parse('f0')
294
+ expect(result.value).toEqual({ simpleValue: 16 })
295
+ })
296
+
297
+ it('should parse simple(255)', () => {
298
+ const { parse } = useCborParser()
299
+ const result = parse('f8ff')
300
+ expect(result.value).toEqual({ simpleValue: 255 })
301
+ })
302
+ })
303
+
304
+ describe('Byte Strings', () => {
305
+ it('should parse h\'\'', () => {
306
+ const { parse } = useCborParser()
307
+ const result = parse('40')
308
+ expect(result.value).toEqual(new Uint8Array([]))
309
+ })
310
+
311
+ it('should parse h\'01020304\'', () => {
312
+ const { parse } = useCborParser()
313
+ const result = parse('4401020304')
314
+ expect(result.value).toEqual(new Uint8Array([0x01, 0x02, 0x03, 0x04]))
315
+ })
316
+ })
317
+
318
+ describe('Text Strings', () => {
319
+ it('should parse ""', () => {
320
+ const { parse } = useCborParser()
321
+ const result = parse('60')
322
+ expect(result.value).toBe('')
323
+ })
324
+
325
+ it('should parse "a"', () => {
326
+ const { parse } = useCborParser()
327
+ const result = parse('6161')
328
+ expect(result.value).toBe('a')
329
+ })
330
+
331
+ it('should parse "IETF"', () => {
332
+ const { parse } = useCborParser()
333
+ const result = parse('6449455446')
334
+ expect(result.value).toBe('IETF')
335
+ })
336
+
337
+ it('should parse "\\\\"', () => {
338
+ const { parse } = useCborParser()
339
+ // Hex: 62 (text string, length 2) + 22 (") + 5c (\)
340
+ const result = parse('62225c')
341
+ expect(result.value).toBe('"\\')
342
+ })
343
+
344
+ it('should parse "ü" (U+00FC)', () => {
345
+ const { parse } = useCborParser()
346
+ const result = parse('62c3bc')
347
+ expect(result.value).toBe('ü')
348
+ })
349
+
350
+ it('should parse "水" (U+6C34)', () => {
351
+ const { parse } = useCborParser()
352
+ const result = parse('63e6b0b4')
353
+ expect(result.value).toBe('水')
354
+ })
355
+
356
+ it('should parse "𐅑" (U+10151)', () => {
357
+ const { parse } = useCborParser()
358
+ const result = parse('64f0908591')
359
+ expect(result.value).toBe('𐅑')
360
+ })
361
+ })
362
+
363
+ describe('Arrays', () => {
364
+ it('should parse []', () => {
365
+ const { parse } = useCborParser()
366
+ const result = parse('80')
367
+ expect(result.value).toEqual([])
368
+ })
369
+
370
+ it('should parse [1, 2, 3]', () => {
371
+ const { parse } = useCborParser()
372
+ const result = parse('83010203')
373
+ expect(result.value).toEqual([1, 2, 3])
374
+ })
375
+
376
+ it('should parse [1, [2, 3], [4, 5]]', () => {
377
+ const { parse } = useCborParser()
378
+ const result = parse('8301820203820405')
379
+ expect(result.value).toEqual([1, [2, 3], [4, 5]])
380
+ })
381
+
382
+ it('should parse [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]', () => {
383
+ const { parse } = useCborParser()
384
+ const result = parse('98190102030405060708090a0b0c0d0e0f101112131415161718181819')
385
+ expect(result.value).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25])
386
+ })
387
+ })
388
+
389
+ describe('Maps', () => {
390
+ it('should parse {}', () => {
391
+ const { parse } = useCborParser()
392
+ const result = parse('a0')
393
+ expect(result.value).toEqual(new Map())
394
+ })
395
+
396
+ it('should parse {1: 2, 3: 4}', () => {
397
+ const { parse } = useCborParser()
398
+ const result = parse('a201020304')
399
+ expect(result.value).toEqual(new Map([[1, 2], [3, 4]]))
400
+ })
401
+
402
+ it('should parse {"a": 1, "b": [2, 3]}', () => {
403
+ const { parse } = useCborParser()
404
+ const result = parse('a26161016162820203')
405
+ expect(result.value).toEqual(new Map([['a', 1], ['b', [2, 3]]]))
406
+ })
407
+
408
+ it('should parse ["a", {"b": "c"}]', () => {
409
+ const { parse } = useCborParser()
410
+ const result = parse('826161a161626163')
411
+ expect(result.value).toEqual(['a', new Map([['b', 'c']])])
412
+ })
413
+
414
+ it('should parse {"a": "A", "b": "B", "c": "C", "d": "D", "e": "E"}', () => {
415
+ const { parse } = useCborParser()
416
+ const result = parse('a56161614161626142616361436164614461656145')
417
+ expect(result.value).toEqual(new Map([['a', 'A'], ['b', 'B'], ['c', 'C'], ['d', 'D'], ['e', 'E']]))
418
+ })
419
+ })
420
+
421
+ describe('Tagged Values', () => {
422
+ it('should parse 0("2013-03-21T20:04:00Z")', () => {
423
+ const { parse } = useCborParser()
424
+ const result = parse('c074323031332d30332d3231543230 3a30343a30305a'.replace(/\s/g, ''))
425
+ expect(result.value).toEqual({
426
+ tag: 0,
427
+ value: '2013-03-21T20:04:00Z'
428
+ })
429
+ })
430
+
431
+ it('should parse 1(1363896240)', () => {
432
+ const { parse } = useCborParser()
433
+ const result = parse('c11a514b67b0')
434
+ expect(result.value).toEqual({
435
+ tag: 1,
436
+ value: 1363896240
437
+ })
438
+ })
439
+
440
+ it('should parse 1(1363896240.5)', () => {
441
+ const { parse } = useCborParser()
442
+ const result = parse('c1fb41d452d9ec200000')
443
+ expect(result.value.tag).toBe(1)
444
+ expect(result.value.value).toBeCloseTo(1363896240.5, 1)
445
+ })
446
+
447
+ it('should parse 23(h\'01020304\')', () => {
448
+ const { parse } = useCborParser()
449
+ const result = parse('d74401020304')
450
+ expect(result.value).toEqual({
451
+ tag: 23,
452
+ value: new Uint8Array([0x01, 0x02, 0x03, 0x04])
453
+ })
454
+ })
455
+
456
+ it('should parse 24(h\'6449455446\')', () => {
457
+ const { parse } = useCborParser()
458
+ const result = parse('d818456449455446')
459
+ expect(result.value).toEqual({
460
+ tag: 24,
461
+ value: new Uint8Array([0x64, 0x49, 0x45, 0x54, 0x46])
462
+ })
463
+ })
464
+
465
+ it('should parse 32("http://www.example.com")', () => {
466
+ const { parse } = useCborParser()
467
+ const result = parse('d82076687474703a2f2f7777772e6578616d706c652e636f6d')
468
+ expect(result.value).toEqual({
469
+ tag: 32,
470
+ value: 'http://www.example.com'
471
+ })
472
+ })
473
+ })
474
+
475
+ describe('Indefinite-Length Items', () => {
476
+ it('should parse (_ h\'0102\', h\'030405\')', () => {
477
+ const { parse } = useCborParser()
478
+ const result = parse('5f42010243030405ff')
479
+ // Indefinite byte string returns CborByteString with chunks
480
+ expect(result.value).toMatchObject({
481
+ type: 'cbor-byte-string',
482
+ bytes: new Uint8Array([0x01, 0x02, 0x03, 0x04, 0x05])
483
+ })
484
+ expect((result.value as any).chunks).toBeDefined()
485
+ })
486
+
487
+ it('should parse (_ "strea", "ming")', () => {
488
+ const { parse } = useCborParser()
489
+ const result = parse('7f657374726561646d696e67ff')
490
+ // Indefinite text string returns CborTextString with chunks
491
+ expect(result.value).toMatchObject({
492
+ type: 'cbor-text-string',
493
+ text: 'streaming'
494
+ })
495
+ expect((result.value as any).chunks).toBeDefined()
496
+ })
497
+
498
+ it('should parse [_]', () => {
499
+ const { parse } = useCborParser()
500
+ const result = parse('9fff')
501
+ expect(Array.isArray(result.value)).toBe(true)
502
+ expect(result.value).toHaveLength(0)
503
+ })
504
+
505
+ it('should parse [_ 1, [2, 3], [_ 4, 5]]', () => {
506
+ const { parse } = useCborParser()
507
+ const result = parse('9f018202039f0405ffff')
508
+ expect(Array.isArray(result.value)).toBe(true)
509
+ const arr = result.value as any[]
510
+ expect(arr[0]).toBe(1)
511
+ expect(arr[1]).toEqual([2, 3])
512
+ expect(Array.isArray(arr[2])).toBe(true)
513
+ expect(arr[2][0]).toBe(4)
514
+ expect(arr[2][1]).toBe(5)
515
+ })
516
+
517
+ it('should parse [_ 1, [2, 3], [4, 5]]', () => {
518
+ const { parse } = useCborParser()
519
+ const result = parse('9f01820203820405ff')
520
+ expect(Array.isArray(result.value)).toBe(true)
521
+ const arr = result.value as any[]
522
+ expect(arr[0]).toBe(1)
523
+ expect(arr[1]).toEqual([2, 3])
524
+ expect(arr[2]).toEqual([4, 5])
525
+ })
526
+
527
+ it('should parse [1, [2, 3], [_ 4, 5]]', () => {
528
+ const { parse } = useCborParser()
529
+ const result = parse('83018202039f0405ff')
530
+ expect(Array.isArray(result.value)).toBe(true)
531
+ const arr = result.value as any[]
532
+ expect(arr[0]).toBe(1)
533
+ expect(arr[1]).toEqual([2, 3])
534
+ expect(Array.isArray(arr[2])).toBe(true)
535
+ expect(arr[2][0]).toBe(4)
536
+ expect(arr[2][1]).toBe(5)
537
+ })
538
+
539
+ it('should parse [1, [_ 2, 3], [4, 5]]', () => {
540
+ const { parse } = useCborParser()
541
+ const result = parse('83019f0203ff820405')
542
+ expect(Array.isArray(result.value)).toBe(true)
543
+ const arr = result.value as any[]
544
+ expect(arr[0]).toBe(1)
545
+ expect(Array.isArray(arr[1])).toBe(true)
546
+ expect(arr[1][0]).toBe(2)
547
+ expect(arr[1][1]).toBe(3)
548
+ expect(arr[2]).toEqual([4, 5])
549
+ })
550
+
551
+ it('should parse [_ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]', () => {
552
+ const { parse } = useCborParser()
553
+ const result = parse('9f0102030405060708090a0b0c0d0e0f101112131415161718181819ff')
554
+ expect(Array.isArray(result.value)).toBe(true)
555
+ expect(result.value).toHaveLength(25)
556
+ const expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
557
+ expected.forEach((val, idx) => {
558
+ expect((result.value as any[])[idx]).toBe(val)
559
+ })
560
+ })
561
+
562
+ it('should parse {_ "a": 1, "b": [_ 2, 3]}', () => {
563
+ const { parse } = useCborParser()
564
+ const result = parse('bf61610161629f0203ffff')
565
+ expect(result.value instanceof Map).toBe(true)
566
+ const map = result.value as Map<any, any>
567
+ expect(map.get('a')).toBe(1)
568
+ expect(Array.isArray(map.get('b'))).toBe(true)
569
+ const bArr = map.get('b') as any[]
570
+ expect(bArr[0]).toBe(2)
571
+ expect(bArr[1]).toBe(3)
572
+ })
573
+
574
+ it('should parse ["a", {_ "b": "c"}]', () => {
575
+ const { parse } = useCborParser()
576
+ const result = parse('826161bf61626163ff')
577
+ expect(result.value).toEqual(['a', new Map([['b', 'c']])])
578
+ })
579
+
580
+ it('should parse {_ "Fun": true, "Amt": -2}', () => {
581
+ const { parse } = useCborParser()
582
+ const result = parse('bf6346756ef563416d7421ff')
583
+ expect(result.value).toEqual(new Map([['Fun', true], ['Amt', -2]]))
584
+ })
585
+ })
586
+
587
+ describe('Edge Cases and Special Combinations', () => {
588
+ it('should parse array with all basic types [0, -1, "", h\'\', [], {}, false, null]', () => {
589
+ const { parse } = useCborParser()
590
+ const result = parse('880020604080a0f4f6')
591
+ expect(result.value).toEqual([0, -1, '', new Uint8Array([]), [], new Map(), false, null])
592
+ })
593
+
594
+ it('should parse nested indefinite [_ [_ 1], [_ 2, 3]]', () => {
595
+ const { parse } = useCborParser()
596
+ const result = parse('9f9f01ff9f0203ffff')
597
+ expect(Array.isArray(result.value)).toBe(true)
598
+ const arr = result.value as any[]
599
+ expect(arr).toHaveLength(2)
600
+ expect(Array.isArray(arr[0])).toBe(true)
601
+ expect(arr[0][0]).toBe(1)
602
+ expect(Array.isArray(arr[1])).toBe(true)
603
+ expect(arr[1][0]).toBe(2)
604
+ expect(arr[1][1]).toBe(3)
605
+ })
606
+ })
607
+ })