@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.
- package/CHANGELOG.md +64 -0
- package/LICENSE +674 -0
- package/README.md +345 -0
- package/dist/chunk-2FUTHZQQ.cjs +755 -0
- package/dist/chunk-2FUTHZQQ.cjs.map +1 -0
- package/dist/chunk-2HBCILJS.cjs +2034 -0
- package/dist/chunk-2HBCILJS.cjs.map +1 -0
- package/dist/chunk-7CFYWHS6.js +742 -0
- package/dist/chunk-7CFYWHS6.js.map +1 -0
- package/dist/chunk-PD72MVTX.cjs +160 -0
- package/dist/chunk-PD72MVTX.cjs.map +1 -0
- package/dist/chunk-ZDZ2B5PE.js +149 -0
- package/dist/chunk-ZDZ2B5PE.js.map +1 -0
- package/dist/chunk-ZRPJUEIZ.js +2020 -0
- package/dist/chunk-ZRPJUEIZ.js.map +1 -0
- package/dist/encoder/index.cjs +57 -0
- package/dist/encoder/index.cjs.map +1 -0
- package/dist/encoder/index.d.cts +72 -0
- package/dist/encoder/index.d.ts +72 -0
- package/dist/encoder/index.js +4 -0
- package/dist/encoder/index.js.map +1 -0
- package/dist/index.cjs +606 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +494 -0
- package/dist/index.d.ts +494 -0
- package/dist/index.js +523 -0
- package/dist/index.js.map +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/parser/index.cjs +85 -0
- package/dist/parser/index.cjs.map +1 -0
- package/dist/parser/index.d.cts +72 -0
- package/dist/parser/index.d.ts +72 -0
- package/dist/parser/index.js +4 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/types-DvNlfbKB.d.cts +301 -0
- package/dist/types-DvNlfbKB.d.ts +301 -0
- package/dist/useCborSimpleEncoder-ButVU988.d.cts +268 -0
- package/dist/useCborSimpleEncoder-TVxzNJ_9.d.ts +268 -0
- package/dist/useCborTag-B_iaShG6.d.ts +142 -0
- package/dist/useCborTag-BfTIV8HM.d.cts +142 -0
- package/package.json +102 -0
- package/src/__tests__/public-api.test.ts +326 -0
- package/src/encoder/__tests__/cbor-collection-encoder.test.ts +331 -0
- package/src/encoder/__tests__/cbor-integer-encoder.test.ts +283 -0
- package/src/encoder/__tests__/cbor-simple-encoder.test.ts +224 -0
- package/src/encoder/__tests__/cbor-string-encoder.test.ts +345 -0
- package/src/encoder/__tests__/cbor-tag-encoder.test.ts +565 -0
- package/src/encoder/composables/#useCborTagEncoder.ts# +158 -0
- package/src/encoder/composables/useCborCollectionEncoder.ts +424 -0
- package/src/encoder/composables/useCborEncoder.ts +203 -0
- package/src/encoder/composables/useCborIntegerEncoder.ts +188 -0
- package/src/encoder/composables/useCborSimpleEncoder.ts +266 -0
- package/src/encoder/composables/useCborStringEncoder.ts +266 -0
- package/src/encoder/composables/useCborTagEncoder.ts +158 -0
- package/src/encoder/index.ts +35 -0
- package/src/encoder/types.ts +88 -0
- package/src/encoder/utils.ts +80 -0
- package/src/index.ts +434 -0
- package/src/parser/__tests__/ast-tree-structure.test.ts +311 -0
- package/src/parser/__tests__/cbor-collection-errors.test.ts +296 -0
- package/src/parser/__tests__/cbor-collection.test.ts +369 -0
- package/src/parser/__tests__/cbor-deterministic-encoding.test.ts +432 -0
- package/src/parser/__tests__/cbor-diagnostic.test.ts +333 -0
- package/src/parser/__tests__/cbor-duplicate-keys.test.ts +235 -0
- package/src/parser/__tests__/cbor-float-errors.test.ts +222 -0
- package/src/parser/__tests__/cbor-float.test.ts +502 -0
- package/src/parser/__tests__/cbor-integer-errors.test.ts +139 -0
- package/src/parser/__tests__/cbor-integer.test.ts +200 -0
- package/src/parser/__tests__/cbor-map-duplicate-keys.test.ts +403 -0
- package/src/parser/__tests__/cbor-parser-errors.test.ts +126 -0
- package/src/parser/__tests__/cbor-security-dos-protection.test.ts +503 -0
- package/src/parser/__tests__/cbor-sequences.test.ts +150 -0
- package/src/parser/__tests__/cbor-source-map.test.ts +321 -0
- package/src/parser/__tests__/cbor-standard-tags.test.ts +340 -0
- package/src/parser/__tests__/cbor-string-errors.test.ts +227 -0
- package/src/parser/__tests__/cbor-string.test.ts +224 -0
- package/src/parser/__tests__/cbor-tag-advanced.test.ts +500 -0
- package/src/parser/__tests__/cbor-tag-errors.test.ts +447 -0
- package/src/parser/__tests__/cbor-tag-source-map.test.ts +360 -0
- package/src/parser/__tests__/cbor-tag.test.ts +684 -0
- package/src/parser/__tests__/extreme-edge-cases.test.ts +146 -0
- package/src/parser/__tests__/pathBuilder.test.ts +256 -0
- package/src/parser/__tests__/rfc-test-vectors.test.ts +607 -0
- package/src/parser/__tests__/security-limits.test.ts +248 -0
- package/src/parser/__tests__/utils-errors.test.ts +127 -0
- package/src/parser/composables/useCborCollection.ts +509 -0
- package/src/parser/composables/useCborDiagnostic.ts +381 -0
- package/src/parser/composables/useCborFloat.ts +256 -0
- package/src/parser/composables/useCborInteger.ts +114 -0
- package/src/parser/composables/useCborParser.ts +951 -0
- package/src/parser/composables/useCborString.ts +330 -0
- package/src/parser/composables/useCborStringTypes.ts +129 -0
- package/src/parser/composables/useCborTag.ts +739 -0
- package/src/parser/index.ts +56 -0
- package/src/parser/types.ts +371 -0
- package/src/parser/utils/pathBuilder.ts +259 -0
- package/src/parser/utils.ts +398 -0
- package/src/utils/__tests__/logger.test.ts +186 -0
- package/src/utils/logger.ts +96 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CBOR Float Parser Error Handling Tests
|
|
3
|
+
* Tests all error cases and edge cases for 100% code coverage
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, it, expect } from 'vitest'
|
|
7
|
+
import { useCborFloat } from '../composables/useCborFloat'
|
|
8
|
+
|
|
9
|
+
describe('useCborFloat - Error Handling', () => {
|
|
10
|
+
describe('parseSimple - Wrong Major Type', () => {
|
|
11
|
+
it('should throw error when major type is not 7', () => {
|
|
12
|
+
const { parseSimple } = useCborFloat()
|
|
13
|
+
|
|
14
|
+
// MT 0 (integer) should not be parsed as simple value
|
|
15
|
+
expect(() => parseSimple('00')).toThrow('Expected major type 7 (simple/float), got 0')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('should throw error for MT 2 (byte string)', () => {
|
|
19
|
+
const { parseSimple } = useCborFloat()
|
|
20
|
+
expect(() => parseSimple('40')).toThrow('Expected major type 7 (simple/float), got 2')
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('parseFloat - Wrong Major Type', () => {
|
|
25
|
+
it('should throw error when major type is not 7', () => {
|
|
26
|
+
const { parseFloat } = useCborFloat()
|
|
27
|
+
|
|
28
|
+
// MT 0 (integer) should not be parsed as float
|
|
29
|
+
expect(() => parseFloat('00')).toThrow('Expected major type 7 (simple/float), got 0')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('should throw error for MT 3 (text string)', () => {
|
|
33
|
+
const { parseFloat } = useCborFloat()
|
|
34
|
+
expect(() => parseFloat('60')).toThrow('Expected major type 7 (simple/float), got 3')
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
describe('Simple Value - Unexpected End of Buffer', () => {
|
|
39
|
+
it('should throw error when 1-byte simple value has no data', () => {
|
|
40
|
+
const { parseSimple } = useCborFloat()
|
|
41
|
+
|
|
42
|
+
// MT 7, AI 24 (1-byte simple value) but no following byte
|
|
43
|
+
expect(() => parseSimple('f8')).toThrow('Unexpected end of buffer while reading simple value')
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe('Simple Value - Invalid 1-byte Encoding', () => {
|
|
48
|
+
it('should throw error for 1-byte encoding of value < 32', () => {
|
|
49
|
+
const { parseSimple } = useCborFloat()
|
|
50
|
+
|
|
51
|
+
// AI 24 should not be used for values 0-31
|
|
52
|
+
// MT 7, AI 24, value 10 (0x0a) - invalid encoding
|
|
53
|
+
expect(() => parseSimple('f80a')).toThrow('Invalid 1-byte encoding for simple value 10')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('should throw error for 1-byte encoding of value 20', () => {
|
|
57
|
+
const { parseSimple } = useCborFloat()
|
|
58
|
+
|
|
59
|
+
// Value 20 (false) should use direct encoding (f4), not 1-byte
|
|
60
|
+
expect(() => parseSimple('f814')).toThrow('Invalid 1-byte encoding for simple value 20')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should allow 1-byte encoding for value >= 32', () => {
|
|
64
|
+
const { parseSimple } = useCborFloat()
|
|
65
|
+
|
|
66
|
+
// Valid: 1-byte encoding for value 32 or higher
|
|
67
|
+
const result = parseSimple('f820') // Simple value 32
|
|
68
|
+
expect(result.value).toEqual({ simpleValue: 32 })
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
describe('Simple Value - Float Type Error', () => {
|
|
73
|
+
it('should throw error when parseSimple is called on Float16', () => {
|
|
74
|
+
const { parseSimple } = useCborFloat()
|
|
75
|
+
|
|
76
|
+
// MT 7, AI 25 (Float16) should use parseFloat, not parseSimple
|
|
77
|
+
expect(() => parseSimple('f90000')).toThrow('Additional info 25 is a float, use parseFloat instead')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('should throw error when parseSimple is called on Float32', () => {
|
|
81
|
+
const { parseSimple } = useCborFloat()
|
|
82
|
+
|
|
83
|
+
// MT 7, AI 26 (Float32)
|
|
84
|
+
expect(() => parseSimple('fa00000000')).toThrow('Additional info 26 is a float, use parseFloat instead')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('should throw error when parseSimple is called on Float64', () => {
|
|
88
|
+
const { parseSimple } = useCborFloat()
|
|
89
|
+
|
|
90
|
+
// MT 7, AI 27 (Float64)
|
|
91
|
+
expect(() => parseSimple('fb0000000000000000')).toThrow('Additional info 27 is a float, use parseFloat instead')
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
describe('Simple Value - Reserved Additional Info', () => {
|
|
96
|
+
it('should throw error for reserved AI 28', () => {
|
|
97
|
+
const { parseSimple } = useCborFloat()
|
|
98
|
+
|
|
99
|
+
// MT 7, AI 28 - reserved
|
|
100
|
+
expect(() => parseSimple('fc')).toThrow('Reserved additional info value: 28')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('should throw error for reserved AI 29', () => {
|
|
104
|
+
const { parseSimple } = useCborFloat()
|
|
105
|
+
|
|
106
|
+
// MT 7, AI 29 - reserved
|
|
107
|
+
expect(() => parseSimple('fd')).toThrow('Reserved additional info value: 29')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('should throw error for reserved AI 30', () => {
|
|
111
|
+
const { parseSimple } = useCborFloat()
|
|
112
|
+
|
|
113
|
+
// MT 7, AI 30 - reserved
|
|
114
|
+
expect(() => parseSimple('fe')).toThrow('Reserved additional info value: 30')
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
describe('Simple Value - Break Marker Error', () => {
|
|
119
|
+
it('should throw error for break marker (0xff) outside indefinite context', () => {
|
|
120
|
+
const { parseSimple } = useCborFloat()
|
|
121
|
+
|
|
122
|
+
// MT 7, AI 31 (break marker) - only valid in indefinite-length items
|
|
123
|
+
expect(() => parseSimple('ff')).toThrow('Break marker (0xff) should only appear in indefinite-length items')
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
describe('parseFloat - Invalid Additional Info', () => {
|
|
128
|
+
it('should throw error when parseFloat is called on simple value', () => {
|
|
129
|
+
const { parseFloat } = useCborFloat()
|
|
130
|
+
|
|
131
|
+
// MT 7, AI 20 (false) is not a float
|
|
132
|
+
expect(() => parseFloat('f4')).toThrow('Additional info 20 is not a float type')
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('should throw error for AI 24 (1-byte simple)', () => {
|
|
136
|
+
const { parseFloat } = useCborFloat()
|
|
137
|
+
|
|
138
|
+
// AI 24 is for simple values, not floats
|
|
139
|
+
expect(() => parseFloat('f8ff')).toThrow('Additional info 24 is not a float type')
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
describe('Float - Unexpected End of Buffer', () => {
|
|
144
|
+
it('should throw error when Float16 has insufficient data (0 bytes)', () => {
|
|
145
|
+
const { parseFloat } = useCborFloat()
|
|
146
|
+
|
|
147
|
+
// MT 7, AI 25 (Float16) needs 2 bytes, but has none
|
|
148
|
+
expect(() => parseFloat('f9')).toThrow('Unexpected end of buffer while reading Float16')
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('should throw error when Float16 has insufficient data (1 byte)', () => {
|
|
152
|
+
const { parseFloat } = useCborFloat()
|
|
153
|
+
|
|
154
|
+
// MT 7, AI 25 (Float16) needs 2 bytes, but has only 1
|
|
155
|
+
expect(() => parseFloat('f900')).toThrow('Unexpected end of buffer while reading Float16')
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('should throw error when Float32 has insufficient data', () => {
|
|
159
|
+
const { parseFloat } = useCborFloat()
|
|
160
|
+
|
|
161
|
+
// MT 7, AI 26 (Float32) needs 4 bytes, but has only 3
|
|
162
|
+
expect(() => parseFloat('fa000000')).toThrow('Unexpected end of buffer while reading Float32')
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('should throw error when Float64 has insufficient data', () => {
|
|
166
|
+
const { parseFloat } = useCborFloat()
|
|
167
|
+
|
|
168
|
+
// MT 7, AI 27 (Float64) needs 8 bytes, but has only 7
|
|
169
|
+
expect(() => parseFloat('fb00000000000000')).toThrow('Unexpected end of buffer while reading Float64')
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
describe('Simple Value - All Unassigned Values', () => {
|
|
174
|
+
it('should parse unassigned simple values 0-19', () => {
|
|
175
|
+
const { parseSimple } = useCborFloat()
|
|
176
|
+
|
|
177
|
+
// Test some unassigned values
|
|
178
|
+
expect(parseSimple('f0').value).toEqual({ simpleValue: 16 }) // AI 16
|
|
179
|
+
expect(parseSimple('f1').value).toEqual({ simpleValue: 17 }) // AI 17
|
|
180
|
+
expect(parseSimple('f2').value).toEqual({ simpleValue: 18 }) // AI 18
|
|
181
|
+
expect(parseSimple('f3').value).toEqual({ simpleValue: 19 }) // AI 19
|
|
182
|
+
|
|
183
|
+
// 0-15 are also unassigned
|
|
184
|
+
expect(parseSimple('e0').value).toEqual({ simpleValue: 0 }) // AI 0
|
|
185
|
+
expect(parseSimple('e1').value).toEqual({ simpleValue: 1 }) // AI 1
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
describe('parse() auto-detection', () => {
|
|
190
|
+
it('should auto-detect and parse simple values', () => {
|
|
191
|
+
const { parse } = useCborFloat()
|
|
192
|
+
|
|
193
|
+
expect(parse('f4').value).toBe(false)
|
|
194
|
+
expect(parse('f5').value).toBe(true)
|
|
195
|
+
expect(parse('f6').value).toBe(null)
|
|
196
|
+
expect(parse('f7').value).toBe(undefined)
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
it('should auto-detect and parse floats', () => {
|
|
200
|
+
const { parse } = useCborFloat()
|
|
201
|
+
|
|
202
|
+
expect(parse('f90000').value).toBe(0.0)
|
|
203
|
+
expect(parse('fa47c35000').value).toBe(100000.0)
|
|
204
|
+
expect(parse('fb3ff0000000000000').value).toBe(1.0)
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
it('should handle unassigned simple values via auto-detect', () => {
|
|
208
|
+
const { parse } = useCborFloat()
|
|
209
|
+
|
|
210
|
+
expect(parse('f0').value).toEqual({ simpleValue: 16 })
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
describe('Wrong Major Type in parse()', () => {
|
|
215
|
+
it('should throw error when auto-detecting with wrong major type', () => {
|
|
216
|
+
const { parse } = useCborFloat()
|
|
217
|
+
|
|
218
|
+
// MT 4 (array) is not MT 7
|
|
219
|
+
expect(() => parse('80')).toThrow('Expected major type 7 (simple/float), got 4')
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
})
|