| 1 | const expectEqual = @import("std").testing.expectEqual; |
| 2 | |
| 3 | test "inline for loop" { |
| 4 | const nums = [_]i32{ 2, 4, 6 }; |
| 5 | var sum: usize = 0; |
| 6 | inline for (nums) |i| { |
| 7 | const T = switch (i) { |
| 8 | 2 => f32, |
| 9 | 4 => i8, |
| 10 | 6 => bool, |
| 11 | else => unreachable, |
| 12 | }; |
| 13 | sum += typeNameLength(T); |
| 14 | } |
| 15 | try expectEqual(9, sum); |
| 16 | } |
| 17 | |
| 18 | fn typeNameLength(comptime T: type) usize { |
| 19 | return @typeName(T).len; |
| 20 | } |
| 21 | |
| 22 | // test |