rhai/tests/while_loop.rs
Stephen Chung 6069a4cf55 do loop.
2020-11-20 22:23:37 +08:00

52 lines
957 B
Rust

use rhai::{Engine, EvalAltResult, INT};
#[test]
fn test_while() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(
engine.eval::<INT>(
r"
let x = 0;
while x < 10 {
x += 1;
if x > 5 { break; }
if x > 3 { continue; }
x += 3;
}
x
",
)?,
6
);
Ok(())
}
#[test]
fn test_do() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(
engine.eval::<INT>(
r"
let x = 0;
do {
x += 1;
if x > 5 { break; }
if x > 3 { continue; }
x += 3;
} while x < 10;
x
",
)?,
6
);
Ok(())
}