2020-03-10 12:48:47 +01:00
|
|
|
#![cfg(not(feature = "no_index"))]
|
2020-03-10 16:06:20 +01:00
|
|
|
use rhai::{Engine, EvalAltResult, INT};
|
2020-02-23 15:48:46 +01:00
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_for() -> Result<(), EvalAltResult> {
|
2020-02-23 15:48:46 +01:00
|
|
|
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
|
|
|
|
";
|
|
|
|
|
2020-03-10 16:06:20 +01:00
|
|
|
assert_eq!(engine.eval::<INT>(script)?, 30);
|
2020-03-02 15:11:56 +01:00
|
|
|
|
|
|
|
Ok(())
|
2020-02-23 15:48:46 +01:00
|
|
|
}
|