|
24 | 24 | #include "common/value_testing.h" |
25 | 25 | #include "eval/eval/attribute_trail.h" |
26 | 26 | #include "eval/eval/cel_expression_flat_impl.h" |
27 | | -#include "eval/eval/compiler_constant_step.h" |
28 | 27 | #include "eval/eval/const_value_step.h" |
29 | | -#include "eval/eval/create_map_step.h" |
30 | 28 | #include "eval/eval/evaluator_core.h" |
31 | 29 | #include "eval/eval/ident_step.h" |
32 | 30 | #include "eval/public/activation.h" |
33 | 31 | #include "eval/public/cel_attribute.h" |
34 | 32 | #include "eval/public/cel_value.h" |
35 | 33 | #include "eval/public/containers/container_backed_map_impl.h" |
36 | 34 | #include "eval/public/structs/cel_proto_wrapper.h" |
37 | | -#include "eval/public/structs/legacy_type_adapter.h" |
38 | 35 | #include "eval/public/structs/trivial_legacy_type_info.h" |
39 | | -#include "eval/public/testing/matchers.h" |
40 | 36 | #include "eval/public/unknown_attribute_set.h" |
41 | 37 | #include "eval/public/unknown_set.h" |
42 | 38 | #include "eval/testutil/test_extensions.pb.h" |
@@ -81,43 +77,15 @@ using ::cel::internal::test::EqualsProto; |
81 | 77 | using ::cel::runtime_internal::NewTestingRuntimeEnv; |
82 | 78 | using ::cel::runtime_internal::RuntimeEnv; |
83 | 79 | using ::cel::test::IntValueIs; |
84 | | -using ::testing::_; |
85 | 80 | using ::testing::Eq; |
86 | 81 | using ::testing::HasSubstr; |
87 | | -using ::testing::Return; |
88 | 82 | using ::testing::UnorderedElementsAre; |
89 | 83 |
|
90 | 84 | struct RunExpressionOptions { |
91 | 85 | bool enable_unknowns = false; |
92 | 86 | bool enable_wrapper_type_null_unboxing = false; |
93 | 87 | }; |
94 | 88 |
|
95 | | -// Simple implementation LegacyTypeAccessApis / LegacyTypeInfoApis that allows |
96 | | -// mocking for getters/setters. |
97 | | -class MockAccessor : public LegacyTypeAccessApis, public LegacyTypeInfoApis { |
98 | | - public: |
99 | | - MOCK_METHOD(absl::StatusOr<bool>, HasField, |
100 | | - (absl::string_view field_name, |
101 | | - const CelValue::MessageWrapper& value), |
102 | | - (const, override)); |
103 | | - MOCK_METHOD(absl::StatusOr<CelValue>, GetField, |
104 | | - (absl::string_view field_name, |
105 | | - const CelValue::MessageWrapper& instance, |
106 | | - ProtoWrapperTypeOptions unboxing_option, |
107 | | - cel::MemoryManagerRef memory_manager), |
108 | | - (const, override)); |
109 | | - MOCK_METHOD(absl::string_view, GetTypename, |
110 | | - (const CelValue::MessageWrapper& instance), (const, override)); |
111 | | - MOCK_METHOD(std::string, DebugString, |
112 | | - (const CelValue::MessageWrapper& instance), (const, override)); |
113 | | - MOCK_METHOD(std::vector<absl::string_view>, ListFields, |
114 | | - (const CelValue::MessageWrapper& value), (const, override)); |
115 | | - const LegacyTypeAccessApis* GetAccessApis( |
116 | | - const CelValue::MessageWrapper& instance) const override { |
117 | | - return this; |
118 | | - } |
119 | | -}; |
120 | | - |
121 | 89 | class SelectStepTest : public testing::Test { |
122 | 90 | public: |
123 | 91 | SelectStepTest() : env_(NewTestingRuntimeEnv()) {} |
@@ -702,68 +670,6 @@ TEST_P(SelectStepConformanceTest, NullMessageAccessor) { |
702 | 670 | EXPECT_THAT(*result.ErrorOrDie(), StatusIs(absl::StatusCode::kNotFound)); |
703 | 671 | } |
704 | 672 |
|
705 | | -TEST_P(SelectStepConformanceTest, CustomAccessor) { |
706 | | - TestMessage message; |
707 | | - TestMessage* message2 = message.mutable_message_value(); |
708 | | - message2->set_int32_value(1); |
709 | | - message2->set_string_value("test"); |
710 | | - RunExpressionOptions options; |
711 | | - options.enable_unknowns = GetParam(); |
712 | | - testing::NiceMock<MockAccessor> accessor; |
713 | | - CelValue value = CelValue::CreateMessageWrapper( |
714 | | - CelValue::MessageWrapper(&message, &accessor)); |
715 | | - |
716 | | - ON_CALL(accessor, GetField(_, _, _, _)) |
717 | | - .WillByDefault(Return(CelValue::CreateInt64(2))); |
718 | | - ON_CALL(accessor, HasField(_, _)).WillByDefault(Return(false)); |
719 | | - |
720 | | - ASSERT_OK_AND_ASSIGN(CelValue result, |
721 | | - RunExpression(value, "message_value", |
722 | | - /*test=*/false, |
723 | | - /*unknown_path=*/"", options)); |
724 | | - |
725 | | - EXPECT_THAT(result, test::IsCelInt64(2)); |
726 | | - |
727 | | - // testonly select (has) |
728 | | - ASSERT_OK_AND_ASSIGN(result, RunExpression(value, "message_value", |
729 | | - /*test=*/true, |
730 | | - /*unknown_path=*/"", options)); |
731 | | - |
732 | | - EXPECT_THAT(result, test::IsCelBool(false)); |
733 | | -} |
734 | | - |
735 | | -TEST_P(SelectStepConformanceTest, CustomAccessorErrorHandling) { |
736 | | - TestMessage message; |
737 | | - TestMessage* message2 = message.mutable_message_value(); |
738 | | - message2->set_int32_value(1); |
739 | | - message2->set_string_value("test"); |
740 | | - RunExpressionOptions options; |
741 | | - options.enable_unknowns = GetParam(); |
742 | | - testing::NiceMock<MockAccessor> accessor; |
743 | | - CelValue value = CelValue::CreateMessageWrapper( |
744 | | - CelValue::MessageWrapper(&message, &accessor)); |
745 | | - |
746 | | - ON_CALL(accessor, GetField(_, _, _, _)) |
747 | | - .WillByDefault(Return(absl::InternalError("bad data"))); |
748 | | - ON_CALL(accessor, HasField(_, _)) |
749 | | - .WillByDefault(Return(absl::NotFoundError("not found"))); |
750 | | - |
751 | | - // For get field, implementation may return an error-type cel value or a |
752 | | - // status (e.g. broken assumption using a core type). |
753 | | - ASSERT_OK_AND_ASSIGN(CelValue result, |
754 | | - RunExpression(value, "message_value", |
755 | | - /*test=*/false, |
756 | | - /*unknown_path=*/"", options)); |
757 | | - EXPECT_THAT(result, test::IsCelError(StatusIs(absl::StatusCode::kInternal))); |
758 | | - |
759 | | - // testonly select (has) errors are coerced to CelError. |
760 | | - ASSERT_OK_AND_ASSIGN(result, RunExpression(value, "message_value", |
761 | | - /*test=*/true, |
762 | | - /*unknown_path=*/"", options)); |
763 | | - |
764 | | - EXPECT_THAT(result, test::IsCelError(StatusIs(absl::StatusCode::kNotFound))); |
765 | | -} |
766 | | - |
767 | 673 | TEST_P(SelectStepConformanceTest, SimpleEnumTest) { |
768 | 674 | TestMessage message; |
769 | 675 | message.set_enum_value(TestMessage::TEST_ENUM_1); |
|
0 commit comments