Skip to content

Commit

Permalink
improve expectJson error message
Browse files Browse the repository at this point in the history
  • Loading branch information
karlseguin committed Nov 24, 2024
1 parent 656dfca commit 5af6d11
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ pub const Testing = struct {

for (diffs.items, 0..) |diff, i| {
std.debug.print("\n==Difference #{d}==\n", .{i + 1});
std.debug.print(" {s}: {s}\n Left: {s}\n Right: {s}\n", .{ diff.path, diff.err, diff.a, diff.b });
std.debug.print(" Actual:\n {s}\n", .{self.body});
std.debug.print("{s}: {s} {s} {s}\n", .{ diff.path, diff.a, diff.err, diff.b });
std.debug.print("Actual:\n{s}\n", .{jc.pretty_actual orelse self.body});
}
return error.JsonNotEqual;
}
Expand Down Expand Up @@ -349,6 +349,7 @@ fn isUnreserved(c: u8) bool {

const JsonComparer = struct {
_arena: std.heap.ArenaAllocator,
pretty_actual: ?[]const u8 = null,

const Diff = struct {
err: []const u8,
Expand Down Expand Up @@ -390,6 +391,8 @@ const JsonComparer = struct {
const a_value = try std.json.parseFromSliceLeaky(std.json.Value, allocator, a_bytes, .{});
const b_value = try std.json.parseFromSliceLeaky(std.json.Value, allocator, b_bytes, .{});

self.pretty_actual = try std.json.stringifyAlloc(allocator, b_value, .{.whitespace = .indent_2}) ;

var diffs = ArrayList(Diff).init(allocator);
var path = ArrayList([]const u8).init(allocator);
try self.compareValue(a_value, b_value, &diffs, &path);
Expand Down

0 comments on commit 5af6d11

Please sign in to comment.