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

Function TEST

env/env_runtime_test.cc:162–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160 ValuesIn(GetEnvRuntimeTestCases()));
161
162TEST(EnvRuntimeTest, RegisterExtensionFunctions) {
163 auto descriptor_pool = cel::internal::GetSharedTestingDescriptorPool();
164 Config config;
165 ASSERT_THAT(config.AddExtensionConfig("math", 2), IsOk());
166
167 Env env;
168 env.SetDescriptorPool(descriptor_pool);
169 RegisterStandardExtensions(env);
170 env.SetConfig(config);
171 ASSERT_OK_AND_ASSIGN(std::unique_ptr<Compiler> compiler, env.NewCompiler());
172 ASSERT_OK_AND_ASSIGN(ValidationResult result,
173 compiler->Compile("math.sqrt(4) == 2.0"));
174 EXPECT_THAT(result.GetIssues(), IsEmpty()) << result.FormatError();
175 ASSERT_OK_AND_ASSIGN(std::unique_ptr<Ast> ast, result.ReleaseAst());
176
177 EnvRuntime env_runtime;
178 env_runtime.SetDescriptorPool(descriptor_pool);
179 env_runtime.RegisterExtensionFunctions(
180 "cel.lib.math", "math", 2,
181 [](cel::RuntimeBuilder& runtime_builder,
182 const cel::RuntimeOptions& opts) -> absl::Status {
183 return cel::extensions::RegisterMathExtensionFunctions(
184 runtime_builder.function_registry(), opts, 2);
185 });
186 env_runtime.SetConfig(config);
187 ASSERT_OK_AND_ASSIGN(std::unique_ptr<Runtime> runtime,
188 env_runtime.NewRuntime());
189 ASSERT_OK_AND_ASSIGN(std::unique_ptr<Program> program,
190 runtime->CreateProgram(std::move(ast)));
191 ASSERT_NE(program, nullptr);
192
193 google::protobuf::Arena arena;
194 Activation activation;
195 ASSERT_OK_AND_ASSIGN(Value value, program->Evaluate(&arena, activation));
196 EXPECT_TRUE(value.GetBool());
197}
198} // namespace
199} // namespace cel

Callers

nothing calls this directly

Calls 14

AddExtensionConfigMethod · 0.80
NewCompilerMethod · 0.80
GetIssuesMethod · 0.80
FormatErrorMethod · 0.80
ReleaseAstMethod · 0.80
NewRuntimeMethod · 0.80
ASSERT_OK_AND_ASSIGNFunction · 0.70
SetDescriptorPoolMethod · 0.45
SetConfigMethod · 0.45

Tested by

no test coverage detected