Fix tests.
This commit is contained in:
parent
a9b6e8b98c
commit
f9d74fe313
@ -26,6 +26,7 @@ where
|
||||
x.checked_add(&y)
|
||||
}
|
||||
#[inline(always)]
|
||||
#[allow(dead_code)]
|
||||
fn regular_add<T>(x: T, y: T) -> Option<T>
|
||||
where
|
||||
T: Debug + Copy + PartialOrd + std::ops::Add<Output = T>,
|
||||
|
@ -1,19 +1,20 @@
|
||||
use rhai::packages::{Package, StandardPackage as SSS};
|
||||
use rhai::{def_package, Engine, EvalAltResult, Module, Scope, INT};
|
||||
|
||||
def_package! {
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
#[test]
|
||||
fn test_packages() -> Result<(), Box<EvalAltResult>> {
|
||||
def_package! {
|
||||
/// My custom package.
|
||||
MyPackage(m) : SSS {
|
||||
m.set_native_fn("hello", |x: INT| Ok(x + 1));
|
||||
m.set_native_fn("@", |x: INT, y: INT| Ok(x * x + y * y));
|
||||
} |> |engine| {
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
engine.register_custom_operator("@", 160).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_packages() -> Result<(), Box<EvalAltResult>> {
|
||||
let pkg = MyPackage::new();
|
||||
|
||||
let make_call = |x: INT| -> Result<INT, Box<EvalAltResult>> {
|
||||
@ -32,19 +33,11 @@ fn test_packages() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
// Evaluate script.
|
||||
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
return engine.eval_with_scope::<INT>(&mut scope, "hello(x) @ foo::hello(x)");
|
||||
|
||||
#[cfg(feature = "no_custom_syntax")]
|
||||
return engine.eval_with_scope::<INT>(&mut scope, "hello(x) + foo::hello(x)");
|
||||
engine.eval_with_scope::<INT>(&mut scope, "hello(x) @ foo::hello(x)")
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
assert_eq!(make_call(42)?, 3698);
|
||||
|
||||
#[cfg(feature = "no_custom_syntax")]
|
||||
assert_eq!(make_call(42)?, 86);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user