about summary refs log tree commit diff
path: root/lang/zig/while-inline.zig
blob: 2af11600187d2973b5373f5fa842fbae3070e095 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const expect = @import("std").testing.expect;

fn typeNameLength(comptime T: type) usize {
    return @typeName(T).len;
}

test "inline while loop" {
    comptime var i = 0;
    var sum: usize = 0;
    inline while (i < 3) : (i += 1) {
        const T = switch (i) {
            0 => f32,
            1 => i8,
            2 => bool,
            else => unreachable,
        };
        sum += typeNameLength(T);
    }
    expect(sum == 9);
}