Skip to content

Commit

Permalink
Return an empty string as the only 'example' for an empty regex
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-lord committed Nov 9, 2017
1 parent 8416080 commit b3451fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/regexp-examples/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(regexp_string, regexp_options)
end

def parse
repeaters = []
repeaters = [PlaceHolderGroup.new]
until end_of_regexp
group = parse_group(repeaters)
return [group] if group.is_a? OrGroup
Expand Down
4 changes: 4 additions & 0 deletions spec/regexp-examples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def self.examples_are_empty(*regexps)
)
end

context 'for empty regex' do
it { expect(//.examples).to eq [''] }
end

context 'for comment groups' do
examples_exist_and_match(
/a(?#comment)b/,
Expand Down

0 comments on commit b3451fc

Please sign in to comment.