macro_rules! pointwise {
    ($matcher:expr, $container:expr) => { ... };
    ($matcher:expr, $left_container:expr, $right_container:expr) => { ... };
    ($matcher:expr, $left_container:expr, $middle_container:expr, $right_container:expr) => { ... };
}
Expand description

Generates a matcher which matches a container each of whose elements match the given matcher name applied respectively to each element of the given container.

For example, the following matches a container of integers each of which does not exceed the given upper bounds:

let value = vec![1, 2, 3];
verify_that!(value, pointwise!(le, [1, 3, 3]))?; // Passes
verify_that!(value, pointwise!(le, vec![1, 3, 3]))?; // Passes
verify_that!(value, pointwise!(le, [1, 1, 3]))?; // Fails

One can also use a closure which returns a matcher:

let value = vec![1.00001, 2.000001, 3.00001];
verify_that!(value, pointwise!(|v| near(v, 0.001), [1.0, 2.0, 3.0]))?;

One can pass up to three containers to supply arguments to the function creating the matcher:

let value = vec![1.00001, 2.000001, 3.00001];
verify_that!(value, pointwise!(|v, t| near(v, t), [1.0, 2.0, 3.0], [0.001, 0.0001, 0.01]))?;
verify_that!(value, pointwise!(near, [1.0, 2.0, 3.0], [0.001, 0.0001, 0.01]))?; // Same as above
verify_that!(
    value,
    pointwise!(
        |v, t, u| near(v, t * u),
        [1.0, 2.0, 3.0],
        [0.001, 0.0001, 0.01],
        [0.5, 0.5, 1.0]
    )
)?;

When using pointwise! with multiple containers, the caller must ensure that all of the containers have the same size. This matcher does not check whether the sizes match.

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 value = vec![1, 2, 3];
verify_that!(*value.as_slice(), pointwise!(le, [1, 3, 3]))?; // Passes
verify_that!([1, 2, 3], pointwise!(le, [1, 3, 3]))?; // Passes

This matcher does not support matching directly against an Iterator. To match against an iterator, use Iterator::collect to build a Vec first.

The second argument can be any value implementing IntoIterator, such as a Vec or an array. The container does not have to have the same type as the actual value, but the value type must be the same.

Note for users of the Pointwise matcher in C++ GoogleTest:

This macro differs from Pointwise in that the first parameter is not a matcher which matches a pair but rather the name of a function of one argument whose output is a matcher. This means that one can use standard matchers like eq, le, and so on with pointwise! but certain C++ tests using Pointwise will require some extra work to port.