fix: default clippy lints

This commit is contained in:
Mathieu Lala
2022-12-30 18:07:39 +01:00
parent 4c2630b71f
commit 9af5b1c78e
42 changed files with 191 additions and 190 deletions

View File

@@ -1,10 +1,10 @@
#![cfg(not(feature = "no_index"))]
use rhai::{Array, Dynamic, Engine, EvalAltResult, ParseErrorType, INT};
use std::iter::FromIterator;
#[test]
fn test_arrays() -> Result<(), Box<EvalAltResult>> {
let mut a = Array::new();
a.push((42 as INT).into());
let a = Array::from_iter([(42 as INT).into()]);
assert_eq!(a[0].clone_cast::<INT>(), 42);
@@ -125,7 +125,7 @@ fn test_arrays() -> Result<(), Box<EvalAltResult>> {
let y = [4, 5];
x.append(y);
x
x
"
)?
.into_typed_array::<INT>()?,
@@ -501,15 +501,14 @@ fn test_arrays_map_reduce() -> Result<(), Box<EvalAltResult>> {
3
);
assert_eq!(
engine.eval::<()>(
engine
.eval::<()>(
"
let x = [1, 2, 3, 2, 1];
x.find(|v| v > 4)
"
)?,
()
);
",
)
.unwrap();
assert_eq!(
engine.eval::<INT>(
@@ -521,15 +520,14 @@ fn test_arrays_map_reduce() -> Result<(), Box<EvalAltResult>> {
2
);
assert_eq!(
engine.eval::<()>(
engine
.eval::<()>(
"
let x = [#{alice: 1}, #{bob: 2}, #{clara: 3}];
x.find_map(|v| v.dave)
"
)?,
()
);
",
)
.unwrap();
Ok(())
}
@@ -538,7 +536,7 @@ fn test_arrays_map_reduce() -> Result<(), Box<EvalAltResult>> {
fn test_arrays_elvis() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(engine.eval::<()>("let x = (); x?[2]")?, ());
engine.eval::<()>("let x = (); x?[2]").unwrap();
engine.run("let x = (); x?[2] = 42")?;

View File

@@ -1,12 +1,10 @@
#![cfg(not(feature = "no_index"))]
use rhai::{Blob, Engine, EvalAltResult, Scope, INT};
use std::iter::FromIterator;
#[test]
fn test_blobs() -> Result<(), Box<EvalAltResult>> {
let mut a = Blob::new();
a.push(1);
a.push(2);
a.push(3);
let a = Blob::from_iter([1, 2, 3]);
let engine = Engine::new();
let mut scope = Scope::new();

View File

@@ -4,8 +4,8 @@ use rhai::{Engine, EvalAltResult};
fn test_bool_op1() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(engine.eval::<bool>("true && (false || true)")?, true);
assert_eq!(engine.eval::<bool>("true & (false | true)")?, true);
assert!(engine.eval::<bool>("true && (false || true)").unwrap());
assert!(engine.eval::<bool>("true & (false | true)").unwrap());
Ok(())
}
@@ -14,8 +14,8 @@ fn test_bool_op1() -> Result<(), Box<EvalAltResult>> {
fn test_bool_op2() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(engine.eval::<bool>("false && (false || true)")?, false);
assert_eq!(engine.eval::<bool>("false & (false | true)")?, false);
assert!(!engine.eval::<bool>("false && (false || true)").unwrap());
assert!(!engine.eval::<bool>("false & (false | true)").unwrap());
Ok(())
}
@@ -25,9 +25,9 @@ fn test_bool_op3() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert!(engine.eval::<bool>("true && (false || 123)").is_err());
assert_eq!(engine.eval::<bool>("true && (true || { throw })")?, true);
assert!(engine.eval::<bool>("true && (true || { throw })").unwrap());
assert!(engine.eval::<bool>("123 && (false || true)").is_err());
assert_eq!(engine.eval::<bool>("false && (true || { throw })")?, false);
assert!(!engine.eval::<bool>("false && (true || { throw })").unwrap());
Ok(())
}
@@ -36,25 +36,23 @@ fn test_bool_op3() -> Result<(), Box<EvalAltResult>> {
fn test_bool_op_short_circuit() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(
engine.eval::<bool>(
assert!(engine
.eval::<bool>(
"
let x = true;
x || { throw; };
"
)?,
true
);
)
.unwrap());
assert_eq!(
engine.eval::<bool>(
assert!(!engine
.eval::<bool>(
"
let x = false;
x && { throw; };
"
)?,
false
);
)
.unwrap());
Ok(())
}
@@ -63,14 +61,14 @@ fn test_bool_op_short_circuit() -> Result<(), Box<EvalAltResult>> {
fn test_bool_op_no_short_circuit1() {
let engine = Engine::new();
assert!(engine
let _ = engine
.eval::<bool>(
"
let x = true;
x | { throw; }
"
",
)
.is_err());
.unwrap_err();
}
#[test]

View File

@@ -169,7 +169,7 @@ fn test_fn_ptr_raw() -> Result<(), Box<EvalAltResult>> {
.register_fn("mul", |x: &mut INT, y: INT| *x *= y)
.register_raw_fn(
"bar",
&[
[
TypeId::of::<INT>(),
TypeId::of::<FnPtr>(),
TypeId::of::<INT>(),

View File

@@ -21,7 +21,7 @@ fn test_comments() -> Result<(), Box<EvalAltResult>> {
42
);
assert_eq!(engine.run("/* Hello world */")?, ());
engine.run("/* Hello world */").unwrap();
Ok(())
}

View File

@@ -5,8 +5,8 @@ fn test_or_equals() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(engine.eval::<INT>("let x = 16; x |= 74; x")?, 90);
assert_eq!(engine.eval::<bool>("let x = true; x |= false; x")?, true);
assert_eq!(engine.eval::<bool>("let x = false; x |= true; x")?, true);
assert!(engine.eval::<bool>("let x = true; x |= false; x").unwrap());
assert!(engine.eval::<bool>("let x = false; x |= true; x").unwrap());
Ok(())
}
@@ -16,9 +16,9 @@ fn test_and_equals() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(engine.eval::<INT>("let x = 16; x &= 31; x")?, 16);
assert_eq!(engine.eval::<bool>("let x = true; x &= false; x")?, false);
assert_eq!(engine.eval::<bool>("let x = false; x &= true; x")?, false);
assert_eq!(engine.eval::<bool>("let x = true; x &= true; x")?, true);
assert!(!engine.eval::<bool>("let x = true; x &= false; x").unwrap());
assert!(!engine.eval::<bool>("let x = false; x &= true; x").unwrap());
assert!(engine.eval::<bool>("let x = true; x &= true; x").unwrap());
Ok(())
}

View File

@@ -91,11 +91,12 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
}
// Do not rewind if the variable is upper-case
if var_name.to_uppercase() == var_name {
context.eval_expression_tree_raw(stmt, false)?;
let _: Dynamic = if var_name.to_uppercase() == var_name {
#[allow(deprecated)] // not deprecated but unstable
context.eval_expression_tree_raw(stmt, false)
} else {
context.eval_expression_tree(stmt)?;
}
context.eval_expression_tree(stmt)
}?;
count += 1;

View File

@@ -90,6 +90,7 @@ fn test_expressions() -> Result<(), Box<EvalAltResult>> {
#[test]
#[cfg(not(feature = "no_object"))]
fn test_expressions_eval() -> Result<(), Box<EvalAltResult>> {
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone)]
struct AGENT {
pub gender: String,
@@ -124,14 +125,12 @@ fn test_expressions_eval() -> Result<(), Box<EvalAltResult>> {
scope.push_constant("agent", my_agent);
// Evaluate the expression
let result: bool = engine.eval_expression_with_scope(
assert!(engine.eval_expression_with_scope(
&mut scope,
r#"
agent.age > 10 && agent.gender == "male"
"#,
)?;
assert_eq!(result, true);
)?);
Ok(())
}

View File

@@ -7,9 +7,11 @@ const EPSILON: FLOAT = 0.000_000_000_1;
fn test_float() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert!(engine.eval::<bool>("let x = 0.0; let y = 1.0; x < y")?,);
assert!(!engine.eval::<bool>("let x = 0.0; let y = 1.0; x > y")?,);
assert_eq!(engine.eval::<bool>("let x = 0.; let y = 1.; x > y")?, false);
assert!(engine.eval::<bool>("let x = 0.0; let y = 1.0; x < y")?);
assert!(!engine.eval::<bool>("let x = 0.0; let y = 1.0; x > y")?);
assert!(!engine
.eval::<bool>("let x = 0.; let y = 1.; x > y")
.unwrap());
assert!((engine.eval::<FLOAT>("let x = 9.9999; x")? - 9.9999 as FLOAT).abs() < EPSILON);
Ok(())

View File

@@ -8,6 +8,7 @@ fn test_functions_trait_object() -> Result<(), Box<EvalAltResult>> {
fn greet(&self) -> INT;
}
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone)]
struct ABC(INT);

View File

@@ -267,7 +267,7 @@ fn test_get_set_collection() -> Result<(), Box<EvalAltResult>> {
engine
.register_type_with_name::<MyBag>("MyBag")
.register_iterator::<MyBag>()
.register_fn("new_bag", || MyBag::new())
.register_fn("new_bag", MyBag::new)
.register_fn("len", |col: &mut MyBag| col.len() as INT)
.register_get("len", |col: &mut MyBag| col.len() as INT)
.register_fn("clear", |col: &mut MyBag| col.clear())
@@ -314,7 +314,7 @@ fn test_get_set_indexer() -> Result<(), Box<EvalAltResult>> {
engine
.register_type_with_name::<MyMap>("MyMap")
.register_fn("new_map", || MyMap::new())
.register_fn("new_map", MyMap::new)
.register_indexer_get(
|map: &mut MyMap, index: &str| -> Result<_, Box<EvalAltResult>> {
map.get(index).cloned().ok_or_else(|| {
@@ -376,7 +376,7 @@ fn test_get_set_indexer() -> Result<(), Box<EvalAltResult>> {
r#"
let my_map = new_map();
my_map["eggs"] = 42;
try {
let eggs = my_map["eggs"];
let eggs = my_map["not found"];
@@ -385,7 +385,7 @@ fn test_get_set_indexer() -> Result<(), Box<EvalAltResult>> {
{
print("Not found!");
}
my_map["eggs"]
"#,
)?,
@@ -399,9 +399,11 @@ fn test_get_set_indexer() -> Result<(), Box<EvalAltResult>> {
fn test_get_set_elvis() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(engine.eval::<()>("let x = (); x?.foo.bar.baz")?, ());
assert_eq!(engine.eval::<()>("let x = (); x?.foo(1,2,3)")?, ());
assert_eq!(engine.eval::<()>("let x = #{a:()}; x.a?.foo.bar.baz")?, ());
engine.eval::<()>("let x = (); x?.foo.bar.baz").unwrap();
engine.eval::<()>("let x = (); x?.foo(1,2,3)").unwrap();
engine
.eval::<()>("let x = #{a:()}; x.a?.foo.bar.baz")
.unwrap();
assert_eq!(engine.eval::<String>("let x = 'x'; x?.type_of()")?, "char");
Ok(())

View File

@@ -111,7 +111,7 @@ b`: 1}; y["a\nb"]
fn test_map_prop() -> Result<(), Box<EvalAltResult>> {
let mut engine = Engine::new();
assert_eq!(engine.eval::<()>("let x = #{a: 42}; x.b")?, ());
engine.eval::<()>("let x = #{a: 42}; x.b").unwrap();
engine.set_fail_on_invalid_map_property(true);
@@ -182,7 +182,7 @@ fn test_map_assign() -> Result<(), Box<EvalAltResult>> {
let x = engine.eval::<Map>(r#"let x = #{a: 1, b: true, "c$": "hello"}; x"#)?;
assert_eq!(x["a"].as_int().unwrap(), 1);
assert_eq!(x["b"].as_bool().unwrap(), true);
assert!(x["b"].as_bool().unwrap());
assert_eq!(x["c$"].clone_cast::<String>(), "hello");
Ok(())
@@ -195,7 +195,7 @@ fn test_map_return() -> Result<(), Box<EvalAltResult>> {
let x = engine.eval::<Map>(r#"#{a: 1, b: true, "c$": "hello"}"#)?;
assert_eq!(x["a"].as_int().unwrap(), 1);
assert_eq!(x["b"].as_bool().unwrap(), true);
assert!(x["b"].as_bool().unwrap());
assert_eq!(x["c$"].clone_cast::<String>(), "hello");
Ok(())
@@ -240,10 +240,10 @@ fn test_map_json() -> Result<(), Box<EvalAltResult>> {
assert!(!map.contains_key("x"));
assert_eq!(map["a"].as_int().unwrap(), 1);
assert_eq!(map["b"].as_bool().unwrap(), true);
assert!(map["b"].as_bool().unwrap());
assert_eq!(map["c"].as_int().unwrap(), 42);
assert_eq!(map["$d e f!"].clone_cast::<String>(), "hello");
assert_eq!(map["z"].as_unit().unwrap(), ());
let _: () = map["z"].as_unit().unwrap();
#[cfg(not(feature = "no_index"))]
{

View File

@@ -56,7 +56,7 @@ fn test_method_call_with_full_optimization() -> Result<(), Box<EvalAltResult>> {
engine.set_optimization_level(rhai::OptimizationLevel::Full);
engine
.register_fn("new_ts", || TestStruct::new())
.register_fn("new_ts", TestStruct::new)
.register_fn("ymd", |_: INT, _: INT, _: INT| 42 as INT)
.register_fn("range", |_: &mut TestStruct, _: INT, _: INT| {
TestStruct::new()

View File

@@ -13,6 +13,7 @@ fn test_mismatched_op() {
#[test]
#[cfg(not(feature = "no_object"))]
fn test_mismatched_op_custom_type() -> Result<(), Box<EvalAltResult>> {
#[allow(dead_code)] // used inside `register_type_with_name`
#[derive(Debug, Clone)]
struct TestStruct {
x: INT,

View File

@@ -1,9 +1,12 @@
#![cfg(not(feature = "no_module"))]
use rhai::{
module_resolvers::{DummyModuleResolver, StaticModuleResolver},
Dynamic, Engine, EvalAltResult, FnNamespace, FnPtr, ImmutableString, Module, NativeCallContext,
ParseError, ParseErrorType, Scope, INT,
Dynamic, Engine, EvalAltResult, FnNamespace, ImmutableString, Module, ParseError,
ParseErrorType, Scope, INT,
};
//
#[cfg(all(not(feature = "no_function"), feature = "internals"))]
use rhai::{FnPtr, NativeCallContext};
#[test]
fn test_module() {
@@ -241,7 +244,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
"#
)
.expect_err("should error"),
EvalAltResult::ErrorInFunctionCall(fn_name, _, ..) if fn_name == "foo"
EvalAltResult::ErrorInFunctionCall(fn_name, ..) if fn_name == "foo"
));
engine.set_max_modules(1000);
@@ -269,9 +272,9 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
}
foo(1) + { import "hello" as h; h::answer }
"#;
let mut scope = Scope::new();
let scope = Scope::new();
let ast = engine.compile_into_self_contained(&mut scope, script)?;
let ast = engine.compile_into_self_contained(&scope, script)?;
engine.set_module_resolver(DummyModuleResolver::new());
@@ -329,15 +332,15 @@ fn test_module_from_ast() -> Result<(), Box<EvalAltResult>> {
private fn hidden() {
throw "you shouldn't see me!";
}
// Imported modules become sub-modules
import "another module" as extra;
// Variables defined at global level become module variables
export const x = 123;
let foo = 41;
let hello;
// Final variable values become constant module variable values
foo = calc(foo);
hello = `hello, ${foo} worlds!`;
@@ -527,8 +530,7 @@ fn test_module_ast_namespace2() -> Result<(), Box<EvalAltResult>> {
Ok(())
}
#[cfg(not(feature = "no_function"))]
#[cfg(feature = "internals")]
#[cfg(all(not(feature = "no_function"), feature = "internals"))]
#[test]
fn test_module_context() -> Result<(), Box<EvalAltResult>> {
let script = "fn bar() { calc(|x| x + 1) }";

View File

@@ -33,12 +33,12 @@ fn test_native_context_fn_name() -> Result<(), Box<EvalAltResult>> {
engine
.register_raw_fn(
"add_double",
&[TypeId::of::<INT>(), TypeId::of::<INT>()],
[TypeId::of::<INT>(), TypeId::of::<INT>()],
add_double,
)
.register_raw_fn(
"append_x2",
&[TypeId::of::<INT>(), TypeId::of::<INT>()],
[TypeId::of::<INT>(), TypeId::of::<INT>()],
add_double,
);

View File

@@ -4,15 +4,14 @@ use rhai::{Engine, EvalAltResult};
fn test_not() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(
engine.eval::<bool>("let not_true = !true; not_true")?,
false
);
assert!(!engine
.eval::<bool>("let not_true = !true; not_true")
.unwrap());
#[cfg(not(feature = "no_function"))]
assert_eq!(engine.eval::<bool>("fn not(x) { !x } not(false)")?, true);
assert!(engine.eval::<bool>("fn not(x) { !x } not(false)").unwrap());
assert_eq!(engine.eval::<bool>("!!!!true")?, true);
assert!(engine.eval::<bool>("!!!!true").unwrap());
Ok(())
}

View File

@@ -83,7 +83,7 @@ fn test_options_strict_var() -> Result<(), Box<EvalAltResult>> {
assert!(engine.compile("let x = if y { z } else { w };").is_err());
#[cfg(not(feature = "no_object"))]
engine.compile_with_scope(&mut scope, "if x.abs() { y } else { x + y.len };")?;
engine.compile_with_scope(&scope, "if x.abs() { y } else { x + y.len };")?;
engine.compile("let y = 42; let x = y;")?;

View File

@@ -127,6 +127,7 @@ fn test_serde_ser_unit_enum() -> Result<(), Box<EvalAltResult>> {
#[test]
#[cfg(not(feature = "no_object"))]
fn test_serde_ser_externally_tagged_enum() -> Result<(), Box<EvalAltResult>> {
#[allow(clippy::enum_variant_names)]
#[derive(Serialize)]
enum MyEnum {
VariantUnit,
@@ -227,6 +228,7 @@ fn test_serde_ser_internally_tagged_enum() -> Result<(), Box<EvalAltResult>> {
#[test]
#[cfg(not(feature = "no_object"))]
fn test_serde_ser_adjacently_tagged_enum() -> Result<(), Box<EvalAltResult>> {
#[allow(clippy::enum_variant_names)]
#[derive(Serialize)]
#[serde(tag = "tag", content = "content")]
enum MyEnum {
@@ -355,8 +357,8 @@ fn test_serde_ser_untagged_enum() -> Result<(), Box<EvalAltResult>> {
fn test_serde_de_primary_types() -> Result<(), Box<EvalAltResult>> {
assert_eq!(42, from_dynamic::<u16>(&Dynamic::from(42_u16))?);
assert_eq!(42, from_dynamic::<INT>(&(42 as INT).into())?);
assert_eq!(true, from_dynamic::<bool>(&true.into())?);
assert_eq!((), from_dynamic::<()>(&().into())?);
assert!(from_dynamic::<bool>(&true.into())?);
let _: () = from_dynamic::<()>(&().into()).unwrap();
#[cfg(not(feature = "no_float"))]
{
@@ -447,12 +449,14 @@ fn test_serde_de_struct() -> Result<(), Box<EvalAltResult>> {
#[cfg(not(feature = "no_object"))]
#[cfg(not(feature = "no_float"))]
fn test_serde_de_script() -> Result<(), Box<EvalAltResult>> {
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
struct Point {
x: FLOAT,
y: FLOAT,
}
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
struct MyStruct {
a: i64,
@@ -500,6 +504,7 @@ fn test_serde_de_unit_enum() -> Result<(), Box<EvalAltResult>> {
#[test]
#[cfg(not(feature = "no_object"))]
fn test_serde_de_externally_tagged_enum() -> Result<(), Box<EvalAltResult>> {
#[allow(clippy::enum_variant_names)]
#[derive(Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
enum MyEnum {
@@ -598,6 +603,7 @@ fn test_serde_de_internally_tagged_enum() -> Result<(), Box<EvalAltResult>> {
#[test]
#[cfg(not(feature = "no_object"))]
fn test_serde_de_adjacently_tagged_enum() -> Result<(), Box<EvalAltResult>> {
#[allow(clippy::enum_variant_names)]
#[derive(Debug, PartialEq, Deserialize)]
#[serde(tag = "tag", content = "content", deny_unknown_fields)]
enum MyEnum {
@@ -814,7 +820,7 @@ fn test_serde_optional() -> Result<(), Box<EvalAltResult>> {
let map = r.cast::<Map>();
assert_eq!(map.len(), 1);
assert_eq!(map.get("foo").unwrap().as_unit().unwrap(), ());
let _: () = map.get("foo").unwrap().as_unit().unwrap();
Ok(())
}
@@ -882,7 +888,7 @@ fn test_serde_scope() {
assert_eq!(scope.len(), 3);
assert_eq!(scope.get_value::<INT>("x").unwrap(), 42);
assert_eq!(scope.get_value::<bool>("y").unwrap(), true);
assert!(scope.get_value::<bool>("y").unwrap());
assert_eq!(
scope.get_value::<String>("z").unwrap(),
"serde::test_serde_scope::TestStruct"

View File

@@ -19,6 +19,7 @@ impl Command {
}
}
#[allow(clippy::upper_case_acronyms)]
type API = Arc<Mutex<Command>>;
#[cfg(not(feature = "no_object"))]

View File

@@ -10,10 +10,9 @@ fn test_switch() -> Result<(), Box<EvalAltResult>> {
engine.eval::<char>("switch 2 { 1 => (), 2 => 'a', 42 => true }")?,
'a'
);
assert_eq!(
engine.run("switch 3 { 1 => (), 2 => 'a', 42 => true }")?,
()
);
engine
.run("switch 3 { 1 => (), 2 => 'a', 42 => true }")
.unwrap();
assert_eq!(
engine.eval::<INT>("switch 3 { 1 => (), 2 => 'a', 42 => true, _ => 123 }")?,
123
@@ -32,18 +31,16 @@ fn test_switch() -> Result<(), Box<EvalAltResult>> {
)?,
'a'
);
assert_eq!(
engine.eval_with_scope::<bool>(&mut scope, "switch x { 1 => (), 2 => 'a', 42 => true }")?,
true
);
assert_eq!(
engine.eval_with_scope::<bool>(&mut scope, "switch x { 1 => (), 2 => 'a', _ => true }")?,
true
);
assert_eq!(
engine.eval_with_scope::<()>(&mut scope, "switch x { 1 => 123, 2 => 'a' }")?,
()
);
assert!(engine
.eval_with_scope::<bool>(&mut scope, "switch x { 1 => (), 2 => 'a', 42 => true }")
.unwrap());
assert!(engine
.eval_with_scope::<bool>(&mut scope, "switch x { 1 => (), 2 => 'a', _ => true }")
.unwrap());
let _: () = engine
.eval_with_scope::<()>(&mut scope, "switch x { 1 => 123, 2 => 'a' }")
.unwrap();
assert_eq!(
engine.eval_with_scope::<INT>(
&mut scope,

View File

@@ -2,6 +2,7 @@ use rhai::{Engine, EvalAltResult, INT};
#[test]
fn test_type_of() -> Result<(), Box<EvalAltResult>> {
#[allow(dead_code)]
#[derive(Clone)]
struct TestStruct {
x: INT,

View File

@@ -10,13 +10,15 @@ fn test_unit() -> Result<(), Box<EvalAltResult>> {
#[test]
fn test_unit_eq() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(engine.eval::<bool>("let x = (); let y = (); x == y")?, true);
assert!(engine
.eval::<bool>("let x = (); let y = (); x == y")
.unwrap());
Ok(())
}
#[test]
fn test_unit_with_spaces() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
engine.run("let x = ( ); x").expect_err("should error");
let _ = engine.run("let x = ( ); x").expect_err("should error");
Ok(())
}

View File

@@ -167,6 +167,7 @@ fn test_var_resolver() -> Result<(), Box<EvalAltResult>> {
#[cfg(not(feature = "no_closure"))]
let shared = base.clone();
#[allow(deprecated)] // not deprecated but unstable
engine.on_var(move |name, _, context| {
match name {
"MYSTIC_NUMBER" => Ok(Some((42 as INT).into())),
@@ -222,6 +223,7 @@ fn test_var_def_filter() -> Result<(), Box<EvalAltResult>> {
let ast = engine.compile("let x = 42;")?;
engine.run_ast(&ast)?;
#[allow(deprecated)] // not deprecated but unstable
engine.on_def_var(|_, info, _| match (info.name, info.nesting_level) {
("x", 0 | 1) => Ok(false),
_ => Ok(true),