diff --git a/engine/src/ast/field_expr.rs b/engine/src/ast/field_expr.rs index 147b4362..36f1f89d 100644 --- a/engine/src/ast/field_expr.rs +++ b/engine/src/ast/field_expr.rs @@ -799,7 +799,7 @@ mod tests { use crate::ast::logical_expr::LogicalExpr; use crate::execution_context::ExecutionContext; use crate::functions::{ - CompiledFunction, FunctionArgKind, FunctionArgs, FunctionDefinition, + AllFunction, CompiledFunction, FunctionArgKind, FunctionArgs, FunctionDefinition, FunctionDefinitionContext, FunctionParam, FunctionParamError, SimpleFunctionDefinition, SimpleFunctionImpl, SimpleFunctionOptParam, SimpleFunctionParam, }; @@ -967,6 +967,8 @@ mod tests { tcp.port: Int, tcp.ports: Array(Int), array.of.bool: Array(Bool), + map.bool.arr: Map(Array(Bool)), + map.bytes.arr: Map(Array(Bytes)), http.parts: Array(Array(Bytes)), }; builder @@ -983,6 +985,7 @@ mod tests { }, ) .unwrap(); + builder.add_function("all", AllFunction::default()).unwrap(); builder .add_function( "echo", @@ -2633,6 +2636,34 @@ mod tests { assert_eq!(expr.execute_one(ctx), false); } + #[test] + fn test_any_all_functions_with_missing_arrays() { + let ctx = &mut ExecutionContext::new(&SCHEME); + ctx.set_field_value( + field("map.bool.arr"), + Map::new(Type::Array(Type::Bool.into())), + ) + .unwrap(); + ctx.set_field_value( + field("map.bytes.arr"), + Map::new(Type::Array(Type::Bytes.into())), + ) + .unwrap(); + + let execute = |input| SCHEME.parse(input).unwrap().compile().execute(ctx).unwrap(); + + assert_eq!(execute(r#"any(map.bool.arr["missing"])"#), false); + assert_eq!(execute(r#"all(map.bool.arr["missing"])"#), false); + assert_eq!( + execute(r#"any(map.bytes.arr["missing"][*] matches "bar")"#), + false + ); + assert_eq!( + execute(r#"all(map.bytes.arr["missing"][*] matches "bar")"#), + true + ); + } + #[test] fn test_map_each_nested() { let expr = assert_ok!(