1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
const expect = @import("std").testing.expect;
const Color = enum { auto, off, on };
test "enum literals" {
const color1: Color = .auto;
const color2 = Color.auto;
expect(color1 == color2);
expect(color1 == .auto);
}
test "switch using enum literals" {
expect(switch (Color.on) {
.auto => false,
.on => true,
.off => false,
});
}
const Number = enum(u8) { one, two, three, _ };
test "switch on non-exhaustive enum" {
const number = Number.one;
expect(switch (number) {
.one => true,
.two,
.three => false,
_ => false,
});
const is_one = switch (number) {
.one => true,
else => false,
};
expect(is_one);
}
|