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