App-Test-Generator
view release on metacpan or search on metacpan
The `matches` and `nomatch` sub-keys are treated specially â their
values are compiled to `Regexp` objects via `eval { qr/.../ }` and
then rendered using `perl_quote` so they appear as `qr{...}` in the
generated test. This prevents unmatched bracket characters in the
pattern from causing compilation failures.
Other sub-keys are rendered via `perl_quote`.
### API specification
#### input
{ href => { type => 'any', optional => 1 } }
#### output
{ type => 'string' }
## render\_args\_hash
Render a flat hashref into a Perl source-code argument list of the
form `'key' =` value, ...>, suitable for embedding in a function call
in a generated test file.
my $code = render_args_hash({ type => 'string', min => 1 });
# returns: "'min' => 1, 'type' => 'string'"
### Arguments
- `$href`
A flat hashref of key-value pairs. Values may be scalars, arrayrefs,
or Regexp objects â all are handled by `perl_quote`.
### Returns
A comma-separated string of `key =` value> pairs sorted by key.
Returns an empty string if `$href` is undef, empty, or not a hashref.
### Notes
Keys and values are both rendered via `perl_quote`. In particular,
`Regexp` values are rendered as `qr{...}` which is correct for
[Params::Validate::Strict](https://metacpan.org/pod/Params%3A%3AValidate%3A%3AStrict) and [Return::Set](https://metacpan.org/pod/Return%3A%3ASet) schema arguments in
the generated test.
### API specification
#### input
{ href => { type => 'any', optional => 1 } }
#### output
{ type => 'string' }
## render\_arrayref\_map
Render a hashref whose values are arrayrefs into a Perl source-code
fragment suitable for use as a hash literal in a generated test file.
my $code = render_arrayref_map({ name => ['', 'a' x 100] });
### Arguments
- `$href`
A hashref whose values are arrayrefs. Keys whose values are not
arrayrefs are silently skipped.
### Returns
A comma-separated string of `'key' =` \[ val, ... \]> entries, one per
qualifying key, sorted alphabetically. Returns the string `'()'` if
`$href` is undef, empty, or not a hashref â this produces an empty
hash assignment in the generated test rather than a syntax error.
### Notes
Array element values are rendered via `perl_quote` which handles
scalars, arrayrefs, and Regexp objects. Non-arrayref values are
skipped without warning â this is intentional since callers may pass
mixed-value hashes and only want the arrayref entries rendered.
### API specification
#### input
{ href => { type => 'any', optional => 1 } }
#### output
{ type => 'string' }
## perl\_quote
Convert any Perl value into a source-code fragment that reproduces that value
when evaluated in a generated test file.
### Arguments
- `$v`
Any Perl value. May be undef, a scalar, an arrayref, a Regexp, or a blessed
object. All types are handled â undef becomes `'undef'`, the strings
`'true'`/`'false'` become the Perl boolean constants `!!1`/`!!0`,
numbers are unquoted, other strings are single-quoted, arrayrefs recurse,
Regexps become `qr{...}`, and anything else (including hashrefs and
blessed objects) falls through to `render_fallback`.
### API specification
#### input
{ v => { type => 'any', optional => 1 } }
#### output
{ type => 'string' }
# NOTES
`seed` and `iterations` really should be within `config`.
# SEE ALSO
- [Test Dashboard](https://nigelhorne.github.io/App-Test-Generator/coverage/)
- [App::Test::Generator::Template](https://metacpan.org/pod/App%3A%3ATest%3A%3AGenerator%3A%3ATemplate) - Template of the file of tests created by `App::Test::Generator`
- [App::Test::Generator::SchemaExtractor](https://metacpan.org/pod/App%3A%3ATest%3A%3AGenerator%3A%3ASchemaExtractor) - Create schemas from Perl programs
- [Params::Validate::Strict](https://metacpan.org/pod/Params%3A%3AValidate%3A%3AStrict): Schema Definition
- [Params::Get](https://metacpan.org/pod/Params%3A%3AGet): Input validation
- [Return::Set](https://metacpan.org/pod/Return%3A%3ASet): Output validation
- [Test::LectroTest](https://metacpan.org/pod/Test%3A%3ALectroTest)
- [Test::Most](https://metacpan.org/pod/Test%3A%3AMost)
- [YAML::XS](https://metacpan.org/pod/YAML%3A%3AXS)
# AUTHOR
Nigel Horne, `<njh at nigelhorne.com>`
Portions of this module's initial design and documentation were created with the
assistance of AI.
# SUPPORT
This module is provided as-is without any warranty.
You can find documentation for this module with the perldoc command.
perldoc App::Test::Generator
You can also look for information at:
- MetaCPAN
[https://metacpan.org/release/App-Test-Generator](https://metacpan.org/release/App-Test-Generator)
( run in 1.206 second using v1.01-cache-2.11-cpan-364913b4093 )