1
0
dust/tests/statements.rs

53 lines
946 B
Rust
Raw Permalink Normal View History

2024-03-08 17:24:11 +00:00
use dust_lang::*;
#[test]
fn loops_and_breaks() {
assert_eq!(
interpret(
"
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(
"
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-11 19:17:01 +00:00
interpret("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-11 19:17:01 +00:00
interpret("if false { 'foo' } else { 'bar' }"),
Ok(Some(Value::string("bar".to_string())))
2024-03-08 19:29:53 +00:00
)
}