mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
std: format enum-literals
This commit is contained in:
parent
debcc79d56
commit
1091fee242
@ -491,6 +491,13 @@ pub fn formatType(
|
||||
return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });
|
||||
},
|
||||
.Type => return output(context, @typeName(T)),
|
||||
.EnumLiteral => {
|
||||
const name = @tagName(value);
|
||||
var buffer: [name.len + 1]u8 = undefined;
|
||||
buffer[0] = '.';
|
||||
std.mem.copy(u8, buffer[1..], name);
|
||||
return formatType(buffer, fmt, options, context, Errors, output, max_depth);
|
||||
},
|
||||
else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
|
||||
}
|
||||
}
|
||||
@ -1744,3 +1751,7 @@ test "vector" {
|
||||
try testFmt("{ 1kB, 2kB, 3kB, 4kB }", "{B}", .{vu64});
|
||||
try testFmt("{ 1000B, 1.953125KiB, 2.9296875KiB, 3.90625KiB }", "{Bi}", .{vu64});
|
||||
}
|
||||
|
||||
test "enum-literal" {
|
||||
try testFmt(".hello_world", "{}", .{.hello_world});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user