zig

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

test_enum_literals.zig (450B) - Raw


      1 const std = @import("std");
      2 const expect = std.testing.expect;
      3 
      4 const Color = enum {
      5     auto,
      6     off,
      7     on,
      8 };
      9 
     10 test "enum literals" {
     11     const color1: Color = .auto;
     12     const color2 = Color.auto;
     13     try expect(color1 == color2);
     14 }
     15 
     16 test "switch using enum literals" {
     17     const color = Color.on;
     18     const result = switch (color) {
     19         .auto => false,
     20         .on => true,
     21         .off => false,
     22     };
     23     try expect(result);
     24 }
     25 
     26 // test