PatternValueGenerator
Generates string values based on regular expression patterns using the regexp-gen library.
This class encapsulates the Cornutum regexp-gen library for generating strings that either match or do not match a given ECMA-262 (JavaScript-style) regular expression pattern.
Usage
// Use default options
val generator = PatternValueGenerator()
val value = generator.generateValidValue("^[A-Z]{3}$", null, null, 0)
// Or use the shared default instance
val value = PatternValueGenerator.getDefault().generateValidValue("^[A-Z]{3}$", null, null, 0)
// Custom options
val customGenerator = PatternValueGenerator(PatternGenerationOptions(defaultMinLength = 10))Options
Generation behavior is controlled by PatternGenerationOptions passed to the constructor:
PatternGenerationOptions.defaultMinLength: fallback minimum length when not specified
PatternGenerationOptions.spaceChars: characters that match
\s(and affect\S)PatternGenerationOptions.anyPrintableChars: characters that match
.(any printable)
Library Limitations
The underlying regexp-gen library has the following limitations:
No negative lookahead/lookbehind: Patterns like
(?!...)or(?<!...)are not supportedNo word boundary assertions:
\band\Bare not supportedNo backreferences: Patterns referencing earlier capture groups are not supported
Some patterns accept all strings: For patterns like
.*, generating non-matching strings is impossible
When these limitations are encountered, the generator will return null and log a warning.
Determinism:
Valid generation uses
variationIndexas the random seed.Invalid generation uses a fixed seed and applies length hints only.