refactor: add tests for short reads in structs and unions

This commit is contained in:
CJ van den Berg 2026-03-12 21:13:18 +01:00
parent 45277e05a0
commit d1f35f9725
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -160,6 +160,19 @@ test "cbor.matchI64 error.TooShort" {
try expectError(error.TooShort, result);
}
test "cbor.extract struct error.TooShort" {
const buf = [_]u8{0xb9}; // map(2-byte length), length bytes missing
var val: struct { x: i64 } = undefined;
try expectError(error.TooShort, match(&buf, extract(&val)));
}
test "cbor.extract union error.TooShort" {
const TestUnion = union(enum) { a: i64 };
const buf = [_]u8{0x99}; // array(2-byte length), length bytes missing
var val: TestUnion = undefined;
try expectError(error.TooShort, match(&buf, extract(&val)));
}
test "cbor.matchI64Value" {
var buf = [_]u8{ 7, 0xDF };
var iter: []const u8 = &buf;