mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
22 lines
452 B
Zig
22 lines
452 B
Zig
const expect = @import("std").testing.expect;
|
|
|
|
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 expect(sum == 9);
|
|
}
|
|
|
|
fn typeNameLength(comptime T: type) usize {
|
|
return @typeName(T).len;
|
|
}
|
|
|
|
// test
|