Change Engine::consume_XXX to Engine::run_XXX.

This commit is contained in:
Stephen Chung
2021-08-06 14:46:27 +08:00
parent e0125a1033
commit 180ad77224
23 changed files with 160 additions and 67 deletions

View File

@@ -15,7 +15,7 @@ fn test_constant() -> Result<(), Box<EvalAltResult>> {
#[cfg(not(feature = "no_index"))]
assert!(matches!(
*engine.consume("const x = [1, 2, 3, 4, 5]; x[2] = 42;").expect_err("expects error"),
*engine.run("const x = [1, 2, 3, 4, 5]; x[2] = 42;").expect_err("expects error"),
EvalAltResult::ErrorAssignmentToConstant(x, _) if x == "x"
));
@@ -30,7 +30,7 @@ fn test_constant_scope() -> Result<(), Box<EvalAltResult>> {
scope.push_constant("x", 42 as INT);
assert!(matches!(
*engine.consume_with_scope(&mut scope, "x = 1").expect_err("expects error"),
*engine.run_with_scope(&mut scope, "x = 1").expect_err("expects error"),
EvalAltResult::ErrorAssignmentToConstant(x, _) if x == "x"
));
@@ -80,7 +80,7 @@ fn test_constant_mut() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine
.consume(
.run(
"
const MY_NUMBER = new_ts();
MY_NUMBER.value = 42;
@@ -118,7 +118,7 @@ fn test_constant_mut() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine
.consume_with_scope(&mut scope, "MY_NUMBER.value = 42;")
.run_with_scope(&mut scope, "MY_NUMBER.value = 42;")
.expect_err("should error"),
EvalAltResult::ErrorAssignmentToConstant(_, _)
));

View File

@@ -6,7 +6,7 @@ use rhai::{
fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
let mut engine = Engine::new();
engine.consume("while false {}")?;
engine.run("while false {}")?;
// Disable 'while' and make sure it still works with custom syntax
engine.disable_symbol("while");
@@ -79,7 +79,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine
.consume("let foo = (exec [x<<15] -> { x += 2 } while x < 42) * 10;")
.run("let foo = (exec [x<<15] -> { x += 2 } while x < 42) * 10;")
.expect_err("should error"),
EvalAltResult::ErrorRuntime(_, _)
));

View File

@@ -208,7 +208,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine
.consume(
.run(
"
let x = #{};
loop { x.a = x; }

View File

@@ -368,7 +368,7 @@ fn test_module_from_ast() -> Result<(), Box<EvalAltResult>> {
);
assert!(matches!(
*engine
.consume(r#"import "testing" as ttt; ttt::hidden()"#)
.run(r#"import "testing" as ttt; ttt::hidden()"#)
.expect_err("should error"),
EvalAltResult::ErrorFunctionNotFound(fn_name, _) if fn_name == "ttt::hidden ()"
));
@@ -498,7 +498,7 @@ fn test_module_ast_namespace2() -> Result<(), Box<EvalAltResult>> {
static_modules.insert("test_module", module);
engine.set_module_resolver(static_modules);
engine.consume(SCRIPT)?;
engine.run(SCRIPT)?;
Ok(())
}

View File

@@ -87,11 +87,11 @@ fn test_plugins_package() -> Result<(), Box<EvalAltResult>> {
#[cfg(not(feature = "no_object"))]
{
assert_eq!(engine.eval::<INT>("let a = [1, 2, 3]; a.foo")?, 1);
engine.consume("const A = [1, 2, 3]; A.no_effect(42);")?;
engine.consume("const A = [1, 2, 3]; A.no_effect = 42;")?;
engine.run("const A = [1, 2, 3]; A.no_effect(42);")?;
engine.run("const A = [1, 2, 3]; A.no_effect = 42;")?;
assert!(
matches!(*engine.consume("const A = [1, 2, 3]; A.test(42);").expect_err("should error"),
matches!(*engine.run("const A = [1, 2, 3]; A.test(42);").expect_err("should error"),
EvalAltResult::ErrorAssignmentToConstant(x, _) if x == "array")
)
}

View File

@@ -50,10 +50,10 @@ fn test_print_debug() -> Result<(), Box<EvalAltResult>> {
});
// Evaluate script
engine.consume("print(40 + 2)")?;
engine.run("print(40 + 2)")?;
let mut ast = engine.compile(r#"let x = "hello!"; debug(x)"#)?;
ast.set_source("world");
engine.consume_ast(&ast)?;
engine.run_ast(&ast)?;
// 'logbook' captures all the 'print' and 'debug' output
assert_eq!(logbook.read().unwrap().len(), 2);
@@ -96,7 +96,7 @@ fn test_print_custom_type() -> Result<(), Box<EvalAltResult>> {
.register_fn("debug", |x: &mut MyStruct| x.to_string())
.register_fn("new_ts", || MyStruct { field: 42 });
engine.consume("let x = new_ts(); debug(x);")?;
engine.run("let x = new_ts(); debug(x);")?;
#[cfg(not(feature = "no_index"))]
assert_eq!(

View File

@@ -74,7 +74,7 @@ fn test_side_effects_print() -> Result<(), Box<EvalAltResult>> {
let logger = result.clone();
engine.on_print(move |s| logger.write().unwrap().push_str(s));
engine.consume("print(40 + 2);")?;
engine.run("print(40 + 2);")?;
assert_eq!(*result.read().unwrap(), "42");
Ok(())

View File

@@ -57,9 +57,9 @@ fn test_infinite_loops() -> Result<(), Box<EvalAltResult>> {
engine.set_max_operations(1024);
assert!(engine.consume("loop {}").is_err());
assert!(engine.consume("while true {}").is_err());
assert!(engine.consume("do {} while true").is_err());
assert!(engine.run("loop {}").is_err());
assert!(engine.run("while true {}").is_err());
assert!(engine.run("do {} while true").is_err());
Ok(())
}