authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-02-25 00:01:09+11:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-03-31 23:19:24+11:00
log3a0875d9e805e524a12756ff975fedb0d94fb217
tree8b0a5b31c668b6e32aadc7b59eb90958a1357856
parent45dc2587a395c02afb12f1781f3539d4bc77c225
signaturelock-open Commit is signed but in an unrecognized format.

std: have json tests take options parameter


1 files changed, 28 insertions(+), 28 deletions(-)

lib/std/json.zig+28-28
......@@ -2390,7 +2390,7 @@ pub fn stringify(
23902390 unreachable;
23912391}
23922392
2393fn teststringify(expected: []const u8, value: var) !void {
2393fn teststringify(expected: []const u8, value: var, options: StringifyOptions) !void {
23942394 const ValidationOutStream = struct {
23952395 const Self = @This();
23962396 pub const OutStream = std.io.OutStream(*Self, Error, write);
......@@ -2442,55 +2442,55 @@ fn teststringify(expected: []const u8, value: var) !void {
24422442 };
24432443
24442444 var vos = ValidationOutStream.init(expected);
2445 try stringify(value, StringifyOptions{}, vos.outStream());
2445 try stringify(value, options, vos.outStream());
24462446 if (vos.expected_remaining.len > 0) return error.NotEnoughData;
24472447}
24482448
24492449test "stringify basic types" {
2450 try teststringify("false", false);
2451 try teststringify("true", true);
2452 try teststringify("null", @as(?u8, null));
2453 try teststringify("null", @as(?*u32, null));
2454 try teststringify("42", 42);
2455 try teststringify("4.2e+01", 42.0);
2456 try teststringify("42", @as(u8, 42));
2457 try teststringify("42", @as(u128, 42));
2458 try teststringify("4.2e+01", @as(f32, 42));
2459 try teststringify("4.2e+01", @as(f64, 42));
2450 try teststringify("false", false, StringifyOptions{});
2451 try teststringify("true", true, StringifyOptions{});
2452 try teststringify("null", @as(?u8, null), StringifyOptions{});
2453 try teststringify("null", @as(?*u32, null), StringifyOptions{});
2454 try teststringify("42", 42, StringifyOptions{});
2455 try teststringify("4.2e+01", 42.0, StringifyOptions{});
2456 try teststringify("42", @as(u8, 42), StringifyOptions{});
2457 try teststringify("42", @as(u128, 42), StringifyOptions{});
2458 try teststringify("4.2e+01", @as(f32, 42), StringifyOptions{});
2459 try teststringify("4.2e+01", @as(f64, 42), StringifyOptions{});
24602460}
24612461
24622462test "stringify string" {
2463 try teststringify("\"hello\"", "hello");
2464 try teststringify("\"with\\nescapes\\r\"", "with\nescapes\r");
2465 try teststringify("\"with unicode\\u0001\"", "with unicode\u{1}");
2466 try teststringify("\"with unicode\\u0080\"", "with unicode\u{80}");
2467 try teststringify("\"with unicode\\u00ff\"", "with unicode\u{FF}");
2468 try teststringify("\"with unicode\\u0100\"", "with unicode\u{100}");
2469 try teststringify("\"with unicode\\u0800\"", "with unicode\u{800}");
2470 try teststringify("\"with unicode\\u8000\"", "with unicode\u{8000}");
2471 try teststringify("\"with unicode\\ud799\"", "with unicode\u{D799}");
2472 try teststringify("\"with unicode\\ud800\\udc00\"", "with unicode\u{10000}");
2473 try teststringify("\"with unicode\\udbff\\udfff\"", "with unicode\u{10FFFF}");
2463 try teststringify("\"hello\"", "hello", StringifyOptions{});
2464 try teststringify("\"with\\nescapes\\r\"", "with\nescapes\r", StringifyOptions{});
2465 try teststringify("\"with unicode\\u0001\"", "with unicode\u{1}", StringifyOptions{});
2466 try teststringify("\"with unicode\\u0080\"", "with unicode\u{80}", StringifyOptions{});
2467 try teststringify("\"with unicode\\u00ff\"", "with unicode\u{FF}", StringifyOptions{});
2468 try teststringify("\"with unicode\\u0100\"", "with unicode\u{100}", StringifyOptions{});
2469 try teststringify("\"with unicode\\u0800\"", "with unicode\u{800}", StringifyOptions{});
2470 try teststringify("\"with unicode\\u8000\"", "with unicode\u{8000}", StringifyOptions{});
2471 try teststringify("\"with unicode\\ud799\"", "with unicode\u{D799}", StringifyOptions{});
2472 try teststringify("\"with unicode\\ud800\\udc00\"", "with unicode\u{10000}", StringifyOptions{});
2473 try teststringify("\"with unicode\\udbff\\udfff\"", "with unicode\u{10FFFF}", StringifyOptions{});
24742474}
24752475
24762476test "stringify tagged unions" {
24772477 try teststringify("42", union(enum) {
24782478 Foo: u32,
24792479 Bar: bool,
2480 }{ .Foo = 42 });
2480 }{ .Foo = 42 }, StringifyOptions{});
24812481}
24822482
24832483test "stringify struct" {
24842484 try teststringify("{\"foo\":42}", struct {
24852485 foo: u32,
2486 }{ .foo = 42 });
2486 }{ .foo = 42 }, StringifyOptions{});
24872487}
24882488
24892489test "stringify struct with void field" {
24902490 try teststringify("{\"foo\":42}", struct {
24912491 foo: u32,
24922492 bar: void = {},
2493 }{ .foo = 42 });
2493 }{ .foo = 42 }, StringifyOptions{});
24942494}
24952495
24962496test "stringify array of structs" {
......@@ -2501,7 +2501,7 @@ test "stringify array of structs" {
25012501 MyStruct{ .foo = 42 },
25022502 MyStruct{ .foo = 100 },
25032503 MyStruct{ .foo = 1000 },
2504 });
2504 }, StringifyOptions{});
25052505}
25062506
25072507test "stringify struct with custom stringifier" {
......@@ -2517,5 +2517,5 @@ test "stringify struct with custom stringifier" {
25172517 try stringify(42, options, out_stream);
25182518 try out_stream.writeAll("]");
25192519 }
2520 }{ .foo = 42 });
2520 }{ .foo = 42 }, StringifyOptions{});
25212521}