From b3451fc004f3f4646b1262410e9c73ddae227e2c Mon Sep 17 00:00:00 2001 From: Tom Lord Date: Thu, 9 Nov 2017 19:59:17 +0000 Subject: [PATCH] Return an empty string as the only 'example' for an empty regex --- lib/regexp-examples/parser.rb | 2 +- spec/regexp-examples_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/regexp-examples/parser.rb b/lib/regexp-examples/parser.rb index 2c85eb9..96bf19e 100644 --- a/lib/regexp-examples/parser.rb +++ b/lib/regexp-examples/parser.rb @@ -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 diff --git a/spec/regexp-examples_spec.rb b/spec/regexp-examples_spec.rb index 019d943..2fb7403 100644 --- a/spec/regexp-examples_spec.rb +++ b/spec/regexp-examples_spec.rb @@ -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/,