proptest/arbitrary/
primitives.rs

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 primitive types.
11
12use crate::bool;
13use crate::char;
14use crate::num::{
15    f32, f64, i16, i32, i64, i8, isize, u16, u32, u64, u8, usize,
16};
17#[cfg(not(target_arch = "wasm32"))]
18use crate::num::{i128, u128};
19
20arbitrary!(bool, i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
21
22#[cfg(not(target_arch = "wasm32"))]
23arbitrary!(i128, u128);
24
25// Note that for floating point types we limit the space since a lot of code
26// isn't prepared for (and is not intended to be) things like NaN and infinity.
27arbitrary!(f32, f32::Any; {
28    f32::POSITIVE | f32::NEGATIVE | f32::ZERO | f32::SUBNORMAL | f32::NORMAL
29});
30arbitrary!(f64, f64::Any; {
31    f64::POSITIVE | f64::NEGATIVE | f64::ZERO | f64::SUBNORMAL | f64::NORMAL
32});
33
34arbitrary!(char, char::CharStrategy<'static>; char::any());
35
36#[cfg(test)]
37mod test {
38    no_panic_test!(
39        bool => bool,
40        char => char,
41        f32 => f32, f64 => f64,
42        isize => isize, usize => usize,
43        i8 => i8, i16 => i16, i32 => i32, i64 => i64, i128 => i128,
44        u8 => u8, u16 => u16, u32 => u32, u64 => u64, u128 => u128
45    );
46}