MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / MatchAndExplain

Method MatchAndExplain

internal/equals_text_proto.cc:45–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45bool TextProtoMatcher::MatchAndExplain(
46 const google::protobuf::MessageLite& other,
47 ::testing::MatchResultListener* listener) const {
48 if (other.GetTypeName() != message_->GetTypeName()) {
49 if (listener->IsInterested()) {
50 *listener << "whose type should be " << message_->GetTypeName()
51 << " but actually is " << other.GetTypeName();
52 }
53 return false;
54 }
55 google::protobuf::util::MessageDifferencer differencer;
56 std::string diff;
57 if (listener->IsInterested()) {
58 differencer.ReportDifferencesToString(&diff);
59 }
60 bool match;
61 if (const auto* other_full_message =
62 google::protobuf::DynamicCastMessage<google::protobuf::Message>(&other);
63 other_full_message != nullptr &&
64 other_full_message->GetDescriptor() == message_->GetDescriptor()) {
65 match = differencer.Compare(*other_full_message, *message_);
66 } else {
67 auto other_message = absl::WrapUnique(message_->New());
68 absl::Cord serialized;
69 ABSL_CHECK(other.SerializeToString(&serialized)); // Crash OK
70 ABSL_CHECK(other_message->ParseFromString(serialized)); // Crash OK
71 match = differencer.Compare(*other_message, *message_);
72 }
73 if (!match && listener->IsInterested()) {
74 if (!diff.empty() && diff.back() == '\n') {
75 diff.erase(diff.end() - 1);
76 }
77 *listener << "with the difference:\n" << diff;
78 }
79 return match;
80}
81
82} // namespace cel::internal

Callers

nothing calls this directly

Calls 7

WrapUniqueFunction · 0.85
GetTypeNameMethod · 0.45
GetDescriptorMethod · 0.45
CompareMethod · 0.45
NewMethod · 0.45
emptyMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected