rhai/tests/looping.rs

28 lines
337 B
Rust
Raw Normal View History

2020-03-02 15:11:56 +01:00
use rhai::{Engine, EvalAltResult};
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-02 15:11:56 +01:00
assert!(engine.eval::<bool>(
r"
2017-11-03 17:58:51 +01:00
let x = 0;
let i = 0;
loop {
if i < 10 {
x = x + i;
i = i + 1;
}
else {
break;
}
}
x == 45
2019-09-18 12:21:07 +02:00
"
2020-03-02 15:11:56 +01:00
)?);
Ok(())
2017-11-03 17:58:51 +01:00
}