proptest_arbitrary/_std/
str.rs

1//! Arbitrary implementations for `std::str`.
2
3use super::*;
4use std::iter::repeat;
5use std::str::{ParseBoolError, Utf8Error, from_utf8};
6
7arbitrary!(ParseBoolError; "".parse::<bool>().unwrap_err());
8
9type ELSeq  = W<Just<&'static [u8]>>;
10type ELSeqs = TupleUnion<(ELSeq, ELSeq, ELSeq, ELSeq)>;
11
12fn gen_el_seqs() -> ELSeqs {
13    prop_oneof![
14        Just(&[0xC2]), // None
15        Just(&[0x80]), // Some(1)
16        Just(&[0xE0, 0xA0, 0x00]), // Some(2)
17        Just(&[0xF0, 0x90, 0x80, 0x00]) // Some(3)
18    ]
19}
20
21arbitrary!(Utf8Error, SFnPtrMap<(StrategyType<'a, u16>, ELSeqs), Utf8Error>;
22    static_map((any::<u16>(), gen_el_seqs()), |(vut, elseq)| {
23        let v = repeat(b'_').take(vut as usize)
24                    .chain(elseq.iter().cloned())
25                    .collect::<Vec<u8>>();
26        from_utf8(&v).unwrap_err()
27    })
28);
29
30#[cfg(test)]
31mod test {
32    no_panic_test!(
33        parse_bool_errror => ParseBoolError,
34        utf8_error => Utf8Error
35    );
36}