diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-02-28 17:18:03 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-02-28 17:18:03 +0700 |
commit | ee9b8fc921f48dc893808e1c9dbfbef321aa362c (patch) | |
tree | 0d0a5247b139ba68d2c2aa2d94e1d631476dbc62 /lang/zig/switch-enum-literal.zig | |
parent | 2b91f9554b326aea138bd8a0acbfaa10d9ad59aa (diff) | |
download | cp-ee9b8fc921f48dc893808e1c9dbfbef321aa362c.tar.gz |
[lang/zig] Learn some Zig
Diffstat (limited to 'lang/zig/switch-enum-literal.zig')
-rw-r--r-- | lang/zig/switch-enum-literal.zig | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lang/zig/switch-enum-literal.zig b/lang/zig/switch-enum-literal.zig new file mode 100644 index 0000000..550de93 --- /dev/null +++ b/lang/zig/switch-enum-literal.zig @@ -0,0 +1,13 @@ +const std = @import("std"); +const expect = std.testing.expect; + +const Color = enum { auto, off, on }; + +test "enum literals with switch" { + const color = Color.off; + const result = switch (color) { + .auto, .on => false, + .off => true, + }; + expect(result); +} |