| 179 | } |
| 180 | |
| 181 | class MapValueElementsMatcher { |
| 182 | public: |
| 183 | using is_gtest_matcher = void; |
| 184 | |
| 185 | explicit MapValueElementsMatcher( |
| 186 | testing::Matcher<std::vector<std::pair<Value, Value>>>&& m, |
| 187 | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
| 188 | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 189 | google::protobuf::MessageFactory* absl_nonnull message_factory |
| 190 | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 191 | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND) |
| 192 | : m_(std::move(m)), |
| 193 | descriptor_pool_(ABSL_DIE_IF_NULL(descriptor_pool)), // Crash OK |
| 194 | message_factory_(ABSL_DIE_IF_NULL(message_factory)), // Crash OK |
| 195 | arena_(ABSL_DIE_IF_NULL(arena)) // Crash OK |
| 196 | {} |
| 197 | |
| 198 | bool MatchAndExplain(const MapValue& arg, |
| 199 | testing::MatchResultListener* result_listener) const { |
| 200 | std::vector<std::pair<Value, Value>> elements; |
| 201 | absl::Status s = arg.ForEach( |
| 202 | [&](const Value& key, const Value& value) -> absl::StatusOr<bool> { |
| 203 | elements.push_back({key, value}); |
| 204 | return true; |
| 205 | }, |
| 206 | descriptor_pool_, message_factory_, arena_); |
| 207 | if (!s.ok()) { |
| 208 | *result_listener << "cannot convert to list of values: " << s; |
| 209 | return false; |
| 210 | } |
| 211 | return m_.MatchAndExplain(elements, result_listener); |
| 212 | } |
| 213 | |
| 214 | void DescribeTo(std::ostream* os) const { *os << m_; } |
| 215 | void DescribeNegationTo(std::ostream* os) const { *os << m_; } |
| 216 | |
| 217 | private: |
| 218 | testing::Matcher<std::vector<std::pair<Value, Value>>> m_; |
| 219 | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool_; |
| 220 | google::protobuf::MessageFactory* absl_nonnull message_factory_; |
| 221 | google::protobuf::Arena* absl_nonnull arena_; |
| 222 | }; |
| 223 | |
| 224 | // Returns a matcher that tests the elements of a cel::MapValue on a given |
| 225 | // matcher as if they were a std::vector<std::pair<cel::Value, cel::Value>>. |