diff --git a/tests/operations.rs b/tests/operations.rs index 5114ab05..8f31530f 100644 --- a/tests/operations.rs +++ b/tests/operations.rs @@ -29,6 +29,38 @@ fn test_max_operations() -> Result<(), Box> { Ok(()) } +#[test] +fn test_max_operations_literal() -> Result<(), Box> { + let mut engine = Engine::new(); + #[cfg(not(feature = "no_optimize"))] + engine.set_optimization_level(rhai::OptimizationLevel::None); + engine.set_max_operations(10); + + #[cfg(not(feature = "no_index"))] + engine.run("[1, 2, 3, 4, 5, 6, 7]")?; + + #[cfg(not(feature = "no_index"))] + assert!(matches!( + *engine + .run("[1, 2, 3, 4, 5, 6, 7, 8, 9]") + .expect_err("should error"), + EvalAltResult::ErrorTooManyOperations(_) + )); + + #[cfg(not(feature = "no_object"))] + engine.run("#{a:1, b:2, c:3, d:4, e:5, f:6, g:7}")?; + + #[cfg(not(feature = "no_object"))] + assert!(matches!( + *engine + .run("#{a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8, i:9}") + .expect_err("should error"), + EvalAltResult::ErrorTooManyOperations(_) + )); + + Ok(()) +} + #[test] fn test_max_operations_functions() -> Result<(), Box> { let mut engine = Engine::new();