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 {
|
2024-02-18 15:53:34 +00:00
|
|
|
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 {
|
2024-02-18 15:53:34 +00:00
|
|
|
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 {
|
2024-02-18 15:53:34 +00:00
|
|
|
Option::None -> false,
|
|
|
|
Option::Some(content) -> content,
|
2024-02-15 12:04:38 +00:00
|
|
|
}
|
|
|
|
",
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(result, Ok(Value::Boolean(true)));
|
|
|
|
}
|