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

test "simple union" {
    var payload = Payload{ .int = 1234 };
    expect(payload.int == 1234);
    // Nope this is not how it works.
    // payload.float = 12.34;
    payload = Payload{ .float = 12.34 };
    expect(payload.float == 12.34);
}