-
Notifications
You must be signed in to change notification settings - Fork 0
/
testutils.zig
38 lines (30 loc) · 1.1 KB
/
testutils.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const std = @import("std");
const io = std.io;
const mem = std.mem;
const protocol = @import("protocol.zig");
pub fn printHRBytes(comptime fmt: []const u8, exp: []const u8, args: anytype) void {
const hextable = "0123456789abcdef";
var buffer = std.ArrayList(u8).init(std.testing.allocator);
defer buffer.deinit();
var column: usize = 0;
for (exp) |c| {
if (column % 80 == 0) {
buffer.append('\n') catch unreachable;
column = 0;
}
if (std.ascii.isAlphanumeric(c) or c == '_') {
buffer.append(c) catch unreachable;
} else {
buffer.appendSlice("\\x") catch unreachable;
buffer.append(hextable[(c & 0xF0) >> 4]) catch unreachable;
buffer.append(hextable[(c & 0x0F)]) catch unreachable;
}
column += 1;
}
std.debug.print(fmt, .{buffer.items} ++ args);
}
/// Creates an arena allocator backed by the testing allocator.
/// Only intended to be used for tests.
pub fn arenaAllocator() std.heap.ArenaAllocator {
return std.heap.ArenaAllocator.init(std.testing.allocator);
}