| 77 | class RegexPrecompilationTest : public testing::TestWithParam<TestCase> {}; |
| 78 | |
| 79 | TEST_P(RegexPrecompilationTest, Basic) { |
| 80 | RuntimeOptions options; |
| 81 | const TestCase& test_case = GetParam(); |
| 82 | ASSERT_OK_AND_ASSIGN(cel::RuntimeBuilder builder, |
| 83 | CreateStandardRuntimeBuilder( |
| 84 | internal::GetTestingDescriptorPool(), options)); |
| 85 | |
| 86 | auto status = RegisterHelper<BinaryFunctionAdapter< |
| 87 | absl::StatusOr<Value>, const StringValue&, const StringValue&>>:: |
| 88 | RegisterGlobalOverload( |
| 89 | "prepend", |
| 90 | [](const StringValue& value, const StringValue& prefix) { |
| 91 | return StringValue( |
| 92 | absl::StrCat(prefix.ToString(), value.ToString())); |
| 93 | }, |
| 94 | builder.function_registry()); |
| 95 | ASSERT_THAT(status, IsOk()); |
| 96 | |
| 97 | ASSERT_THAT(EnableRegexPrecompilation(builder), IsOk()); |
| 98 | |
| 99 | ASSERT_OK_AND_ASSIGN(auto runtime, std::move(builder).Build()); |
| 100 | |
| 101 | ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr, Parse(test_case.expression)); |
| 102 | |
| 103 | auto program_or = |
| 104 | ProtobufRuntimeAdapter::CreateProgram(*runtime, parsed_expr); |
| 105 | if (!test_case.create_status.ok()) { |
| 106 | ASSERT_THAT(program_or.status(), |
| 107 | StatusIs(test_case.create_status.code(), |
| 108 | HasSubstr(test_case.create_status.message()))); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | ASSERT_OK_AND_ASSIGN(auto program, std::move(program_or)); |
| 113 | |
| 114 | google::protobuf::Arena arena; |
| 115 | Activation activation; |
| 116 | activation.InsertOrAssignValue("string_var", |
| 117 | StringValue(&arena, "string_var")); |
| 118 | |
| 119 | ASSERT_OK_AND_ASSIGN(Value value, program->Evaluate(&arena, activation)); |
| 120 | EXPECT_THAT(value, test_case.result_matcher); |
| 121 | } |
| 122 | |
| 123 | TEST_P(RegexPrecompilationTest, WithConstantFolding) { |
| 124 | RuntimeOptions options; |
nothing calls this directly
no test coverage detected