Skip to content

Commit 12e588f

Browse files
committed
Improve the example in the documentation for the and extension method.
The existing example referenced a struct which is not visible to the reader, so it could not easily be copied out. Making the struct visible would create a great deal more visible clutter. This PR changes the example to use strings and the `starts_with` and `ends_with` matchers. It also adds some failing examples for more illustration.
1 parent be4e5d2 commit 12e588f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

googletest/src/matchers/conjunction_matcher.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ pub trait AndMatcherExt<T: Debug>: Matcher<ActualT = T> {
2222
/// Constructs a matcher that matches both `self` and `right`.
2323
///
2424
/// ```
25-
/// # use googletest::{field, matchers::{eq, AndMatcherExt}, verify_that, Result};
26-
/// # #[derive(Debug)]
27-
/// # struct Struct { a: u32, b: u32 };
25+
/// # use googletest::{matchers::{ends_with, starts_with, AndMatcherExt}, verify_that, Result};
2826
/// # fn should_pass() -> Result<()> {
29-
/// verify_that!(Struct { a: 1, b: 2 }, field!(Struct.a, eq(1)).and(field!(Struct.b, eq(2))))?;
27+
/// verify_that!("A string", starts_with("A").and(ends_with("string")))?; // Passes
28+
/// # Ok(())
29+
/// # }
30+
/// # fn should_fail_1() -> Result<()> {
31+
/// verify_that!("A string", starts_with("Another").and(ends_with("string")))?; // Fails
32+
/// # Ok(())
33+
/// # }
34+
/// # fn should_fail_2() -> Result<()> {
35+
/// verify_that!("A string", starts_with("A").and(ends_with("non-string")))?; // Fails
3036
/// # Ok(())
3137
/// # }
3238
/// # should_pass().unwrap();
39+
/// # should_fail_1().unwrap_err();
40+
/// # should_fail_2().unwrap_err();
3341
/// ```
3442
// TODO(b/264518763): Replace the return type with impl Matcher and reduce
3543
// visibility of ConjunctionMatcher once impl in return position in trait

0 commit comments

Comments
 (0)