Skip to content

Commit b3451fc

Browse files
committed
Return an empty string as the only 'example' for an empty regex
1 parent 8416080 commit b3451fc

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/regexp-examples/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def initialize(regexp_string, regexp_options)
2929
end
3030

3131
def parse
32-
repeaters = []
32+
repeaters = [PlaceHolderGroup.new]
3333
until end_of_regexp
3434
group = parse_group(repeaters)
3535
return [group] if group.is_a? OrGroup

spec/regexp-examples_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ def self.examples_are_empty(*regexps)
261261
)
262262
end
263263

264+
context 'for empty regex' do
265+
it { expect(//.examples).to eq [''] }
266+
end
267+
264268
context 'for comment groups' do
265269
examples_exist_and_match(
266270
/a(?#comment)b/,

0 commit comments

Comments
 (0)