Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support minLength and maxLength for stringMatching #5562

Open
TomerAberbach opened this issue Dec 26, 2024 · 0 comments
Open

Support minLength and maxLength for stringMatching #5562

TomerAberbach opened this issue Dec 26, 2024 · 0 comments

Comments

@TomerAberbach
Copy link
Contributor

TomerAberbach commented Dec 26, 2024

🚀 Feature Request

stringMatching generates based on the regular expression, but doesn't provide a way to set a min or max length on the generated strings.

Motivation

Sometimes you want to test specific lengths of a string matching a regex, but modifying a regular expression to have a specific min and/or max length can be pretty hard and confusing. It would be a lot easier to just be able to pass minLength and maxLength like the string arbitrary.

Example

const nameRegex = /^[a-z]+$/

// Test different lengths without having to modify regex
fc.stringMatching(nameRegex, { minLength: 10 })
fc.stringMatching(nameRegex, { maxLength: 10 })
fc.stringMatching(nameRegex, { minLength: 5, maxLength: 10 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant