authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-01-07 19:03:11+01:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-01-07 19:03:11+01:00
log814b54d7980c2b71b99539ceb23fc09b21d347c0
tree18e6e050a6af5375bf924037ec676cfc93c9447d
parent6bebf741f92481ae3dbc9aeb8659c2476e4d211b

json tests: don't use debug allocator


1 files changed, 19 insertions(+), 8 deletions(-)

lib/std/json.zig+19-8
......@@ -1457,7 +1457,10 @@ fn unescapeString(output: []u8, input: []const u8) !void {
14571457}
14581458
14591459test "json.parser.dynamic" {
1460 var p = Parser.init(debug.global_allocator, false);
1460 var memory: [1024 * 16]u8 = undefined;
1461 var buf_alloc = std.heap.FixedBufferAllocator.init(&memory);
1462
1463 var p = Parser.init(&buf_alloc.allocator, false);
14611464 defer p.deinit();
14621465
14631466 const s =
......@@ -1560,17 +1563,21 @@ test "write json then parse it" {
15601563 testing.expect(mem.eql(u8, tree.root.Object.get("str").?.value.String, "hello"));
15611564}
15621565
1563fn test_parse(json_str: []const u8) !Value {
1564 var p = Parser.init(debug.global_allocator, false);
1566fn test_parse(memory: []u8, json_str: []const u8) !Value {
1567 // buf_alloc goes out of scope, but we don't use it after parsing
1568 var buf_alloc = std.heap.FixedBufferAllocator.init(memory);
1569 var p = Parser.init(&buf_alloc.allocator, false);
15651570 return (try p.parse(json_str)).root;
15661571}
15671572
15681573test "parsing empty string gives appropriate error" {
1569 testing.expectError(error.UnexpectedEndOfJson, test_parse(""));
1574 var memory: [1024 * 4]u8 = undefined;
1575 testing.expectError(error.UnexpectedEndOfJson, test_parse(&memory, ""));
15701576}
15711577
15721578test "integer after float has proper type" {
1573 const json = try test_parse(
1579 var memory: [1024 * 8]u8 = undefined;
1580 const json = try test_parse(&memory,
15741581 \\{
15751582 \\ "float": 3.14,
15761583 \\ "ints": [1, 2, 3]
......@@ -1580,6 +1587,7 @@ test "integer after float has proper type" {
15801587}
15811588
15821589test "escaped characters" {
1590 var memory: [1024 * 16]u8 = undefined;
15831591 const input =
15841592 \\{
15851593 \\ "backslash": "\\",
......@@ -1595,7 +1603,7 @@ test "escaped characters" {
15951603 \\}
15961604 ;
15971605
1598 const obj = (try test_parse(input)).Object;
1606 const obj = (try test_parse(&memory, input)).Object;
15991607
16001608 testing.expectEqualSlices(u8, obj.get("backslash").?.value.String, "\\");
16011609 testing.expectEqualSlices(u8, obj.get("forwardslash").?.value.String, "/");
......@@ -1619,10 +1627,13 @@ test "string copy option" {
16191627 \\}
16201628 ;
16211629
1622 const tree_nocopy = try Parser.init(debug.global_allocator, false).parse(input);
1630 var mem_buffer: [1024 * 16]u8 = undefined;
1631 var buf_alloc = std.heap.FixedBufferAllocator.init(&mem_buffer);
1632
1633 const tree_nocopy = try Parser.init(&buf_alloc.allocator, false).parse(input);
16231634 const obj_nocopy = tree_nocopy.root.Object;
16241635
1625 const tree_copy = try Parser.init(debug.global_allocator, true).parse(input);
1636 const tree_copy = try Parser.init(&buf_alloc.allocator, true).parse(input);
16261637 const obj_copy = tree_copy.root.Object;
16271638
16281639 for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| {