v2 / vlib / v / tests / enums / enum_short_infix_commutative_test.v
34 lines · 28 sloc · 611 bytes · 527e1c03b7f8523ca9de50612b3db5b5ef9d4af8
Raw
1enum EnumCommutative {
2 a
3 b
4}
5
6fn short_eq_left(x EnumCommutative) bool {
7 return .a == x
8}
9
10fn short_eq_right(x EnumCommutative) bool {
11 return x == .a
12}
13
14fn short_ne_left(x EnumCommutative) bool {
15 return .a != x
16}
17
18fn short_ne_right(x EnumCommutative) bool {
19 return x != .a
20}
21
22fn test_short_enum_infix_equality_is_commutative() {
23 assert short_eq_left(.a)
24 assert short_eq_right(.a)
25 assert !short_eq_left(.b)
26 assert !short_eq_right(.b)
27}
28
29fn test_short_enum_infix_inequality_is_commutative() {
30 assert !short_ne_left(.a)
31 assert !short_ne_right(.a)
32 assert short_ne_left(.b)
33 assert short_ne_right(.b)
34}
35