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(...@@ -2390,7 +2390,7 @@ pub fn stringify(
2390 unreachable;2390 unreachable;
2391}2391}
23922392
2393fn teststringify(expected: []const u8, value: var) !void {2393fn teststringify(expected: []const u8, value: var, options: StringifyOptions) !void {
2394 const ValidationOutStream = struct {2394 const ValidationOutStream = struct {
2395 const Self = @This();2395 const Self = @This();
2396 pub const OutStream = std.io.OutStream(*Self, Error, write);2396 pub const OutStream = std.io.OutStream(*Self, Error, write);
...@@ -2442,55 +2442,55 @@ fn teststringify(expected: []const u8, value: var) !void {...@@ -2442,55 +2442,55 @@ fn teststringify(expected: []const u8, value: var) !void {
2442 };2442 };
24432443
2444 var vos = ValidationOutStream.init(expected);2444 var vos = ValidationOutStream.init(expected);
2445 try stringify(value, StringifyOptions{}, vos.outStream());2445 try stringify(value, options, vos.outStream());
2446 if (vos.expected_remaining.len > 0) return error.NotEnoughData;2446 if (vos.expected_remaining.len > 0) return error.NotEnoughData;
2447}2447}
24482448
2449test "stringify basic types" {2449test "stringify basic types" {
2450 try teststringify("false", false);2450 try teststringify("false", false, StringifyOptions{});
2451 try teststringify("true", true);2451 try teststringify("true", true, StringifyOptions{});
2452 try teststringify("null", @as(?u8, null));2452 try teststringify("null", @as(?u8, null), StringifyOptions{});
2453 try teststringify("null", @as(?*u32, null));2453 try teststringify("null", @as(?*u32, null), StringifyOptions{});
2454 try teststringify("42", 42);2454 try teststringify("42", 42, StringifyOptions{});
2455 try teststringify("4.2e+01", 42.0);2455 try teststringify("4.2e+01", 42.0, StringifyOptions{});
2456 try teststringify("42", @as(u8, 42));2456 try teststringify("42", @as(u8, 42), StringifyOptions{});
2457 try teststringify("42", @as(u128, 42));2457 try teststringify("42", @as(u128, 42), StringifyOptions{});
2458 try teststringify("4.2e+01", @as(f32, 42));2458 try teststringify("4.2e+01", @as(f32, 42), StringifyOptions{});
2459 try teststringify("4.2e+01", @as(f64, 42));2459 try teststringify("4.2e+01", @as(f64, 42), StringifyOptions{});
2460}2460}
24612461
2462test "stringify string" {2462test "stringify string" {
2463 try teststringify("\"hello\"", "hello");2463 try teststringify("\"hello\"", "hello", StringifyOptions{});
2464 try teststringify("\"with\\nescapes\\r\"", "with\nescapes\r");2464 try teststringify("\"with\\nescapes\\r\"", "with\nescapes\r", StringifyOptions{});
2465 try teststringify("\"with unicode\\u0001\"", "with unicode\u{1}");2465 try teststringify("\"with unicode\\u0001\"", "with unicode\u{1}", StringifyOptions{});
2466 try teststringify("\"with unicode\\u0080\"", "with unicode\u{80}");2466 try teststringify("\"with unicode\\u0080\"", "with unicode\u{80}", StringifyOptions{});
2467 try teststringify("\"with unicode\\u00ff\"", "with unicode\u{FF}");2467 try teststringify("\"with unicode\\u00ff\"", "with unicode\u{FF}", StringifyOptions{});
2468 try teststringify("\"with unicode\\u0100\"", "with unicode\u{100}");2468 try teststringify("\"with unicode\\u0100\"", "with unicode\u{100}", StringifyOptions{});
2469 try teststringify("\"with unicode\\u0800\"", "with unicode\u{800}");2469 try teststringify("\"with unicode\\u0800\"", "with unicode\u{800}", StringifyOptions{});
2470 try teststringify("\"with unicode\\u8000\"", "with unicode\u{8000}");2470 try teststringify("\"with unicode\\u8000\"", "with unicode\u{8000}", StringifyOptions{});
2471 try teststringify("\"with unicode\\ud799\"", "with unicode\u{D799}");2471 try teststringify("\"with unicode\\ud799\"", "with unicode\u{D799}", StringifyOptions{});
2472 try teststringify("\"with unicode\\ud800\\udc00\"", "with unicode\u{10000}");2472 try teststringify("\"with unicode\\ud800\\udc00\"", "with unicode\u{10000}", StringifyOptions{});
2473 try teststringify("\"with unicode\\udbff\\udfff\"", "with unicode\u{10FFFF}");2473 try teststringify("\"with unicode\\udbff\\udfff\"", "with unicode\u{10FFFF}", StringifyOptions{});
2474}2474}
24752475
2476test "stringify tagged unions" {2476test "stringify tagged unions" {
2477 try teststringify("42", union(enum) {2477 try teststringify("42", union(enum) {
2478 Foo: u32,2478 Foo: u32,
2479 Bar: bool,2479 Bar: bool,
2480 }{ .Foo = 42 });2480 }{ .Foo = 42 }, StringifyOptions{});
2481}2481}
24822482
2483test "stringify struct" {2483test "stringify struct" {
2484 try teststringify("{\"foo\":42}", struct {2484 try teststringify("{\"foo\":42}", struct {
2485 foo: u32,2485 foo: u32,
2486 }{ .foo = 42 });2486 }{ .foo = 42 }, StringifyOptions{});
2487}2487}
24882488
2489test "stringify struct with void field" {2489test "stringify struct with void field" {
2490 try teststringify("{\"foo\":42}", struct {2490 try teststringify("{\"foo\":42}", struct {
2491 foo: u32,2491 foo: u32,
2492 bar: void = {},2492 bar: void = {},
2493 }{ .foo = 42 });2493 }{ .foo = 42 }, StringifyOptions{});
2494}2494}
24952495
2496test "stringify array of structs" {2496test "stringify array of structs" {
...@@ -2501,7 +2501,7 @@ test "stringify array of structs" {...@@ -2501,7 +2501,7 @@ test "stringify array of structs" {
2501 MyStruct{ .foo = 42 },2501 MyStruct{ .foo = 42 },
2502 MyStruct{ .foo = 100 },2502 MyStruct{ .foo = 100 },
2503 MyStruct{ .foo = 1000 },2503 MyStruct{ .foo = 1000 },
2504 });2504 }, StringifyOptions{});
2505}2505}
25062506
2507test "stringify struct with custom stringifier" {2507test "stringify struct with custom stringifier" {
...@@ -2517,5 +2517,5 @@ test "stringify struct with custom stringifier" {...@@ -2517,5 +2517,5 @@ test "stringify struct with custom stringifier" {
2517 try stringify(42, options, out_stream);2517 try stringify(42, options, out_stream);
2518 try out_stream.writeAll("]");2518 try out_stream.writeAll("]");
2519 }2519 }
2520 }{ .foo = 42 });2520 }{ .foo = 42 }, StringifyOptions{});
2521}2521}