Feature request checklist
Change
To make CEL environment setup consistent across CEL implementations, I propose to add equivalent runtime options that control string conversion and list/string concatenation equivalent to those found in CEL-cpp:
// Enable string() overloads.
bool enable_string_conversion = true ;
// Enable string concatenation overload.
bool enable_string_concat = true ;
// Enable list concatenation overload.
bool enable_list_concat = true ;
Example
CelCompiler CEL_COMPILER = CelCompilerFactory .standardCelCompilerBuilder ()
.setResultType (SimpleType .BOOL )
.build ();
@ Test
public void cel_stringConversionDisabled () throws Exception {
CelRuntime CEL_RUNTIME = CelRuntimeFactory .standardCelRuntimeBuilder ()
.setOptions (CelOptions .current ().enableStringConversion (false ).build ())
.build ();
// TODO: verify conversions to all types.
String expr = "string(3.14) == '3.14'" ;
CelRuntime .Program program = CEL_RUNTIME .createProgram (CEL_COMPILER .compile (expr ).getAst ());
CelEvaluationException celErr = assertThrows (CelEvaluationException .class , program ::eval );
assertThat (celErr .getErrorCode ()).isEqualTo (CelErrorCode .OVERLOAD_NOT_FOUND );
}
@ Test
public void cel_stringConcatDisabled () throws Exception {
CelRuntime CEL_RUNTIME = CelRuntimeFactory .standardCelRuntimeBuilder ()
.setOptions (CelOptions .current ().enableStringConcat (false ).build ())
.build ();
String expr = "'ab' + 'cd' == 'abcd'" ;
CelRuntime .Program program = CEL_RUNTIME .createProgram (CEL_COMPILER .compile (expr ).getAst ());
CelEvaluationException celErr = assertThrows (CelEvaluationException .class , program ::eval );
assertThat (celErr .getErrorCode ()).isEqualTo (CelErrorCode .OVERLOAD_NOT_FOUND );
}
@ Test
public void cel_listConcatDisabled () throws Exception {
CelRuntime CEL_RUNTIME = CelRuntimeFactory .standardCelRuntimeBuilder ()
.setOptions (CelOptions .current ().enableListConcat (false ).build ())
.build ();
String expr = "size([1, 2] + [3, 4]) == 4" ;
CelRuntime .Program program = CEL_RUNTIME .createProgram (CEL_COMPILER .compile (expr ).getAst ());
CelEvaluationException celErr = assertThrows (CelEvaluationException .class , program ::eval );
assertThat (celErr .getErrorCode ()).isEqualTo (CelErrorCode .OVERLOAD_NOT_FOUND );
}
Related
Reactions are currently unavailable
Feature request checklist
Change
To make CEL environment setup consistent across CEL implementations, I propose to add equivalent runtime options that control string conversion and list/string concatenation equivalent to those found in CEL-cpp:
Example
Related
ProgramOptions to disable string conversion and list/string concatenation cel-go#1078