No more pub_only.
This commit is contained in:
@@ -105,11 +105,8 @@ fn test_call_fn_private() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
let ast = engine.compile("private fn add(x, n, ) { x + n }")?;
|
||||
|
||||
assert!(matches!(
|
||||
*(engine.call_fn(&mut scope, &ast, "add", (40 as INT, 2 as INT)) as Result<INT, Box<EvalAltResult>>)
|
||||
.expect_err("should error"),
|
||||
EvalAltResult::ErrorFunctionNotFound(fn_name, _) if fn_name == "add"
|
||||
));
|
||||
let r: INT = engine.call_fn(&mut scope, &ast, "add", (40 as INT, 2 as INT))?;
|
||||
assert_eq!(r, 42);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -165,8 +162,8 @@ fn test_fn_ptr_raw() -> Result<(), Box<EvalAltResult>> {
|
||||
42
|
||||
);
|
||||
|
||||
assert!(matches!(
|
||||
*engine.eval::<INT>(
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
r#"
|
||||
private fn foo(x) { this += x; }
|
||||
|
||||
@@ -174,9 +171,9 @@ fn test_fn_ptr_raw() -> Result<(), Box<EvalAltResult>> {
|
||||
x.bar(Fn("foo"), 1);
|
||||
x
|
||||
"#
|
||||
).expect_err("should error"),
|
||||
EvalAltResult::ErrorFunctionNotFound(x, _) if x.starts_with("foo (")
|
||||
));
|
||||
)?,
|
||||
42
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
@@ -210,16 +207,13 @@ fn test_anonymous_fn() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
assert_eq!(calc_func(42, "hello".to_string(), 9)?, 423);
|
||||
|
||||
let calc_func = Func::<(INT, INT, INT), INT>::create_from_script(
|
||||
let calc_func = Func::<(INT, String, INT), INT>::create_from_script(
|
||||
Engine::new(),
|
||||
"private fn calc(x, y, z) { (x + y) * z }",
|
||||
"private fn calc(x, y, z) { (x + len(y)) * z }",
|
||||
"calc",
|
||||
)?;
|
||||
|
||||
assert!(matches!(
|
||||
*calc_func(42, 123, 9).expect_err("should error"),
|
||||
EvalAltResult::ErrorFunctionNotFound(fn_name, _) if fn_name == "calc"
|
||||
));
|
||||
assert_eq!(calc_func(42, "hello".to_string(), 9)?, 423);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, RegisterFn, Scope, INT};
|
||||
use rhai::{Engine, EvalAltResult, ImmutableString, RegisterFn, Scope, INT};
|
||||
|
||||
#[test]
|
||||
fn test_string() -> Result<(), Box<EvalAltResult>> {
|
||||
|
Reference in New Issue
Block a user