|
| 1 | +//! Generators for String type. |
| 2 | +
|
| 3 | +use crate::BoxGen; |
| 4 | +use crate::MapWithGen; |
| 5 | + |
| 6 | +/// Build String generator from char generator. |
| 7 | +fn strings_from_chars(chars: BoxGen<char>) -> BoxGen<String> { |
| 8 | + crate::gens::vec::any(chars) |
| 9 | + .map(|v| v.into_iter().collect(), |s| s.chars().collect()) |
| 10 | +} |
| 11 | + |
| 12 | +/// Strings of any possible Rust `char` value, that is any valid unicode scalar |
| 13 | +/// value. |
| 14 | +/// |
| 15 | +/// For implementation details, see [crate::gens::char::unicode]. |
| 16 | +pub fn unicode() -> BoxGen<String> { |
| 17 | + strings_from_chars(crate::gens::char::unicode()) |
| 18 | +} |
| 19 | + |
| 20 | +/// Shorthand for [unicode]. |
| 21 | +pub fn any() -> BoxGen<String> { |
| 22 | + unicode() |
| 23 | +} |
| 24 | + |
| 25 | +/// Strings of any arabic numeral 0..9. |
| 26 | +/// |
| 27 | +/// For implementation details, see [crate::gens::char::number]. |
| 28 | +pub fn number() -> BoxGen<String> { |
| 29 | + strings_from_chars(crate::gens::char::number()) |
| 30 | +} |
| 31 | + |
| 32 | +/// Strings of any alpha upper char. |
| 33 | +/// |
| 34 | +/// For implementation details, see [crate::gens::char::alpha_upper]. |
| 35 | +pub fn alpha_upper() -> BoxGen<String> { |
| 36 | + strings_from_chars(crate::gens::char::alpha_upper()) |
| 37 | +} |
| 38 | + |
| 39 | +/// Strings of any alpha lower char. |
| 40 | +/// |
| 41 | +/// For implementation details, see [crate::gens::char::alpha_lower]. |
| 42 | +pub fn alpha_lower() -> BoxGen<String> { |
| 43 | + strings_from_chars(crate::gens::char::alpha_lower()) |
| 44 | +} |
| 45 | + |
| 46 | +/// Strings of any alpha char. |
| 47 | +/// |
| 48 | +/// For implementation details, see [crate::gens::char::alpha]. |
| 49 | +pub fn alpha() -> BoxGen<String> { |
| 50 | + strings_from_chars(crate::gens::char::alpha()) |
| 51 | +} |
| 52 | + |
| 53 | +/// Strings of any alpha numeric char. |
| 54 | +/// |
| 55 | +/// For implementation details, see [crate::gens::char::alpha_numeric]. |
| 56 | +pub fn alpha_numeric() -> BoxGen<String> { |
| 57 | + strings_from_chars(crate::gens::char::alpha_numeric()) |
| 58 | +} |
| 59 | + |
| 60 | +/// Strings of any ASCII printable character. |
| 61 | +/// |
| 62 | +/// For implementation details, see [crate::gens::char::ascii_printable]. |
| 63 | +pub fn ascii_printable() -> BoxGen<String> { |
| 64 | + strings_from_chars(crate::gens::char::ascii_printable()) |
| 65 | +} |
| 66 | + |
| 67 | +/// Strings of any ASCII character, including both printable and non-printable |
| 68 | +/// characters. |
| 69 | +/// |
| 70 | +/// For implementation details, see [crate::gens::char::ascii]. |
| 71 | +pub fn ascii() -> BoxGen<String> { |
| 72 | + strings_from_chars(crate::gens::char::ascii()) |
| 73 | +} |
0 commit comments