add behavior test case for anon union literal

master
Andrew Kelley 2019-11-11 11:14:45 -05:00
parent 5b27943498
commit b4ad3e71af
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
1 changed files with 18 additions and 0 deletions

View File

@ -549,3 +549,21 @@ test "initialize global array of union" {
expect(glbl_array[0].U0 == 1);
expect(glbl_array[1].U1 == 2);
}
test "anonymous union literal syntax" {
const S = struct {
const Number = union {
int: i32,
float: f64,
};
fn doTheTest() void {
var i: Number = .{.int = 42};
var f: Number = .{.float = 12.34};
expect(i.int == 42);
expect(f.float == 12.34);
}
};
S.doTheTest();
comptime S.doTheTest();
}