1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/compiler/tests/match_test.v
Delyan Angelov 53c64abdeb compiler: make compiler an ordinary vlib/compiler module
* Move compiler/ under vlib/compiler/ .

* Add a minimal compiler/main.v driver program.

* Cleanup compiler/main.v .

* Make most compiler tests pass again.

* Apply the fix by @joe-conigliaro , so that the rest of the compiler tests are fixed too.

* Thanks to @avitkauskas, now the vlib/vcompiler/tests/str_gen_test.v test does not need to be special cased anymore.

* Reapply @joe-conigliaro fix for vgen.
2019-10-13 16:37:43 +03:00

89 lines
1.3 KiB
V

enum Color{
red, green, blue
}
fn test_match_integers() {
// a := 3
// mut b := 0
// match a {
// 2 => println('two')
// 3 => println('three')
// b = 3
// 4 => println('four')
// else => println('???')
// }
// assert b == 3
assert match 2 {
1 => {2}
2 => {3}
else => {5}
} == 3
assert match 0 {
1 => {2}
2 => {3}
else => 5
} == 5
assert match 1 {
else => {5}
} == 5
mut a := 0
match 2 {
0 => {a = 1}
1 => {a = 2}
else => {
a = 3
println('a is $a')
}
}
assert a == 3
a = 0
match 1 {
0 => {a = 1}
1 => {
a = 2
a = a + 2
a = a + 2
}
}
assert a == 6
a = 0
match 1 {
else => {
a = -2
}
}
assert a == -2
}
fn test_match_enums(){
mut b := Color.red
match b{
.red => {
b = .green
}
.green => {b = .blue}
else => {
println('b is ${b.str()}')
b = .red
}
}
assert b == .green
match b{
.red => {
b = .green
}
else => {
println('b is ${b.str()}')
b = .blue
}
}
assert b == .blue
}