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

add 2 methods to Generex: generateMaxLength + generateMinLength #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

astik
Copy link

@astik astik commented Feb 9, 2017

Automaton is not exposed though Generex.
This is a not cool because it exposes some useful methods for information.

Those changes expose 2 methods to get sizes for the shortest and longest string that can be generated (which can be useful if you need to define regexp that produce string with a constraint length)

@astik
Copy link
Author

astik commented Feb 9, 2017

In the meantime, here is a workaround :

  private Automaton getAutomaton() {
    // this method is necessary as Generex does not expose automaton.
    // as soon as it will (if it will), this method should be remove
    // see https://github.com/mifmif/Generex/pull/37
    try {
      return (Automaton) FieldUtils.readField(generex, "automaton", true);
    } catch (IllegalAccessException e) {
      throw new TechnicalException("Failure to access private attribute automaton from generex instance", e);
    }
  }

This allow me to access the automaton instance from the generex one.
As it uses reflection, be careful =)

@mifmif
Copy link
Owner

mifmif commented Feb 15, 2017

Could you please provide a description with some examples that shows when to use the exposed Automaton and the two additional methods (min/max). Test cases are also required to validate the implementation of those methods.

Thanks.

@astik
Copy link
Author

astik commented Feb 16, 2017

I added the unit test for min and max length expectations.

Here is a use case we have currently with Generex :

  • we create random identifier for multiple entity's types
  • an entity's type have a grammar that defines the identifier regex
  • a grammar / regex is defined and should be bound between a minimum possible length (for example 3) and a maximum possible length (for example 20), so that we are sure that identifier's length is between 3 and 20.
  • when creating a grammar we need a way to validate the theoretical min and max length for a regex in order to display proper message to the user

For this particular validation need, we need to access those 2 status from automaton.

@astik astik force-pushed the feature-expose-automaton-information branch from 330a7c7 to 9945af9 Compare September 28, 2018 14:48
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

Successfully merging this pull request may close these issues.

2 participants