authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-12-05 11:10:44+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-08 19:16:17-05:00
log21550bb7cd5596e24a623f5ae1374502e879b553
tree9620fcd1953415df0f01eb214216ead02f07f386
parent8ac711596d3fd698bf3ee84ec2514c8c84103680

std.json: unreachable -> expect in tests


1 files changed, 21 insertions(+), 34 deletions(-)

lib/std/json/test.zig+21-34
......@@ -9,60 +9,47 @@
99// Read also http://seriot.ch/parsing_json.php for a good overview.
1010
1111const std = @import("../std.zig");
12const json = std.json;
13const testing = std.testing;
1214
13fn ok(comptime s: []const u8) void {
14 std.testing.expect(std.json.validate(s));
15
16 var p = std.json.Parser.init(std.testing.allocator, false);
15fn testNonStreaming(comptime s: []const u8) !void {
16 var p = json.Parser.init(testing.allocator, false);
1717 defer p.deinit();
1818
19 var tree = p.parse(s) catch unreachable;
19 var tree = try p.parse(s);
2020 defer tree.deinit();
2121}
2222
23fn err(comptime s: []const u8) void {
24 std.testing.expect(!std.json.validate(s));
23fn ok(comptime s: []const u8) void {
24 testing.expect(json.validate(s));
2525
26 var p = std.json.Parser.init(std.testing.allocator, false);
27 defer p.deinit();
26 testNonStreaming(s) catch testing.expect(false);
27}
28
29fn err(comptime s: []const u8) void {
30 testing.expect(!json.validate(s));
2831
29 if (p.parse(s)) |_| {
30 unreachable;
31 } else |_| {}
32 testNonStreaming(s) catch return;
33 testing.expect(false);
3234}
3335
3436fn utf8Error(comptime s: []const u8) void {
35 std.testing.expect(!std.json.validate(s));
37 testing.expect(!json.validate(s));
3638
37 var p = std.json.Parser.init(std.testing.allocator, false);
38 defer p.deinit();
39
40 if (p.parse(s)) |_| {
41 unreachable;
42 } else |e| {
43 std.testing.expect(e == error.InvalidUtf8Byte);
44 }
39 testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
4540}
4641
4742fn any(comptime s: []const u8) void {
48 _ = std.json.validate(s);
49
50 var p = std.json.Parser.init(std.testing.allocator, false);
51 defer p.deinit();
43 _ = json.validate(s);
5244
53 var tree = p.parse(s) catch return;
54 defer tree.deinit();
45 testNonStreaming(s) catch {};
5546}
5647
5748fn anyStreamingErrNonStreaming(comptime s: []const u8) void {
58 _ = std.json.validate(s);
59
60 var p = std.json.Parser.init(std.testing.allocator, false);
61 defer p.deinit();
49 _ = json.validate(s);
6250
63 if (p.parse(s)) |_| {
64 unreachable;
65 } else |_| {}
51 testNonStreaming(s) catch return;
52 testing.expect(false);
6653}
6754
6855////////////////////////////////////////////////////////////////////////////////////////////////////