From 8416080179bc5218ddf193cbcb6c37429a122aa2 Mon Sep 17 00:00:00 2001 From: Tom Lord Date: Mon, 16 Oct 2017 09:59:07 +0100 Subject: [PATCH] Updated rubocop config and run auto-correct --- .rubocop.yml | 2 +- spec/config_spec.rb | 32 ++++++++++++------------- spec/regexp-examples_spec.rb | 46 ++++++++++++++++++------------------ spec/spec_helper.rb | 2 +- 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2ce6253..1df265a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ Metrics/LineLength: Max: 90 -Style/FileName: +Naming/FileName: Enabled: false diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 51f3380..f1ffa9e 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -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) @@ -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' @@ -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 @@ -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' @@ -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 @@ -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' @@ -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 diff --git a/spec/regexp-examples_spec.rb b/spec/regexp-examples_spec.rb index 2a31f1c..019d943 100644 --- a/spec/regexp-examples_spec.rb +++ b/spec/regexp-examples_spec.rb @@ -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| @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 70e65d9..1c10d08 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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