| 42 | class DeclFromProtoTest : public ::testing::TestWithParam<TestCase> {}; |
| 43 | |
| 44 | TEST_P(DeclFromProtoTest, FromProtoWorks) { |
| 45 | const TestCase& test_case = GetParam(); |
| 46 | google::protobuf::Arena arena; |
| 47 | const google::protobuf::DescriptorPool* descriptor_pool = |
| 48 | google::protobuf::DescriptorPool::generated_pool(); |
| 49 | cel::expr::Decl decl_pb; |
| 50 | ASSERT_TRUE( |
| 51 | google::protobuf::TextFormat::ParseFromString(test_case.proto_decl, &decl_pb)); |
| 52 | absl::StatusOr<absl::variant<VariableDecl, FunctionDecl>> decl_or = |
| 53 | DeclFromProto(decl_pb, descriptor_pool, &arena); |
| 54 | switch (test_case.decl_type) { |
| 55 | case DeclType::kVariable: { |
| 56 | ASSERT_OK_AND_ASSIGN(auto decl, decl_or); |
| 57 | EXPECT_TRUE(absl::holds_alternative<VariableDecl>(decl)); |
| 58 | break; |
| 59 | } |
| 60 | case DeclType::kFunction: { |
| 61 | ASSERT_OK_AND_ASSIGN(auto decl, decl_or); |
| 62 | EXPECT_TRUE(absl::holds_alternative<FunctionDecl>(decl)); |
| 63 | break; |
| 64 | } |
| 65 | case DeclType::kInvalid: { |
| 66 | EXPECT_THAT(decl_or, StatusIs(absl::StatusCode::kInvalidArgument)); |
| 67 | break; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Tests that the v1alpha1 proto can be converted to the unversioned proto. |
| 73 | // Same underlying implementation. |
nothing calls this directly
no test coverage detected