spec/regexp-examples_spec.rb in regexp-examples-0.3.2 vs spec/regexp-examples_spec.rb in regexp-examples-0.4.0
- old
+ new
@@ -113,11 +113,13 @@
/(repeat) \1/,
/(ref1) (ref2) \1 \2/,
/((ref2)ref1) \1 \2/,
/((ref1and2)) \1 \2/,
/(one)(two)(three)(four)(five)(six)(seven)(eight)(nine)(ten) \10\9\8\7\6\5\4\3\2\1/,
- /(a?(b?(c?(d?(e?)))))/
+ /(a?(b?(c?(d?(e?)))))/,
+ /(a)? \1/,
+ /(a|(b)) \2/
)
end
context "for complex patterns" do
# Longer combinations of the above
@@ -206,14 +208,38 @@
/[^\w\W]/,
/[^\s\S]/,
/[^\h\H]/,
/[^\D0-9]/,
/[^\Wa-zA-Z0-9_]/,
- /[^\d\D]*/,
/[^\d\D]+/,
/[^\d\D]{2}/,
/[^\d\D]word/
)
+ end
+
+ context "exact examples match" do
+ # More rigorous tests to assert that ALL examples are being listed
+ context "default options" do
+ it { expect(/[ab]{2}/.examples).to eq ["aa", "ab", "ba", "bb"] }
+ it { expect(/(a|b){2}/.examples).to eq ["aa", "ab", "ba", "bb"] }
+ it { expect(/a+|b?/.examples).to eq ["a", "aa", "aaa", "", "b"] }
+ end
+ context "max_repeater_variance option" do
+ it do
+ expect(/a+/.examples(max_repeater_variance: 5))
+ .to eq %w(a aa aaa aaaa aaaaa aaaaaa)
+ end
+ it do
+ expect(/a{4,8}/.examples(max_repeater_variance: 0))
+ .to eq %w(aaaa)
+ end
+ end
+ context "max_group_results option" do
+ it do
+ expect(/\d/.examples(max_group_results: 10))
+ .to eq %w(0 1 2 3 4 5 6 7 8 9)
+ end
+ end
end
end
end