From d1f35f97254565ad4448d0e62eab56f9e69fb1e4 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 12 Mar 2026 21:13:18 +0100 Subject: [PATCH] refactor: add tests for short reads in structs and unions --- test/tests.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/tests.zig b/test/tests.zig index e455e0a..6015882 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -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;