1
0
dust/dust-lang/tests/statements.rs

75 lines
1.3 KiB
Rust
Raw Permalink Normal View History

2024-06-26 20:24:41 +00:00
mod validation;
2024-03-08 17:24:11 +00:00
use dust_lang::*;
2024-03-20 21:18:47 +00:00
#[test]
fn async_block() {
assert_eq!(
interpret(
2024-03-24 19:35:19 +00:00
"test",
2024-03-20 21:18:47 +00:00
"
x = 41
async {
x += 1
5
}
x
"
),
Ok(Some(Value::integer(42)))
)
}
2024-03-08 17:24:11 +00:00
#[test]
fn loops_and_breaks() {
assert_eq!(
interpret(
2024-03-24 19:35:19 +00:00
"test",
2024-03-08 17:24:11 +00:00
"
2024-03-11 19:17:01 +00:00
i = 0
2024-03-08 17:24:11 +00:00
loop {
if i == 3 {
2024-03-11 19:17:01 +00:00
break
2024-03-08 17:24:11 +00:00
} else {
i += 1
}
}
2024-03-11 19:17:01 +00:00
i
2024-03-08 17:24:11 +00:00
"
),
2024-03-11 19:17:01 +00:00
Ok(Some(Value::integer(3)))
);
assert_eq!(
interpret(
2024-03-24 19:35:19 +00:00
"test",
"
foobar = {
while true {
break
}
'foobar'
}
foobar
"
),
Ok(Some(Value::string("foobar".to_string())))
);
2024-03-08 17:24:11 +00:00
}
2024-03-08 19:29:53 +00:00
#[test]
fn r#if() {
assert_eq!(
2024-03-24 19:35:19 +00:00
interpret("test", "if true { 'foobar' }"),
Ok(Some(Value::string("foobar".to_string())))
2024-03-08 19:29:53 +00:00
)
}
#[test]
fn if_else() {
assert_eq!(
2024-03-24 19:35:19 +00:00
interpret("test", "if false { 'foo' } else { 'bar' }"),
Ok(Some(Value::string("bar".to_string())))
2024-03-08 19:29:53 +00:00
)
}