|
36 | 36 | /// verify_that!(value, pointwise!(|v| near(v, 0.001), [1.0, 2.0, 3.0]))?;
|
37 | 37 | /// ```
|
38 | 38 | ///
|
| 39 | +/// One can pass up to three containers to supply arguments to the function |
| 40 | +/// creating the matcher: |
| 41 | +/// |
| 42 | +/// ``` |
| 43 | +/// let value = vec![1.00001, 2.000001, 3.00001]; |
| 44 | +/// verify_that!(value, pointwise!(|v, t| near(v, t), [1.0, 2.0, 3.0], [0.001, 0.0001, 0.01]))?; |
| 45 | +/// verify_that!(value, pointwise!(near, [1.0, 2.0, 3.0], [0.001, 0.0001, 0.01]))?; // Same as above |
| 46 | +/// verify_that!( |
| 47 | +/// value, |
| 48 | +/// pointwise!( |
| 49 | +/// |v, t, u| near(v, t * u), |
| 50 | +/// [1.0, 2.0, 3.0], |
| 51 | +/// [0.001, 0.0001, 0.01], |
| 52 | +/// [0.5, 0.5, 1.0] |
| 53 | +/// ) |
| 54 | +/// )?; |
| 55 | +/// ``` |
| 56 | +/// |
| 57 | +/// When using `pointwise!` with multiple containers, the caller must ensure |
| 58 | +/// that all of the containers have the same size. This matcher does not check |
| 59 | +/// whether the sizes match. |
| 60 | +/// |
39 | 61 | /// The actual value must be a container implementing [`IntoIterator`]. This
|
40 | 62 | /// includes standard containers, slices (when dereferenced) and arrays.
|
41 | 63 | ///
|
|
63 | 85 | #[macro_export]
|
64 | 86 | macro_rules! pointwise {
|
65 | 87 | ($matcher:expr, $container:expr) => {{
|
66 |
| - #[cfg(google3)] |
67 |
| - use $crate::internal::PointwiseMatcher; |
68 |
| - #[cfg(not(google3))] |
69 |
| - use $crate::matchers::pointwise_matcher::internal::PointwiseMatcher; |
70 |
| - PointwiseMatcher::new($container.into_iter().map($matcher).collect()) |
71 |
| - }}; |
| 88 | + #[cfg(google3)] |
| 89 | + use $crate::internal::PointwiseMatcher; |
| 90 | + #[cfg(not(google3))] |
| 91 | + use $crate::matchers::pointwise_matcher::internal::PointwiseMatcher; |
| 92 | + PointwiseMatcher::new($container.into_iter().map($matcher).collect()) |
| 93 | + }}; |
| 94 | + |
| 95 | + ($matcher:expr, $left_container:expr, $right_container:expr) => {{ |
| 96 | + #[cfg(google3)] |
| 97 | + use $crate::internal::PointwiseMatcher; |
| 98 | + #[cfg(not(google3))] |
| 99 | + use $crate::matchers::pointwise_matcher::internal::PointwiseMatcher; |
| 100 | + PointwiseMatcher::new( |
| 101 | + $left_container |
| 102 | + .into_iter() |
| 103 | + .zip($right_container.into_iter()) |
| 104 | + .map(|(l, r)| $matcher(l, r)) |
| 105 | + .collect(), |
| 106 | + ) |
| 107 | + }}; |
| 108 | + |
| 109 | + ($matcher:expr, $left_container:expr, $middle_container:expr, $right_container:expr) => {{ |
| 110 | + #[cfg(google3)] |
| 111 | + use $crate::internal::PointwiseMatcher; |
| 112 | + #[cfg(not(google3))] |
| 113 | + use $crate::matchers::pointwise_matcher::internal::PointwiseMatcher; |
| 114 | + PointwiseMatcher::new( |
| 115 | + $left_container |
| 116 | + .into_iter() |
| 117 | + .zip($right_container.into_iter().zip($middle_container.into_iter())) |
| 118 | + .map(|(l, (m, r))| $matcher(l, m, r)) |
| 119 | + .collect(), |
| 120 | + ) |
| 121 | + }}; |
72 | 122 | }
|
73 | 123 |
|
74 | 124 | /// Module for use only by the procedural macros in this module.
|
|
0 commit comments