test_anonymous_union.zig (361B) - Raw
1 const std = @import("std"); 2 const expect = std.testing.expect; 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 expect(i.int == 42); 13 try expect(f.float == 12.34); 14 } 15 16 fn makeNumber() Number { 17 return .{ .float = 12.34 }; 18 } 19 20 // test