| 54 | using ::testing::TestWithParam; |
| 55 | |
| 56 | absl::StatusOr<std::unique_ptr<Program>> CreateProgram( |
| 57 | const std::string& expression, bool enable_mutable_accumulator, |
| 58 | int max_recursion_depth) { |
| 59 | // Configure the compiler |
| 60 | CEL_ASSIGN_OR_RETURN( |
| 61 | auto compiler_builder, |
| 62 | NewCompilerBuilder(internal::GetTestingDescriptorPool())); |
| 63 | CEL_RETURN_IF_ERROR(compiler_builder->AddLibrary(StandardCheckerLibrary())); |
| 64 | CEL_RETURN_IF_ERROR(compiler_builder->AddLibrary(OptionalCompilerLibrary())); |
| 65 | CEL_RETURN_IF_ERROR(compiler_builder->AddLibrary(BindingsCompilerLibrary())); |
| 66 | CEL_RETURN_IF_ERROR(compiler_builder->AddLibrary(StringsCompilerLibrary())); |
| 67 | CEL_RETURN_IF_ERROR(compiler_builder->AddLibrary( |
| 68 | extensions::ComprehensionsV2CompilerLibrary())); |
| 69 | |
| 70 | CEL_ASSIGN_OR_RETURN(auto compiler, std::move(*compiler_builder).Build()); |
| 71 | |
| 72 | // Configure the runtime |
| 73 | cel::RuntimeOptions options; |
| 74 | options.enable_qualified_type_identifiers = true; |
| 75 | options.enable_comprehension_list_append = enable_mutable_accumulator; |
| 76 | options.enable_comprehension_mutable_map = enable_mutable_accumulator; |
| 77 | options.max_recursion_depth = max_recursion_depth; |
| 78 | |
| 79 | CEL_ASSIGN_OR_RETURN(auto runtime_builder, |
| 80 | CreateStandardRuntimeBuilder( |
| 81 | internal::GetTestingDescriptorPool(), options)); |
| 82 | CEL_RETURN_IF_ERROR(EnableOptionalTypes(runtime_builder)); |
| 83 | CEL_RETURN_IF_ERROR( |
| 84 | RegisterStringsFunctions(runtime_builder.function_registry(), options)); |
| 85 | CEL_RETURN_IF_ERROR(RegisterComprehensionsV2Functions( |
| 86 | runtime_builder.function_registry(), options)); |
| 87 | CEL_ASSIGN_OR_RETURN(std::unique_ptr<const Runtime> runtime, |
| 88 | std::move(runtime_builder).Build()); |
| 89 | |
| 90 | CEL_ASSIGN_OR_RETURN(ValidationResult result, compiler->Compile(expression)); |
| 91 | if (!result.IsValid()) { |
| 92 | return absl::Status(absl::StatusCode::kInvalidArgument, |
| 93 | result.FormatError()); |
| 94 | } |
| 95 | return runtime->CreateProgram(*result.ReleaseAst()); |
| 96 | } |
| 97 | |
| 98 | struct TestOptions { |
| 99 | bool enable_mutable_accumulator; |
no test coverage detected