| 122 | } |
| 123 | |
| 124 | class ListValueElementsMatcher { |
| 125 | public: |
| 126 | using is_gtest_matcher = void; |
| 127 | |
| 128 | explicit ListValueElementsMatcher( |
| 129 | testing::Matcher<std::vector<Value>>&& m, |
| 130 | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
| 131 | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 132 | google::protobuf::MessageFactory* absl_nonnull message_factory |
| 133 | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 134 | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND) |
| 135 | : m_(std::move(m)), |
| 136 | descriptor_pool_(ABSL_DIE_IF_NULL(descriptor_pool)), // Crash OK |
| 137 | message_factory_(ABSL_DIE_IF_NULL(message_factory)), // Crash OK |
| 138 | arena_(ABSL_DIE_IF_NULL(arena)) // Crash OK |
| 139 | {} |
| 140 | |
| 141 | bool MatchAndExplain(const ListValue& arg, |
| 142 | testing::MatchResultListener* result_listener) const { |
| 143 | std::vector<Value> elements; |
| 144 | absl::Status s = arg.ForEach( |
| 145 | [&](const Value& v) -> absl::StatusOr<bool> { |
| 146 | elements.push_back(v); |
| 147 | return true; |
| 148 | }, |
| 149 | descriptor_pool_, message_factory_, arena_); |
| 150 | if (!s.ok()) { |
| 151 | *result_listener << "cannot convert to list of values: " << s; |
| 152 | return false; |
| 153 | } |
| 154 | return m_.MatchAndExplain(elements, result_listener); |
| 155 | } |
| 156 | |
| 157 | void DescribeTo(std::ostream* os) const { *os << m_; } |
| 158 | void DescribeNegationTo(std::ostream* os) const { *os << m_; } |
| 159 | |
| 160 | private: |
| 161 | testing::Matcher<std::vector<Value>> m_; |
| 162 | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool_; |
| 163 | google::protobuf::MessageFactory* absl_nonnull message_factory_; |
| 164 | google::protobuf::Arena* absl_nonnull arena_; |
| 165 | }; |
| 166 | |
| 167 | // Returns a matcher that tests the elements of a cel::ListValue on a given |
| 168 | // matcher as if they were a std::vector<cel::Value>. |
no outgoing calls