| 160 | ValuesIn(GetEnvRuntimeTestCases())); |
| 161 | |
| 162 | TEST(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 |
nothing calls this directly
no test coverage detected