proptest/arbitrary/
tuples.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 tuples.
11
12use crate::arbitrary::{any_with, Arbitrary};
13
14macro_rules! impl_tuple {
15    ($($typ: ident),*) => {
16        impl<$($typ : Arbitrary),*> Arbitrary for ($($typ,)*) {
17            type Parameters = product_type![$($typ::Parameters,)*];
18            type Strategy = ($($typ::Strategy,)*);
19            fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
20                #[allow(non_snake_case)]
21                let product_unpack![$($typ),*] = args;
22                ($(any_with::<$typ>($typ)),*,)
23            }
24        }
25    };
26}
27
28arbitrary!((); ());
29impl_tuple!(T0);
30impl_tuple!(T0, T1);
31impl_tuple!(T0, T1, T2);
32impl_tuple!(T0, T1, T2, T3);
33impl_tuple!(T0, T1, T2, T3, T4);
34impl_tuple!(T0, T1, T2, T3, T4, T5);
35impl_tuple!(T0, T1, T2, T3, T4, T5, T6);
36impl_tuple!(T0, T1, T2, T3, T4, T5, T6, T7);
37impl_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8);
38impl_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9);
39
40#[cfg(test)]
41mod test {
42    no_panic_test!(
43        tuple_n10 => ((), bool, u8, u16, u32, u64, i8, i16, i32, i64)
44    );
45}