proptest/arbitrary/_alloc/
char.rs1use crate::std_facade::Vec;
13use core::char::*;
14use core::iter::once;
15use core::ops::Range;
16
17use crate::collection::vec;
18
19multiplex_alloc! {
20 core::char::DecodeUtf16, std::char::DecodeUtf16,
21 core::char::DecodeUtf16Error, std::char::DecodeUtf16Error,
22 core::char::decode_utf16, std::char::decode_utf16
23}
24
25const VEC_MAX: usize = ::core::u16::MAX as usize;
26
27use crate::arbitrary::*;
28use crate::strategy::statics::static_map;
29use crate::strategy::*;
30
31macro_rules! impl_wrap_char {
32 ($type: ty, $mapper: expr) => {
33 arbitrary!($type, SMapped<char, Self>;
34 static_map(any::<char>(), $mapper));
35 };
36}
37
38impl_wrap_char!(EscapeDebug, char::escape_debug);
39impl_wrap_char!(EscapeDefault, char::escape_default);
40impl_wrap_char!(EscapeUnicode, char::escape_unicode);
41#[cfg(feature = "unstable")]
42impl_wrap_char!(ToLowercase, char::to_lowercase);
43#[cfg(feature = "unstable")]
44impl_wrap_char!(ToUppercase, char::to_uppercase);
45
46arbitrary!(DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>,
47 SMapped<Vec<u16>, Self>;
48 static_map(vec(any::<u16>(), ..VEC_MAX), decode_utf16)
49);
50
51arbitrary!(ParseCharError, IndFlatten<Mapped<bool, Just<Self>>>;
52 any::<bool>().prop_ind_flat_map(|is_two|
53 Just((if is_two { "__" } else { "" }).parse::<char>().unwrap_err()))
54);
55
56#[cfg(feature = "unstable")]
57arbitrary!(CharTryFromError; {
58 use core::convert::TryFrom;
59 char::try_from(0xD800 as u32).unwrap_err()
60});
61
62arbitrary!(DecodeUtf16Error, SFnPtrMap<Range<u16>, Self>;
63 static_map(0xD800..0xE000, |x|
64 decode_utf16(once(x)).next().unwrap().unwrap_err())
65);
66
67#[cfg(test)]
68mod test {
69 no_panic_test!(
70 escape_debug => EscapeDebug,
71 escape_default => EscapeDefault,
72 escape_unicode => EscapeUnicode,
73 parse_char_error => ParseCharError,
74 decode_utf16_error => DecodeUtf16Error
75 );
76
77 no_panic_test!(
78 decode_utf16 => DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>
79 );
80
81 #[cfg(feature = "unstable")]
82 no_panic_test!(
83 to_lowercase => ToLowercase,
84 to_uppercase => ToUppercase,
85 char_try_from_error => CharTryFromError
86 );
87}