2018-06-16 11:50:59 +00:00
|
|
|
require "../../../spec_helper"
|
2017-11-17 21:41:30 +00:00
|
|
|
|
2018-06-16 11:50:59 +00:00
|
|
|
module Ameba::Rule::Lint
|
2017-11-17 21:41:30 +00:00
|
|
|
describe PercentArrays do
|
|
|
|
subject = PercentArrays.new
|
|
|
|
|
|
|
|
it "passes if percent arrays are written correctly" do
|
|
|
|
s = Source.new %q(
|
|
|
|
%i(one two three)
|
|
|
|
%w(one two three)
|
|
|
|
|
|
|
|
%i(1 2 3)
|
|
|
|
%w(1 2 3)
|
|
|
|
|
|
|
|
%i()
|
|
|
|
%w()
|
|
|
|
)
|
|
|
|
subject.catch(s).should be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if string percent array has commas" do
|
|
|
|
s = Source.new %( %w(one, two) )
|
|
|
|
subject.catch(s).should_not be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if string percent array has quotes" do
|
|
|
|
s = Source.new %( %w("one" "two") )
|
|
|
|
subject.catch(s).should_not be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if symbols percent array has commas" do
|
|
|
|
s = Source.new %( %i(one, two) )
|
|
|
|
subject.catch(s).should_not be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if symbols percent array has a colon" do
|
|
|
|
s = Source.new %( %i(:one :two) )
|
|
|
|
subject.catch(s).should_not be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, location and message for %i" do
|
|
|
|
s = Source.new %(
|
|
|
|
%i(:one)
|
|
|
|
), "source.cr"
|
|
|
|
|
|
|
|
subject.catch(s).should_not be_valid
|
2018-06-10 21:15:12 +00:00
|
|
|
issue = s.issues.first
|
|
|
|
issue.rule.should_not be_nil
|
2018-09-07 12:07:03 +00:00
|
|
|
issue.location.to_s.should eq "source.cr:1:1"
|
2018-06-10 21:15:12 +00:00
|
|
|
issue.message.should eq(
|
2017-11-17 21:41:30 +00:00
|
|
|
"Symbols `,:` may be unwanted in %i array literals"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, location and message for %w" do
|
|
|
|
s = Source.new %(
|
|
|
|
%w("one")
|
|
|
|
), "source.cr"
|
|
|
|
|
|
|
|
subject.catch(s).should_not be_valid
|
2018-06-10 21:15:12 +00:00
|
|
|
issue = s.issues.first
|
|
|
|
issue.rule.should_not be_nil
|
2018-09-07 12:07:03 +00:00
|
|
|
issue.location.to_s.should eq "source.cr:1:1"
|
2018-11-24 17:38:13 +00:00
|
|
|
issue.end_location.should be_nil
|
2018-06-10 21:15:12 +00:00
|
|
|
issue.message.should eq(
|
2017-11-17 21:41:30 +00:00
|
|
|
"Symbols `,\"` may be unwanted in %w array literals"
|
|
|
|
)
|
|
|
|
end
|
2017-11-22 06:44:29 +00:00
|
|
|
|
|
|
|
context "properties" do
|
|
|
|
it "allows to configure string_array_unwanted_symbols" do
|
|
|
|
rule = PercentArrays.new
|
|
|
|
rule.string_array_unwanted_symbols = ","
|
|
|
|
s = Source.new %( %w("one") )
|
|
|
|
rule.catch(s).should be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows to configure symbol_array_unwanted_symbols" do
|
|
|
|
rule = PercentArrays.new
|
|
|
|
rule.symbol_array_unwanted_symbols = ","
|
|
|
|
s = Source.new %( %i(:one) )
|
|
|
|
rule.catch(s).should be_valid
|
|
|
|
end
|
|
|
|
end
|
2017-11-17 21:41:30 +00:00
|
|
|
end
|
|
|
|
end
|