|
58 | 58 | /// `verify_that!(actual, elements_are![m1, m2, ...])`
|
59 | 59 | /// * `verify_that!(actual, {m1, m2, ...})` is equivalent to
|
60 | 60 | /// `verify_that!(actual, unordered_elements_are![m1, m2, ...])`
|
| 61 | +/// |
| 62 | +/// ## Matching against tuples |
| 63 | +/// |
| 64 | +/// One can match against a tuple by constructing a tuple of matchers as follows: |
| 65 | +/// |
| 66 | +/// ``` |
| 67 | +/// # use googletest::prelude::*; |
| 68 | +/// # fn should_pass() -> Result<()> { |
| 69 | +/// verify_that!((123, 456), (eq(123), eq(456)))?; // Passes |
| 70 | +/// # Ok(()) |
| 71 | +/// # } |
| 72 | +/// # fn should_fail() -> Result<()> { |
| 73 | +/// verify_that!((123, 456), (eq(123), eq(0)))?; // Fails: second matcher does not match |
| 74 | +/// # Ok(()) |
| 75 | +/// # } |
| 76 | +/// # should_pass().unwrap(); |
| 77 | +/// # should_fail().unwrap_err(); |
| 78 | +/// ``` |
| 79 | +/// |
| 80 | +/// This also works with composed matchers: |
| 81 | +/// |
| 82 | +/// ``` |
| 83 | +/// # use googletest::prelude::*; |
| 84 | +/// # fn should_pass() -> Result<()> { |
| 85 | +/// verify_that!((123, 456), not((eq(456), eq(123))))?; // Passes |
| 86 | +/// # Ok(()) |
| 87 | +/// # } |
| 88 | +/// # should_pass().unwrap(); |
| 89 | +/// ``` |
| 90 | +/// |
| 91 | +/// Matchers must correspond to the actual tuple in count and type. Otherwise |
| 92 | +/// the test will fail to compile. |
| 93 | +/// |
| 94 | +/// ```compile_fail |
| 95 | +/// # use googletest::prelude::*; |
| 96 | +/// # fn should_not_compile() -> Result<()> { |
| 97 | +/// verify_that!((123, 456), (eq(123),))?; // Does not compile: wrong tuple size |
| 98 | +/// verify_that!((123, "A string"), (eq(123), eq(456)))?; // Does not compile: wrong type |
| 99 | +/// # Ok(()) |
| 100 | +/// # } |
| 101 | +/// ``` |
| 102 | +/// |
| 103 | +/// All fields must be covered by matchers. Use |
| 104 | +/// [`anything`][crate::matchers::anything] for fields which are not relevant |
| 105 | +/// for the test. |
| 106 | +/// |
| 107 | +/// ``` |
| 108 | +/// # use googletest::prelude::*; |
| 109 | +/// verify_that!((123, 456), (eq(123), anything())) |
| 110 | +/// # .unwrap(); |
| 111 | +/// ``` |
| 112 | +/// |
| 113 | +/// This supports tuples of up to 12 elements. Tuples longer than that do not |
| 114 | +/// automatically inherit the `Debug` trait from their members, so are generally |
| 115 | +/// not supported; see [Rust by Example](https://doc.rust-lang.org/rust-by-example/primitives/tuples.html#tuples). |
61 | 116 | #[macro_export]
|
62 | 117 | macro_rules! verify_that {
|
63 | 118 | ($actual:expr, [$($expecteds:expr),+]) => {
|
|
0 commit comments