mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 07:44:51 +01:00
22 lines
467 B
Zig
22 lines
467 B
Zig
const expectEqual = @import("std").testing.expectEqual;
|
|
|
|
test "inline for loop" {
|
|
const nums = [_]i32{ 2, 4, 6 };
|
|
var sum: usize = 0;
|
|
inline for (nums) |i| {
|
|
const T = switch (i) {
|
|
2 => f32,
|
|
4 => i8,
|
|
6 => bool,
|
|
else => unreachable,
|
|
};
|
|
sum += typeNameLength(T);
|
|
}
|
|
try expectEqual(9, sum);
|
|
}
|
|
|
|
fn typeNameLength(comptime T: type) usize {
|
|
return @typeName(T).len;
|
|
}
|
|
|
|
// test
|