v/vlib/compiler/tests/enum_test.v

39 lines
606 B
V
Raw Normal View History

2019-07-13 08:45:40 +02:00
enum Color {
red
blue
green
}
fn test_enum() {
assert Color.red == .red
assert Color.blue == .blue
assert Color.green == .green
2019-10-30 14:38:47 +01:00
assert Color.red != .blue
assert Color.red != .green
assert Color.blue != .green
2019-07-13 08:45:40 +02:00
mut color := Color.red
2019-10-30 14:38:47 +01:00
assert color == .red
2019-07-13 08:45:40 +02:00
color = .green
2019-10-30 14:38:47 +01:00
assert color == .green
2019-07-13 08:45:40 +02:00
}
2019-10-24 13:56:02 +02:00
fn test_in() {
color := Color.red
num := 3 // used to be an expr bug before `in`
2019-10-24 13:56:02 +02:00
assert color in [.red, .green]
assert num == 3
2019-10-24 13:56:02 +02:00
}
fn test_match() {
color := Color.red
num := 3
match color {
.red { assert true }
.green { assert false }
else { assert false }
}
assert num == 3
}