diff options
| author | Cody Tapscott <topolarity@tapscott.me> | 2022-07-08 15:09:56 -0700 |
|---|---|---|
| committer | Cody Tapscott <topolarity@tapscott.me> | 2022-07-08 19:50:28 -0700 |
| commit | 2fff25fd220632cc6943680d3d6bbb1f21fa141f (patch) | |
| tree | c4d7be35ec022324c46761db643e2f28418cccb4 /test/behavior/tuple.zig | |
| parent | 6f0807f50f4e946bb850e746beaa5d6556cf7750 (diff) | |
| download | zig-2fff25fd220632cc6943680d3d6bbb1f21fa141f.tar.gz zig-2fff25fd220632cc6943680d3d6bbb1f21fa141f.zip | |
stage2: Support initializing anonymous struct type
This commit adds support for initializing `.anon_struct` types. There
is also some follow-up work to do for both tuples and structs regarding
comptime fields, so this also adds some tests to keep track of that
work.
Diffstat (limited to 'test/behavior/tuple.zig')
| -rw-r--r-- | test/behavior/tuple.zig | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig index 13772865ef..7cec421588 100644 --- a/test/behavior/tuple.zig +++ b/test/behavior/tuple.zig @@ -197,3 +197,61 @@ test "initializing tuple with explicit type" { var a = T{ 0, 0 }; _ = a; } + +test "initializing anon struct with explicit type" { + const T = @TypeOf(.{ .foo = @as(i32, 1), .bar = @as(i32, 2) }); + var a = T{ .foo = 1, .bar = 2 }; + _ = a; +} + +test "fieldParentPtr of tuple" { + if (builtin.zig_backend != .stage1) return error.SkipZigTest; + + var x: u32 = 0; + const tuple = .{ x, x }; + try testing.expect(&tuple == @fieldParentPtr(@TypeOf(tuple), "1", &tuple[1])); +} + +test "fieldParentPtr of anon struct" { + if (builtin.zig_backend != .stage1) return error.SkipZigTest; + + var x: u32 = 0; + const anon_st = .{ .foo = x, .bar = x }; + try testing.expect(&anon_st == @fieldParentPtr(@TypeOf(anon_st), "bar", &anon_st.bar)); +} + +test "offsetOf tuple" { + if (builtin.zig_backend != .stage1) return error.SkipZigTest; + + var x: u32 = 0; + const T = @TypeOf(.{ x, x }); + + _ = @offsetOf(T, "1"); +} + +test "offsetOf anon struct" { + if (builtin.zig_backend != .stage1) return error.SkipZigTest; + + var x: u32 = 0; + const T = @TypeOf(.{ .foo = x, .bar = x }); + + _ = @offsetOf(T, "bar"); +} + +test "initializing tuple with mixed comptime-runtime fields" { + if (true) return error.SkipZigTest; // TODO + + var x: u32 = 15; + const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); + var a: T = .{ -1234, 5678, x + 1 }; + _ = a; +} + +test "initializing anon struct with mixed comptime-runtime fields" { + if (true) return error.SkipZigTest; // TODO + + var x: u32 = 15; + const T = @TypeOf(.{ .foo = @as(i32, -1234), .bar = x }); + var a: T = .{ .foo = -1234, .bar = x + 1 }; + _ = a; +} |
