Skip to content

Commit 43ac2d0

Browse files
committed
add custom strategies to property_test macro docs
1 parent c09a4c5 commit 43ac2d0

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

proptest-macro/src/lib.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mod property_test;
3535
/// of setting up the test harness and generating input values, allowing the user to focus
3636
/// on writing the test logic.
3737
///
38-
/// # Attributes
38+
/// ## Attributes
3939
///
4040
/// The `property_test` macro can take an optional `config` attribute, which allows you to
4141
/// customize the configuration of the `proptest` runner.
@@ -48,6 +48,22 @@ mod property_test;
4848
/// assert_eq!(x, x);
4949
/// }
5050
/// ```
51+
///
52+
/// ## Custom strategies
53+
///
54+
/// By default, [`property_test`] will use the `Arbitrary` impl for parameters. However, you can
55+
/// provide a custom `Strategy` with `#[strategy = <expr>]` on an argument:
56+
///
57+
/// ```
58+
/// #[property_test]
59+
/// fn foo(#[strategy = "[0-9]*"] s: String) {
60+
/// for c in s.chars() {
61+
/// assert!(c.is_numeric());
62+
/// }
63+
/// }
64+
/// ```
65+
/// Multiple `#[strategy = <expr>]` attributes on an argument are not allowed.
66+
///
5167
#[proc_macro_attribute]
5268
pub fn property_test(attr: TokenStream, item: TokenStream) -> TokenStream {
5369
property_test::property_test(attr.into(), item.into()).into()

0 commit comments

Comments
 (0)