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

Generate Strings using Character generator #38

Open
doctau opened this issue Dec 14, 2017 · 1 comment
Open

Generate Strings using Character generator #38

doctau opened this issue Dec 14, 2017 · 1 comment

Comments

@doctau
Copy link

doctau commented Dec 14, 2017

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)

@hyperpape
Copy link
Contributor

hyperpape commented Dec 6, 2019

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.

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

2 participants