use rhai::{Engine, EvalAltResult}; #[test] fn test_bool_op1() -> Result<(), Box> { let engine = Engine::new(); assert!(engine.eval::("true && (false || true)").unwrap()); assert!(engine.eval::("true & (false | true)").unwrap()); Ok(()) } #[test] fn test_bool_op2() -> Result<(), Box> { let engine = Engine::new(); assert!(!engine.eval::("false && (false || true)").unwrap()); assert!(!engine.eval::("false & (false | true)").unwrap()); Ok(()) } #[test] fn test_bool_op3() -> Result<(), Box> { let engine = Engine::new(); assert!(engine.eval::("true && (false || 123)").is_err()); assert!(engine.eval::("true && (true || { throw })").unwrap()); assert!(engine.eval::("123 && (false || true)").is_err()); assert!(!engine.eval::("false && (true || { throw })").unwrap()); Ok(()) } #[test] fn test_bool_op_short_circuit() -> Result<(), Box> { let engine = Engine::new(); assert!(engine .eval::( " let x = true; x || { throw; }; " ) .unwrap()); assert!(!engine .eval::( " let x = false; x && { throw; }; " ) .unwrap()); Ok(()) } #[test] fn test_bool_op_no_short_circuit1() { let engine = Engine::new(); let _ = engine .eval::( " let x = true; x | { throw; } ", ) .unwrap_err(); } #[test] fn test_bool_op_no_short_circuit2() { let engine = Engine::new(); assert!(engine .eval::( " let x = false; x & { throw; } " ) .is_err()); }