Test optimizer with overriding operator.

This commit is contained in:
Stephen Chung 2020-10-08 10:34:32 +08:00
parent b2d603ec06
commit e34a370f33

View File

@ -1,6 +1,6 @@
#![cfg(not(feature = "no_optimize"))]
use rhai::{Engine, EvalAltResult, OptimizationLevel, INT};
use rhai::{Engine, EvalAltResult, OptimizationLevel, INT, RegisterFn};
#[test]
fn test_optimizer_run() -> Result<(), Box<EvalAltResult>> {
@ -28,6 +28,23 @@ fn test_optimizer_run() -> Result<(), Box<EvalAltResult>> {
engine.set_optimization_level(OptimizationLevel::Full);
run_test(&mut engine)?;
// Override == operator
engine.register_fn("==", |_x: INT, _y: INT| false);
engine.set_optimization_level(OptimizationLevel::Simple);
assert_eq!(
engine.eval::<INT>(r"if 1 == 1 || 2 > 3 { 42 } else { 123 }")?,
123
);
engine.set_optimization_level(OptimizationLevel::Full);
assert_eq!(
engine.eval::<INT>(r"if 1 == 1 || 2 > 3 { 42 } else { 123 }")?,
123
);
Ok(())
}