Skip to content

Commit

Permalink
Updated rubocop config and run auto-correct
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-lord committed Nov 9, 2017
1 parent 66af143 commit 8416080
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Metrics/LineLength:
Max: 90

Style/FileName:
Naming/FileName:
Enabled: false
32 changes: 15 additions & 17 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
RSpec.describe RegexpExamples::Config do

describe 'max_repeater_variance' do
context 'as a passed parameter' do
it 'with low limit' do
expect(/[A-Z]/.examples(max_results_limit: 5))
.to match_array %w(A B C D E)
.to match_array %w[A B C D E]
end
it 'with (default) high limit' do
expect(/[ab]{14}/.examples.length)
.to be <= 10000 # NOT 2**14 == 16384, because it's been limited
.to be <= 10_000 # NOT 2**14 == 16384, because it's been limited
end
it 'with (custom) high limit' do
expect(/[ab]{14}/.examples(max_results_limit: 20000).length)
.to eq 16384 # NOT 10000, because it's below the limit
expect(/[ab]{14}/.examples(max_results_limit: 20_000).length)
.to eq 16_384 # NOT 10000, because it's below the limit
end
it 'for boolean or groups' do
expect(/[ab]{3}|[cd]{3}/.examples(max_results_limit: 10).length)
Expand Down Expand Up @@ -47,7 +46,7 @@

it 'sets limit without passing explicitly' do
expect(/[A-Z]/.examples)
.to match_array %w(A B C D E)
.to match_array %w[A B C D E]
end
end
end # describe 'max_results_limit'
Expand All @@ -56,11 +55,11 @@
context 'as a passed parameter' do
it 'with a larger value' do
expect(/a+/.examples(max_repeater_variance: 5))
.to match_array %w(a aa aaa aaaa aaaaa aaaaaa)
.to match_array %w[a aa aaa aaaa aaaaa aaaaaa]
end
it 'with a lower value' do
expect(/a{4,8}/.examples(max_repeater_variance: 0))
.to eq %w(aaaa)
.to eq %w[aaaa]
end
end

Expand All @@ -75,7 +74,7 @@

it 'sets limit without passing explicitly' do
expect(/a+/.examples)
.to match_array %w(a aa aaa aaaa aaaaa aaaaaa)
.to match_array %w[a aa aaa aaaa aaaaa aaaaaa]
end
end
end # describe 'max_repeater_variance'
Expand All @@ -84,11 +83,11 @@
context 'as a passed parameter' do
it 'with a larger value' do
expect(/\d/.examples(max_group_results: 10))
.to match_array %w(0 1 2 3 4 5 6 7 8 9)
.to match_array %w[0 1 2 3 4 5 6 7 8 9]
end
it 'with a lower value' do
expect(/\d/.examples(max_group_results: 3))
.to match_array %w(0 1 2)
.to match_array %w[0 1 2]
end
end

Expand All @@ -103,7 +102,7 @@

it 'sets limit without passing explicitly' do
expect(/\d/.examples)
.to match_array %w(0 1 2 3 4 5 6 7 8 9)
.to match_array %w[0 1 2 3 4 5 6 7 8 9]
end
end
end # describe 'max_group_results'
Expand All @@ -112,24 +111,23 @@
it 'uses thread-local global config values' do
thread = Thread.new do
RegexpExamples::Config.max_group_results = 1
expect(/\d/.examples).to eq %w(0)
expect(/\d/.examples).to eq %w[0]
end
sleep 0.1 # Give the above thread time to run
expect(/\d/.examples).to eq %w(0 1 2 3 4)
expect(/\d/.examples).to eq %w[0 1 2 3 4]
thread.join
end

it 'uses thread-local block config values' do
thread = Thread.new do
RegexpExamples::Config.with_configuration(max_group_results: 1) do
expect(/\d/.examples).to eq %w(0)
expect(/\d/.examples).to eq %w[0]
sleep 0.2 # Give the below thread time to run while this block is open
end
end
sleep 0.1 # Give the above thread time to run
expect(/\d/.examples).to eq %w(0 1 2 3 4)
expect(/\d/.examples).to eq %w[0 1 2 3 4]
thread.join
end
end # describe 'thread safety'

end
46 changes: 23 additions & 23 deletions spec/regexp-examples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def self.examples_are_empty(*regexps)

context 'for escaped characters' do
all_letters = Array('a'..'z') | Array('A'..'Z')
special_letters = %w(b c g p u x z A B C G M P Z)
special_letters = %w[b c g p u x z A B C G M P Z]
valid_letters = all_letters - special_letters

