authorgravatar for wink@saville.comWink Saville <wink@saville.com> 2018-11-18 10:14:37-08:00
committergravatar for wink@saville.comWink Saville <wink@saville.com> 2018-11-18 10:14:37-08:00
log8d54cbb834ab606ecfe23c6514cbac699319f60c
tree1b60a2ecdb86c497b3ab4cfe589d29f66a6e1985
parente9b47d960b81dfc1fd70c5ae663b4b692ab0b19d
signaturelock-open Commit is signed but in an unrecognized format.

Fix pushToParent to work for arrays of Objects

The reference `*array` is a copy of the value on the stack. Instead use a reference to top of stack. This is the same technique used above for `var object` in `Value.String`. Added two simple tests.

1 files changed, 10 insertions(+), 2 deletions(-)

std/json.zig+10-2
......@@ -1323,7 +1323,8 @@ pub const Parser = struct {
13231323 p.state = State.ObjectKey;
13241324 },
13251325 // Array Parent -> [ ..., <array>, value ]
1326 Value.Array => |*array| {
1326 Value.Array => {
1327 var array = &p.stack.items[p.stack.len - 1].Array;
13271328 try array.append(value);
13281329 p.state = State.ArrayValue;
13291330 },
......@@ -1364,7 +1365,8 @@ test "json parser dynamic" {
13641365 \\ "Width": 100
13651366 \\ },
13661367 \\ "Animated" : false,
1367 \\ "IDs": [116, 943, 234, 38793]
1368 \\ "IDs": [116, 943, 234, 38793],
1369 \\ "ArrayOfObject": [{"n": "m"}]
13681370 \\ }
13691371 \\}
13701372 ;
......@@ -1387,4 +1389,10 @@ test "json parser dynamic" {
13871389
13881390 const animated = image.Object.get("Animated").?.value;
13891391 debug.assert(animated.Bool == false);
1392
1393 const array_of_object = image.Object.get("ArrayOfObject").?.value;
1394 debug.assert(array_of_object.Array.len == 1);
1395
1396 const obj0 = array_of_object.Array.at(0).Object.get("n").?.value;
1397 debug.assert(mem.eql(u8, obj0.String, "m"));
13901398}