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 @@...@@ -9,60 +9,47 @@
9// Read also http://seriot.ch/parsing_json.php for a good overview.9// Read also http://seriot.ch/parsing_json.php for a good overview.
1010
11const std = @import("../std.zig");11const std = @import("../std.zig");
12const json = std.json;
13const testing = std.testing;
1214
13fn ok(comptime s: []const u8) void {15fn testNonStreaming(comptime s: []const u8) !void {
14 std.testing.expect(std.json.validate(s));16 var p = json.Parser.init(testing.allocator, false);
15
16 var p = std.json.Parser.init(std.testing.allocator, false);
17 defer p.deinit();17 defer p.deinit();
1818
19 var tree = p.parse(s) catch unreachable;19 var tree = try p.parse(s);
20 defer tree.deinit();20 defer tree.deinit();
21}21}
2222
23fn err(comptime s: []const u8) void {23fn ok(comptime s: []const u8) void {
24 std.testing.expect(!std.json.validate(s));24 testing.expect(json.validate(s));
2525
26 var p = std.json.Parser.init(std.testing.allocator, false);26 testNonStreaming(s) catch testing.expect(false);
27 defer p.deinit();27}
28
29fn err(comptime s: []const u8) void {
30 testing.expect(!json.validate(s));
2831
29 if (p.parse(s)) |_| {32 testNonStreaming(s) catch return;
30 unreachable;33 testing.expect(false);
31 } else |_| {}
32}34}
3335
34fn utf8Error(comptime s: []const u8) void {36fn 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);39 testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
38 defer p.deinit();
39
40 if (p.parse(s)) |_| {
41 unreachable;
42 } else |e| {
43 std.testing.expect(e == error.InvalidUtf8Byte);
44 }
45}40}
4641
47fn any(comptime s: []const u8) void {42fn any(comptime s: []const u8) void {
48 _ = std.json.validate(s);43 _ = json.validate(s);
49
50 var p = std.json.Parser.init(std.testing.allocator, false);
51 defer p.deinit();
5244
53 var tree = p.parse(s) catch return;45 testNonStreaming(s) catch {};
54 defer tree.deinit();
55}46}
5647
57fn anyStreamingErrNonStreaming(comptime s: []const u8) void {48fn anyStreamingErrNonStreaming(comptime s: []const u8) void {
58 _ = std.json.validate(s);49 _ = json.validate(s);
59
60 var p = std.json.Parser.init(std.testing.allocator, false);
61 defer p.deinit();
6250
63 if (p.parse(s)) |_| {51 testNonStreaming(s) catch return;
64 unreachable;52 testing.expect(false);
65 } else |_| {}
66}53}
6754
68////////////////////////////////////////////////////////////////////////////////////////////////////55////////////////////////////////////////////////////////////////////////////////////////////////////