diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f75f681..013025aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Version 1.1.0 Enhancements ------------ +* `Engine::consume_XXX` methods are renamed to `Engine::run_XXX` to make meanings clearer. The `consume_XXX` API is deprecated. * `$symbol$` is supported in custom syntax to match any symbol. * Custom syntax with `$block$`, `}` or `;` as the last symbol are now self-terminating (i.e. no need to attach a terminating `;`). * `Dynamic::as_string` and `Dynamic::as_immutable_string` are deprecated and replaced by `into_string` and `into_immutable_string` respectively. diff --git a/benches/eval_array.rs b/benches/eval_array.rs index 0689bf4f..9dcf2129 100644 --- a/benches/eval_array.rs +++ b/benches/eval_array.rs @@ -15,7 +15,7 @@ fn bench_eval_array_small_get(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -27,7 +27,7 @@ fn bench_eval_array_small_set(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -43,7 +43,7 @@ fn bench_eval_array_large_get(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -59,7 +59,7 @@ fn bench_eval_array_large_set(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -83,5 +83,5 @@ fn bench_eval_array_loop(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } diff --git a/benches/eval_expression.rs b/benches/eval_expression.rs index 9ef69f00..07050ebf 100644 --- a/benches/eval_expression.rs +++ b/benches/eval_expression.rs @@ -15,7 +15,7 @@ fn bench_eval_expression_single(bench: &mut Bencher) { let ast = engine.compile_expression(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -27,7 +27,7 @@ fn bench_eval_expression_number_literal(bench: &mut Bencher) { let ast = engine.compile_expression(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -39,7 +39,7 @@ fn bench_eval_expression_number_operators(bench: &mut Bencher) { let ast = engine.compile_expression(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -56,7 +56,7 @@ fn bench_eval_expression_optimized_simple(bench: &mut Bencher) { engine.set_optimization_level(OptimizationLevel::Simple); let ast = engine.compile_expression(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -73,7 +73,7 @@ fn bench_eval_expression_optimized_full(bench: &mut Bencher) { engine.set_optimization_level(OptimizationLevel::Full); let ast = engine.compile_expression(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -120,7 +120,7 @@ fn bench_eval_loop_number(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -137,7 +137,7 @@ fn bench_eval_loop_strings_build(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -154,7 +154,7 @@ fn bench_eval_loop_strings_no_build(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -186,7 +186,7 @@ fn bench_eval_switch(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -216,5 +216,5 @@ fn bench_eval_nested_if(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } diff --git a/benches/eval_map.rs b/benches/eval_map.rs index afe8d676..df49dcdf 100644 --- a/benches/eval_map.rs +++ b/benches/eval_map.rs @@ -15,7 +15,7 @@ fn bench_eval_map_small_get(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -27,7 +27,7 @@ fn bench_eval_map_small_set(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -47,7 +47,7 @@ fn bench_eval_map_large_get(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -67,5 +67,5 @@ fn bench_eval_map_large_set(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } diff --git a/benches/eval_module.rs b/benches/eval_module.rs index 9b053bcd..3bb4e04e 100644 --- a/benches/eval_module.rs +++ b/benches/eval_module.rs @@ -31,7 +31,7 @@ fn bench_eval_module(bench: &mut Bencher) { ) .unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] @@ -49,5 +49,5 @@ fn bench_eval_function_call(bench: &mut Bencher) { ) .unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } diff --git a/benches/eval_scope.rs b/benches/eval_scope.rs index 5d38f7d7..2237fa8a 100644 --- a/benches/eval_scope.rs +++ b/benches/eval_scope.rs @@ -18,7 +18,7 @@ fn bench_eval_scope_single(bench: &mut Bencher) { let ast = engine.compile_expression(script).unwrap(); - bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap()); + bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap()); } #[bench] @@ -34,7 +34,7 @@ fn bench_eval_scope_multiple(bench: &mut Bencher) { let ast = engine.compile_expression(script).unwrap(); - bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap()); + bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap()); } #[bench] @@ -50,7 +50,7 @@ fn bench_eval_scope_longer(bench: &mut Bencher) { let ast = engine.compile_expression(script).unwrap(); - bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap()); + bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap()); } #[bench] @@ -73,5 +73,5 @@ fn bench_eval_scope_complex(bench: &mut Bencher) { let ast = engine.compile_expression(script).unwrap(); - bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap()); + bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap()); } diff --git a/benches/eval_type.rs b/benches/eval_type.rs index 469e6332..7cee4394 100644 --- a/benches/eval_type.rs +++ b/benches/eval_type.rs @@ -41,7 +41,7 @@ fn bench_type_field(bench: &mut Bencher) { let mut scope = Scope::new(); scope.push("foo", Test { x: 42 }); - bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap()); + bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap()); } #[bench] @@ -59,7 +59,7 @@ fn bench_type_method(bench: &mut Bencher) { let mut scope = Scope::new(); scope.push("foo", Test { x: 42 }); - bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap()); + bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap()); } #[bench] @@ -77,7 +77,7 @@ fn bench_type_method_with_params(bench: &mut Bencher) { let mut scope = Scope::new(); scope.push("foo", Test { x: 42 }); - bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap()); + bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap()); } #[bench] @@ -96,5 +96,5 @@ fn bench_type_method_nested(bench: &mut Bencher) { let mut scope = Scope::new(); scope.push("foo", Test { x: 42 }); - bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap()); + bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap()); } diff --git a/benches/iterations.rs b/benches/iterations.rs index b70e9432..243756ae 100644 --- a/benches/iterations.rs +++ b/benches/iterations.rs @@ -21,7 +21,7 @@ fn bench_iterations_1000(bench: &mut Bencher) { let ast = engine.compile(script).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } #[bench] diff --git a/benches/primes.rs b/benches/primes.rs index 1b1b022b..e6a059fc 100644 --- a/benches/primes.rs +++ b/benches/primes.rs @@ -39,5 +39,5 @@ fn bench_eval_primes(bench: &mut Bencher) { let ast = engine.compile(SCRIPT).unwrap(); - bench.iter(|| engine.consume_ast(&ast).unwrap()); + bench.iter(|| engine.run_ast(&ast).unwrap()); } diff --git a/examples/hello.rs b/examples/hello.rs index 4133cd3f..7de8898e 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -3,7 +3,7 @@ use rhai::{Engine, EvalAltResult, INT}; fn main() -> Result<(), Box> { let engine = Engine::new(); - engine.consume(r#"print("hello, world!")"#)?; + engine.run(r#"print("hello, world!")"#)?; let result = engine.eval::("40 + 2")?; diff --git a/examples/strings.rs b/examples/strings.rs index ba5749ec..6d0489ef 100644 --- a/examples/strings.rs +++ b/examples/strings.rs @@ -61,7 +61,7 @@ fn main() -> Result<(), Box> { println!("Line: {}", input.replace('\r', "\\r").replace('\n', "\\n")); - engine.consume_with_scope( + engine.run_with_scope( &mut scope, r#" display("Length", x.len()); diff --git a/examples/threading.rs b/examples/threading.rs index ad80aedb..f96a8866 100644 --- a/examples/threading.rs +++ b/examples/threading.rs @@ -34,7 +34,7 @@ fn main() { // Run script engine - .consume( + .run( r#" print("Starting script loop..."); diff --git a/src/bin/rhai-run.rs b/src/bin/rhai-run.rs index 4d1749df..567d4b45 100644 --- a/src/bin/rhai-run.rs +++ b/src/bin/rhai-run.rs @@ -90,7 +90,7 @@ fn main() { .map_err(|err| err.into()) .and_then(|mut ast| { ast.set_source(filename.to_string_lossy().to_string()); - engine.consume_ast(&ast) + engine.run_ast(&ast) }) { let filename = filename.to_string_lossy(); diff --git a/src/dynamic.rs b/src/dynamic.rs index 0a6b50d2..15862f6a 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -1906,7 +1906,7 @@ impl Dynamic { /// This method is deprecated. Use [`into_string`][Dynamic::into_string] instead. /// /// This method will be removed in the next major version. - #[deprecated(since = "1.0.1", note = "use `into_string` instead")] + #[deprecated(since = "1.1.0", note = "use `into_string` instead")] #[inline(always)] pub fn as_string(self) -> Result { self.into_string() @@ -1927,7 +1927,7 @@ impl Dynamic { /// This method is deprecated. Use [`into_immutable_string`][Dynamic::into_immutable_string] instead. /// /// This method will be removed in the next major version. - #[deprecated(since = "1.0.1", note = "use `into_immutable_string` instead")] + #[deprecated(since = "1.1.0", note = "use `into_immutable_string` instead")] #[inline(always)] pub fn as_immutable_string(self) -> Result { self.into_immutable_string() diff --git a/src/engine_api.rs b/src/engine_api.rs index 48e0a8bd..00e531a8 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -1745,16 +1745,39 @@ impl Engine { /// Useful for when you don't need the result, but still need to keep track of possible errors. /// /// Not available under `no_std` or `WASM`. + /// + /// # Deprecated + /// + /// This method is deprecated. Use [`run_file`][Engine::run_file] instead. + /// + /// This method will be removed in the next major version. + #[deprecated(since = "1.1.0", note = "use `run_file` instead")] #[cfg(not(feature = "no_std"))] #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] #[inline(always)] pub fn consume_file(&self, path: std::path::PathBuf) -> Result<(), Box> { - Self::read_file(path).and_then(|contents| self.consume(&contents)) + self.run_file(path) + } + /// Evaluate a file, returning any error (if any). + /// + /// Not available under `no_std` or `WASM`. + #[cfg(not(feature = "no_std"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] + #[inline(always)] + pub fn run_file(&self, path: std::path::PathBuf) -> Result<(), Box> { + Self::read_file(path).and_then(|contents| self.run(&contents)) } /// Evaluate a file with own scope, but throw away the result and only return error (if any). /// Useful for when you don't need the result, but still need to keep track of possible errors. /// /// Not available under `no_std` or `WASM`. + /// + /// # Deprecated + /// + /// This method is deprecated. Use [`run_file_with_scope`][Engine::run_file_with_scope] instead. + /// + /// This method will be removed in the next major version. + #[deprecated(since = "1.1.0", note = "use `run_file_with_scope` instead")] #[cfg(not(feature = "no_std"))] #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] #[inline(always)] @@ -1763,21 +1786,62 @@ impl Engine { scope: &mut Scope, path: std::path::PathBuf, ) -> Result<(), Box> { - Self::read_file(path).and_then(|contents| self.consume_with_scope(scope, &contents)) + self.run_file_with_scope(scope, path) + } + /// Evaluate a file with own scope, returning any error (if any). + /// + /// Not available under `no_std` or `WASM`. + #[cfg(not(feature = "no_std"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] + #[inline(always)] + pub fn run_file_with_scope( + &self, + scope: &mut Scope, + path: std::path::PathBuf, + ) -> Result<(), Box> { + Self::read_file(path).and_then(|contents| self.run_with_scope(scope, &contents)) } /// Evaluate a string, but throw away the result and only return error (if any). /// Useful for when you don't need the result, but still need to keep track of possible errors. + /// + /// # Deprecated + /// + /// This method is deprecated. Use [`run`][Engine::run] instead. + /// + /// This method will be removed in the next major version. + #[deprecated(since = "1.1.0", note = "use `run` instead")] #[inline(always)] pub fn consume(&self, script: &str) -> Result<(), Box> { - self.consume_with_scope(&mut Default::default(), script) + self.run(script) + } + /// Evaluate a script, returning any error (if any). + #[inline(always)] + pub fn run(&self, script: &str) -> Result<(), Box> { + self.run_with_scope(&mut Default::default(), script) } /// Evaluate a string with own scope, but throw away the result and only return error (if any). /// Useful for when you don't need the result, but still need to keep track of possible errors. - #[inline] + /// + /// # Deprecated + /// + /// This method is deprecated. Use [`run_with_scope`][Engine::run_with_scope] instead. + /// + /// This method will be removed in the next major version. + #[deprecated(since = "1.1.0", note = "use `run_with_scope` instead")] + #[inline(always)] pub fn consume_with_scope( &self, scope: &mut Scope, script: &str, + ) -> Result<(), Box> { + self.run_with_scope(scope, script) + } + /// Evaluate a script with own scope, returning any error (if any). + #[inline] + pub fn run_with_scope( + &self, + scope: &mut Scope, + script: &str, ) -> Result<(), Box> { let scripts = [script]; let (stream, tokenizer_control) = self.lex_raw(&scripts, None); @@ -1790,21 +1854,49 @@ impl Engine { self.optimization_level, )?; - self.consume_ast_with_scope(scope, &ast) + self.run_ast_with_scope(scope, &ast) } /// Evaluate an AST, but throw away the result and only return error (if any). /// Useful for when you don't need the result, but still need to keep track of possible errors. + /// + /// # Deprecated + /// + /// This method is deprecated. Use [`run_ast`][Engine::run_ast] instead. + /// + /// This method will be removed in the next major version. + #[deprecated(since = "1.1.0", note = "use `run_ast` instead")] #[inline(always)] pub fn consume_ast(&self, ast: &AST) -> Result<(), Box> { - self.consume_ast_with_scope(&mut Default::default(), ast) + self.run_ast(ast) + } + /// Evaluate an AST, returning any error (if any). + #[inline(always)] + pub fn run_ast(&self, ast: &AST) -> Result<(), Box> { + self.run_ast_with_scope(&mut Default::default(), ast) } /// Evaluate an [`AST`] with own scope, but throw away the result and only return error (if any). /// Useful for when you don't need the result, but still need to keep track of possible errors. - #[inline] + /// + /// # Deprecated + /// + /// This method is deprecated. Use [`run_ast_with_scope`][Engine::run_ast_with_scope] instead. + /// + /// This method will be removed in the next major version. + #[deprecated(since = "1.1.0", note = "use `run_ast_with_scope` instead")] + #[inline(always)] pub fn consume_ast_with_scope( &self, scope: &mut Scope, ast: &AST, + ) -> Result<(), Box> { + self.run_ast_with_scope(scope, ast) + } + /// Evaluate an [`AST`] with own scope, returning any error (if any). + #[inline] + pub fn run_ast_with_scope( + &self, + scope: &mut Scope, + ast: &AST, ) -> Result<(), Box> { let mods = &mut Default::default(); let mut state = EvalState::new(); @@ -2151,8 +2243,8 @@ impl Engine { /// } /// }); /// - /// engine.consume("for x in range(0, 50000) {}") - /// .expect_err("should error"); + /// engine.run("for x in range(0, 50000) {}") + /// .expect_err("should error"); /// /// assert_eq!(*result.read().unwrap(), 9600); /// @@ -2186,7 +2278,7 @@ impl Engine { /// 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(()) @@ -2219,7 +2311,7 @@ impl Engine { /// /// let mut ast = engine.compile(r#"let x = "hello"; debug(x);"#)?; /// ast.set_source("world"); - /// engine.consume_ast(&ast)?; + /// engine.run_ast(&ast)?; /// /// #[cfg(not(feature = "no_position"))] /// assert_eq!(*result.read().unwrap(), r#"world @ 1:18 > "hello""#); diff --git a/tests/constants.rs b/tests/constants.rs index c64ecb1b..9f3b35e0 100644 --- a/tests/constants.rs +++ b/tests/constants.rs @@ -15,7 +15,7 @@ fn test_constant() -> Result<(), Box> { #[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> { 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> { assert!(matches!( *engine - .consume( + .run( " const MY_NUMBER = new_ts(); MY_NUMBER.value = 42; @@ -118,7 +118,7 @@ fn test_constant_mut() -> Result<(), Box> { 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(_, _) )); diff --git a/tests/custom_syntax.rs b/tests/custom_syntax.rs index 0d130be4..a2ba015e 100644 --- a/tests/custom_syntax.rs +++ b/tests/custom_syntax.rs @@ -6,7 +6,7 @@ use rhai::{ fn test_custom_syntax() -> Result<(), Box> { 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> { 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(_, _) )); diff --git a/tests/data_size.rs b/tests/data_size.rs index aa92c91b..303496f8 100644 --- a/tests/data_size.rs +++ b/tests/data_size.rs @@ -208,7 +208,7 @@ fn test_max_map_size() -> Result<(), Box> { assert!(matches!( *engine - .consume( + .run( " let x = #{}; loop { x.a = x; } diff --git a/tests/modules.rs b/tests/modules.rs index b55e275d..8a6f8d67 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -368,7 +368,7 @@ fn test_module_from_ast() -> Result<(), Box> { ); 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> { static_modules.insert("test_module", module); engine.set_module_resolver(static_modules); - engine.consume(SCRIPT)?; + engine.run(SCRIPT)?; Ok(()) } diff --git a/tests/plugins.rs b/tests/plugins.rs index 9e5548f6..40e2a31a 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -87,11 +87,11 @@ fn test_plugins_package() -> Result<(), Box> { #[cfg(not(feature = "no_object"))] { assert_eq!(engine.eval::("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") ) } diff --git a/tests/print.rs b/tests/print.rs index 0bfcefcf..ac7dbcef 100644 --- a/tests/print.rs +++ b/tests/print.rs @@ -50,10 +50,10 @@ fn test_print_debug() -> Result<(), Box> { }); // 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> { .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!( diff --git a/tests/side_effects.rs b/tests/side_effects.rs index 6f729ded..ad5a8f42 100644 --- a/tests/side_effects.rs +++ b/tests/side_effects.rs @@ -74,7 +74,7 @@ fn test_side_effects_print() -> Result<(), Box> { 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(()) diff --git a/tests/while_loop.rs b/tests/while_loop.rs index 7507242b..4e18a371 100644 --- a/tests/while_loop.rs +++ b/tests/while_loop.rs @@ -57,9 +57,9 @@ fn test_infinite_loops() -> Result<(), Box> { 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(()) }