aboutsummaryrefslogtreecommitdiff
path: root/std/json.zig
diff options
context:
space:
mode:
authorBenoitJGirard <BenoitJGirard@users.noreply.github.com>2019-02-17 14:38:55 -0500
committerGitHub <noreply@github.com>2019-02-17 14:38:55 -0500
commit6daa041932ae5ab03eed953dacf3ca506078390c (patch)
tree0f51f6c2ff84dde51b61bba6799e5c5abccf91b4 /std/json.zig
parentf0ec308e26ff957c7fbb50ccc69d3d549c42c4da (diff)
parent8d2a902945ef97f28152c3d5a68bb974809c8539 (diff)
downloadzig-6daa041932ae5ab03eed953dacf3ca506078390c.tar.gz
zig-6daa041932ae5ab03eed953dacf3ca506078390c.zip
Merge pull request #2 from ziglang/master
Refreshing fork.
Diffstat (limited to 'std/json.zig')
-rw-r--r--std/json.zig25
1 files changed, 15 insertions, 10 deletions
diff --git a/std/json.zig b/std/json.zig
index 4d07d7b89d..dd053e7635 100644
--- a/std/json.zig
+++ b/std/json.zig
@@ -4,6 +4,7 @@
const std = @import("index.zig");
const debug = std.debug;
+const testing = std.testing;
const mem = std.mem;
const maxInt = std.math.maxInt;
@@ -960,7 +961,7 @@ test "json.token" {
checkNext(&p, Token.Id.ObjectEnd);
checkNext(&p, Token.Id.ObjectEnd);
- debug.assert((try p.next()) == null);
+ testing.expect((try p.next()) == null);
}
// Validate a JSON string. This does not limit number precision so a decoder may not necessarily
@@ -981,7 +982,7 @@ pub fn validate(s: []const u8) bool {
}
test "json.validate" {
- debug.assert(validate("{}"));
+ testing.expect(validate("{}"));
}
const Allocator = std.mem.Allocator;
@@ -1344,7 +1345,7 @@ pub const Parser = struct {
return if (token.number_is_integer)
Value{ .Integer = try std.fmt.parseInt(i64, token.slice(input, i), 10) }
else
- @panic("TODO: fmt.parseFloat not yet implemented");
+ Value{ .Float = try std.fmt.parseFloat(f64, token.slice(input, i)) };
}
};
@@ -1365,7 +1366,8 @@ test "json.parser.dynamic" {
\\ },
\\ "Animated" : false,
\\ "IDs": [116, 943, 234, 38793],
- \\ "ArrayOfObject": [{"n": "m"}]
+ \\ "ArrayOfObject": [{"n": "m"}],
+ \\ "double": 1.3412
\\ }
\\}
;
@@ -1378,20 +1380,23 @@ test "json.parser.dynamic" {
var image = root.Object.get("Image").?.value;
const width = image.Object.get("Width").?.value;
- debug.assert(width.Integer == 800);
+ testing.expect(width.Integer == 800);
const height = image.Object.get("Height").?.value;
- debug.assert(height.Integer == 600);
+ testing.expect(height.Integer == 600);
const title = image.Object.get("Title").?.value;
- debug.assert(mem.eql(u8, title.String, "View from 15th Floor"));
+ testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
const animated = image.Object.get("Animated").?.value;
- debug.assert(animated.Bool == false);
+ testing.expect(animated.Bool == false);
const array_of_object = image.Object.get("ArrayOfObject").?.value;
- debug.assert(array_of_object.Array.len == 1);
+ testing.expect(array_of_object.Array.len == 1);
const obj0 = array_of_object.Array.at(0).Object.get("n").?.value;
- debug.assert(mem.eql(u8, obj0.String, "m"));
+ testing.expect(mem.eql(u8, obj0.String, "m"));
+
+ const double = image.Object.get("double").?.value;
+ testing.expect(double.Float == 1.3412);
}