| ... | ... | @@ -373,11 +373,11 @@ pub fn formatType( |
| 373 | 373 | try output(context, @typeName(T)); |
| 374 | 374 | if (enumInfo.is_exhaustive) { |
| 375 | 375 | try output(context, "."); |
| 376 | | return formatType(@tagName(value), "", options, context, Errors, output, max_depth); |
| 376 | try output(context, @tagName(value)); |
| 377 | 377 | } else { |
| 378 | 378 | // TODO: when @tagName works on exhaustive enums print known enum strings |
| 379 | 379 | try output(context, "("); |
| 380 | | try formatType(@enumToInt(value), "", options, context, Errors, output, max_depth); |
| 380 | try formatType(@enumToInt(value), fmt, options, context, Errors, output, max_depth); |
| 381 | 381 | try output(context, ")"); |
| 382 | 382 | } |
| 383 | 383 | }, |
| ... | ... | @@ -397,7 +397,7 @@ pub fn formatType( |
| 397 | 397 | try output(context, " = "); |
| 398 | 398 | inline for (info.fields) |u_field| { |
| 399 | 399 | if (@enumToInt(@as(UnionTagType, value)) == u_field.enum_field.?.value) { |
| 400 | | try formatType(@field(value, u_field.name), "", options, context, Errors, output, max_depth - 1); |
| 400 | try formatType(@field(value, u_field.name), fmt, options, context, Errors, output, max_depth - 1); |
| 401 | 401 | } |
| 402 | 402 | } |
| 403 | 403 | try output(context, " }"); |
| ... | ... | @@ -424,7 +424,7 @@ pub fn formatType( |
| 424 | 424 | } |
| 425 | 425 | try output(context, @memberName(T, field_i)); |
| 426 | 426 | try output(context, " = "); |
| 427 | | try formatType(@field(value, @memberName(T, field_i)), "", options, context, Errors, output, max_depth - 1); |
| 427 | try formatType(@field(value, @memberName(T, field_i)), fmt, options, context, Errors, output, max_depth - 1); |
| 428 | 428 | } |
| 429 | 429 | try output(context, " }"); |
| 430 | 430 | }, |
| ... | ... | @@ -1343,6 +1343,20 @@ test "enum" { |
| 1343 | 1343 | try testFmt("enum: Enum.Two\n", "enum: {}\n", .{&value}); |
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | test "non-exhaustive enum" { |
| 1347 | const Enum = enum(u16) { |
| 1348 | One = 0x000f, |
| 1349 | Two = 0xbeef, |
| 1350 | _, |
| 1351 | }; |
| 1352 | try testFmt("enum: Enum(15)\n", "enum: {}\n", .{Enum.One}); |
| 1353 | try testFmt("enum: Enum(48879)\n", "enum: {}\n", .{Enum.Two}); |
| 1354 | try testFmt("enum: Enum(4660)\n", "enum: {}\n", .{@intToEnum(Enum, 0x1234)}); |
| 1355 | try testFmt("enum: Enum(f)\n", "enum: {x}\n", .{Enum.One}); |
| 1356 | try testFmt("enum: Enum(beef)\n", "enum: {x}\n", .{Enum.Two}); |
| 1357 | try testFmt("enum: Enum(1234)\n", "enum: {x}\n", .{@intToEnum(Enum, 0x1234)}); |
| 1358 | } |
| 1359 | |
| 1346 | 1360 | test "float.scientific" { |
| 1347 | 1361 | try testFmt("f32: 1.34000003e+00", "f32: {e}", .{@as(f32, 1.34)}); |
| 1348 | 1362 | try testFmt("f32: 1.23400001e+01", "f32: {e}", .{@as(f32, 12.34)}); |