|
47 | 47 | @RunWith(TestParameterInjector.class) |
48 | 48 | public class ConstantFoldingOptimizerTest { |
49 | 49 | private static final CelOptions CEL_OPTIONS = |
50 | | - CelOptions.current() |
51 | | - .enableTimestampEpoch(true) |
52 | | - .build(); |
| 50 | + CelOptions.current().populateMacroCalls(true).enableTimestampEpoch(true).build(); |
53 | 51 | private static final Cel CEL = |
54 | 52 | CelFactory.standardCelBuilder() |
55 | 53 | .addVar("x", SimpleType.DYN) |
56 | 54 | .addVar("y", SimpleType.DYN) |
57 | 55 | .addVar("list_var", ListType.create(SimpleType.STRING)) |
58 | 56 | .addVar("map_var", MapType.create(SimpleType.STRING, SimpleType.STRING)) |
| 57 | + .setStandardMacros(CelStandardMacro.STANDARD_MACROS) |
59 | 58 | .addFunctionDeclarations( |
60 | 59 | CelFunctionDecl.newFunctionDeclaration( |
61 | 60 | "get_true", |
62 | | - CelOverloadDecl.newGlobalOverload("get_true_overload", SimpleType.BOOL))) |
| 61 | + CelOverloadDecl.newGlobalOverload("get_true_overload", SimpleType.BOOL)), |
| 62 | + CelFunctionDecl.newFunctionDeclaration( |
| 63 | + "get_list", |
| 64 | + CelOverloadDecl.newGlobalOverload( |
| 65 | + "get_list_overload", |
| 66 | + ListType.create(SimpleType.INT), |
| 67 | + ListType.create(SimpleType.INT)))) |
63 | 68 | .addFunctionBindings( |
64 | 69 | CelFunctionBinding.from("get_true_overload", ImmutableList.of(), unused -> true)) |
65 | 70 | .addMessageTypes(TestAllTypes.getDescriptor()) |
@@ -371,6 +376,8 @@ public void constantFold_macros_withoutMacroCallMetadata(String source) throws E |
371 | 376 | @TestParameters("{source: 'x == 42'}") |
372 | 377 | @TestParameters("{source: 'timestamp(100)'}") |
373 | 378 | @TestParameters("{source: 'duration(\"1h\")'}") |
| 379 | + @TestParameters("{source: '[true].exists(x, x == get_true())'}") |
| 380 | + @TestParameters("{source: 'get_list([1, 2]).map(x, x * 2)'}") |
374 | 381 | public void constantFold_noOp(String source) throws Exception { |
375 | 382 | CelAbstractSyntaxTree ast = CEL.compile(source).getAst(); |
376 | 383 |
|
|
0 commit comments