]> git.proxmox.com Git - cargo.git/blob - vendor/proptest/src/arbitrary/_alloc/ops.rs
New upstream version 0.37.0
[cargo.git] / vendor / proptest / src / arbitrary / _alloc / ops.rs
1 //-
2 // Copyright 2017, 2018 The proptest developers
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 //! Arbitrary implementations for `std::ops`.
11
12 use crate::std_facade::Arc;
13 use core::ops::*;
14
15 use crate::arbitrary::*;
16 use crate::strategy::statics::static_map;
17 use crate::strategy::*;
18
19 arbitrary!(RangeFull; ..);
20 wrap_ctor!(RangeFrom, |a| a..);
21 wrap_ctor!(RangeTo, |a| ..a);
22
23 wrap_ctor!(RangeToInclusive, |a| ..=a);
24
25 arbitrary!(
26 [A: PartialOrd + Arbitrary] RangeInclusive<A>,
27 SMapped<(A, A), Self>, product_type![A::Parameters, A::Parameters];
28 args => static_map(any_with::<(A, A)>(args),
29 |(a, b)| if b < a { b..=a } else { a..=b })
30 );
31
32 lift1!([PartialOrd] RangeInclusive<A>; base => {
33 let base = Arc::new(base);
34 (base.clone(), base).prop_map(|(a, b)| if b < a { b..=a } else { a..=b })
35 });
36
37 arbitrary!(
38 [A: PartialOrd + Arbitrary] Range<A>,
39 SMapped<(A, A), Self>, product_type![A::Parameters, A::Parameters];
40 args => static_map(any_with::<(A, A)>(args),
41 |(a, b)| if b < a { b..a } else { a..b })
42 );
43
44 lift1!([PartialOrd] Range<A>; base => {
45 let base = Arc::new(base);
46 (base.clone(), base).prop_map(|(a, b)| if b < a { b..a } else { a..b })
47 });
48
49 #[cfg(feature = "unstable")]
50 arbitrary!(
51 [Y: Arbitrary, R: Arbitrary] GeneratorState<Y, R>,
52 LazyTupleUnion<(WA<SMapped<Y, Self>>, WA<SMapped<R, Self>>)>,
53 product_type![Y::Parameters, R::Parameters];
54 args => {
55 let product_unpack![y, r] = args;
56 prop_oneof![
57 static_map(any_with::<Y>(y), GeneratorState::Yielded),
58 static_map(any_with::<R>(r), GeneratorState::Complete)
59 ]
60 }
61 );
62
63 #[cfg(feature = "unstable")]
64 use core::fmt;
65
66 #[cfg(feature = "unstable")]
67 impl<A: fmt::Debug + 'static, B: fmt::Debug + 'static>
68 functor::ArbitraryF2<A, B> for GeneratorState<A, B>
69 {
70 type Parameters = ();
71
72 fn lift2_with<AS, BS>(
73 fst: AS,
74 snd: BS,
75 _args: Self::Parameters,
76 ) -> BoxedStrategy<Self>
77 where
78 AS: Strategy<Value = A> + 'static,
79 BS: Strategy<Value = B> + 'static,
80 {
81 prop_oneof![
82 fst.prop_map(GeneratorState::Yielded),
83 snd.prop_map(GeneratorState::Complete)
84 ]
85 .boxed()
86 }
87 }
88
89 #[cfg(test)]
90 mod test {
91 no_panic_test!(
92 range_full => RangeFull,
93 range_from => RangeFrom<usize>,
94 range_to => RangeTo<usize>,
95 range => Range<usize>,
96 range_inclusive => RangeInclusive<usize>,
97 range_to_inclusive => RangeToInclusive<usize>
98 );
99
100 #[cfg(feature = "unstable")]
101 no_panic_test!(
102 generator_state => GeneratorState<u32, u64>
103 );
104 }