Skip to content

Conversation

@tom-lord
Copy link
Owner

@tom-lord tom-lord commented Mar 8, 2015

Implemented a second core extension method:

Regexp#random_example

Tom Lord added 12 commits March 8, 2015 04:08
e.g. If multiline option is enabled, this should be made clear in the examples
This works, but there are still a few obvious improvements to be made, such as performace optimisation when the regex uses capture groups.
Previously, for capture groups and "Or" groups, the #random_example method was basically calling #examples under the hood. This meant that for a "complex" pattern, the system simple froze! E.g. /\w{1000}/.random_example # worked fine /(\w{1000})/.random_example # tries to store 63**1000 examples in memory; not fine!! This is now fixed. ALL regexes can have a random example generated "quickly".
* These should not be the concern of the parser; moved the logic out. * Implemented for #random_example (max_repeater_variance only, since max_group_results is irrelevant here!) * Used modern ruby syntax
Just making it clear that there's no private methods being called!
I never really liked it, anyway...
Possible future tests to add, if needed: * Performance test * "How random is it?" test
Implemented Regexp#random_example !!! This is effectively just a (MUCH) more efficient way of doing: /complicated .{20} regex/.examples(max_group_results: 9999999999).sample(1) Instead, you can use much more optimised code for this method via: /complicated .{20} regex/.random_example The key differrence being that Regexp#random_example does not store any more than 1 result in memory, at any time, making its performance scale linearly rather than exponentially.
Missing test area for 100% coverage
tom-lord added a commit that referenced this pull request Mar 8, 2015
@tom-lord tom-lord merged commit e20ad25 into master Mar 8, 2015
@tom-lord tom-lord deleted the random_example branch March 8, 2015 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants