perl-test-generators 0.17.0

Proptest strategies and Arbitrary impls for Perl domain objects
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use proptest::prelude::*;

use super::chars::{ascii_alphanumeric_or_underscore, ascii_letter_or_underscore};

/// Generate a plain ASCII Perl identifier without a sigil.
pub fn perl_identifier() -> impl Strategy<Value = String> {
    (
        ascii_letter_or_underscore(),
        prop::collection::vec(ascii_alphanumeric_or_underscore(), 0..=10_usize),
    )
        .prop_map(|(first, rest)| std::iter::once(first).chain(rest).collect())
}

/// Generate a scalar variable name such as `$value`.
pub fn scalar_variable() -> impl Strategy<Value = String> {
    perl_identifier().prop_map(|name| format!("${name}"))
}