proptest 0.9.3

Hypothesis-like property-based testing and shrinking.
// Copyright 2017, 2018 The proptest developers
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
//> or the MIT license
// <LICENSE-MIT or>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Arbitrary implementations for `std::option`.

use core::option as opt;
use core::ops::RangeInclusive;
use crate::std_facade::string;

use crate::option::{weighted, OptionStrategy, Probability};
use crate::strategy::*;
use crate::strategy::statics::static_map;
use crate::arbitrary::*;

arbitrary!(Probability, MapInto<RangeInclusive<f64>, Self>;

// These are Option<AnUninhabitedType> impls:

arbitrary!(Option<string::ParseError>; None);
#[cfg(feature = "unstable")]
arbitrary!(Option<!>; None);

arbitrary!([A: Arbitrary] opt::Option<A>, OptionStrategy<A::Strategy>,
    product_type![Probability, A::Parameters];
    args => {
        let product_unpack![prob, a] = args;
        weighted(prob, any_with::<A>(a))

lift1!([] Option<A>, Probability; base, prob => weighted(prob, base));

arbitrary!([A: Arbitrary] opt::IntoIter<A>, SMapped<Option<A>, Self>,
    <Option<A> as Arbitrary>::Parameters;
    args => static_map(any_with::<Option<A>>(args), Option::into_iter));

lift1!(['static] opt::IntoIter<A>, Probability;
    base, prob => weighted(prob, base).prop_map(Option::into_iter)

#[cfg(feature = "unstable")]
arbitrary!(opt::NoneError; opt::NoneError);

mod test {
        probability => Probability,
        option      => Option<u8>,
        option_iter => opt::IntoIter<u8>,
        option_parse_error => Option<string::ParseError>