aboutsummaryrefslogtreecommitdiff
path: root/lib/std/json.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-07-04 01:31:29 +0000
committerAndrew Kelley <andrew@ziglang.org>2020-07-05 21:11:42 +0000
commit632acffcbd96a085ea92899e6f37465e40178f44 (patch)
tree77b4af87060b43172eefb66943564faed365ec84 /lib/std/json.zig
parentb3b6ccba50ef7a683ad05546cba2b71e7d10489f (diff)
downloadzig-632acffcbd96a085ea92899e6f37465e40178f44.tar.gz
zig-632acffcbd96a085ea92899e6f37465e40178f44.zip
update std lib to new hash map API
Diffstat (limited to 'lib/std/json.zig')
-rw-r--r--lib/std/json.zig56
1 files changed, 28 insertions, 28 deletions
diff --git a/lib/std/json.zig b/lib/std/json.zig
index 6377b69a80..a8b19756da 100644
--- a/lib/std/json.zig
+++ b/lib/std/json.zig
@@ -2149,27 +2149,27 @@ test "json.parser.dynamic" {
var root = tree.root;
- var image = root.Object.get("Image").?.value;
+ var image = root.Object.get("Image").?;
- const width = image.Object.get("Width").?.value;
+ const width = image.Object.get("Width").?;
testing.expect(width.Integer == 800);
- const height = image.Object.get("Height").?.value;
+ const height = image.Object.get("Height").?;
testing.expect(height.Integer == 600);
- const title = image.Object.get("Title").?.value;
+ const title = image.Object.get("Title").?;
testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
- const animated = image.Object.get("Animated").?.value;
+ const animated = image.Object.get("Animated").?;
testing.expect(animated.Bool == false);
- const array_of_object = image.Object.get("ArrayOfObject").?.value;
+ const array_of_object = image.Object.get("ArrayOfObject").?;
testing.expect(array_of_object.Array.items.len == 1);
- const obj0 = array_of_object.Array.items[0].Object.get("n").?.value;
+ const obj0 = array_of_object.Array.items[0].Object.get("n").?;
testing.expect(mem.eql(u8, obj0.String, "m"));
- const double = image.Object.get("double").?.value;
+ const double = image.Object.get("double").?;
testing.expect(double.Float == 1.3412);
}
@@ -2217,12 +2217,12 @@ test "write json then parse it" {
var tree = try parser.parse(fixed_buffer_stream.getWritten());
defer tree.deinit();
- testing.expect(tree.root.Object.get("f").?.value.Bool == false);
- testing.expect(tree.root.Object.get("t").?.value.Bool == true);
- testing.expect(tree.root.Object.get("int").?.value.Integer == 1234);
- testing.expect(tree.root.Object.get("array").?.value.Array.items[0].Null == {});
- testing.expect(tree.root.Object.get("array").?.value.Array.items[1].Float == 12.34);
- testing.expect(mem.eql(u8, tree.root.Object.get("str").?.value.String, "hello"));
+ testing.expect(tree.root.Object.get("f").?.Bool == false);
+ testing.expect(tree.root.Object.get("t").?.Bool == true);
+ testing.expect(tree.root.Object.get("int").?.Integer == 1234);
+ testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});
+ testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);
+ testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
}
fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value {
@@ -2245,7 +2245,7 @@ test "integer after float has proper type" {
\\ "ints": [1, 2, 3]
\\}
);
- std.testing.expect(json.Object.getValue("ints").?.Array.items[0] == .Integer);
+ std.testing.expect(json.Object.get("ints").?.Array.items[0] == .Integer);
}
test "escaped characters" {
@@ -2271,16 +2271,16 @@ test "escaped characters" {
const obj = (try test_parse(&arena_allocator.allocator, input)).Object;
- testing.expectEqualSlices(u8, obj.get("backslash").?.value.String, "\\");
- testing.expectEqualSlices(u8, obj.get("forwardslash").?.value.String, "/");
- testing.expectEqualSlices(u8, obj.get("newline").?.value.String, "\n");
- testing.expectEqualSlices(u8, obj.get("carriagereturn").?.value.String, "\r");
- testing.expectEqualSlices(u8, obj.get("tab").?.value.String, "\t");
- testing.expectEqualSlices(u8, obj.get("formfeed").?.value.String, "\x0C");
- testing.expectEqualSlices(u8, obj.get("backspace").?.value.String, "\x08");
- testing.expectEqualSlices(u8, obj.get("doublequote").?.value.String, "\"");
- testing.expectEqualSlices(u8, obj.get("unicode").?.value.String, "ą");
- testing.expectEqualSlices(u8, obj.get("surrogatepair").?.value.String, "😂");
+ testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
+ testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
+ testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
+ testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
+ testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
+ testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
+ testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
+ testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
+ testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");
+ testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");
}
test "string copy option" {
@@ -2306,11 +2306,11 @@ test "string copy option" {
const obj_copy = tree_copy.root.Object;
for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| {
- testing.expectEqualSlices(u8, obj_nocopy.getValue(field_name).?.String, obj_copy.getValue(field_name).?.String);
+ testing.expectEqualSlices(u8, obj_nocopy.get(field_name).?.String, obj_copy.get(field_name).?.String);
}
- const nocopy_addr = &obj_nocopy.getValue("noescape").?.String[0];
- const copy_addr = &obj_copy.getValue("noescape").?.String[0];
+ const nocopy_addr = &obj_nocopy.get("noescape").?.String[0];
+ const copy_addr = &obj_copy.get("noescape").?.String[0];
var found_nocopy = false;
for (input) |_, index| {