-
-
Notifications
You must be signed in to change notification settings - Fork 64
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 pattern(regex) for StringArbitrary #68
Comments
Supporting full regex syntax sounds like a monumental task. What are the basic features you need? |
@jlink
|
What about being a bit more explicit about how those different formats compose, e.g.
It's definitely more verbose but IMO communicates better how an email (or any other format) is composed. |
@jlink |
The feature is in the backlog. But not scheduled for implementation yet. Thanks for using jqwik! |
There seems to be a javascript library for creating strings with regex. |
@mhyeon-lee Thanks for the hint. I’ll check it out. |
There is also mifmif/Generex which uses cs-au-dk/dk.brics.automaton under the covers to generate strings from regular expressions. Both of these are Java libraries. |
The problem with external libs in a testing framework is dependency on something that might possibly be in the (transitive) dependency list of a subject under test. That's why I'm fighting hard to not have those external deps in jqwik. One possible solution is to provide regex generation as external 3rd party extension. |
@jlink |
An Extension API is what I’m currently working on. |
Just funny note about valid email address and regexp. It seems way more complex to cover all valid email address: https://www.regular-expressions.info/email.html |
@mmerdes The article you link to really seems to offer a low effort approach that might work. Don’t you want to give it a try? |
yes |
also helpful: this tool for generating regexes from examples |
This would enable an interesting workflow: Start with a few examples and let the lib generate regexes from that, which can then be validated/modified by hand. |
Link about the problem of well-balanced generation: https://www.drmaciver.com/2017/03/fully-automated-luxury-boltzmann-sampling-for-regular-languages/ And a simple implementation: https://github.com/hyperpape/needle/blob/main/needle-compiler/src/test/java/com/justinblank/strings/RegexGenerator.java |
Moreover, the Here's an example: https://github.com/jlink/jqwik/blob/main/documentation/src/test/java/net/jqwik/docs/state/RegexChainExample.java |
I just created a small project that supports generation of regex constrained strings for jqwik. Have a look and leave feedback if you're keen: https://github.com/SimY4/coregex jqwik usage example in unit tests: https://github.com/SimY4/coregex/blob/main/jqwik/src/test/java/com/github/simy4/coregex/jqwik/CoregexArbitraryConfiguratorTest.java |
@SimY4 Cool project. Just browsed through the jqwik-related code and stumbled upon the shrinking. It looks (I may be wrong though) as if shrinking is not deterministic since some kind of RNG is being used. If that’s the case it would break repeatability of test runs. One option I see to solve this problem is to generate a seed while generating the initial shrinkable and then use this seed as input to the RNG for shrinking. But that’s just an idea. |
Apart from https://github.com/SimY4/coregex as suggested by @SimY4, there are also some more mature/old libraries available to handle this. If introducing an external depedency for this is acceptable, then this could be pretty easily implemented with Xeger or Rxgen; https://github.com/agarciadom/xeger This would allow for a pretty quick implementation of |
I haven’t looked at the exact libraries, but keep in mind that shrinking capabilities often account for a major part of arbitrary implementation. Often data generation libs do not cover that at all. |
@jlink Yes.... I could take a look at that. Took a quick look at the library, and looks very simple... It even has functionality to estimate the amount of unique values a regexp can generate. Question, what is the preferred way for an extension to provide a new Arbitrary type like |
ˋArbitraries.strings()ˋ is probably the wrong starting point since regex generated strings won’t have the same configuration capabilities as character-based strings. You could have a look at the web module, which starts its DSL from a freshly introduced class ˋWebˋ. Maybe st like ˋRegex.fromPattern(..)ˋ could be the starting point for a regex module. And a ˋ@FromRegexˋ annotation as you suggested. |
Just one note according do human aspect. If we would be able to use regexp to generate some random strings, this regexp would be most probably copied from code under the test. It would lower than quality of PBT. PBT should re-define needs and invariant (properties) of some processes. And one thing is also to define input requirements again and have them separate to implementation. Please, at least give some WARNING into documentation to this feature, when it will be available. |
There is also https://github.com/wolfendale/scalacheck-gen-regexp which provides similar functionality by parsing the regex and converting its various constructs into generators. |
Testing Problem
I want to generate a string of sophisticated patterns.
It would be nice to support string patterning like REGEX.
Suggested Solution
Discussion
The text was updated successfully, but these errors were encountered: