mirror of https://git.sr.ht/~garritfra/sabre
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
708 B
38 lines
708 B
3 years ago
|
fn test_basic_match() {
|
||
|
let x = 1
|
||
|
|
||
|
match x {
|
||
|
1 => assert(true)
|
||
|
2 => assert(false)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn test_boolean_match() {
|
||
|
let x = true
|
||
|
|
||
|
match x {
|
||
|
true => assert(true)
|
||
|
false => assert(false)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn test_match_with_block_statement() {
|
||
|
let x = 42
|
||
|
|
||
|
match x {
|
||
|
1 => println("x is 1")
|
||
|
2 => {
|
||
|
println("This is a branch with multiple statements.")
|
||
|
println("x is 2, in case you are wondering")
|
||
|
}
|
||
|
42 => println("The answer to the universe and everything!")
|
||
|
else => println("Default case")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
test_basic_match()
|
||
|
test_boolean_match()
|
||
|
test_match_with_block_statement()
|
||
|
}
|