Add no_function
feature to disable script-defined functions.
This commit is contained in:
@@ -39,10 +39,9 @@ fn test_bool_op_short_circuit() -> Result<(), EvalAltResult> {
|
||||
assert_eq!(
|
||||
engine.eval::<bool>(
|
||||
r"
|
||||
fn this() { true }
|
||||
fn that() { 9/0 }
|
||||
let this = true;
|
||||
|
||||
this() || that();
|
||||
this || { throw; };
|
||||
"
|
||||
)?,
|
||||
true
|
||||
@@ -51,10 +50,9 @@ fn test_bool_op_short_circuit() -> Result<(), EvalAltResult> {
|
||||
assert_eq!(
|
||||
engine.eval::<bool>(
|
||||
r"
|
||||
fn this() { false }
|
||||
fn that() { 9/0 }
|
||||
let this = false;
|
||||
|
||||
this() && that();
|
||||
this && { throw; };
|
||||
"
|
||||
)?,
|
||||
false
|
||||
@@ -72,10 +70,9 @@ fn test_bool_op_no_short_circuit1() {
|
||||
engine
|
||||
.eval::<bool>(
|
||||
r"
|
||||
fn this() { false }
|
||||
fn that() { 9/0 }
|
||||
let this = true;
|
||||
|
||||
this() | that();
|
||||
this | { throw; }
|
||||
"
|
||||
)
|
||||
.unwrap(),
|
||||
@@ -92,10 +89,9 @@ fn test_bool_op_no_short_circuit2() {
|
||||
engine
|
||||
.eval::<bool>(
|
||||
r"
|
||||
fn this() { false }
|
||||
fn that() { 9/0 }
|
||||
let this = false;
|
||||
|
||||
this() & that();
|
||||
this & { throw; }
|
||||
"
|
||||
)
|
||||
.unwrap(),
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#![cfg(not(feature = "no_stdlib"))]
|
||||
#![cfg(not(feature = "no_function"))]
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#![cfg(not(feature = "no_function"))]
|
||||
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
|
@@ -9,6 +9,7 @@ fn test_not() -> Result<(), EvalAltResult> {
|
||||
false
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
assert_eq!(engine.eval::<bool>("fn not(x) { !x } not(false)")?, true);
|
||||
|
||||
// TODO - do we allow stacking unary operators directly? e.g '!!!!!!!true'
|
||||
|
@@ -5,7 +5,10 @@ fn test_unary_minus() -> Result<(), EvalAltResult> {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = -5; x")?, -5);
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
assert_eq!(engine.eval::<INT>("fn neg(x) { -x } neg(5)")?, -5);
|
||||
|
||||
assert_eq!(engine.eval::<INT>("5 - -+++--+-5")?, 0);
|
||||
|
||||
Ok(())
|
||||
|
Reference in New Issue
Block a user