proptest_arbitrary/_std/
ops.rs

1//! Arbitrary implementations for `std::ops`.
2
3use super::*;
4use std::ops::*;
5
6arbitrary!(RangeFull; ..);
7wrap_ctor!(RangeFrom, |a| a..);
8wrap_ctor!(RangeTo, |a| ..a);
9
10#[cfg(feature = "unstable")]
11wrap_ctor!(RangeToInclusive, |a| ..=a);
12
13#[cfg(feature = "unstable")]
14arbitrary!(
15    [A: PartialOrd + Arbitrary<'a>] RangeInclusive<A>,
16    SMapped<'a, (A, A), Self>, product_type![A::Parameters, A::Parameters];
17    args => any_with_smap(args, |(a, b)| if b < a { b..=a } else { a..=b })
18);
19
20arbitrary!(
21    [A: PartialOrd + Arbitrary<'a>] Range<A>,
22    SMapped<'a, (A, A), Self>, product_type![A::Parameters, A::Parameters];
23    args => any_with_smap(args, |(a, b)| if b < a { b..a } else { a..b })
24);
25
26#[cfg(feature = "unstable")]
27arbitrary!(
28    [Y: Arbitrary<'a>, R: Arbitrary<'a>] GeneratorState<Y, R>,
29    TupleUnion<(W<SMapped<'a, Y, Self>>, W<SMapped<'a, R, Self>>)>,
30    product_type![Y::Parameters, R::Parameters];
31    args => {
32        let product_unpack![y, r] = args;
33        prop_oneof![
34            any_with_smap(y, GeneratorState::Yielded),
35            any_with_smap(r, GeneratorState::Complete)
36        ]
37    }
38);
39
40#[cfg(test)]
41mod test {
42    no_panic_test!(
43        range_full => RangeFull,
44        range_from => RangeFrom<usize>,
45        range_to   => RangeTo<usize>,
46        range      => Range<usize>
47    );
48
49    #[cfg(feature = "unstable")]
50    no_panic_test!(
51        range_to_inclusive => RangeToInclusive<usize>,
52        range_inclusive => RangeInclusive<usize>,
53        generator_state => GeneratorState<u32, u64>
54    );
55}