More tests.
This commit is contained in:
parent
e84d4a88e9
commit
d7c69c4f51
@ -22,7 +22,7 @@ fn test_float() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
fn struct_with_float() -> Result<(), Box<EvalAltResult>> {
|
fn test_struct_with_float() -> Result<(), Box<EvalAltResult>> {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct TestStruct {
|
struct TestStruct {
|
||||||
x: f64,
|
x: f64,
|
||||||
@ -64,3 +64,16 @@ fn struct_with_float() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_float_func() -> Result<(), Box<EvalAltResult>> {
|
||||||
|
let mut engine = Engine::new();
|
||||||
|
|
||||||
|
engine.register_fn("sum", |x: FLOAT, y: FLOAT, z: FLOAT, w: FLOAT| {
|
||||||
|
x + y + z + w
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(engine.eval::<FLOAT>("sum(1.0, 2.0, 3.0, 4.0)")?, 10.0);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
@ -63,6 +63,9 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
let mut module = Module::new();
|
let mut module = Module::new();
|
||||||
module.set_var("answer", 42 as INT);
|
module.set_var("answer", 42 as INT);
|
||||||
|
module.set_fn_4("sum".to_string(), |x: INT, y: INT, z: INT, w: INT| {
|
||||||
|
Ok(x + y + z + w)
|
||||||
|
});
|
||||||
|
|
||||||
resolver.insert("hello".to_string(), module);
|
resolver.insert("hello".to_string(), module);
|
||||||
|
|
||||||
@ -74,7 +77,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
r#"
|
r#"
|
||||||
import "hello" as h1;
|
import "hello" as h1;
|
||||||
import "hello" as h2;
|
import "hello" as h2;
|
||||||
h2::answer
|
h1::sum(h2::answer, -10, 3, 7)
|
||||||
"#
|
"#
|
||||||
)?,
|
)?,
|
||||||
42
|
42
|
||||||
|
Loading…
Reference in New Issue
Block a user