Debian Codegraph @

debian/missing-sources/proptest/src/arbitrary/_alloc/alloc.rs

raw
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::hash`.
11
12 use core::cmp;
13 use core::ops::Range;
14 use core::usize;
15
16 multiplex_alloc!(::alloc::alloc, ::std::alloc);
17
18 use crate::arbitrary::*;
19 use crate::strategy::statics::static_map;
20 use crate::strategy::*;
21
22 arbitrary!(self::alloc::Global; self::alloc::Global);
23
24 // Not Debug.
25 //lazy_just!(System, || System);
26
27 arbitrary!(self::alloc::Layout, SFnPtrMap<(Range<u8>, StrategyFor<usize>), Self>;
28 // 1. align must be a power of two and <= (1 << 31):
29 // 2. "when rounded up to the nearest multiple of align, must not overflow".
30 static_map((0u8..32u8, any::<usize>()), |(align_power, size)| {
31 let align = 1usize << align_power;
32 // TODO: This may only work on 64 bit processors, but previously it was broken
33 // even on 64 bit so still an improvement. 63 -> uint size - 1.
34 let max_size = (1usize << (usize::BITS - 1)) - (1 << usize::from(align_power));
35 // Not quite a uniform distribution due to clamping,
36 // but probably good enough
37 self::alloc::Layout::from_size_align(cmp::min(max_size, size), align).unwrap()
38 })
39 );
40
41 arbitrary!(self::alloc::AllocError, Just<Self>; Just(self::alloc::AllocError));
42 /* 2018-07-28 CollectionAllocErr is not currently available outside of using
43 * the `alloc` crate, which would require a different nightly feature. For now,
44 * disable.
45 arbitrary!(alloc::collections::CollectionAllocErr, TupleUnion<(WA<Just<Self>>, WA<Just<Self>>)>;
46 prop_oneof![Just(alloc::collections::CollectionAllocErr::AllocErr),
47 Just(alloc::collections::CollectionAllocErr::CapacityOverflow)]);
48 */
49
50 #[cfg(test)]
51 mod test {
52 multiplex_alloc!(::alloc::alloc, ::std::alloc);
53
54 no_panic_test!(
55 layout => self::alloc::Layout,
56 alloc_err => self::alloc::AllocError
57 //collection_alloc_err => alloc::collections::CollectionAllocErr
58 );
59 }