| 1 | @[comptime] |
| 2 | fn pack_color(r u8, g u8, b u8, a u8) u32 { |
| 3 | return (u32(r) << 24) | (u32(g) << 16) | (u32(b) << 8) | u32(a) |
| 4 | } |
| 5 | |
| 6 | enum Colors as u32 { |
| 7 | red = pack_color(255, 0, 0, 255) |
| 8 | green = pack_color(0, 255, 0, 255) |
| 9 | blue = pack_color(0, 0, 255, 255) |
| 10 | } |
| 11 | |
| 12 | enum CastedColors { |
| 13 | red = int(pack_color(1, 2, 3, 4)) |
| 14 | green = int(pack_color(5, 6, 7, 8)) |
| 15 | blue = int(pack_color(9, 10, 11, 12)) |
| 16 | } |
| 17 | |
| 18 | fn test_enum_values_from_comptime_function_calls() { |
| 19 | assert u32(Colors.red) == u32(0xff0000ff) |
| 20 | assert u32(Colors.green) == u32(0x00ff00ff) |
| 21 | assert u32(Colors.blue) == u32(0x0000ffff) |
| 22 | } |
| 23 | |
| 24 | fn test_enum_values_from_casted_comptime_function_calls() { |
| 25 | assert int(CastedColors.red) == 0x01020304 |
| 26 | assert int(CastedColors.green) == 0x05060708 |
| 27 | assert int(CastedColors.blue) == 0x090a0b0c |
| 28 | } |
| 29 | |