diff options
Diffstat (limited to 'vendor/proptest/src/arbitrary/_alloc')
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/alloc.rs | 59 | ||||
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/borrow.rs | 27 | ||||
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/boxed.rs | 19 | ||||
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/char.rs | 89 | ||||
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/collections.rs | 304 | ||||
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/hash.rs | 32 | ||||
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/mod.rs | 22 | ||||
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/ops.rs | 104 | ||||
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/rc.rs | 21 | ||||
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/str.rs | 49 | ||||
-rw-r--r-- | vendor/proptest/src/arbitrary/_alloc/sync.rs | 76 |
11 files changed, 802 insertions, 0 deletions
diff --git a/vendor/proptest/src/arbitrary/_alloc/alloc.rs b/vendor/proptest/src/arbitrary/_alloc/alloc.rs new file mode 100644 index 000000000..598c80ff0 --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/alloc.rs @@ -0,0 +1,59 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for `std::hash`. + +use core::cmp; +use core::ops::Range; +use core::usize; + +multiplex_alloc!(::alloc::alloc, ::std::alloc); + +use crate::arbitrary::*; +use crate::strategy::statics::static_map; +use crate::strategy::*; + +arbitrary!(self::alloc::Global; self::alloc::Global); + +// Not Debug. +//lazy_just!(System, || System); + +arbitrary!(self::alloc::Layout, SFnPtrMap<(Range<u8>, StrategyFor<usize>), Self>; + // 1. align must be a power of two and <= (1 << 31): + // 2. "when rounded up to the nearest multiple of align, must not overflow". + static_map((0u8..32u8, any::<usize>()), |(align_power, size)| { + let align = 1usize << align_power; + // TODO: This may only work on 64 bit processors, but previously it was broken + // even on 64 bit so still an improvement. 63 -> uint size - 1. + let max_size = (1usize << 63) - (1 << usize::from(align_power)); + // Not quite a uniform distribution due to clamping, + // but probably good enough + self::alloc::Layout::from_size_align(cmp::min(max_size, size), align).unwrap() + }) +); + +arbitrary!(self::alloc::AllocError, Just<Self>; Just(self::alloc::AllocError)); +/* 2018-07-28 CollectionAllocErr is not currently available outside of using + * the `alloc` crate, which would require a different nightly feature. For now, + * disable. +arbitrary!(alloc::collections::CollectionAllocErr, TupleUnion<(WA<Just<Self>>, WA<Just<Self>>)>; + prop_oneof![Just(alloc::collections::CollectionAllocErr::AllocErr), + Just(alloc::collections::CollectionAllocErr::CapacityOverflow)]); + */ + +#[cfg(test)] +mod test { + multiplex_alloc!(::alloc::alloc, ::std::alloc); + + no_panic_test!( + layout => self::alloc::Layout, + alloc_err => self::alloc::AllocError + //collection_alloc_err => alloc::collections::CollectionAllocErr + ); +} diff --git a/vendor/proptest/src/arbitrary/_alloc/borrow.rs b/vendor/proptest/src/arbitrary/_alloc/borrow.rs new file mode 100644 index 000000000..153115e18 --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/borrow.rs @@ -0,0 +1,27 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for std::borrow. + +use crate::std_facade::fmt; +use crate::std_facade::{Cow, ToOwned}; +use core::borrow::Borrow; + +use crate::arbitrary::{any_with, Arbitrary, SMapped}; +use crate::strategy::statics::static_map; + +arbitrary!( + [A: Arbitrary + Borrow<B>, B: ToOwned<Owned = A> + fmt::Debug + ?Sized] + Cow<'static, B>, SMapped<A, Self>, A::Parameters; + args => static_map(any_with::<A>(args), Cow::Owned) +); + +lift1!([Borrow<B> + 'static, B: ToOwned<Owned = A> + fmt::Debug + ?Sized] + Cow<'static, B>; base => static_map(base, Cow::Owned) +); diff --git a/vendor/proptest/src/arbitrary/_alloc/boxed.rs b/vendor/proptest/src/arbitrary/_alloc/boxed.rs new file mode 100644 index 000000000..222362504 --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/boxed.rs @@ -0,0 +1,19 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for `std::boxed`. + +use crate::std_facade::Box; + +wrap_from!(Box); + +#[cfg(test)] +mod test { + no_panic_test!(boxed => Box<u8>); +} diff --git a/vendor/proptest/src/arbitrary/_alloc/char.rs b/vendor/proptest/src/arbitrary/_alloc/char.rs new file mode 100644 index 000000000..fab9dd824 --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/char.rs @@ -0,0 +1,89 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for `std::char`. + +use crate::std_facade::Vec; +use core::char::*; +use core::iter::once; +use core::ops::Range; + +use crate::collection::vec; + +multiplex_alloc! { + core::char::DecodeUtf16, std::char::DecodeUtf16, + core::char::DecodeUtf16Error, std::char::DecodeUtf16Error, + core::char::decode_utf16, std::char::decode_utf16 +} + +const VEC_MAX: usize = ::core::u16::MAX as usize; + +use crate::arbitrary::*; +use crate::strategy::statics::static_map; +use crate::strategy::*; + +macro_rules! impl_wrap_char { + ($type: ty, $mapper: expr) => { + arbitrary!($type, SMapped<char, Self>; + static_map(any::<char>(), $mapper)); + }; +} + +impl_wrap_char!(EscapeDebug, char::escape_debug); +impl_wrap_char!(EscapeDefault, char::escape_default); +impl_wrap_char!(EscapeUnicode, char::escape_unicode); +#[cfg(feature = "unstable")] +impl_wrap_char!(ToLowercase, char::to_lowercase); +#[cfg(feature = "unstable")] +impl_wrap_char!(ToUppercase, char::to_uppercase); + +#[cfg(feature = "break-dead-code")] +arbitrary!(DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>, + SMapped<Vec<u16>, Self>; + static_map(vec(any::<u16>(), ..VEC_MAX), decode_utf16) +); + +arbitrary!(ParseCharError, IndFlatten<Mapped<bool, Just<Self>>>; + any::<bool>().prop_ind_flat_map(|is_two| + Just((if is_two { "__" } else { "" }).parse::<char>().unwrap_err())) +); + +#[cfg(feature = "unstable")] +arbitrary!(CharTryFromError; { + use core::convert::TryFrom; + char::try_from(0xD800 as u32).unwrap_err() +}); + +arbitrary!(DecodeUtf16Error, SFnPtrMap<Range<u16>, Self>; + static_map(0xD800..0xE000, |x| + decode_utf16(once(x)).next().unwrap().unwrap_err()) +); + +#[cfg(test)] +mod test { + no_panic_test!( + escape_debug => EscapeDebug, + escape_default => EscapeDefault, + escape_unicode => EscapeUnicode, + parse_char_error => ParseCharError, + decode_utf16_error => DecodeUtf16Error + ); + + #[cfg(feature = "break-dead-code")] + no_panic_test!( + decode_utf16 => DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter> + ); + + #[cfg(feature = "unstable")] + no_panic_test!( + to_lowercase => ToLowercase, + to_uppercase => ToUppercase, + char_try_from_error => CharTryFromError + ); +} diff --git a/vendor/proptest/src/arbitrary/_alloc/collections.rs b/vendor/proptest/src/arbitrary/_alloc/collections.rs new file mode 100644 index 000000000..20f3a9292 --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/collections.rs @@ -0,0 +1,304 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for `std::collections`. + +//#![cfg_attr(feature="cargo-clippy", allow(implicit_hasher))] + +//============================================================================== +// Imports: +//============================================================================== + +use crate::std_facade::{ + binary_heap, btree_map, btree_set, fmt, linked_list, vec, vec_deque, Arc, + BTreeMap, BTreeSet, BinaryHeap, Box, LinkedList, Rc, Vec, VecDeque, +}; +use core::hash::Hash; +use core::ops::{Bound, RangeInclusive}; + +#[cfg(feature = "std")] +use crate::std_facade::{hash_map, hash_set, HashMap, HashSet}; + +use crate::arbitrary::*; +use crate::collection::*; +use crate::strategy::statics::static_map; +use crate::strategy::*; + +//============================================================================== +// Macros: +//============================================================================== + +/// Parameters for configuring the generation of `StrategyFor<...<A>>`. +type RangedParams1<A> = product_type![SizeRange, A]; + +/// Parameters for configuring the generation of `StrategyFor<...<A, B>>`. +type RangedParams2<A, B> = product_type![SizeRange, A, B]; + +macro_rules! impl_1 { + ($typ: ident, $strat: ident, $($bound : path),* => $fun: ident) => { + arbitrary!([A: Arbitrary $(+ $bound)*] $typ<A>, + $strat<A::Strategy>, RangedParams1<A::Parameters>; + args => { + let product_unpack![range, a] = args; + $fun(any_with::<A>(a), range) + }); + + lift1!([$($bound+)*] $typ<A>, SizeRange; + base, args => $fun(base, args)); + }; +} + +arbitrary!(SizeRange, MapInto<StrategyFor<RangeInclusive<usize>>, Self>; + any::<RangeInclusive<usize>>().prop_map_into() +); + +//============================================================================== +// Vec, VecDeque, LinkedList, BTreeSet, BinaryHeap, HashSet, HashMap: +//============================================================================== + +macro_rules! dst_wrapped { + ($($w: ident),*) => { + $(arbitrary!([A: Arbitrary] $w<[A]>, + MapInto<StrategyFor<Vec<A>>, Self>, + <Vec<A> as Arbitrary>::Parameters; + a => any_with::<Vec<A>>(a).prop_map_into() + );)* + }; +} + +impl_1!(Vec, VecStrategy, => vec); +dst_wrapped!(Box, Rc, Arc); +impl_1!(VecDeque, VecDequeStrategy, => vec_deque); +impl_1!(LinkedList, LinkedListStrategy, => linked_list); +impl_1!(BTreeSet, BTreeSetStrategy, Ord => btree_set); +impl_1!(BinaryHeap, BinaryHeapStrategy, Ord => binary_heap); +#[cfg(feature = "std")] +impl_1!(HashSet, HashSetStrategy, Hash, Eq => hash_set); + +//============================================================================== +// IntoIterator: +//============================================================================== + +macro_rules! into_iter_1 { + ($module: ident, $type: ident $(, $bound : path)*) => { + arbitrary!([A: Arbitrary $(+ $bound)*] + $module::IntoIter<A>, + SMapped<$type<A>, Self>, + <$type<A> as Arbitrary>::Parameters; + args => static_map(any_with::<$type<A>>(args), $type::into_iter)); + + lift1!(['static + $($bound+)*] $module::IntoIter<A>, SizeRange; + base, args => + $module(base, args).prop_map($type::into_iter)); + }; +} + +into_iter_1!(vec, Vec); +into_iter_1!(vec_deque, VecDeque); +into_iter_1!(linked_list, LinkedList); +into_iter_1!(btree_set, BTreeSet, Ord); +into_iter_1!(binary_heap, BinaryHeap, Ord); +#[cfg(feature = "std")] +into_iter_1!(hash_set, HashSet, Hash, Eq); + +//============================================================================== +// HashMap: +//============================================================================== + +#[cfg(feature = "std")] +arbitrary!([A: Arbitrary + Hash + Eq, B: Arbitrary] HashMap<A, B>, +HashMapStrategy<A::Strategy, B::Strategy>, +RangedParams2<A::Parameters, B::Parameters>; +args => { + let product_unpack![range, a, b] = args; + hash_map(any_with::<A>(a), any_with::<B>(b), range) +}); + +#[cfg(feature = "std")] +arbitrary!([A: Arbitrary + Hash + Eq, B: Arbitrary] hash_map::IntoIter<A, B>, + SMapped<HashMap<A, B>, Self>, + <HashMap<A, B> as Arbitrary>::Parameters; + args => static_map(any_with::<HashMap<A, B>>(args), HashMap::into_iter)); + +#[cfg(feature = "std")] +lift1!([, K: Hash + Eq + Arbitrary + 'static] HashMap<K, A>, + RangedParams1<K::Parameters>; + base, args => { + let product_unpack![range, k] = args; + hash_map(any_with::<K>(k), base, range) + } +); + +#[cfg(feature = "std")] +lift1!(['static, K: Hash + Eq + Arbitrary + 'static] hash_map::IntoIter<K, A>, + RangedParams1<K::Parameters>; + base, args => { + let product_unpack![range, k] = args; + static_map(hash_map(any_with::<K>(k), base, range), HashMap::into_iter) + } +); + +#[cfg(feature = "std")] +impl<A: fmt::Debug + Eq + Hash, B: fmt::Debug> functor::ArbitraryF2<A, B> + for HashMap<A, B> +{ + type Parameters = SizeRange; + + fn lift2_with<AS, BS>( + fst: AS, + snd: BS, + args: Self::Parameters, + ) -> BoxedStrategy<Self> + where + AS: Strategy<Value = A> + 'static, + BS: Strategy<Value = B> + 'static, + { + hash_map(fst, snd, args).boxed() + } +} + +#[cfg(feature = "std")] +impl<A: fmt::Debug + Eq + Hash + 'static, B: fmt::Debug + 'static> + functor::ArbitraryF2<A, B> for hash_map::IntoIter<A, B> +{ + type Parameters = SizeRange; + + fn lift2_with<AS, BS>( + fst: AS, + snd: BS, + args: Self::Parameters, + ) -> BoxedStrategy<Self> + where + AS: Strategy<Value = A> + 'static, + BS: Strategy<Value = B> + 'static, + { + static_map(hash_map(fst, snd, args), HashMap::into_iter).boxed() + } +} + +//============================================================================== +// BTreeMap: +//============================================================================== + +arbitrary!([A: Arbitrary + Ord, B: Arbitrary] BTreeMap<A, B>, +BTreeMapStrategy<A::Strategy, B::Strategy>, +RangedParams2<A::Parameters, B::Parameters>; +args => { + let product_unpack![range, a, b] = args; + btree_map(any_with::<A>(a), any_with::<B>(b), range) +}); + +lift1!([, K: Ord + Arbitrary + 'static] BTreeMap<K, A>, + RangedParams1<K::Parameters>; + base, args => { + let product_unpack![range, k] = args; + btree_map(any_with::<K>(k), base, range) + } +); + +impl<A: fmt::Debug + Ord, B: fmt::Debug> functor::ArbitraryF2<A, B> + for BTreeMap<A, B> +{ + type Parameters = SizeRange; + fn lift2_with<AS, BS>( + fst: AS, + snd: BS, + args: Self::Parameters, + ) -> BoxedStrategy<Self> + where + AS: Strategy<Value = A> + 'static, + BS: Strategy<Value = B> + 'static, + { + btree_map(fst, snd, args).boxed() + } +} + +arbitrary!([A: Arbitrary + Ord, B: Arbitrary] btree_map::IntoIter<A, B>, + SMapped<BTreeMap<A, B>, Self>, + <BTreeMap<A, B> as Arbitrary>::Parameters; + args => static_map(any_with::<BTreeMap<A, B>>(args), BTreeMap::into_iter)); + +impl<A: fmt::Debug + Ord + 'static, B: fmt::Debug + 'static> + functor::ArbitraryF2<A, B> for btree_map::IntoIter<A, B> +{ + type Parameters = SizeRange; + + fn lift2_with<AS, BS>( + fst: AS, + snd: BS, + args: Self::Parameters, + ) -> BoxedStrategy<Self> + where + AS: Strategy<Value = A> + 'static, + BS: Strategy<Value = B> + 'static, + { + static_map(btree_map(fst, snd, args), BTreeMap::into_iter).boxed() + } +} + +//============================================================================== +// Bound: +//============================================================================== + +arbitrary!([A: Arbitrary] Bound<A>, + TupleUnion<( + WA<SFnPtrMap<Arc<A::Strategy>, Self>>, + WA<SFnPtrMap<Arc<A::Strategy>, Self>>, + WA<LazyJustFn<Self>> + )>, + A::Parameters; + args => { + let base = Arc::new(any_with::<A>(args)); + prop_oneof![ + 2 => static_map(base.clone(), Bound::Included), + 2 => static_map(base, Bound::Excluded), + 1 => LazyJust::new(|| Bound::Unbounded), + ] + } +); + +lift1!(['static] Bound<A>; base => { + let base = Rc::new(base); + prop_oneof![ + 2 => base.clone().prop_map(Bound::Included), + 2 => base.prop_map(Bound::Excluded), + 1 => LazyJustFn::new(|| Bound::Unbounded), + ] +}); + +#[cfg(test)] +mod test { + no_panic_test!( + size_bounds => SizeRange, + vec => Vec<u8>, + box_slice => Box<[u8]>, + rc_slice => Rc<[u8]>, + arc_slice => Arc<[u8]>, + vec_deque => VecDeque<u8>, + linked_list => LinkedList<u8>, + btree_set => BTreeSet<u8>, + btree_map => BTreeMap<u8, u8>, + bound => Bound<u8>, + binary_heap => BinaryHeap<u8>, + into_iter_vec => vec::IntoIter<u8>, + into_iter_vec_deque => vec_deque::IntoIter<u8>, + into_iter_linked_list => linked_list::IntoIter<u8>, + into_iter_binary_heap => binary_heap::IntoIter<u8>, + into_iter_btree_set => btree_set::IntoIter<u8>, + into_iter_btree_map => btree_map::IntoIter<u8, u8> + ); + + #[cfg(feature = "std")] + no_panic_test!( + hash_set => HashSet<u8>, + hash_map => HashMap<u8, u8>, + into_iter_hash_set => hash_set::IntoIter<u8>, + into_iter_hash_map => hash_map::IntoIter<u8, u8> + ); +} diff --git a/vendor/proptest/src/arbitrary/_alloc/hash.rs b/vendor/proptest/src/arbitrary/_alloc/hash.rs new file mode 100644 index 000000000..8979bafca --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/hash.rs @@ -0,0 +1,32 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for `std::hash`. + +#[cfg(feature = "std")] +use crate::std_facade::hash_map::{DefaultHasher, RandomState}; +use core::hash::{BuildHasherDefault, Hasher}; + +// NOTE: don't impl for std::hash::SipHasher.. since deprecated! + +// over-constrain on purpose! +arbitrary!([H: Default + Hasher] BuildHasherDefault<H>; Default::default()); + +#[cfg(feature = "std")] +lazy_just!(DefaultHasher, Default::default; RandomState, Default::default); + +#[cfg(test)] +mod test { + #[cfg(feature = "std")] + no_panic_test!( + default_hasher => DefaultHasher, + random_state => RandomState, + build_hasher_default => BuildHasherDefault<DefaultHasher> + ); +} diff --git a/vendor/proptest/src/arbitrary/_alloc/mod.rs b/vendor/proptest/src/arbitrary/_alloc/mod.rs new file mode 100644 index 000000000..f286cab6d --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/mod.rs @@ -0,0 +1,22 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for liballoc. + +#[cfg(feature = "unstable")] +mod alloc; +mod borrow; +mod boxed; +mod char; +mod collections; +mod hash; +mod ops; +mod rc; +mod str; +mod sync; diff --git a/vendor/proptest/src/arbitrary/_alloc/ops.rs b/vendor/proptest/src/arbitrary/_alloc/ops.rs new file mode 100644 index 000000000..338f52c50 --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/ops.rs @@ -0,0 +1,104 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for `std::ops`. + +use crate::std_facade::Arc; +use core::ops::*; + +use crate::arbitrary::*; +use crate::strategy::statics::static_map; +use crate::strategy::*; + +arbitrary!(RangeFull; ..); +wrap_ctor!(RangeFrom, |a| a..); +wrap_ctor!(RangeTo, |a| ..a); + +wrap_ctor!(RangeToInclusive, |a| ..=a); + +arbitrary!( + [A: PartialOrd + Arbitrary] RangeInclusive<A>, + SMapped<(A, A), Self>, product_type![A::Parameters, A::Parameters]; + args => static_map(any_with::<(A, A)>(args), + |(a, b)| if b < a { b..=a } else { a..=b }) +); + +lift1!([PartialOrd] RangeInclusive<A>; base => { + let base = Arc::new(base); + (base.clone(), base).prop_map(|(a, b)| if b < a { b..=a } else { a..=b }) +}); + +arbitrary!( + [A: PartialOrd + Arbitrary] Range<A>, + SMapped<(A, A), Self>, product_type![A::Parameters, A::Parameters]; + args => static_map(any_with::<(A, A)>(args), + |(a, b)| if b < a { b..a } else { a..b }) +); + +lift1!([PartialOrd] Range<A>; base => { + let base = Arc::new(base); + (base.clone(), base).prop_map(|(a, b)| if b < a { b..a } else { a..b }) +}); + +#[cfg(feature = "unstable")] +arbitrary!( + [Y: Arbitrary, R: Arbitrary] GeneratorState<Y, R>, + TupleUnion<(WA<SMapped<Y, Self>>, WA<SMapped<R, Self>>)>, + product_type![Y::Parameters, R::Parameters]; + args => { + let product_unpack![y, r] = args; + prop_oneof![ + static_map(any_with::<Y>(y), GeneratorState::Yielded), + static_map(any_with::<R>(r), GeneratorState::Complete) + ] + } +); + +#[cfg(feature = "unstable")] +use core::fmt; + +#[cfg(feature = "unstable")] +impl<A: fmt::Debug + 'static, B: fmt::Debug + 'static> + functor::ArbitraryF2<A, B> for GeneratorState<A, B> +{ + type Parameters = (); + + fn lift2_with<AS, BS>( + fst: AS, + snd: BS, + _args: Self::Parameters, + ) -> BoxedStrategy<Self> + where + AS: Strategy<Value = A> + 'static, + BS: Strategy<Value = B> + 'static, + { + prop_oneof![ + fst.prop_map(GeneratorState::Yielded), + snd.prop_map(GeneratorState::Complete) + ] + .boxed() + } +} + +#[cfg(test)] +mod test { + no_panic_test!( + range_full => RangeFull, + range_from => RangeFrom<usize>, + range_to => RangeTo<usize>, + range => Range<usize>, + range_inclusive => RangeInclusive<usize>, + range_to_inclusive => RangeToInclusive<usize> + ); + + #[cfg(feature = "unstable")] + no_panic_test!( + generator_state => GeneratorState<u32, u64> + ); +} diff --git a/vendor/proptest/src/arbitrary/_alloc/rc.rs b/vendor/proptest/src/arbitrary/_alloc/rc.rs new file mode 100644 index 000000000..1ddb6aa00 --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/rc.rs @@ -0,0 +1,21 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for `std::rc`. + +use crate::std_facade::Rc; + +// Weak would always give None on upgrade since there's no owned Rc. + +wrap_from!(Rc); + +#[cfg(test)] +mod test { + no_panic_test!(rc => Rc<u8>); +} diff --git a/vendor/proptest/src/arbitrary/_alloc/str.rs b/vendor/proptest/src/arbitrary/_alloc/str.rs new file mode 100644 index 000000000..72ba248da --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/str.rs @@ -0,0 +1,49 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for `std::str`. + +use crate::std_facade::Vec; +use core::iter::repeat; +use core::str::{from_utf8, ParseBoolError, Utf8Error}; + +use crate::arbitrary::*; +use crate::strategy::statics::static_map; +use crate::strategy::*; + +arbitrary!(ParseBoolError; "".parse::<bool>().unwrap_err()); + +type ELSeq = WA<Just<&'static [u8]>>; +type ELSeqs = TupleUnion<(ELSeq, ELSeq, ELSeq, ELSeq)>; + +fn gen_el_seqs() -> ELSeqs { + prop_oneof![ + Just(&[0xC2]), // None + Just(&[0x80]), // Some(1) + Just(&[0xE0, 0xA0, 0x00]), // Some(2) + Just(&[0xF0, 0x90, 0x80, 0x00]) // Some(3) + ] +} + +arbitrary!(Utf8Error, SFnPtrMap<(StrategyFor<u16>, ELSeqs), Utf8Error>; + static_map((any::<u16>(), gen_el_seqs()), |(vut, elseq)| { + let v = repeat(b'_').take(vut as usize) + .chain(elseq.iter().cloned()) + .collect::<Vec<u8>>(); + from_utf8(&v).unwrap_err() + }) +); + +#[cfg(test)] +mod test { + no_panic_test!( + parse_bool_errror => ParseBoolError, + utf8_error => Utf8Error + ); +} diff --git a/vendor/proptest/src/arbitrary/_alloc/sync.rs b/vendor/proptest/src/arbitrary/_alloc/sync.rs new file mode 100644 index 000000000..ebc222581 --- /dev/null +++ b/vendor/proptest/src/arbitrary/_alloc/sync.rs @@ -0,0 +1,76 @@ +//- +// Copyright 2017, 2018 The proptest developers +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Arbitrary implementations for `std::sync`. + +use crate::std_facade::Arc; +use core::sync::atomic::*; + +use crate::arbitrary::*; +use crate::strategy::statics::static_map; +use crate::strategy::*; + +wrap_from!(Arc); + +macro_rules! atomic { + ($($type: ident, $base: ty);+) => { + $(arbitrary!($type, SMapped<$base, Self>; + static_map(any::<$base>(), $type::new) + );)+ + }; +} + +// impl_wrap_gen!(AtomicPtr); // We don't have impl Arbitrary for *mut T yet. +atomic!(AtomicBool, bool; AtomicIsize, isize; AtomicUsize, usize); + +#[cfg(feature = "unstable")] +atomic!(AtomicI8, i8; AtomicI16, i16; AtomicI32, i32; + AtomicU8, u8; AtomicU16, u16; AtomicU32, u32); + +#[cfg(all(feature = "unstable", feature = "atomic64bit"))] +atomic!(AtomicI64, i64; AtomicU64, u64); + +arbitrary!(Ordering, + TupleUnion<(WA<Just<Self>>, WA<Just<Self>>, WA<Just<Self>>, + WA<Just<Self>>, WA<Just<Self>>)>; + prop_oneof![ + Just(Ordering::Relaxed), + Just(Ordering::Release), + Just(Ordering::Acquire), + Just(Ordering::AcqRel), + Just(Ordering::SeqCst) + ] +); + +#[cfg(test)] +mod test { + no_panic_test!( + arc => Arc<u8>, + atomic_bool => AtomicBool, + atomic_isize => AtomicIsize, + atomic_usize => AtomicUsize, + ordering => Ordering + ); + + #[cfg(feature = "unstable")] + no_panic_test!( + atomic_i8 => AtomicI8, + atomic_i16 => AtomicI16, + atomic_i32 => AtomicI32, + atomic_u8 => AtomicU8, + atomic_u16 => AtomicU16, + atomic_u32 => AtomicU32 + ); + + #[cfg(all(feature = "unstable", feature = "atomic64bit"))] + no_panic_test!( + atomic_i64 => AtomicI64, + atomic_u64 => AtomicU64 + ); +} |