| ... | @@ -592,11 +592,41 @@ pub fn FieldEnum(comptime T: type) type { | ... | @@ -592,11 +592,41 @@ pub fn FieldEnum(comptime T: type) type { |
| 592 | fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { | 592 | fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { |
| 593 | // TODO: https://github.com/ziglang/zig/issues/7419 | 593 | // TODO: https://github.com/ziglang/zig/issues/7419 |
| 594 | // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum); | 594 | // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum); |
| 595 | try testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout); | 595 | try testing.expectEqual( |
| 596 | try testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type); | 596 | @typeInfo(expected).Enum.layout, |
| 597 | comptime try testing.expectEqualSlices(std.builtin.Type.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields); | 597 | @typeInfo(actual).Enum.layout, |
| 598 | comptime try testing.expectEqualSlices(std.builtin.Type.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls); | 598 | ); |
| 599 | try testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive); | 599 | try testing.expectEqual( |
| | 600 | @typeInfo(expected).Enum.tag_type, |
| | 601 | @typeInfo(actual).Enum.tag_type, |
| | 602 | ); |
| | 603 | // For comparing decls and fields, we cannot use the meta eql function here |
| | 604 | // because the language does not guarantee that the slice pointers for field names |
| | 605 | // and decl names will be the same. |
| | 606 | comptime { |
| | 607 | const expected_fields = @typeInfo(expected).Enum.fields; |
| | 608 | const actual_fields = @typeInfo(actual).Enum.fields; |
| | 609 | if (expected_fields.len != actual_fields.len) return error.FailedTest; |
| | 610 | for (expected_fields) |expected_field, i| { |
| | 611 | const actual_field = actual_fields[i]; |
| | 612 | try testing.expectEqual(expected_field.value, actual_field.value); |
| | 613 | try testing.expectEqualStrings(expected_field.name, actual_field.name); |
| | 614 | } |
| | 615 | } |
| | 616 | comptime { |
| | 617 | const expected_decls = @typeInfo(expected).Enum.decls; |
| | 618 | const actual_decls = @typeInfo(actual).Enum.decls; |
| | 619 | if (expected_decls.len != actual_decls.len) return error.FailedTest; |
| | 620 | for (expected_decls) |expected_decl, i| { |
| | 621 | const actual_decl = actual_decls[i]; |
| | 622 | try testing.expectEqual(expected_decl.is_pub, actual_decl.is_pub); |
| | 623 | try testing.expectEqualStrings(expected_decl.name, actual_decl.name); |
| | 624 | } |
| | 625 | } |
| | 626 | try testing.expectEqual( |
| | 627 | @typeInfo(expected).Enum.is_exhaustive, |
| | 628 | @typeInfo(actual).Enum.is_exhaustive, |
| | 629 | ); |
| 600 | } | 630 | } |
| 601 | | 631 | |
| 602 | test "std.meta.FieldEnum" { | 632 | test "std.meta.FieldEnum" { |