aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2022-03-14 10:47:35 -0700
committerGitHub <noreply@github.com>2022-03-14 13:47:35 -0400
commit1ebe3bd01d13b28b3ecd4962f0f70344fe75ba4d (patch)
tree602b9f3bac03851ee11dac3a9afe0b911c9d2530 /test
parent5919b10048be6efa8c0ca6bcb259706098b2d5ec (diff)
downloadzig-1ebe3bd01d13b28b3ecd4962f0f70344fe75ba4d.tar.gz
zig-1ebe3bd01d13b28b3ecd4962f0f70344fe75ba4d.zip
stage2: reify structs and tuples (#11144)
Implements `@Type` for structs, anon structs, and tuples. This is another place that would probably benefit from a `.reified_struct` type tag but will defer for later in the interest of getting tests passing first.
Diffstat (limited to 'test')
-rw-r--r--test/behavior/type.zig46
1 files changed, 45 insertions, 1 deletions
diff --git a/test/behavior/type.zig b/test/behavior/type.zig
index ff86aa28e8..15b4638488 100644
--- a/test/behavior/type.zig
+++ b/test/behavior/type.zig
@@ -260,7 +260,11 @@ test "Type.ErrorSet" {
}
test "Type.Struct" {
- if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
const A = @Type(@typeInfo(struct { x: u8, y: u32 }));
const infoA = @typeInfo(A).Struct;
@@ -303,6 +307,46 @@ test "Type.Struct" {
try testing.expectEqual(@as(u32, 5), @ptrCast(*const u32, infoC.fields[1].default_value.?).*);
try testing.expectEqual(@as(usize, 0), infoC.decls.len);
try testing.expectEqual(@as(bool, false), infoC.is_tuple);
+
+ // anon structs
+ const D = @Type(@typeInfo(@TypeOf(.{ .x = 3, .y = 5 })));
+ const infoD = @typeInfo(D).Struct;
+ try testing.expectEqual(Type.ContainerLayout.Auto, infoD.layout);
+ try testing.expectEqualSlices(u8, "x", infoD.fields[0].name);
+ try testing.expectEqual(comptime_int, infoD.fields[0].field_type);
+ try testing.expectEqual(@as(comptime_int, 3), @ptrCast(*const comptime_int, infoD.fields[0].default_value.?).*);
+ try testing.expectEqualSlices(u8, "y", infoD.fields[1].name);
+ try testing.expectEqual(comptime_int, infoD.fields[1].field_type);
+ try testing.expectEqual(@as(comptime_int, 5), @ptrCast(*const comptime_int, infoD.fields[1].default_value.?).*);
+ try testing.expectEqual(@as(usize, 0), infoD.decls.len);
+ try testing.expectEqual(@as(bool, false), infoD.is_tuple);
+
+ // tuples
+ const E = @Type(@typeInfo(@TypeOf(.{ 1, 2 })));
+ const infoE = @typeInfo(E).Struct;
+ try testing.expectEqual(Type.ContainerLayout.Auto, infoE.layout);
+ try testing.expectEqualSlices(u8, "0", infoE.fields[0].name);
+ try testing.expectEqual(comptime_int, infoE.fields[0].field_type);
+ try testing.expectEqual(@as(comptime_int, 1), @ptrCast(*const comptime_int, infoE.fields[0].default_value.?).*);
+ try testing.expectEqualSlices(u8, "1", infoE.fields[1].name);
+ try testing.expectEqual(comptime_int, infoE.fields[1].field_type);
+ try testing.expectEqual(@as(comptime_int, 2), @ptrCast(*const comptime_int, infoE.fields[1].default_value.?).*);
+ try testing.expectEqual(@as(usize, 0), infoE.decls.len);
+ try testing.expectEqual(@as(bool, true), infoE.is_tuple);
+
+ // empty struct
+ const F = @Type(@typeInfo(struct {}));
+ const infoF = @typeInfo(F).Struct;
+ try testing.expectEqual(Type.ContainerLayout.Auto, infoF.layout);
+ try testing.expect(infoF.fields.len == 0);
+ try testing.expectEqual(@as(bool, false), infoF.is_tuple);
+
+ // empty tuple
+ const G = @Type(@typeInfo(@TypeOf(.{})));
+ const infoG = @typeInfo(G).Struct;
+ try testing.expectEqual(Type.ContainerLayout.Auto, infoG.layout);
+ try testing.expect(infoG.fields.len == 0);
+ try testing.expectEqual(@as(bool, true), infoG.is_tuple);
}
test "Type.Enum" {