1
0
dust/tests/for_loop.rs

74 lines
1.3 KiB
Rust
Raw Normal View History

2024-01-06 07:26:51 +00:00
use dust_lang::*;
#[test]
fn simple_for_loop() {
let result = interpret("for i in [1 2 3] { output(i) }");
assert_eq!(Ok(Value::none()), result);
}
#[test]
fn modify_value() {
let result = interpret(
"
list = []
for i in [1 2 3] { list += i }
list
",
);
assert_eq!(
Ok(Value::List(List::with_items(vec![
Value::Integer(1),
Value::Integer(2),
Value::Integer(3),
]))),
result
);
}
2024-01-30 05:24:13 +00:00
#[test]
fn modify_iteration_values() {
let result = interpret(
"
list = [1 2 3]
for i in list { i += i }
list
",
);
assert_eq!(
Ok(Value::List(List::with_items(vec![
Value::Integer(2),
Value::Integer(3),
Value::Integer(4),
]))),
result
);
}
#[test]
fn r#break() {
let result = interpret(
"
list = []
for i in [1 2 3] {
if i > 2 {
break
} else {
list += i
}
}
list
",
);
assert_eq!(
Ok(Value::List(List::with_items(vec![
Value::Integer(1),
Value::Integer(2),
]))),
result
);
}