authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-09-26 08:55:32-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-10-01 15:01:26-06:00
logc2ee66108c399b0359ce996980bd8593c3eb22ef
tree618421339a87f6e2adbf2919dcc5e877a8a80e14
parentd81648ce8ce93780c7eb8c93f05b6f99f160474c
signature Commit is signed but in an unrecognized format.

Add tests for alignment field in UnionField and StructFIeld


1 files changed, 12 insertions(+), 1 deletions(-)

test/stage1/behavior/type_info.zig+12-1
...@@ -211,7 +211,9 @@ fn testUnion() void {...@@ -211,7 +211,9 @@ fn testUnion() void {
211 expect(notag_union_info.Union.tag_type == null);211 expect(notag_union_info.Union.tag_type == null);
212 expect(notag_union_info.Union.layout == .Auto);212 expect(notag_union_info.Union.layout == .Auto);
213 expect(notag_union_info.Union.fields.len == 2);213 expect(notag_union_info.Union.fields.len == 2);
214 expect(notag_union_info.Union.fields[0].alignment == @alignOf(void));
214 expect(notag_union_info.Union.fields[1].field_type == u32);215 expect(notag_union_info.Union.fields[1].field_type == u32);
216 expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32));
215217
216 const TestExternUnion = extern union {218 const TestExternUnion = extern union {
217 foo: *c_void,219 foo: *c_void,
...@@ -229,13 +231,18 @@ test "type info: struct info" {...@@ -229,13 +231,18 @@ test "type info: struct info" {
229}231}
230232
231fn testStruct() void {233fn testStruct() void {
234 const unpacked_struct_info = @typeInfo(TestUnpackedStruct);
235 expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
236
232 const struct_info = @typeInfo(TestStruct);237 const struct_info = @typeInfo(TestStruct);
233 expect(struct_info == .Struct);238 expect(struct_info == .Struct);
234 expect(struct_info.Struct.layout == .Packed);239 expect(struct_info.Struct.layout == .Packed);
235 expect(struct_info.Struct.fields.len == 4);240 expect(struct_info.Struct.fields.len == 4);
241 expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
236 expect(struct_info.Struct.fields[2].field_type == *TestStruct);242 expect(struct_info.Struct.fields[2].field_type == *TestStruct);
237 expect(struct_info.Struct.fields[2].default_value == null);243 expect(struct_info.Struct.fields[2].default_value == null);
238 expect(struct_info.Struct.fields[3].default_value.? == 4);244 expect(struct_info.Struct.fields[3].default_value.? == 4);
245 expect(struct_info.Struct.fields[3].alignment == 1);
239 expect(struct_info.Struct.decls.len == 2);246 expect(struct_info.Struct.decls.len == 2);
240 expect(struct_info.Struct.decls[0].is_pub);247 expect(struct_info.Struct.decls[0].is_pub);
241 expect(!struct_info.Struct.decls[0].data.Fn.is_extern);248 expect(!struct_info.Struct.decls[0].data.Fn.is_extern);
...@@ -244,8 +251,12 @@ fn testStruct() void {...@@ -244,8 +251,12 @@ fn testStruct() void {
244 expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void);251 expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void);
245}252}
246253
254const TestUnpackedStruct = struct {
255 fieldA: u32 = 4,
256};
257
247const TestStruct = packed struct {258const TestStruct = packed struct {
248 fieldA: usize,259 fieldA: usize align(2 * @alignOf(usize)),
249 fieldB: void,260 fieldB: void,
250 fieldC: *Self,261 fieldC: *Self,
251 fieldD: u32 = 4,262 fieldD: u32 = 4,