1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2024 Google LLC. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
8 use googletest::description::Description;
9 use googletest::matcher::{Matcher, MatcherBase, MatcherResult};
10 use protobuf::__internal::MatcherEq;
12 #[derive(MatcherBase)]
13 pub struct MessageMatcher<T: MatcherEq> {
17 impl<T> Matcher<&T> for MessageMatcher<T>
21 fn matches(&self, actual: &T) -> MatcherResult {
22 actual.matches(&self.expected).into()
25 fn describe(&self, matcher_result: MatcherResult) -> Description {
26 match matcher_result {
27 MatcherResult::Match => format!("is equal to {:?}", self.expected).into(),
28 MatcherResult::NoMatch => format!("is not equal to {:?}", self.expected).into(),
33 impl<T> Matcher<T> for MessageMatcher<T>
37 fn matches(&self, actual: T) -> MatcherResult {
38 actual.matches(&self.expected).into()
41 fn describe(&self, matcher_result: MatcherResult) -> Description {
42 match matcher_result {
43 MatcherResult::Match => format!("is equal to {:?}", self.expected).into(),
44 MatcherResult::NoMatch => format!("is not equal to {:?}", self.expected).into(),
49 pub fn proto_eq<T: MatcherEq>(expected: T) -> MessageMatcher<T> {
50 MessageMatcher { expected }