mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
21 lines
361 B
Zig
21 lines
361 B
Zig
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
|
|
const Number = union {
|
|
int: i32,
|
|
float: f64,
|
|
};
|
|
|
|
test "anonymous union literal syntax" {
|
|
const i: Number = .{ .int = 42 };
|
|
const f = makeNumber();
|
|
try expect(i.int == 42);
|
|
try expect(f.float == 12.34);
|
|
}
|
|
|
|
fn makeNumber() Number {
|
|
return .{ .float = 12.34 };
|
|
}
|
|
|
|
// test
|