1
0
dust/tests/match.rs

51 lines
818 B
Rust
Raw Normal View History

2024-01-06 07:26:51 +00:00
use dust_lang::*;
#[test]
2024-02-15 12:04:38 +00:00
fn match_value() {
2024-01-06 07:26:51 +00:00
let test = interpret(
"
2024-02-15 12:04:38 +00:00
match 1 {
3 -> false
2 -> { false }
1 -> true
2024-02-15 12:04:38 +00:00
}
",
2024-01-06 07:26:51 +00:00
)
.unwrap();
assert_eq!(Value::Boolean(true), test);
}
#[test]
fn match_assignment() {
let test = interpret(
"
2024-02-15 12:04:38 +00:00
x = match 1 {
3 -> false
2 -> { false }
1 -> true
2024-02-15 12:04:38 +00:00
}
x
",
2024-01-06 07:26:51 +00:00
)
.unwrap();
assert_eq!(Value::Boolean(true), test);
}
2024-02-15 12:04:38 +00:00
#[test]
fn match_enum() {
let result = interpret(
"
foobar = Option::Some(true)
match foobar {
Option::None -> false,
Option::Some(content) -> content,
2024-02-15 12:04:38 +00:00
}
",
);
assert_eq!(result, Ok(Value::Boolean(true)));
}