Skip to content

Allow the use of empty look-arounds #18

@tom-lord

Description

@tom-lord

Due to how this library's algorithm works, look-arounds cannot be supported. As explained in the README, a RegexpExamples::IllegalSyntax will be raised if they are used in a pattern you attempt to generate examples for.

However, similar to how the library currently "ignores" \G. ^ and \A anchors at the beginning of a pattern; or $, \z and \Z at the end; it would also be safe to ignore empty look arounds!

For example, the following could be considered safe:

/foo|bar(?=)/.random_example #=> "foo"

One motivation for this stems from the fact that Regexp.union returns an empty look-ahead if no patterns are given:

Regexp.union([]) #=> /(?!)/

Therefore one would expect the following to work as follows, rather than raising an exception:

Regexp.union([]).random_example #=> ""

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions