refactor: add tests for short reads in structs and unions
This commit is contained in:
parent
45277e05a0
commit
d1f35f9725
1 changed files with 13 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue