Function googletest::matchers::eq

source ·
pub fn eq<A: ?Sized, T>(expected: T) -> EqMatcher<A, T>
Expand description

Matches a value equal (in the sense of ==) to expected.

The type of expected must implement the PartialEq trait so that the expected and actual values can be compared.

verify_that!(123, eq(123))?; // Passes
verify_that!(123, eq(234))?; // Fails

expected to actual must be comparable with one another via the PartialEq trait. In most cases, this means that they must be of the same type. However, there are a few cases where different but closely related types are comparable, for example String with &str.

verify_that!(String::from("Some value"), eq("Some value"))?; // Passes

In most cases however, one must convert one of the arguments explicitly. This can be surprising when comparing integer types or references.

verify_that!(123u32, eq(123u64))?; // Does not compile
verify_that!(123u32 as u64, eq(123u64))?; // Passes
let actual: &T = ...;
let expected: T = T{...};
verify_that(actual, eq(expected))?; // Does not compile
verify_that(actual, eq(&expected))?; // Compiles

When matching with string types (&str and String), one can set more options on how equality is checked through the StrMatcherConfigurator extension trait, which is implemented for this matcher.