4848public class ConstantFoldingOptimizerTest {
4949 private static final CelOptions CEL_OPTIONS =
5050 CelOptions .current ()
51+ .populateMacroCalls (true )
5152 .enableTimestampEpoch (true )
5253 .build ();
5354 private static final Cel CEL =
@@ -56,12 +57,23 @@ public class ConstantFoldingOptimizerTest {
5657 .addVar ("y" , SimpleType .DYN )
5758 .addVar ("list_var" , ListType .create (SimpleType .STRING ))
5859 .addVar ("map_var" , MapType .create (SimpleType .STRING , SimpleType .STRING ))
60+ .setStandardMacros (CelStandardMacro .STANDARD_MACROS )
5961 .addFunctionDeclarations (
6062 CelFunctionDecl .newFunctionDeclaration (
6163 "get_true" ,
62- CelOverloadDecl .newGlobalOverload ("get_true_overload" , SimpleType .BOOL )))
64+ CelOverloadDecl .newGlobalOverload ("get_true_overload" , SimpleType .BOOL )),
65+ CelFunctionDecl .newFunctionDeclaration (
66+ "get_list" ,
67+ CelOverloadDecl .newGlobalOverload (
68+ "get_list_overload" ,
69+ ListType .create (SimpleType .INT ),
70+ ListType .create (SimpleType .INT )))
71+ )
6372 .addFunctionBindings (
64- CelFunctionBinding .from ("get_true_overload" , ImmutableList .of (), unused -> true ))
73+ CelFunctionBinding .from ("get_true_overload" , ImmutableList .of (), unused -> true ),
74+ CelFunctionBinding .from (
75+ "get_list_overload" , ImmutableList .class , arg -> arg )
76+ )
6577 .addMessageTypes (TestAllTypes .getDescriptor ())
6678 .setContainer (CelContainer .ofName ("cel.expr.conformance.proto3" ))
6779 .setOptions (CEL_OPTIONS )
@@ -371,6 +383,8 @@ public void constantFold_macros_withoutMacroCallMetadata(String source) throws E
371383 @ TestParameters ("{source: 'x == 42'}" )
372384 @ TestParameters ("{source: 'timestamp(100)'}" )
373385 @ TestParameters ("{source: 'duration(\" 1h\" )'}" )
386+ @ TestParameters ("{source: '[true].exists(x, x == get_true())'}" )
387+ @ TestParameters ("{source: 'get_list([1, 2]).map(x, x * 2)'}" )
374388 public void constantFold_noOp (String source ) throws Exception {
375389 CelAbstractSyntaxTree ast = CEL .compile (source ).getAst ();
376390
0 commit comments