zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

test_inline_while.zig (454B) - Raw


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