bolero_generator/
char.rs

1use crate::{
2    bounded::{BoundedGenerator, BoundedValue},
3    Driver, TypeGenerator, TypeGeneratorWithParams, ValueGenerator,
4};
5use core::ops::{Bound, Range};
6
7impl TypeGenerator for char {
8    fn generate<D: Driver>(driver: &mut D) -> Option<Self> {
9        driver.gen_char(Bound::Unbounded, Bound::Unbounded)
10    }
11}
12
13impl BoundedValue for char {
14    fn gen_bounded<D: Driver>(
15        driver: &mut D,
16        min: Bound<&Self>,
17        max: Bound<&Self>,
18    ) -> Option<Self> {
19        driver.gen_char(min, max)
20    }
21}
22
23impl ValueGenerator for char {
24    type Output = char;
25
26    fn generate<D: Driver>(&self, _driver: &mut D) -> Option<Self> {
27        Some(*self)
28    }
29}
30
31impl TypeGeneratorWithParams for char {
32    type Output = BoundedGenerator<Self, Range<Self>>;
33
34    fn gen_with() -> Self::Output {
35        BoundedGenerator::new((0 as char)..core::char::MAX)
36    }
37}
38
39#[test]
40fn char_type_test() {
41    let _ = generator_test!(produce::<char>());
42}
43
44#[test]
45fn char_bounds_test() {
46    let _ = generator_test!(produce::<char>().with().bounds('a'..='f'));
47}