aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-09-25 17:52:50 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-09-25 17:54:52 -0700
commit04366576ea4be4959b596ebff7041d17e18d08d8 (patch)
tree94dceb8f1e846e09356e5b40b884791a7cc314eb /test
parent15f55b2805541276f491d255f60f501c8cbd1191 (diff)
downloadzig-04366576ea4be4959b596ebff7041d17e18d08d8.tar.gz
zig-04366576ea4be4959b596ebff7041d17e18d08d8.zip
stage2: implement `@sizeOf` for non-packed structs
Diffstat (limited to 'test')
-rw-r--r--test/behavior/struct.zig21
-rw-r--r--test/behavior/struct_stage1.zig17
2 files changed, 22 insertions, 16 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index 6f00b71057..e048848799 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -31,3 +31,24 @@ test "return empty struct instance" {
fn returnEmptyStructInstance() StructWithNoFields {
return empty_global_instance;
}
+
+const StructFoo = struct {
+ a: i32,
+ b: bool,
+ c: f32,
+};
+test "structs" {
+ var foo: StructFoo = undefined;
+ @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
+ foo.a += 1;
+ foo.b = foo.a == 1;
+ try testFoo(foo);
+ testMutation(&foo);
+ try expect(foo.c == 100);
+}
+fn testFoo(foo: StructFoo) !void {
+ try expect(foo.b);
+}
+fn testMutation(foo: *StructFoo) void {
+ foo.c = 100;
+}
diff --git a/test/behavior/struct_stage1.zig b/test/behavior/struct_stage1.zig
index 9f084ceb85..fd19b37661 100644
--- a/test/behavior/struct_stage1.zig
+++ b/test/behavior/struct_stage1.zig
@@ -30,26 +30,11 @@ const VoidStructFieldsFoo = struct {
c: void,
};
-test "structs" {
- var foo: StructFoo = undefined;
- @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
- foo.a += 1;
- foo.b = foo.a == 1;
- try testFoo(foo);
- testMutation(&foo);
- try expect(foo.c == 100);
-}
const StructFoo = struct {
a: i32,
b: bool,
c: f32,
};
-fn testFoo(foo: StructFoo) !void {
- try expect(foo.b);
-}
-fn testMutation(foo: *StructFoo) void {
- foo.c = 100;
-}
const Node = struct {
val: Val,
@@ -84,7 +69,7 @@ test "struct byval assign" {
try expect(foo2.a == 1234);
}
-fn structInitializer() void {
+test "struct initializer" {
const val = Val{ .x = 42 };
try expect(val.x == 42);
}