• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2024 Google LLC.  All rights reserved.
3 //
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
7 
8 use googletest::description::Description;
9 use googletest::matcher::{Matcher, MatcherBase, MatcherResult};
10 use protobuf::__internal::MatcherEq;
11 
12 #[derive(MatcherBase)]
13 pub struct MessageMatcher<T: MatcherEq> {
14     expected: T,
15 }
16 
17 impl<T> Matcher<&T> for MessageMatcher<T>
18 where
19     T: MatcherEq,
20 {
matches(&self, actual: &T) -> MatcherResult21     fn matches(&self, actual: &T) -> MatcherResult {
22         actual.matches(&self.expected).into()
23     }
24 
describe(&self, matcher_result: MatcherResult) -> Description25     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(),
29         }
30     }
31 }
32 
proto_eq<T: MatcherEq>(expected: T) -> MessageMatcher<T>33 pub fn proto_eq<T: MatcherEq>(expected: T) -> MessageMatcher<T> {
34     MessageMatcher { expected }
35 }
36