1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use std::marker::PhantomData;
use std::fmt::Debug;
use super::*;
use proptest::strategy::{Strategy, Map, ValueFor};
pub (crate) use proptest::strategy::statics::{
Map as SMap,
MapFn as SMapFn,
};
pub (crate) fn any_with_map<'a, A, B, F>(args: A::Parameters, fun: F)
-> Map<StrategyType<'a, A>, F>
where
A: Arbitrary<'a>,
B: Debug,
F: Fn(A) -> B,
{
any_with::<A>(args).prop_map(fun)
}
pub (crate) fn any_with_sinto<'a, A, B>(args: A::Parameters)
-> FMapped<'a, A, B>
where A: Arbitrary<'a>,
B: Debug + From<A>
{
from_map_strategy(any_with::<A>(args))
}
pub (crate) fn any_sinto<'a, A, B>()
-> FMapped<'a, A, B>
where A: Arbitrary<'a>,
B: Debug + From<A>
{
from_map_strategy(any::<A>())
}
pub (crate) fn any_with_smap<'a, A, B>(args: A::Parameters, fun: fn(A) -> B)
-> SMapped<'a, A, B>
where
A: Arbitrary<'a>,
B: Debug,
{
static_map(any_with::<A>(args), fun)
}
pub (crate) fn default<D: Default>() -> D { D::default() }
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct FromMapper<I, O>(PhantomData<(I, O)>);
impl<I, O> Default for FromMapper<I, O> {
fn default() -> Self { FromMapper(PhantomData) }
}
impl<I, O> Clone for FromMapper<I, O> {
fn clone(&self) -> Self { default() }
}
impl<I, O: From<I> + Debug> SMapFn<I> for FromMapper<I, O> {
type Output = O;
fn apply(&self, val: I) -> Self::Output {
val.into()
}
}
pub(crate) type FromMapStrategy<S, O> = SMap<S, FromMapper<ValueFor<S>, O>>;
pub (crate) fn from_map_strategy<S: Strategy, O>(strat: S)
-> FromMapStrategy<S, O> {
FromMapStrategy::new(strat, default())
}
pub type FMapped<'a, I, O> = FromMapStrategy<StrategyType<'a, I>, O>;
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct SFnMap<I, O>(fn(I) -> O);
impl<I, O> Clone for SFnMap<I, O> {
fn clone(&self) -> Self { SFnMap(self.0) }
}
impl<I, O: Debug> SMapFn<I> for SFnMap<I, O> {
type Output = O;
fn apply(&self, x: I) -> Self::Output { self.0(x) }
}
pub(crate) type StaticMap<S, I, O> = SMap<S, SFnMap<I, O>>;
pub(crate) type SFnPtrMap<S, O> = SMap<S, SFnMap<ValueFor<S>, O>>;
pub(crate) fn static_map<S, O>(strat: S, fun: fn(ValueFor<S>) -> O)
-> StaticMap<S, ValueFor<S>, O>
where
S: Strategy,
O: Debug
{
StaticMap::new(strat, SFnMap(fun))
}
pub type SMapped<'a, I, O> = SMap<StrategyType<'a, I>, SFnMap<I, O>>;
pub type Mapped<'a, I, O> = Map<StrategyType<'a, I>, fn(I) -> O>;