From 89254a04c4fe37fc03daa84b5d45795a8ca19853 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 14 Nov 2020 17:22:01 +0800 Subject: [PATCH] Fix tests. --- benches/eval_expression.rs | 8 ++++++-- src/engine.rs | 2 +- src/fn_call.rs | 7 ++----- tests/switch.rs | 4 +--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/benches/eval_expression.rs b/benches/eval_expression.rs index b9ac24f2..79d606b0 100644 --- a/benches/eval_expression.rs +++ b/benches/eval_expression.rs @@ -161,9 +161,12 @@ fn bench_eval_loop_strings_no_build(bench: &mut Bencher) { fn bench_eval_switch(bench: &mut Bencher) { let script = r#" let sum = 0; + let rem = 0; for x in range(0, 10000) { - sum += switch x % 5 { + rem = x % 5; + + sum += switch rem { 0 => 10, 1 => 12, 2 => 42, @@ -185,9 +188,10 @@ fn bench_eval_switch(bench: &mut Bencher) { fn bench_eval_nested_if(bench: &mut Bencher) { let script = r#" let sum = 0; + let rem = 0; for x in range(0, 10000) { - let rem = x % 5; + rem = x % 5; sum += if rem == 0 { 10 diff --git a/src/engine.rs b/src/engine.rs index dfbf7102..a401160e 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1718,7 +1718,7 @@ impl Engine { Expr::Array(x, _) => Ok(Dynamic(Union::Array(Box::new( x.iter() .map(|item| self.eval_expr(scope, mods, state, lib, this_ptr, item, level)) - .collect::, _>>()?, + .collect::>()?, )))), #[cfg(not(feature = "no_object"))] diff --git a/src/fn_call.rs b/src/fn_call.rs index 68c51605..99991bea 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -12,17 +12,14 @@ use crate::module::{Module, NamespaceRef}; use crate::optimize::OptimizationLevel; use crate::parse_error::ParseErrorType; use crate::result::EvalAltResult; -use crate::scope::Scope; +use crate::scope::{EntryType as ScopeEntryType, Scope}; use crate::stdlib::ops::Deref; use crate::token::NO_POS; use crate::utils::ImmutableString; use crate::{calc_native_fn_hash, calc_script_fn_hash, StaticVec, INT}; #[cfg(not(feature = "no_function"))] -use crate::{ - ast::ScriptFnDef, r#unsafe::unsafe_cast_var_name_to_lifetime, - scope::EntryType as ScopeEntryType, -}; +use crate::{ast::ScriptFnDef, r#unsafe::unsafe_cast_var_name_to_lifetime}; #[cfg(not(feature = "no_float"))] use crate::FLOAT; diff --git a/tests/switch.rs b/tests/switch.rs index 9e6dcad2..b5992005 100644 --- a/tests/switch.rs +++ b/tests/switch.rs @@ -90,9 +90,7 @@ mod test_switch_enum { fn test_switch_enum() -> Result<(), Box> { let mut engine = Engine::new(); - engine - .register_type_with_name::("MyEnum") - .register_get("get_data", MyEnum::get_enum_data); + engine.register_get("get_data", MyEnum::get_enum_data); let mut scope = Scope::new(); scope.push("x", MyEnum::Baz("hello".to_string(), true));