authorgravatar for twostepted@gmail.comTravis Staloch <twostepted@gmail.com> 2024-12-24 19:44:43-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-29 13:37:39-05:00
log45e4b16caf30093bcb98b266b25d1a226efd1641
tree98f4e90c6e6689816b99676f5bc6dfff3fe0040f
parentb99dbb6fb50e7b10f05287470df577b2726754fa

add `@Type` behavior tests from #19985


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

test/behavior/type.zig+26
......@@ -377,6 +377,32 @@ test "Type.Enum" {
377377 try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a));
378378 try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b));
379379 try testing.expectEqual(@as(u32, 6), @intFromEnum(@as(Bar, @enumFromInt(6))));
380
381 { // from https://github.com/ziglang/zig/issues/19985
382 { // enum with single field can be initialized.
383 const E = @Type(.{ .@"enum" = .{
384 .tag_type = u0,
385 .is_exhaustive = true,
386 .fields = &.{.{ .name = "foo", .value = 0 }},
387 .decls = &.{},
388 } });
389 const s: struct { E } = .{.foo};
390 try testing.expectEqual(.foo, s[0]);
391 }
392
393 { // meta.FieldEnum() with single field
394 const S = struct { foo: u8 };
395 const Fe = std.meta.FieldEnum(S);
396 var s: S = undefined;
397 const fe = std.meta.stringToEnum(Fe, "foo") orelse return error.InvalidField;
398 switch (fe) {
399 inline else => |tag| {
400 @field(s, @tagName(tag)) = 42;
401 },
402 }
403 try testing.expectEqual(42, s.foo);
404 }
405 }
380406}
381407
382408test "Type.Union" {