about summary refs log tree commit diff
path: root/lang/zig/union-anon.zig
blob: d26dcae7a569e93a2022ec799639297741b83d6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
const expect = @import("std").testing.expect;
const Number = union { int: i32, float: f64 };

fn makeNumber() Number {
    return .{.float = 12.34};
}

test "anonymous union literal syntax" {
    var i: Number = .{.int = 42};
    var f = makeNumber();
    expect(i.int == 42);
    expect(f.float == 12.34);
}