Like niceTypeName to its own file of utils
This commit is contained in:
parent
7d1d02f2a6
commit
cd86e774d5
1 changed files with 24 additions and 0 deletions
24
src/args/utils.zig
Normal file
24
src/args/utils.zig
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn niceTypeName(comptime T: type) []const u8 {
|
||||||
|
if (T == []const u8) {
|
||||||
|
return "string";
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = @typeName(T);
|
||||||
|
|
||||||
|
if (std.mem.startsWith(u8, name, "array_list.ArrayListAligned")) {
|
||||||
|
return "array";
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const t = std.testing;
|
||||||
|
|
||||||
|
test "nice type names" {
|
||||||
|
try t.expectEqualStrings("string", niceTypeName([]const u8));
|
||||||
|
try t.expectEqualStrings("array", niceTypeName(std.ArrayList(u8)));
|
||||||
|
|
||||||
|
try t.expectEqualStrings("u8", niceTypeName(u8));
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue