| 1 | const std = @import("std"); |
| 2 | const expectEqual = std.testing.expectEqual; |
| 3 | |
| 4 | const Number = union { |
| 5 | int: i32, |
| 6 | float: f64, |
| 7 | }; |
| 8 | |
| 9 | test "anonymous union literal syntax" { |
| 10 | const i: Number = .{ .int = 42 }; |
| 11 | const f = makeNumber(); |
| 12 | try expectEqual(42, i.int); |
| 13 | try expectEqual(12.34, f.float); |
| 14 | } |
| 15 | |
| 16 | fn makeNumber() Number { |
| 17 | return .{ .float = 12.34 }; |
| 18 | } |
| 19 | |
| 20 | // test |