aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-08-25 17:28:40 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-08-25 17:28:40 -0400
commit56a53021a17f36ff048d95b9efce8697653e98e1 (patch)
tree2503e925ecda0bfca1a24828d4d59fca3293094e /std
parent4003cd4747019d79ff50aaa22415d2d3dfc15cf4 (diff)
parent2cce171448449fa107aaab1e37a8e8ee8985c6bd (diff)
downloadzig-56a53021a17f36ff048d95b9efce8697653e98e1.tar.gz
zig-56a53021a17f36ff048d95b9efce8697653e98e1.zip
Merge branch 'tgschultz-patch-3'
Diffstat (limited to 'std')
-rw-r--r--std/fmt/index.zig14
1 files changed, 14 insertions, 0 deletions
diff --git a/std/fmt/index.zig b/std/fmt/index.zig
index 812f5e72cd..82e9a5ba39 100644
--- a/std/fmt/index.zig
+++ b/std/fmt/index.zig
@@ -166,6 +166,11 @@ pub fn formatType(
if (has_cust_fmt) return value.format(fmt, context, Errors, output);
try output(context, @typeName(T));
+ if (comptime @typeId(T) == builtin.TypeId.Enum) {
+ try output(context, ".");
+ try formatType(@tagName(value), "", context, Errors, output);
+ return;
+ }
comptime var field_i = 0;
inline while (field_i < @memberCount(T)) : (field_i += 1) {
if (field_i == 0) {
@@ -935,6 +940,15 @@ test "fmt.format" {
try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value);
}
{
+ const Enum = enum {
+ One,
+ Two,
+ };
+ const value = Enum.Two;
+ try testFmt("enum: Enum.Two\n", "enum: {}\n", value);
+ try testFmt("enum: Enum.Two\n", "enum: {}\n", &value);
+ }
+ {
var buf1: [32]u8 = undefined;
const value: f32 = 1.34;
const result = try bufPrint(buf1[0..], "f32: {e}\n", value);