aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/struct_llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-11-30 16:14:18 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-11-30 16:15:42 -0700
commit1e0addcf73ee71d23a41b744995848bcca38e8d3 (patch)
tree13105910aae6857bffc9fa81ccab893b6507c0f6 /test/behavior/struct_llvm.zig
parent04286e8c3b1a815488c73c011988eb4fa985202b (diff)
downloadzig-1e0addcf73ee71d23a41b744995848bcca38e8d3.tar.gz
zig-1e0addcf73ee71d23a41b744995848bcca38e8d3.zip
put the passing stage2 behavior tests back
This mostly reverts commit 692c254336da71cbe21aaf9fbc21240fd1269b95. The test "for loop over pointers to struct, getting field from struct pointer" is still failing on the CI so that one is not moved over.
Diffstat (limited to 'test/behavior/struct_llvm.zig')
-rw-r--r--test/behavior/struct_llvm.zig80
1 files changed, 16 insertions, 64 deletions
diff --git a/test/behavior/struct_llvm.zig b/test/behavior/struct_llvm.zig
index a809905cef..5c364e183e 100644
--- a/test/behavior/struct_llvm.zig
+++ b/test/behavior/struct_llvm.zig
@@ -6,44 +6,6 @@ const expectEqual = std.testing.expectEqual;
const expectEqualSlices = std.testing.expectEqualSlices;
const maxInt = std.math.maxInt;
-const StructWithNoFields = struct {
- fn add(a: i32, b: i32) i32 {
- return a + b;
- }
-};
-
-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;
-}
-
-test "struct byval assign" {
- var foo1: StructFoo = undefined;
- var foo2: StructFoo = undefined;
-
- foo1.a = 1234;
- foo2.a = 0;
- try expect(foo2.a == 0);
- foo2 = foo1;
- try expect(foo2.a == 1234);
-}
-
const Node = struct {
val: Val,
next: *Node,
@@ -81,32 +43,6 @@ const VoidStructFieldsFoo = struct {
c: void,
};
-test "member functions" {
- const r = MemberFnRand{ .seed = 1234 };
- try expect(r.getSeed() == 1234);
-}
-const MemberFnRand = struct {
- seed: u32,
- pub fn getSeed(r: *const MemberFnRand) u32 {
- return r.seed;
- }
-};
-
-test "return struct byval from function" {
- const bar = makeBar2(1234, 5678);
- try expect(bar.y == 5678);
-}
-const Bar = struct {
- x: i32,
- y: i32,
-};
-fn makeBar2(x: i32, y: i32) Bar {
- return Bar{
- .x = x,
- .y = y,
- };
-}
-
test "return empty struct from fn" {
_ = testReturnEmptyStructFromFn();
}
@@ -114,3 +50,19 @@ const EmptyStruct2 = struct {};
fn testReturnEmptyStructFromFn() EmptyStruct2 {
return EmptyStruct2{};
}
+
+test "pass slice of empty struct to fn" {
+ try expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
+}
+fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
+ return slice.len;
+}
+
+test "self-referencing struct via array member" {
+ const T = struct {
+ children: [1]*@This(),
+ };
+ var x: T = undefined;
+ x = T{ .children = .{&x} };
+ try expect(x.children[0] == &x);
+}