valid_letters.each do |char|
Expand Down Expand Up @@ -185,7 +185,7 @@ def self.examples_are_empty(*regexps)
)
# An exhaustive set of tests for all named properties!!! This is useful
# for verifying the PStore contains correct values for all ruby versions
%w(
%w[
Alnum Alpha Blank Cntrl Digit Graph Lower Print Punct Space Upper XDigit
Word ASCII Any Assigned L Ll Lm Lo Lt Lu M Mn Mc Me N Nd Nl No P Pc Pd
Ps Pe Pi Pf Po S Sm Sc Sk So Z Zs Zl Zp C Cc Cf Cn Co Arabic Armenian
Expand All @@ -196,7 +196,7 @@ def self.examples_are_empty(*regexps)
Mongolian Myanmar New_Tai_Lue Nko Ogham Ol_Chiki Oriya Phags_Pa Rejang
Runic Saurashtra Sinhala Sundanese Syloti_Nagri Syriac Tagalog Tagbanwa
Tai_Le Tamil Telugu Thaana Thai Tibetan Tifinagh Vai Yi
).each do |property|
].each do |property|
it "examples for /\p{#{property}}/" do
regexp_examples = /\p{#{property}}/.examples(max_group_results: 99_999)
expect(regexp_examples)
Expand All @@ -209,10 +209,10 @@ def self.examples_are_empty(*regexps)
end

# The following seem to genuinely have no matching examples (!!??!!?!)
%w(
%w[
Cs Carian Cuneiform Cypriot Deseret Gothic Kharoshthi Linear_B Lycian
Lydian Old_Italic Old_Persian Osmanya Phoenician Shavian Ugaritic
).each do |property|
].each do |property|
examples_are_empty(/\p{#{property}}/)
end
end
Expand Down Expand Up @@ -292,21 +292,21 @@ def self.examples_are_empty(*regexps)
# More rigorous tests to assert that ALL examples are being listed
context 'default config options' do
# Simple examples
it { expect(/[ab]{2}/.examples).to match_array %w(aa ab ba bb) }
it { expect(/(a|b){2}/.examples).to match_array %w(aa ab ba bb) }
it { expect(/[ab]{2}/.examples).to match_array %w[aa ab ba bb] }
it { expect(/(a|b){2}/.examples).to match_array %w[aa ab ba bb] }
it { expect(/a+|b?/.examples).to match_array ['a', 'aa', 'aaa', '', 'b'] }

# Only display unique examples:
it { expect(/a|a|b|b/.examples).to match_array %w(a b) }
it { expect(/[ccdd]/.examples).to match_array %w(c d) }
it { expect(/a|a|b|b/.examples).to match_array %w[a b] }
it { expect(/[ccdd]/.examples).to match_array %w[c d] }

# a{1}? should be equivalent to (?:a{1})?, i.e. NOT a "non-greedy quantifier"
it { expect(/a{1}?/.examples).to match_array ['', 'a'] }
end

context 'end of string' do
it { expect(/test\z/.examples).to match_array %w(test) }
it { expect(/test\Z/.examples).to match_array ['test', "test\n"] }
it { expect(/test\z/.examples).to match_array %w[test] }
it { expect(/test\Z/.examples).to match_array %W[test test\n] }
end

context 'backreferences and escaped octal combined' do
Expand All @@ -317,12 +317,12 @@ def self.examples_are_empty(*regexps)
end

context 'case insensitive' do
it { expect(/ab/i.examples).to match_array %w(ab aB Ab AB) }
it { expect(/ab/i.examples).to match_array %w[ab aB Ab AB] }
it do
expect(/a+/i.examples)
.to match_array %w(a A aa aA Aa AA aaa aaA aAa aAA Aaa AaA AAa AAA)
.to match_array %w[a A aa aA Aa AA aaa aaA aAa aAA Aaa AaA AAa AAA]
end
it { expect(/([ab])\1/i.examples).to match_array %w(aa bb AA BB) }
it { expect(/([ab])\1/i.examples).to match_array %w[aa bb AA BB] }
end

context 'multiline' do
Expand All @@ -331,30 +331,30 @@ def self.examples_are_empty(*regexps)
end

context 'exteded form' do
it { expect(/a b c/x.examples).to eq %w(abc) }
it { expect(/a#comment/x.examples).to eq %w(a) }
it { expect(/a b c/x.examples).to eq %w[abc] }
it { expect(/a#comment/x.examples).to eq %w[a] }
it do
expect(
/
line1 #comment
line2 #comment
/x.examples
).to eq %w(line1line2)
).to eq %w[line1line2]
end
end

context 'options toggling' do
context 'rest of string' do
it { expect(/a(?i)b(?-i)c/.examples).to match_array %w(abc aBc) }
it { expect(/a(?x) b(?-x) c/.examples).to eq %w(ab\ c) }
it { expect(/a(?i)b(?-i)c/.examples).to match_array %w[abc aBc] }
it { expect(/a(?x) b(?-x) c/.examples).to eq %w[ab\ c] }
it { expect(/(?m)./.examples(max_group_results: 999)).to include "\n" }
# Toggle "groups" should not increase backref group count:
it { expect(/(?i)(a)-\1/.examples).to match_array %w(a-a A-A) }
it { expect(/(?i)(a)-\1/.examples).to match_array %w[a-a A-A] }
end
context 'subexpression' do
it { expect(/a(?i:b)c/.examples).to match_array %w(abc aBc) }
it { expect(/a(?i:b(?-i:c))/.examples).to match_array %w(abc aBc) }
it { expect(/a(?-i:b)c/i.examples).to match_array %w(abc abC Abc AbC) }
it { expect(/a(?i:b)c/.examples).to match_array %w[abc aBc] }
it { expect(/a(?i:b(?-i:c))/.examples).to match_array %w[abc aBc] }
it { expect(/a(?-i:b)c/i.examples).to match_array %w[abc abC Abc AbC] }
end
end
end # context 'exact examples match'
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Several of these tests (intentionally) use "weird" regex patterns,
# that spam annoying warnings when running.
# E.g. warning: invalid back reference: /\k/
# and warning: character class has ']' without escape: /[]]/
# and warning: character class has ']' without escape: /[]]/
# This config disables those warnings.
$VERBOSE = nil

Expand Down

0 comments on commit 8416080

Please sign in to comment.