Fix test.

This commit is contained in:
Stephen Chung 2022-10-18 16:54:26 +08:00
parent 4642895de8
commit d49dca8a29
2 changed files with 75 additions and 78 deletions

View File

@ -358,24 +358,14 @@ impl Engine {
});
match guard_val {
Ok(true) => {
if if_block.is_empty() {
Ok(Dynamic::UNIT)
} else {
self.eval_stmt_block(
Ok(true) if if_block.is_empty() => Ok(Dynamic::UNIT),
Ok(true) => self.eval_stmt_block(
scope, global, caches, lib, this_ptr, if_block, true, level,
)
}
}
Ok(false) => {
if else_block.is_empty() {
Ok(Dynamic::UNIT)
} else {
self.eval_stmt_block(
),
Ok(false) if else_block.is_empty() => Ok(Dynamic::UNIT),
Ok(false) => self.eval_stmt_block(
scope, global, caches, lib, this_ptr, else_block, true, level,
)
}
}
),
err => err.map(Into::into),
}
}
@ -490,15 +480,18 @@ impl Engine {
}
// Loop
Stmt::While(x, ..) if matches!(x.0, Expr::Unit(..)) => loop {
Stmt::While(x, ..) if matches!(x.0, Expr::Unit(..) | Expr::BoolConstant(true, ..)) => {
let (.., body) = &**x;
if body.is_empty() {
loop {
self.track_operation(global, body.position())?;
}
} else {
match self
.eval_stmt_block(scope, global, caches, lib, this_ptr, body, true, level)
{
loop {
match self.eval_stmt_block(
scope, global, caches, lib, this_ptr, body, true, level,
) {
Ok(_) => (),
Err(err) => match *err {
ERR::LoopBreak(false, ..) => (),
@ -507,12 +500,14 @@ impl Engine {
},
}
}
},
}
}
// While loop
Stmt::While(x, ..) => loop {
Stmt::While(x, ..) => {
let (expr, body) = &**x;
loop {
let condition = self
.eval_expr(scope, global, caches, lib, this_ptr, expr, level)
.and_then(|v| {
@ -538,17 +533,19 @@ impl Engine {
}
err => break err.map(|_| Dynamic::UNIT),
}
},
}
}
// Do loop
Stmt::Do(x, options, ..) => loop {
Stmt::Do(x, options, ..) => {
let (expr, body) = &**x;
let is_while = !options.contains(ASTFlags::NEGATED);
loop {
if !body.is_empty() {
match self
.eval_stmt_block(scope, global, caches, lib, this_ptr, body, true, level)
{
match self.eval_stmt_block(
scope, global, caches, lib, this_ptr, body, true, level,
) {
Ok(_) => (),
Err(err) => match *err {
ERR::LoopBreak(false, ..) => continue,
@ -571,7 +568,8 @@ impl Engine {
Ok(_) => (),
err => break err.map(|_| Dynamic::UNIT),
}
},
}
}
// For loop
Stmt::For(x, ..) => {

View File

@ -1,5 +1,4 @@
#![cfg(not(feature = "no_std"))]
#![cfg(not(target_family = "wasm"))]
#![cfg(not(feature = "no_time"))]
use rhai::{Engine, EvalAltResult};