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
CelCompilerCEL_COMPILER = CelCompilerFactory.standardCelCompilerBuilder()
.setResultType(SimpleType.BOOL)
.build();
@Testpublicvoidcel_stringConversionDisabled() throwsException {
CelRuntimeCEL_RUNTIME = CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(CelOptions.current().enableStringConversion(false).build())
.build();
// TODO: verify conversions to all types.Stringexpr = "string(3.14) == '3.14'";
CelRuntime.Programprogram = CEL_RUNTIME.createProgram(CEL_COMPILER.compile(expr).getAst());
CelEvaluationExceptioncelErr = assertThrows(CelEvaluationException.class, program::eval);
assertThat(celErr.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND);
}
@Testpublicvoidcel_stringConcatDisabled() throwsException {
CelRuntimeCEL_RUNTIME = CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(CelOptions.current().enableStringConcat(false).build())
.build();
Stringexpr = "'ab' + 'cd' == 'abcd'";
CelRuntime.Programprogram = CEL_RUNTIME.createProgram(CEL_COMPILER.compile(expr).getAst());
CelEvaluationExceptioncelErr = assertThrows(CelEvaluationException.class, program::eval);
assertThat(celErr.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND);
}
@Testpublicvoidcel_listConcatDisabled() throwsException {
CelRuntimeCEL_RUNTIME = CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(CelOptions.current().enableListConcat(false).build())
.build();
Stringexpr = "size([1, 2] + [3, 4]) == 4";
CelRuntime.Programprogram = CEL_RUNTIME.createProgram(CEL_COMPILER.compile(expr).getAst());
CelEvaluationExceptioncelErr = assertThrows(CelEvaluationException.class, program::eval);
assertThat(celErr.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND);
}Related
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