zig

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

test_switch_non-exhaustive.zig (465B) - Raw


      1 const std = @import("std");
      2 const expect = std.testing.expect;
      3 
      4 const Number = enum(u8) {
      5     one,
      6     two,
      7     three,
      8     _,
      9 };
     10 
     11 test "switch on non-exhaustive enum" {
     12     const number = Number.one;
     13     const result = switch (number) {
     14         .one => true,
     15         .two, .three => false,
     16         _ => false,
     17     };
     18     try expect(result);
     19     const is_one = switch (number) {
     20         .one => true,
     21         else => false,
     22     };
     23     try expect(is_one);
     24 }
     25 
     26 // test