authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2020-03-05 12:19:08-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-05 16:03:12-05:00
log1091fee2425f9142c726233f89e0f8d49165d829
treea213a3f8aa4a4f7ad56f4524fce3ad1e3342f5d9
parentdebcc79d56a40f77b92e243b4e344fc9385bd405

std: format enum-literals


1 files changed, 11 insertions(+), 0 deletions(-)

lib/std/fmt.zig+11
...@@ -491,6 +491,13 @@ pub fn formatType(...@@ -491,6 +491,13 @@ pub fn formatType(
491 return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });491 return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });
492 },492 },
493 .Type => return output(context, @typeName(T)),493 .Type => return output(context, @typeName(T)),
494 .EnumLiteral => {
495 const name = @tagName(value);
496 var buffer: [name.len + 1]u8 = undefined;
497 buffer[0] = '.';
498 std.mem.copy(u8, buffer[1..], name);
499 return formatType(buffer, fmt, options, context, Errors, output, max_depth);
500 },
494 else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),501 else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
495 }502 }
496}503}
...@@ -1744,3 +1751,7 @@ test "vector" {...@@ -1744,3 +1751,7 @@ test "vector" {
1744 try testFmt("{ 1kB, 2kB, 3kB, 4kB }", "{B}", .{vu64});1751 try testFmt("{ 1kB, 2kB, 3kB, 4kB }", "{B}", .{vu64});
1745 try testFmt("{ 1000B, 1.953125KiB, 2.9296875KiB, 3.90625KiB }", "{Bi}", .{vu64});1752 try testFmt("{ 1000B, 1.953125KiB, 2.9296875KiB, 3.90625KiB }", "{Bi}", .{vu64});
1746}1753}
1754
1755test "enum-literal" {
1756 try testFmt(".hello_world", "{}", .{.hello_world});
1757}