refactor: add test case for extracAlloc of a json.Value from an object
This commit is contained in:
parent
36bf0aea8f
commit
88bdaa8370
1 changed files with 13 additions and 0 deletions
|
|
@ -790,6 +790,19 @@ test "cbor.extractAlloc json.Value array" {
|
||||||
try expectEqual(true, val.array.items[2].bool);
|
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 {
|
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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue