Function googletest::matchers::each

source ·
pub fn each<ElementT: Debug, ActualT: Debug + ?Sized, MatcherT>(
    inner: MatcherT
) -> impl Matcher<ActualT = ActualT>
where for<'a> &'a ActualT: IntoIterator<Item = &'a ElementT>, MatcherT: Matcher<ActualT = ElementT>,
Expand description

Matches a container all of whose elements are matched by the matcher inner.

T can be any container such that &T implements IntoIterator. This includes Vec, arrays, and (dereferenced) slices.

let value = vec![1, 2, 3];
verify_that!(value, each(gt(0)))?;  // Passes
let array_value = [1, 2, 3];
verify_that!(array_value, each(gt(0)))?;  // Passes
let slice_value = &[1, 2, 3];
verify_that!(*slice_value, each(gt(0)))?;  // Passes
verify_that!(value, each(lt(2)))?;  // Fails: 2 and 3 are not less than 2

let value: HashSet<i32> = [1, 2, 3].into();
verify_that!(value, each(gt(0)))?;  // Passes

One can also verify the contents of a slice by dereferencing it:

let value = &[1, 2, 3];
verify_that!(*value, each(gt(0)))?;