Skip to content

Commit 4654072

Browse files
Merge pull request #332 from google:clarify-container-matcher-docs
PiperOrigin-RevId: 587704605
2 parents f4e6826 + 3d361a7 commit 4654072

9 files changed

+43
-18
lines changed

googletest/src/matchers/container_eq_matcher.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ use std::marker::PhantomData;
2929
/// Unexpected: [4]
3030
/// ```
3131
///
32-
/// The type of `expected` must implement `IntoIterator` with an `Item` which
33-
/// implements `PartialEq`. If the container type is a `Vec`, then the expected
34-
/// type may be a slice of the same element type. For example:
32+
/// The actual value must be a container such as a `Vec`, an array, or a
33+
/// dereferenced slice. More precisely, a shared borrow of the actual value must
34+
/// implement [`IntoIterator`] whose `Item` type implements
35+
/// [`PartialEq<ExpectedT>`], where `ExpectedT` is the element type of the
36+
/// expected value.
37+
///
38+
/// If the container type is a `Vec`, then the expected type may be a slice of
39+
/// the same element type. For example:
3540
///
3641
/// ```
3742
/// # use googletest::prelude::*;

googletest/src/matchers/each_matcher.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ use std::{fmt::Debug, marker::PhantomData};
1919
/// Matches a container all of whose elements are matched by the matcher
2020
/// `inner`.
2121
///
22-
/// `T` can be any container such that `&T` implements `IntoIterator`.
22+
/// `T` can be any container such that `&T` implements `IntoIterator`. This
23+
/// includes `Vec`, arrays, and (dereferenced) slices.
2324
///
2425
/// ```
2526
/// # use googletest::prelude::*;
2627
/// # use std::collections::HashSet;
2728
/// # fn should_pass_1() -> Result<()> {
2829
/// let value = vec![1, 2, 3];
2930
/// verify_that!(value, each(gt(0)))?; // Passes
31+
/// let array_value = [1, 2, 3];
32+
/// verify_that!(array_value, each(gt(0)))?; // Passes
33+
/// let slice_value = &[1, 2, 3];
34+
/// verify_that!(*slice_value, each(gt(0)))?; // Passes
3035
/// # Ok(())
3136
/// # }
3237
/// # fn should_fail() -> Result<()> {

googletest/src/matchers/elements_are_matcher.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
/// # .unwrap();
2929
/// ```
3030
///
31-
/// The actual value must be a container implementing [`IntoIterator`]. This
32-
/// includes standard containers, slices (when dereferenced) and arrays.
31+
/// The actual value must be a container such as a `Vec`, an array, or a
32+
/// dereferenced slice. More precisely, a shared borrow of the actual value must
33+
/// implement [`IntoIterator`].
3334
///
3435
/// ```
3536
/// # use googletest::prelude::*;

googletest/src/matchers/empty_matcher.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use std::{fmt::Debug, marker::PhantomData};
1717

1818
/// Matches an empty container.
1919
///
20-
/// `T` can be any container such that `&T` implements `IntoIterator`.
20+
/// `T` can be any container such that `&T` implements `IntoIterator`. This
21+
/// includes common containers such as `Vec` and
22+
/// [`HashSet`][std::collections::HashSet].
2123
///
2224
/// ```
2325
/// # use googletest::prelude::*;

googletest/src/matchers/len_matcher.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use std::{fmt::Debug, marker::PhantomData};
1919
/// Matches a container whose number of elements matches `expected`.
2020
///
2121
/// This matches against a container over which one can iterate. This includes
22-
/// the standard Rust containers, arrays, and (when dereferenced) slices.
22+
/// the standard Rust containers, arrays, and (when dereferenced) slices. More
23+
/// precisely, a shared borrow of the actual type must implement
24+
/// [`IntoIterator`].
2325
///
2426
/// ```
2527
/// # use googletest::prelude::*;

googletest/src/matchers/pointwise_matcher.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@
7979
/// that all of the containers have the same size. This matcher does not check
8080
/// whether the sizes match.
8181
///
82-
/// The actual value must be a container implementing [`IntoIterator`]. This
83-
/// includes standard containers, slices (when dereferenced) and arrays.
82+
/// The actual value must be a container such as a `Vec`, an array, or a
83+
/// dereferenced slice. More precisely, a shared borrow of the actual value must
84+
/// implement [`IntoIterator`].
8485
///
8586
/// ```
8687
/// # use googletest::prelude::*;

