master
 1const std = @import("../std.zig");
 2const testing = std.testing;
 3const fmt = std.fmt;
 4
 5// Hash using the specified hasher `H` asserting `expected == H(input)`.
 6pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) !void {
 7    var h: [Hasher.digest_length]u8 = undefined;
 8    Hasher.hash(input, &h, .{});
 9
10    try assertEqual(expected_hex, &h);
11}
12
13// Assert `expected` == hex(`input`) where `input` is a bytestring
14pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) !void {
15    var expected_bytes: [expected_hex.len / 2]u8 = undefined;
16    for (&expected_bytes, 0..) |*r, i| {
17        r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable;
18    }
19
20    try testing.expectEqualSlices(u8, &expected_bytes, input);
21}