2020-03-17 10:33:37 +01:00
|
|
|
use rhai::{Engine, EvalAltResult, INT};
|
2017-11-03 17:58:51 +01:00
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_loop() -> Result<(), EvalAltResult> {
|
2019-09-18 12:21:07 +02:00
|
|
|
let mut engine = Engine::new();
|
2017-11-03 17:58:51 +01:00
|
|
|
|
2020-03-17 10:33:37 +01:00
|
|
|
assert_eq!(
|
|
|
|
engine.eval::<INT>(
|
|
|
|
r"
|
|
|
|
let x = 0;
|
|
|
|
let i = 0;
|
2017-11-03 17:58:51 +01:00
|
|
|
|
2020-03-17 10:33:37 +01:00
|
|
|
loop {
|
|
|
|
if i < 10 {
|
2020-04-01 10:22:18 +02:00
|
|
|
i += 1;
|
|
|
|
if x > 20 { continue; }
|
2020-03-17 10:33:37 +01:00
|
|
|
x = x + i;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 10:33:37 +01:00
|
|
|
return x;
|
2019-09-18 12:21:07 +02:00
|
|
|
"
|
2020-03-17 10:33:37 +01:00
|
|
|
)?,
|
2020-04-01 10:22:18 +02:00
|
|
|
21
|
2020-03-17 10:33:37 +01:00
|
|
|
);
|
2020-03-02 15:11:56 +01:00
|
|
|
|
|
|
|
Ok(())
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|