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