Set allow_loop_expressions to true by default.
This commit is contained in:
@@ -20,7 +20,7 @@ fn test_loop() -> Result<(), Box<EvalAltResult>> {
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
x
|
||||
"
|
||||
)?,
|
||||
21
|
||||
@@ -53,3 +53,43 @@ fn test_loop() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_loop_expression() -> Result<(), Box<EvalAltResult>> {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
"
|
||||
let x = 0;
|
||||
|
||||
let value = while x < 10 {
|
||||
if x % 5 == 0 { break 42; }
|
||||
x += 1;
|
||||
};
|
||||
|
||||
value
|
||||
"
|
||||
)?,
|
||||
42
|
||||
);
|
||||
|
||||
engine.set_allow_loop_expressions(false);
|
||||
|
||||
assert!(engine
|
||||
.eval::<INT>(
|
||||
"
|
||||
let x = 0;
|
||||
|
||||
let value = while x < 10 {
|
||||
if x % 5 == 0 { break 42; }
|
||||
x += 1;
|
||||
};
|
||||
|
||||
value
|
||||
"
|
||||
)
|
||||
.is_err());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user