spec/regexp-examples_spec.rb in regexp-examples-0.6.0 vs spec/regexp-examples_spec.rb in regexp-examples-0.7.0
- old
+ new
@@ -1,16 +1,11 @@
RSpec.describe Regexp, "#examples" do
def self.examples_exist_and_match(*regexps)
regexps.each do |regexp|
- it do
- begin
- regexp_examples = regexp.examples(max_group_results: 999)
- rescue
- # TODO: Find a nicer way to display this?
- puts "Error generating examples for /#{regexp.source}/"
- raise $!
- end
+ it "examples for /#{regexp.source}/" do
+ regexp_examples = regexp.examples(max_group_results: 999)
+
expect(regexp_examples).not_to be_empty, "No examples were generated for regexp: /#{regexp.source}/"
regexp_examples.each { |example| expect(example).to match(/\A(?:#{regexp.source})\z/) }
# Note: /\A...\z/ is used to prevent misleading examples from passing the test.
# For example, we don't want things like:
# /a*/.examples to include "xyz"
@@ -19,28 +14,20 @@
end
end
def self.examples_raise_illegal_syntax_error(*regexps)
regexps.each do |regexp|
- it do
+ it "examples for /#{regexp.source}/" do
expect{regexp.examples}.to raise_error RegexpExamples::IllegalSyntaxError
end
end
end
- def self.examples_raise_unsupported_syntax_error(*regexps)
- regexps.each do |regexp|
- it do
- expect{regexp.examples}.to raise_error RegexpExamples::UnsupportedSyntaxError
- end
- end
- end
-
def self.examples_are_empty(*regexps)
regexps.each do |regexp|
- it do
- expect(regexp.examples).to be_empty, "Unexpected examples for regexp: /#{regexp.source}/"
+ it "examples for /#{regexp.source}/" do
+ expect(regexp.examples).to be_empty
end
end
end
context 'returns matching strings' do
@@ -165,11 +152,12 @@
/no\Bn-word-boundary/,
/start-of\A-string/,
/start-of^-line/,
/end-of\Z-string/,
/end-of\z-string/,
- /end-of$-line/
+ /end-of$-line/,
+ /(?<name> ... \g<name>*)/
)
end
context "ignore start/end anchors if at start/end" do
examples_exist_and_match(
@@ -180,16 +168,16 @@
/end\z/,
/end\Z/
)
end
- context "for unsupported syntax" do
- examples_raise_unsupported_syntax_error(
+ context "for named properties" do
+ examples_exist_and_match(
/\p{L}/,
/\p{Arabic}/,
- /\p{^Ll}/,
- /(?<name> ... \g<name>*)/
+ /\p{^Ll}/
)
+
end
context "for control characters" do
examples_exist_and_match(
/\ca/,