mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
std.json: unreachable -> expect in tests
This commit is contained in:
parent
8ac711596d
commit
21550bb7cd
@ -9,60 +9,47 @@
|
||||
// Read also http://seriot.ch/parsing_json.php for a good overview.
|
||||
|
||||
const std = @import("../std.zig");
|
||||
const json = std.json;
|
||||
const testing = std.testing;
|
||||
|
||||
fn ok(comptime s: []const u8) void {
|
||||
std.testing.expect(std.json.validate(s));
|
||||
|
||||
var p = std.json.Parser.init(std.testing.allocator, false);
|
||||
fn testNonStreaming(comptime s: []const u8) !void {
|
||||
var p = json.Parser.init(testing.allocator, false);
|
||||
defer p.deinit();
|
||||
|
||||
var tree = p.parse(s) catch unreachable;
|
||||
var tree = try p.parse(s);
|
||||
defer tree.deinit();
|
||||
}
|
||||
|
||||
fn ok(comptime s: []const u8) void {
|
||||
testing.expect(json.validate(s));
|
||||
|
||||
testNonStreaming(s) catch testing.expect(false);
|
||||
}
|
||||
|
||||
fn err(comptime s: []const u8) void {
|
||||
std.testing.expect(!std.json.validate(s));
|
||||
testing.expect(!json.validate(s));
|
||||
|
||||
var p = std.json.Parser.init(std.testing.allocator, false);
|
||||
defer p.deinit();
|
||||
|
||||
if (p.parse(s)) |_| {
|
||||
unreachable;
|
||||
} else |_| {}
|
||||
testNonStreaming(s) catch return;
|
||||
testing.expect(false);
|
||||
}
|
||||
|
||||
fn utf8Error(comptime s: []const u8) void {
|
||||
std.testing.expect(!std.json.validate(s));
|
||||
testing.expect(!json.validate(s));
|
||||
|
||||
var p = std.json.Parser.init(std.testing.allocator, false);
|
||||
defer p.deinit();
|
||||
|
||||
if (p.parse(s)) |_| {
|
||||
unreachable;
|
||||
} else |e| {
|
||||
std.testing.expect(e == error.InvalidUtf8Byte);
|
||||
}
|
||||
testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
|
||||
}
|
||||
|
||||
fn any(comptime s: []const u8) void {
|
||||
_ = std.json.validate(s);
|
||||
_ = json.validate(s);
|
||||
|
||||
var p = std.json.Parser.init(std.testing.allocator, false);
|
||||
defer p.deinit();
|
||||
|
||||
var tree = p.parse(s) catch return;
|
||||
defer tree.deinit();
|
||||
testNonStreaming(s) catch {};
|
||||
}
|
||||
|
||||
fn anyStreamingErrNonStreaming(comptime s: []const u8) void {
|
||||
_ = std.json.validate(s);
|
||||
_ = json.validate(s);
|
||||
|
||||
var p = std.json.Parser.init(std.testing.allocator, false);
|
||||
defer p.deinit();
|
||||
|
||||
if (p.parse(s)) |_| {
|
||||
unreachable;
|
||||
} else |_| {}
|
||||
testNonStreaming(s) catch return;
|
||||
testing.expect(false);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user