authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-25 17:28:40-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-25 17:28:40-04:00
log56a53021a17f36ff048d95b9efce8697653e98e1
tree2503e925ecda0bfca1a24828d4d59fca3293094e
parent4003cd4747019d79ff50aaa22415d2d3dfc15cf4
parent2cce171448449fa107aaab1e37a8e8ee8985c6bd

Merge branch 'tgschultz-patch-3'


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

std/fmt/index.zig+14
......@@ -166,6 +166,11 @@ pub fn formatType(
166166
167167 if (has_cust_fmt) return value.format(fmt, context, Errors, output);
168168 try output(context, @typeName(T));
169 if (comptime @typeId(T) == builtin.TypeId.Enum) {
170 try output(context, ".");
171 try formatType(@tagName(value), "", context, Errors, output);
172 return;
173 }
169174 comptime var field_i = 0;
170175 inline while (field_i < @memberCount(T)) : (field_i += 1) {
171176 if (field_i == 0) {
......@@ -934,6 +939,15 @@ test "fmt.format" {
934939 try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", value);
935940 try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value);
936941 }
942 {
943 const Enum = enum {
944 One,
945 Two,
946 };
947 const value = Enum.Two;
948 try testFmt("enum: Enum.Two\n", "enum: {}\n", value);
949 try testFmt("enum: Enum.Two\n", "enum: {}\n", &value);
950 }
937951 {
938952 var buf1: [32]u8 = undefined;
939953 const value: f32 = 1.34;