Macro googletest::matchers::elements_are
source · macro_rules! elements_are { ($($matcher:expr),* $(,)?) => { ... }; }
Expand description
Matches a container’s elements to each matcher in order.
This macro produces a matcher against a container. It takes as arguments a sequence of matchers each of which should respectively match the corresponding element of the actual value.
verify_that!(vec![1, 2, 3], elements_are![eq(1), anything(), gt(0).and(lt(123))])
The actual value must be a container such as a Vec
, an array, or a
dereferenced slice. More precisely, a shared borrow of the actual value must
implement IntoIterator
.
let vector = vec![1, 2, 3];
let slice = vector.as_slice();
verify_that!(*slice, elements_are![eq(1), anything(), gt(0).and(lt(123))])
This can also be omitted in verify_that!
macros and replaced with square
brackets.
verify_that!(vec![1, 2], [eq(1), eq(2)])
Note: This behavior is only possible in verify_that!
macros. In any
other cases, it is still necessary to use the
elements_are!
macro.
verify_that!(vec![vec![1,2], vec![3]], [[eq(1), eq(2)], [eq(3)]])
Use this instead:
verify_that!(vec![vec![1,2], vec![3]], [elements_are![eq(1), eq(2)], elements_are![eq(3)]])
This matcher does not support matching directly against an Iterator
. To
match against an iterator, use Iterator::collect
to build a Vec
.
Do not use this with unordered containers, since that will lead to flaky
tests. Use
unordered_elements_are!
instead.