googletest/src/matchers/subset_of_matcher.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ use std::{fmt::Debug, marker::PhantomData};
2222
/// comparison.
2323
///
2424
/// `ActualT` and `ExpectedT` can each be any container a reference to which
25-
/// implements `IntoIterator`. They need not be the same container type.
25+
/// implements `IntoIterator`. This includes common containers such as `Vec`
26+
/// or arrays. They need not be the same container type.
2627
///
2728
/// ```
2829
/// # use googletest::prelude::*;
2930
/// # use std::collections::HashSet;
3031
/// # fn should_pass_1() -> Result<()> {
3132
/// let value = vec![1, 2, 3];
3233
/// verify_that!(value, subset_of([1, 2, 3, 4]))?; // Passes
34+
/// let array_value = [1, 2, 3];
35+
/// verify_that!(array_value, subset_of([1, 2, 3, 4]))?; // Passes
3336
/// # Ok(())
3437
/// # }
3538
/// # fn should_fail() -> Result<()> {

googletest/src/matchers/superset_of_matcher.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ use std::{fmt::Debug, marker::PhantomData};
2222
/// comparison.
2323
///
2424
/// `ActualT` and `ExpectedT` can each be any container a reference to which
25-
/// implements `IntoIterator`. They need not be the same container type.
25+
/// implements `IntoIterator`. This includes common containers such as `Vec`
26+
/// or arrays. They need not be the same container type.
2627
///
2728
/// ```
2829
/// # use googletest::prelude::*;
2930
/// # use std::collections::HashSet;
3031
/// # fn should_pass_1() -> Result<()> {
3132
/// let value = vec![1, 2, 3];
3233
/// verify_that!(value, superset_of([1, 2]))?; // Passes
34+
/// let array_value = [1, 2, 3];
35+
/// verify_that!(array_value, superset_of([1, 2]))?; // Passes
3336
/// # Ok(())
3437
/// # }
3538
/// # fn should_fail() -> Result<()> {

googletest/src/matchers/unordered_elements_are_matcher.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343
/// # should_fail_3().unwrap_err();
4444
/// ```
4545
///
46-
/// The actual value must be a container implementing [`IntoIterator`]. This
47-
/// includes standard containers, slices (when dereferenced) and arrays.
46+
/// The actual value must be a container such as a `Vec`, an array, or a
47+
/// dereferenced slice. More precisely, a shared borrow of the actual value must
48+
/// implement [`IntoIterator`].
4849
///
4950
/// This can also match against [`HashMap`][std::collections::HashMap] and
5051
/// similar collections. The arguments are a sequence of pairs of matchers
@@ -181,8 +182,9 @@ macro_rules! __unordered_elements_are {
181182
/// # should_fail_3().unwrap_err();
182183
/// ```
183184
///
184-
/// The actual value must be a container implementing [`IntoIterator`]. This
185-
/// includes standard containers, slices (when dereferenced) and arrays.
185+
/// The actual value must be a container such as a `Vec`, an array, or a
186+
/// dereferenced slice. More precisely, a shared borrow of the actual value must
187+
/// implement [`IntoIterator`].
186188
///
187189
/// This can also match against [`HashMap`][std::collections::HashMap] and
188190
/// similar collections. The arguments are a sequence of pairs of matchers
@@ -287,8 +289,9 @@ macro_rules! __contains_each {
287289
/// # should_fail_3().unwrap_err();
288290
/// ```
289291
///
290-
/// The actual value must be a container implementing [`IntoIterator`]. This
291-
/// includes standard containers, slices (when dereferenced) and arrays.
292+
/// The actual value must be a container such as a `Vec`, an array, or a
293+
/// dereferenced slice. More precisely, a shared borrow of the actual value must
294+
/// implement [`IntoIterator`].
292295
///
293296
/// This can also match against [`HashMap`][std::collections::HashMap] and
294297
/// similar collections. The arguments are a sequence of pairs of matchers

0 commit comments

Comments
 (0)