| 48 | using ::testing::HasSubstr; |
| 49 | |
| 50 | TEST(ReferenceResolver, ResolveQualifiedFunctions) { |
| 51 | RuntimeOptions options; |
| 52 | ASSERT_OK_AND_ASSIGN(RuntimeBuilder builder, |
| 53 | CreateStandardRuntimeBuilder( |
| 54 | internal::GetTestingDescriptorPool(), options)); |
| 55 | |
| 56 | ASSERT_OK( |
| 57 | EnableReferenceResolver(builder, ReferenceResolverEnabled::kAlways)); |
| 58 | |
| 59 | absl::Status status = |
| 60 | RegisterHelper<BinaryFunctionAdapter<int64_t, int64_t, int64_t>>:: |
| 61 | RegisterGlobalOverload( |
| 62 | "com.example.Exp", |
| 63 | [](int64_t base, int64_t exp) -> int64_t { |
| 64 | int64_t result = 1; |
| 65 | for (int64_t i = 0; i < exp; ++i) { |
| 66 | result *= base; |
| 67 | } |
| 68 | return result; |
| 69 | }, |
| 70 | builder.function_registry()); |
| 71 | ASSERT_OK(status); |
| 72 | |
| 73 | ASSERT_OK_AND_ASSIGN(auto runtime, std::move(builder).Build()); |
| 74 | |
| 75 | ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr, |
| 76 | Parse("com.example.Exp(2, 3) == 8")); |
| 77 | |
| 78 | ASSERT_OK_AND_ASSIGN(auto program, ProtobufRuntimeAdapter::CreateProgram( |
| 79 | *runtime, parsed_expr)); |
| 80 | |
| 81 | google::protobuf::Arena arena; |
| 82 | Activation activation; |
| 83 | |
| 84 | ASSERT_OK_AND_ASSIGN(Value value, program->Evaluate(&arena, activation)); |
| 85 | ASSERT_TRUE(value->Is<BoolValue>()); |
| 86 | EXPECT_TRUE(value.GetBool().NativeValue()); |
| 87 | } |
| 88 | |
| 89 | TEST(ReferenceResolver, ResolveQualifiedFunctionsCheckedOnly) { |
| 90 | RuntimeOptions options; |
nothing calls this directly
no test coverage detected