refactor: add a test for extractAlloc of json.Value from arrays

This commit is contained in:
CJ van den Berg 2026-03-12 20:30:07 +01:00
parent be1e1f551e
commit 2a23d8f54b
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -776,6 +776,20 @@ test "cbor.extractAlloc optional null" {
try expectEqual(@as(?u32, null), val); try expectEqual(@as(?u32, null), val);
} }
test "cbor.extractAlloc json.Value array" {
var buf: [128]u8 = undefined;
var writer: Io.Writer = .fixed(&buf);
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
const allocator = arena.allocator();
defer arena.deinit();
try writeValue(&writer, .{ @as(i64, 1), "hello", true });
var val = std.json.Value{ .null = {} };
try expect(try match(writer.buffered(), extractAlloc(&val, allocator)));
try expectEqual(@as(i64, 1), val.array.items[0].integer);
try expectEqualStrings("hello", val.array.items[1].string);
try expectEqual(true, val.array.items[2].bool);
}
fn test_value_write_and_extract(T: type, value: T) !void { fn test_value_write_and_extract(T: type, value: T) !void {
const test_value: T = value; const test_value: T = value;
var buf: [1024]u8 = undefined; var buf: [1024]u8 = undefined;