Skip to main content

perl_test_generators/code/
identifiers.rs

1use proptest::prelude::*;
2
3use super::chars::{ascii_alphanumeric_or_underscore, ascii_letter_or_underscore};
4
5/// Generate a plain ASCII Perl identifier without a sigil.
6pub fn perl_identifier() -> impl Strategy<Value = String> {
7    (
8        ascii_letter_or_underscore(),
9        prop::collection::vec(ascii_alphanumeric_or_underscore(), 0..=10_usize),
10    )
11        .prop_map(|(first, rest)| std::iter::once(first).chain(rest).collect())
12}
13
14/// Generate a scalar variable name such as `$value`.
15pub fn scalar_variable() -> impl Strategy<Value = String> {
16    perl_identifier().prop_map(|name| format!("${name}"))
17}