Skip to content

Commit ccd5d9b

Browse files
committed
Add extra documentation regarding the usage of the omitted matchers.
1 parent 3f106d6 commit ccd5d9b

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

googletest/src/matchers/elements_are_matcher.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,28 @@
4040
/// ```
4141
///
4242
/// This can also be omitted in [`verify_that!`] macros and replaced with square brackets.
43-
///
43+
///
4444
/// ```
4545
/// # use googletest::prelude::*;
4646
/// verify_that!(vec![1, 2], [eq(1), eq(2)])
4747
/// # .unwrap();
4848
/// ```
49-
///
49+
///
50+
/// Note: This behavior is only possible in [`verify_that!`] macros. In any other cases, it is still necessary to use the [`elements_are!`] macro.
51+
///
52+
/// ```compile_fail
53+
/// # use googletest::prelude::*;
54+
/// verify_that!(vec![vec![1,2], vec![3]], [[eq(1), eq(2)], [eq(3)]])
55+
/// # .unwrap();
56+
/// ```
57+
///
58+
/// Prefer:
59+
/// ```
60+
/// # use googletest::prelude::*;
61+
/// verify_that!(vec![vec![1,2], vec![3]], [elements_are![eq(1), eq(2)], elements_are![eq(3)]])
62+
/// # .unwrap();
63+
/// ```
64+
///
5065
/// This matcher does not support matching directly against an [`Iterator`]. To
5166
/// match against an iterator, use [`Iterator::collect`] to build a [`Vec`].
5267
///

googletest/src/matchers/unordered_elements_are_matcher.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,30 @@
6262
/// ```
6363
///
6464
/// This can also be omitted in [`verify_that!`] macros and replaced with curly brackets.
65-
///
65+
///
6666
/// ```
6767
/// # use googletest::prelude::*;
6868
/// verify_that!(vec![1, 2], {eq(2), eq(1)})
6969
/// # .unwrap();
7070
/// ```
71-
///
71+
///
72+
/// Note: This behavior is only possible in [`verify_that!`] macros. In any other cases, it is still necessary
73+
/// to use the [`unordered_elements_are!`] macro.
74+
///
75+
/// ```compile_fail
76+
/// # use googletest::prelude::*;
77+
/// verify_that!(vec![vec![1,2], vec![3]], {{eq(2), eq(1)}, {eq(3)}})
78+
/// # .unwrap();
79+
/// ```
80+
///
81+
/// Prefer:
82+
/// ```
83+
/// # use googletest::prelude::*;
84+
/// verify_that!(vec![vec![1,2], vec![3]],
85+
/// {unordered_elements_are![eq(2), eq(1)], unordered_elements_are![eq(3)]})
86+
/// # .unwrap();
87+
/// ```
88+
///
7289
/// This matcher does not support matching directly against an [`Iterator`]. To
7390
/// match against an iterator, use [`Iterator::collect`] to build a [`Vec`].
7491
///

googletest/tests/elements_are_matcher_test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ fn elements_are_works_when_matcher_is_created_in_subroutine() -> Result<()> {
119119
verify_that!(vec![1], create_matcher())
120120
}
121121

122-
123122
#[test]
124123
fn elements_are_implicitly_called() -> Result<()> {
125-
verify_that!(vec![1,2,3], [eq(1), eq(2), eq(3)])
124+
verify_that!(vec![1, 2, 3], [eq(1), eq(2), eq(3)])
126125
}

0 commit comments

Comments
 (0)