spec/regexp-examples_spec.rb in regexp-examples-1.4.2 vs spec/regexp-examples_spec.rb in regexp-examples-1.4.3
- old
+ new
@@ -1,5 +1,10 @@
+# Load from a separate file to avoid unrescuable SyntaxError
+if RUBY_VERSION >= '2.4.1'
+ require_relative 'regexp-examples_spec_2.4.1'
+end
+
RSpec.describe Regexp, '#examples' do
def self.examples_exist_and_match(*regexps)
regexps.each do |regexp|
it "examples for /#{regexp.source}/" do
regexp_examples = regexp.examples(max_group_results: 99_999)
@@ -67,11 +72,11 @@
/[abc]/,
/[a-c]/,
/[abc-e]/,
/[^a-zA-Z]/,
/[\w]/,
- /[]]/, # TODO: How to suppress annoying warnings on this test?
+ /[]]/,
/[\]]/,
/[\\]/,
/[\\\]]/,
/[\n-\r]/,
/[\-]/,
@@ -90,10 +95,11 @@
context 'for complex multi groups' do
examples_exist_and_match(
/(normal)/,
/(?:nocapture)/,
+ /(?:nocapture)(normal) \1/, # Ensure the group counter is correct
/(?<name>namedgroup)/,
/(?<name>namedgroup) \k<name>/,
/(?<name>namedgroup) \k'name'/
)
end
@@ -266,9 +272,10 @@
end
context 'for comment groups' do
examples_exist_and_match(
/a(?#comment)b/,
+ /(?#comment)(group1)\1/, # Ensure the group counter is correct
/a(?#ugly backslashy\ comment\\\))b/
)
end
context 'for POSIX groups' do