Improve niceTypeName, and also swap a warn to an err
This commit is contained in:
parent
166fcc4abe
commit
6a6bffaa3b
2 changed files with 11 additions and 1 deletions
|
|
@ -38,7 +38,7 @@ fn parseEnumFromStr(comptime T: type, str: []const u8) !T {
|
|||
// todo: maybe find a way to get Zig tests to run without stderr *unless* they fail?
|
||||
}
|
||||
|
||||
log.warn("could not parse `{s}` as enum `{s}`", .{ str, @typeName(T) });
|
||||
log.err("could not parse `{s}` as enum `{s}`", .{ str, @typeName(T) });
|
||||
log.warn("hint: try one of the following:", .{});
|
||||
|
||||
inline for (info.Enum.fields) |field| {
|
||||
|
|
|
|||
|
|
@ -11,14 +11,24 @@ pub fn niceTypeName(comptime T: type) []const u8 {
|
|||
return "array";
|
||||
}
|
||||
|
||||
if (std.mem.lastIndexOf(u8, name, ".")) |idx| {
|
||||
return name[idx + 1 ..];
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
const t = std.testing;
|
||||
|
||||
test "nice type names" {
|
||||
const Enum = enum(u8) {
|
||||
ThisIs,
|
||||
ATest,
|
||||
};
|
||||
|
||||
try t.expectEqualStrings("string", niceTypeName([]const u8));
|
||||
try t.expectEqualStrings("array", niceTypeName(std.ArrayList(u8)));
|
||||
try t.expectEqualStrings("Enum", niceTypeName(Enum));
|
||||
|
||||
try t.expectEqualStrings("u8", niceTypeName(u8));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue