@@ -1598,21 +1598,21 @@ test "write json then parse it" {
1598
1598
testing .expect (mem .eql (u8 , tree .root .Object .get ("str" ).? .value .String , "hello" ));
1599
1599
}
1600
1600
1601
- fn test_parse (memory : []u8 , json_str : []const u8 ) ! Value {
1602
- // buf_alloc goes out of scope, but we don't use it after parsing
1603
- var buf_alloc = std .heap .FixedBufferAllocator .init (memory );
1604
- var p = Parser .init (& buf_alloc .allocator , false );
1601
+ fn test_parse (arena_allocator : * std.mem.Allocator , json_str : []const u8 ) ! Value {
1602
+ var p = Parser .init (arena_allocator , false );
1605
1603
return (try p .parse (json_str )).root ;
1606
1604
}
1607
1605
1608
1606
test "parsing empty string gives appropriate error" {
1609
- var memory : [1024 * 4 ]u8 = undefined ;
1610
- testing .expectError (error .UnexpectedEndOfJson , test_parse (& memory , "" ));
1607
+ var arena_allocator = std .heap .ArenaAllocator .init (std .testing .allocator );
1608
+ defer arena_allocator .deinit ();
1609
+ testing .expectError (error .UnexpectedEndOfJson , test_parse (& arena_allocator .allocator , "" ));
1611
1610
}
1612
1611
1613
1612
test "integer after float has proper type" {
1614
- var memory : [1024 * 8 ]u8 = undefined ;
1615
- const json = try test_parse (& memory ,
1613
+ var arena_allocator = std .heap .ArenaAllocator .init (std .testing .allocator );
1614
+ defer arena_allocator .deinit ();
1615
+ const json = try test_parse (& arena_allocator .allocator ,
1616
1616
\\{
1617
1617
\\ "float": 3.14,
1618
1618
\\ "ints": [1, 2, 3]
@@ -1622,7 +1622,8 @@ test "integer after float has proper type" {
1622
1622
}
1623
1623
1624
1624
test "escaped characters" {
1625
- var memory : [1024 * 16 ]u8 = undefined ;
1625
+ var arena_allocator = std .heap .ArenaAllocator .init (std .testing .allocator );
1626
+ defer arena_allocator .deinit ();
1626
1627
const input =
1627
1628
\\{
1628
1629
\\ "backslash": "\\",
@@ -1638,7 +1639,7 @@ test "escaped characters" {
1638
1639
\\}
1639
1640
;
1640
1641
1641
- const obj = (try test_parse (& memory , input )).Object ;
1642
+ const obj = (try test_parse (& arena_allocator . allocator , input )).Object ;
1642
1643
1643
1644
testing .expectEqualSlices (u8 , obj .get ("backslash" ).? .value .String , "\\ " );
1644
1645
testing .expectEqualSlices (u8 , obj .get ("forwardslash" ).? .value .String , "/" );
@@ -1662,13 +1663,13 @@ test "string copy option" {
1662
1663
\\}
1663
1664
;
1664
1665
1665
- var mem_buffer : [ 1024 * 16 ] u8 = undefined ;
1666
- var buf_alloc = std . heap . FixedBufferAllocator . init ( & mem_buffer );
1666
+ var arena_allocator = std . heap . ArenaAllocator . init ( std . testing . allocator ) ;
1667
+ defer arena_allocator . deinit ( );
1667
1668
1668
- const tree_nocopy = try Parser .init (& buf_alloc .allocator , false ).parse (input );
1669
+ const tree_nocopy = try Parser .init (& arena_allocator .allocator , false ).parse (input );
1669
1670
const obj_nocopy = tree_nocopy .root .Object ;
1670
1671
1671
- const tree_copy = try Parser .init (& buf_alloc .allocator , true ).parse (input );
1672
+ const tree_copy = try Parser .init (& arena_allocator .allocator , true ).parse (input );
1672
1673
const obj_copy = tree_copy .root .Object ;
1673
1674
1674
1675
for ([_ ][]const u8 { "noescape" , "simple" , "unicode" , "surrogatepair" }) | field_name | {
0 commit comments