You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the String generators and StringDSL let you specify a minimum and maximum codepoint to restrict the character set, but there is no easy way to do something like generate strings of alpha-numeric characters since that needs non-contiguous character ranges.
One option would be to add a String generator that accepts a Gen. Potentially betweenCodePoints could call through to the new method.
With the DSL changed, I'm thinking of something like
I started hacking together an idea for this, before checking and seeing it had been proposed. My idea was slightly different. I modified StringGeneratorBuilder to store a list of ranges of charpoints, instead of just one min/max pair. Then I added a set of methods to include or exclude ranges:
public StringGeneratorBuilder excludingCodePoint(int codePoint)
public StringGeneratorBuilder excludingRange(int minCodePoint, int maxCodePoint)
public StringGeneratorBuilder includingCodePoint(int codePoint)
public StringGeneratorBuilder includingRange(int minCodePoint, int maxCodePoint)
With that in place, I added a method to the Strings class that mixes the ranges together (automatically determining proportions for you).
static Gen<String> fromRanges(List<Pair<Integer, Integer>> ranges, int minLength, int maxLength)
I haven't finished writing all the methods, or tested it, but I have enough code to be confident it should work and I'd be happy to produce a pull request if you think this is an interesting direction.
Currently the String generators and StringDSL let you specify a minimum and maximum codepoint to restrict the character set, but there is no easy way to do something like generate strings of alpha-numeric characters since that needs non-contiguous character ranges.
One option would be to add a String generator that accepts a Gen. Potentially betweenCodePoints could call through to the new method.
With the DSL changed, I'm thinking of something like
strings().ofCharacters(characters('0', '9').mix(characters('A', 'Z'))).withLength(8)
The text was updated successfully, but these errors were encountered: