proptest/arbitrary/
macros.rs1#![cfg_attr(not(feature = "std"), allow(unused_macros))]
11
12macro_rules! arbitrary {
17 ([$($bounds : tt)*] $typ: ty, $strat: ty, $params: ty;
18 $args: ident => $logic: expr) => {
19 impl<$($bounds)*> $crate::arbitrary::Arbitrary for $typ {
20 type Parameters = $params;
21 type Strategy = $strat;
22 fn arbitrary_with($args: Self::Parameters) -> Self::Strategy {
23 $logic
24 }
25 }
26 };
27 ([$($bounds : tt)*] $typ: ty, $strat: ty; $logic: expr) => {
28 arbitrary!([$($bounds)*] $typ, $strat, (); _args => $logic);
29 };
30 ([$($bounds : tt)*] $typ: ty; $logic: expr) => {
31 arbitrary!([$($bounds)*] $typ,
32 $crate::strategy::Just<Self>, ();
33 _args => $crate::strategy::Just($logic)
34 );
35 };
36 ($typ: ty, $strat: ty, $params: ty; $args: ident => $logic: expr) => {
37 arbitrary!([] $typ, $strat, $params; $args => $logic);
38 };
39 ($typ: ty, $strat: ty; $logic: expr) => {
40 arbitrary!([] $typ, $strat; $logic);
41 };
42 ($strat: ty; $logic: expr) => {
43 arbitrary!([] $strat; $logic);
44 };
45 ($($typ: ident),*) => {
46 $(arbitrary!($typ, $typ::Any; $typ::ANY);)*
47 };
48}
49
50macro_rules! wrap_ctor {
51 ($wrap: ident) => {
52 wrap_ctor!([] $wrap);
53 };
54 ($wrap: ident, $maker: expr) => {
55 wrap_ctor!([] $wrap, $maker);
56 };
57 ([$($bound : tt)*] $wrap: ident) => {
58 wrap_ctor!([$($bound)*] $wrap, $wrap::new);
59 };
60 ([$($bound : tt)*] $wrap: ident, $maker: expr) => {
61 arbitrary!([A: $crate::arbitrary::Arbitrary + $($bound)*] $wrap<A>,
62 $crate::arbitrary::SMapped<A, Self>, A::Parameters;
63 args => $crate::strategy::statics::static_map(
64 $crate::arbitrary::any_with::<A>(args), $maker));
65
66 lift1!([$($bound)*] $wrap<A>; $maker);
67 };
68}
69
70macro_rules! wrap_from {
71 ($wrap: ident) => {
72 wrap_from!([] $wrap);
73 };
74 ([$($bound : tt)*] $wrap: ident) => {
75 arbitrary!([A: $crate::arbitrary::Arbitrary + $($bound)*] $wrap<A>,
76 $crate::strategy::MapInto<A::Strategy, Self>, A::Parameters;
77 args => $crate::strategy::Strategy::prop_map_into(
78 $crate::arbitrary::any_with::<A>(args)));
79
80 lift1!([$($bound)*] $wrap<A>);
81 };
82}
83
84macro_rules! lazy_just {
85 ($($self: ty, $fun: expr);+) => {
86 $(
87 arbitrary!($self, $crate::strategy::LazyJust<Self, fn() -> Self>;
88 $crate::strategy::LazyJust::new($fun));
89 )+
90 };
91}
92
93#[cfg(test)]
102macro_rules! no_panic_test {
103 ($($module: ident => $self: ty),+) => {
104 $(
105 mod $module {
106 #[allow(unused_imports)]
107 use super::super::*;
108 proptest! {
109 #[test]
110 fn no_panic(_ in $crate::arbitrary::any::<$self>()) {}
111 }
112 }
113 )+
114 };
115}