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