diff --git a/tests/optimizer.rs b/tests/optimizer.rs index 2a75e916..da224262 100644 --- a/tests/optimizer.rs +++ b/tests/optimizer.rs @@ -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> { @@ -28,6 +28,23 @@ fn test_optimizer_run() -> Result<(), Box> { 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::(r"if 1 == 1 || 2 > 3 { 42 } else { 123 }")?, + 123 + ); + + engine.set_optimization_level(OptimizationLevel::Full); + + assert_eq!( + engine.eval::(r"if 1 == 1 || 2 > 3 { 42 } else { 123 }")?, + 123 + ); + Ok(()) }