mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-26 13:01:34 +03:00
21 lines
377 B
Zig
21 lines
377 B
Zig
const std = @import("std");
|
|
const expectEqual = std.testing.expectEqual;
|
|
|
|
const Number = union {
|
|
int: i32,
|
|
float: f64,
|
|
};
|
|
|
|
test "anonymous union literal syntax" {
|
|
const i: Number = .{ .int = 42 };
|
|
const f = makeNumber();
|
|
try expectEqual(42, i.int);
|
|
try expectEqual(12.34, f.float);
|
|
}
|
|
|
|
fn makeNumber() Number {
|
|
return .{ .float = 12.34 };
|
|
}
|
|
|
|
// test
|