Skip to content

Commit

Permalink
Flip the PartialEq constaint on EqMatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
bjacotg committed Jan 5, 2024
1 parent 147862d commit fa6aabf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion googletest/src/matchers/contains_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ mod tests {

#[test]
fn contains_does_not_match_empty_slice() -> Result<()> {
let matcher = contains(eq(1));
let matcher = contains(eq::<i32, _>(1));

let result = matcher.matches(&[]);

Expand Down
4 changes: 2 additions & 2 deletions googletest/src/matchers/eq_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ pub struct EqMatcher<A: ?Sized, T> {
phantom: PhantomData<A>,
}

impl<A: Debug + ?Sized, T: PartialEq<A> + Debug> Matcher for EqMatcher<A, T> {
impl<T: Debug, A: Debug + ?Sized + PartialEq<T>> Matcher for EqMatcher<A, T> {
type ActualT = A;

fn matches(&self, actual: &A) -> MatcherResult {
(self.expected == *actual).into()
(*actual == self.expected).into()
}

fn describe(&self, matcher_result: MatcherResult) -> Description {
Expand Down
8 changes: 4 additions & 4 deletions googletest/src/matchers/some_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mod tests {

#[test]
fn some_does_not_match_option_with_none() -> Result<()> {
let matcher = some(eq(1));
let matcher = some(eq::<i32, _>(1));

let result = matcher.matches(&None);

Expand All @@ -131,22 +131,22 @@ mod tests {
#[test]
fn some_describe_matches() -> Result<()> {
verify_that!(
some(eq(1)).describe(MatcherResult::Match),
some(eq::<i32, _>(1)).describe(MatcherResult::Match),
displays_as(eq("has a value which is equal to 1"))
)
}

#[test]
fn some_describe_does_not_match() -> Result<()> {
verify_that!(
some(eq(1)).describe(MatcherResult::NoMatch),
some(eq::<i32, _>(1)).describe(MatcherResult::NoMatch),
displays_as(eq("is None or has a value which isn't equal to 1"))
)
}

#[test]
fn some_explain_match_with_none() -> Result<()> {
verify_that!(some(eq(1)).explain_match(&None), displays_as(eq("which is None")))
verify_that!(some(eq::<i32, _>(1)).explain_match(&None), displays_as(eq("which is None")))
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions googletest/tests/tuple_matcher_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn tuple_matcher_with_trailing_comma_matches_matching_12_tuple() -> Result<()> {
#[test]
fn tuple_matcher_1_has_correct_description_for_match() -> Result<()> {
verify_that!(
(eq(1),).describe(MatcherResult::Match),
(eq::<i32, _>(1),).describe(MatcherResult::Match),
displays_as(eq(indoc!(
"
is a tuple whose values respectively match:
Expand All @@ -188,7 +188,7 @@ fn tuple_matcher_1_has_correct_description_for_match() -> Result<()> {
#[test]
fn tuple_matcher_1_has_correct_description_for_mismatch() -> Result<()> {
verify_that!(
(eq(1),).describe(MatcherResult::NoMatch),
(eq::<i32, _>(1),).describe(MatcherResult::NoMatch),
displays_as(eq(indoc!(
"
is a tuple whose values do not respectively match:
Expand All @@ -200,7 +200,7 @@ fn tuple_matcher_1_has_correct_description_for_mismatch() -> Result<()> {
#[test]
fn tuple_matcher_2_has_correct_description_for_match() -> Result<()> {
verify_that!(
(eq(1), eq(2)).describe(MatcherResult::Match),
(eq::<i32, _>(1), eq::<i32, _>(2)).describe(MatcherResult::Match),
displays_as(eq(indoc!(
"
is a tuple whose values respectively match:
Expand All @@ -213,7 +213,7 @@ fn tuple_matcher_2_has_correct_description_for_match() -> Result<()> {
#[test]
fn tuple_matcher_2_has_correct_description_for_mismatch() -> Result<()> {
verify_that!(
(eq(1), eq(2)).describe(MatcherResult::NoMatch),
(eq::<i32, _>(1), eq::<i32, _>(2)).describe(MatcherResult::NoMatch),
displays_as(eq(indoc!(
"
is a tuple whose values do not respectively match:
Expand Down
2 changes: 1 addition & 1 deletion googletest/tests/unordered_elements_are_matcher_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn is_contained_in_matches_hash_map_with_trailing_comma() -> Result<()> {

#[test]
fn is_contained_in_matches_when_container_is_empty() -> Result<()> {
verify_that!(vec![], is_contained_in!(eq(2), eq(3), eq(4)))
verify_that!(vec![], is_contained_in!(eq::<i32, _>(2), eq(3), eq(4)))
}

#[test]
Expand Down

0 comments on commit fa6aabf

Please sign in to comment.