proptest_arbitrary/
macros.rs1macro_rules! default {
6    ($type: ty, $val: expr) => {
7        impl Default for $type {
8            fn default() -> Self { $val.into() }
9        }
10    };
11}
12
13macro_rules! valuetree {
14    () => {
15        type ValueTree =
16            <Self::Strategy as $crate::proptest::strategy::Strategy>::Value;
17    };
18}
19
20macro_rules! arbitrary {
21    ([$($bounds : tt)*] $typ: ty, $strat: ty, $params: ty;
22        $args: ident => $logic: expr) => {
23        impl<'a, $($bounds)*> $crate::Arbitrary<'a> for $typ {
24            valuetree!();
25            type Parameters = $params;
26            type Strategy = $strat;
27            fn arbitrary_with($args: Self::Parameters) -> Self::Strategy {
28                $logic
29            }
30        }
31    };
32    ([$($bounds : tt)*] $typ: ty, $strat: ty; $logic: expr) => {
33        arbitrary!([$($bounds)*] $typ, $strat, (); _args => $logic);
34    };
35    ([$($bounds : tt)*] $strat: ty; $logic: expr) => {
36        arbitrary!([$($bounds)*] $strat,
37            $crate::proptest::strategy::Just<Self>, ();
38            _args => $crate::proptest::strategy::Just($logic)
39        );
40    };
41    ($typ: ty, $strat: ty, $params: ty; $args: ident => $logic: expr) => {
42        arbitrary!([] $typ, $strat, $params; $args => $logic);
43    };
44    ($typ: ty, $strat: ty; $logic: expr) => {
45        arbitrary!([] $typ, $strat; $logic);
46    };
47    ($strat: ty; $logic: expr) => {
48        arbitrary!([] $strat; $logic);
49    };
50    ($($typ: ident),*) => {
51        $(arbitrary!($typ, $typ::Any; $typ::ANY);)*
52    };
53}
54
55macro_rules! wrap_ctor {
56    ($wrap: ident) => {
57        wrap_ctor!([] $wrap);
58    };
59    ($wrap: ident, $maker: expr) => {
60        wrap_ctor!([] $wrap, $maker);
61    };
62    ([$($bound : tt)*] $wrap: ident) => {
63        wrap_ctor!([$($bound)*] $wrap, $wrap::new);
64    };
65    ([$($bound : tt)*] $wrap: ident, $maker: expr) => {
66        arbitrary!([A: $crate::Arbitrary<'a> + $($bound)*] $wrap<A>,
67            $crate::SMapped<'a, A, Self>, A::Parameters;
68            args => $crate::any_with_smap(args, $maker));
69    };
70}
71
72macro_rules! wrap_from {
73    ($wrap: ident) => {
74        wrap_from!([] $wrap);
75    };
76    ([$($bound : tt)*] $wrap: ident) => {
77        arbitrary!([A: $crate::Arbitrary<'a> + $($bound)*] $wrap<A>,
78            $crate::FMapped<'a, A, Self>, A::Parameters;
79            args => $crate::any_with_sinto::<A, $wrap<A>>(args));
80    };
81}
82
83macro_rules! generator {
84    ($($self: ty, $fun: expr);+) => {
85        $(
86            arbitrary!($self, $crate::FnGenerator<Self>;
87                $crate::FnGenerator::new($fun));
88        )+
89    };
90}
91
92#[cfg(test)]
101macro_rules! no_panic_test {
102    ($($module: ident => $self: ty),+) => {
103        $(
104            mod $module {
105                #[allow(unused_imports)]
106                use super::super::*;
107                proptest! {
108                    #[test]
109                    fn no_panic(_ in $crate::any::<$self>()) {}
110                }
111            }
112        )+
113    };
114}