4 releases
0.1.3 | Sep 13, 2023 |
---|---|
0.1.2 | Aug 25, 2023 |
0.1.1 | Jul 31, 2023 |
0.1.0 | Jul 31, 2023 |
#27 in #quickcheck
1,081 downloads per month
Used in 3 crates
17KB
359 lines
Derive macro for quickcheck::Arbitrary
.
Expands to calling Arbitrary::arbitrary
on every field of a struct.
use derive_quickcheck_arbitrary::Arbitrary;
#[derive(Clone, Arbitrary)]
struct Yakshaver {
id: usize,
name: String,
}
You can customise field generation by either:
- providing a callable that accepts
&mut quickcheck::Gen
. - always using the default value
#[derive(Clone, Arbitrary)]
struct Yakshaver {
/// Must be less than 10_000
#[arbitrary(gen(|g| num::clamp(usize::arbitrary(g), 0, 10_000) ))]
id: usize,
name: String,
#[arbitrary(default)]
always_false: bool,
}
You can skip enum variants:
#[derive(Clone, Arbitrary)]
enum YakType {
Domestic {
name: String,
},
Wild,
#[arbitrary(skip)]
Alien,
}
You can add bounds for generic structs:
#[derive(Clone, Arbitrary)]
#[arbitrary(where(T: Arbitrary))]
struct GenericYak<T> {
name: T,
}
Dependencies
~290–740KB
~17K SLoC