mirror of
https://github.com/ziglang/zig.git
synced 2024-10-22 21:09:26 +00:00
add jsonParseFromValue
to std.json.Value
(#16324)
This commit is contained in:
parent
b9fc0d2908
commit
89396ff02b
|
@ -147,6 +147,12 @@ pub const Value = union(enum) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn jsonParseFromValue(allocator: Allocator, source: Value, options: ParseOptions) !@This() {
|
||||
_ = allocator;
|
||||
_ = options;
|
||||
return source;
|
||||
}
|
||||
};
|
||||
|
||||
fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, value_: Value) !?Value {
|
||||
|
|
|
@ -245,6 +245,23 @@ test "Value.jsonStringify" {
|
|||
}
|
||||
}
|
||||
|
||||
test "parseFromValue(std.json.Value,...)" {
|
||||
const str =
|
||||
\\{
|
||||
\\ "int": 32,
|
||||
\\ "float": 3.2,
|
||||
\\ "str": "str",
|
||||
\\ "array": [3, 2],
|
||||
\\ "object": {}
|
||||
\\}
|
||||
;
|
||||
|
||||
const parsed_tree = try parseFromSlice(Value, testing.allocator, str, .{});
|
||||
defer parsed_tree.deinit();
|
||||
const tree = try parseFromValueLeaky(Value, parsed_tree.arena.allocator(), parsed_tree.value, .{});
|
||||
try testing.expect(std.meta.eql(parsed_tree.value, tree));
|
||||
}
|
||||
|
||||
test "polymorphic parsing" {
|
||||
if (true) return error.SkipZigTest; // See https://github.com/ziglang/zig/issues/16108
|
||||
const doc =
|
||||
|
|
Loading…
Reference in New Issue
Block a user