Add for statement and range function; New register_box_fn for functions returning Box<dyn Any> (which should not be boxed again); Register standard utility functions in library (e.g. print, string concat).
This commit is contained in:
24
tests/for.rs
Normal file
24
tests/for.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use rhai::Engine;
|
||||
|
||||
#[test]
|
||||
fn test_for() {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
let script = r"
|
||||
let sum1 = 0;
|
||||
let sum2 = 0;
|
||||
let inputs = [1, 2, 3, 4, 5];
|
||||
|
||||
for x in inputs {
|
||||
sum1 += x;
|
||||
}
|
||||
|
||||
for x in range(1, 6) {
|
||||
sum2 += x;
|
||||
}
|
||||
|
||||
sum1 + sum2
|
||||
";
|
||||
|
||||
assert_eq!(engine.eval::<i64>(script).unwrap(), 30);
|
||||
}
|
Reference in New Issue
Block a user