From 88bdaa837019fe54f8620bb8e895124a4eff13f2 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 12 Mar 2026 20:33:47 +0100 Subject: [PATCH] refactor: add test case for extracAlloc of a json.Value from an object --- test/tests.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/tests.zig b/test/tests.zig index 58cca24..6fad831 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -790,6 +790,19 @@ test "cbor.extractAlloc json.Value array" { try expectEqual(true, val.array.items[2].bool); } +test "cbor.extractAlloc json.Value object" { + 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, .{ .x = @as(i64, 42), .name = "hello" }); + var val = std.json.Value{ .null = {} }; + try expect(try match(writer.buffered(), extractAlloc(&val, allocator))); + try expectEqual(@as(i64, 42), val.object.get("x").?.integer); + try expectEqualStrings("hello", val.object.get("name").?.string); +} + fn test_value_write_and_extract(T: type, value: T) !void { const test_value: T = value; var buf: [1024]u8 = undefined;