MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / CreateProgram

Function CreateProgram

extensions/comprehensions_v2_test.cc:56–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54using ::testing::TestWithParam;
55
56absl::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
98struct TestOptions {
99 bool enable_mutable_accumulator;

Callers 15

ASSERT_OK_AND_ASSIGNFunction · 0.85
TEST_PFunction · 0.85
TestEvaluateMethod · 0.85
TEST_PFunction · 0.85
TEST_PFunction · 0.85
TESTFunction · 0.85
TEST_PFunction · 0.85
TestEvaluateMethod · 0.85
TEST_PFunction · 0.85
CreateProgramMethod · 0.85
TESTFunction · 0.85
TEST_PFunction · 0.85

Calls 13

StandardCheckerLibraryFunction · 0.85
OptionalCompilerLibraryFunction · 0.85
BindingsCompilerLibraryFunction · 0.85
StringsCompilerLibraryFunction · 0.85
EnableOptionalTypesFunction · 0.85
RegisterStringsFunctionsFunction · 0.85
IsValidMethod · 0.80
FormatErrorMethod · 0.80
ReleaseAstMethod · 0.80
AddLibraryMethod · 0.45

Tested by

no test coverage detected