| ... | @@ -2390,7 +2390,7 @@ pub fn stringify( | ... | @@ -2390,7 +2390,7 @@ pub fn stringify( |
| 2390 | unreachable; | 2390 | unreachable; |
| 2391 | } | 2391 | } |
| 2392 | | 2392 | |
| 2393 | fn teststringify(expected: []const u8, value: var) !void { | 2393 | fn 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 | }; |
| 2443 | | 2443 | |
| 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 | } |
| 2448 | | 2448 | |
| 2449 | test "stringify basic types" { | 2449 | test "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 | } |
| 2461 | | 2461 | |
| 2462 | test "stringify string" { | 2462 | test "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 | } |
| 2475 | | 2475 | |
| 2476 | test "stringify tagged unions" { | 2476 | test "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 | } |
| 2482 | | 2482 | |
| 2483 | test "stringify struct" { | 2483 | test "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 | } |
| 2488 | | 2488 | |
| 2489 | test "stringify struct with void field" { | 2489 | test "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 | } |
| 2495 | | 2495 | |
| 2496 | test "stringify array of structs" { | 2496 | test "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 | } |
| 2506 | | 2506 | |
| 2507 | test "stringify struct with custom stringifier" { | 2507 | test "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 | } |