diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/proptest/src/arbitrary/non_zero.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/proptest/src/arbitrary/non_zero.rs')
-rw-r--r-- | vendor/proptest/src/arbitrary/non_zero.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/vendor/proptest/src/arbitrary/non_zero.rs b/vendor/proptest/src/arbitrary/non_zero.rs new file mode 100644 index 000000000..55a775beb --- /dev/null +++ b/vendor/proptest/src/arbitrary/non_zero.rs @@ -0,0 +1,66 @@ +//- +// Copyright 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. + +use core::convert::TryFrom; +use core::num::{ + NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, + NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, +}; + +use crate::strategy::{FilterMap, Strategy}; + +use super::{any, Arbitrary, StrategyFor}; + +macro_rules! non_zero_impl { + ($nz:ty, $prim:ty) => { + impl Arbitrary for $nz { + type Parameters = (); + type Strategy = + FilterMap<StrategyFor<$prim>, fn($prim) -> Option<Self>>; + + fn arbitrary_with((): Self::Parameters) -> Self::Strategy { + any::<$prim>().prop_filter_map("must be non zero", |i| { + Self::try_from(i).ok() + }) + } + } + }; +} + +non_zero_impl!(NonZeroU8, u8); +non_zero_impl!(NonZeroU16, u16); +non_zero_impl!(NonZeroU32, u32); +non_zero_impl!(NonZeroU64, u64); +non_zero_impl!(NonZeroU128, u128); +non_zero_impl!(NonZeroUsize, usize); + +non_zero_impl!(NonZeroI8, i8); +non_zero_impl!(NonZeroI16, i16); +non_zero_impl!(NonZeroI32, i32); +non_zero_impl!(NonZeroI64, i64); +non_zero_impl!(NonZeroI128, i128); +non_zero_impl!(NonZeroIsize, isize); + +#[cfg(test)] +mod test { + no_panic_test!( + u8 => core::num::NonZeroU8, + u16 => core::num::NonZeroU16, + u32 => core::num::NonZeroU32, + u64 => core::num::NonZeroU64, + u128 => core::num::NonZeroU128, + usize => core::num::NonZeroUsize, + i8 => core::num::NonZeroI8, + i16 => core::num::NonZeroI16, + i32 => core::num::NonZeroI32, + i64 => core::num::NonZeroI64, + i128 => core::num::NonZeroI128, + isize => core::num::NonZeroIsize + ); +} |