diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-11-30 00:19:37 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-11-30 00:19:37 -0700 |
| commit | 692c254336da71cbe21aaf9fbc21240fd1269b95 (patch) | |
| tree | fe9c5fdfd23281c593345ae40c90ccecab48ce9b /test/behavior/struct.zig | |
| parent | 902df103c6151c257c90de9ba5f29f7f4b9dbea2 (diff) | |
| download | zig-692c254336da71cbe21aaf9fbc21240fd1269b95.tar.gz zig-692c254336da71cbe21aaf9fbc21240fd1269b95.zip | |
Revert "I found some more passing behavior tests"
This reverts commit 0a9b4d092f58595888f9e4be8ef683b2ed8a0da1.
Hm, these are all passing for me locally. I'll have to do some
troubleshooting to figure out which one(s) are failing on the CI.
Diffstat (limited to 'test/behavior/struct.zig')
| -rw-r--r-- | test/behavior/struct.zig | 141 |
1 files changed, 0 insertions, 141 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 1e47877fd6..eeaa80ed69 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -6,55 +6,12 @@ const expectEqual = std.testing.expectEqual; const expectEqualSlices = std.testing.expectEqualSlices; const maxInt = std.math.maxInt; -top_level_field: i32, - -test "top level fields" { - var instance = @This(){ - .top_level_field = 1234, - }; - instance.top_level_field += 1; - try expect(@as(i32, 1235) == instance.top_level_field); -} - 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); -} - test "call struct static method" { const result = StructWithNoFields.add(3, 4); try expect(result == 7); @@ -84,23 +41,6 @@ const Val = struct { x: i32, }; -test "fn call of struct field" { - const Foo = struct { - ptr: fn () i32, - }; - const S = struct { - fn aFunc() i32 { - return 13; - } - - fn callStructField(foo: Foo) i32 { - return foo.ptr(); - } - }; - - try expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13); -} - test "struct initializer" { const val = Val{ .x = 42 }; try expect(val.x == 42); @@ -118,84 +58,3 @@ test "call member function directly" { const result = MemberFnTestFoo.member(instance); try expect(result == 1234); } - -test "store member function in variable" { - const instance = MemberFnTestFoo{ .x = 1234 }; - const memberFn = MemberFnTestFoo.member; - const result = memberFn(instance); - try expect(result == 1234); -} - -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 "call method with mutable reference to struct with no fields" { - const S = struct { - fn doC(s: *const @This()) bool { - _ = s; - return true; - } - fn do(s: *@This()) bool { - _ = s; - return true; - } - }; - - var s = S{}; - try expect(S.doC(&s)); - try expect(s.doC()); - try expect(S.do(&s)); - try expect(s.do()); -} - -test "usingnamespace within struct scope" { - const S = struct { - usingnamespace struct { - pub fn inner() i32 { - return 42; - } - }; - }; - try expect(@as(i32, 42) == S.inner()); -} - -test "struct field init with catch" { - const S = struct { - fn doTheTest() !void { - var x: anyerror!isize = 1; - var req = Foo{ - .field = x catch undefined, - }; - try expect(req.field == 1); - } - - pub const Foo = extern struct { - field: isize, - }; - }; - try S.doTheTest(); - comptime try S.doTheTest(); -} |
