2017-11-01 12:18:28 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
2017-11-07 21:50:25 +00:00
|
|
|
module Ameba::Rule
|
2017-11-01 12:18:28 +00:00
|
|
|
subject = LiteralInInterpolation.new
|
|
|
|
|
|
|
|
describe LiteralInInterpolation do
|
|
|
|
it "passes with good interpolation examples" do
|
|
|
|
s = Source.new %q(
|
|
|
|
name = "Ary"
|
|
|
|
"Hello, #{name}"
|
|
|
|
|
|
|
|
"#{name}"
|
|
|
|
|
|
|
|
"Name size: #{name.size}"
|
|
|
|
)
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(s).should be_valid
|
2017-11-01 12:18:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is useless interpolation" do
|
|
|
|
[
|
|
|
|
%q("#{:Ary}"),
|
|
|
|
%q("#{[1, 2, 3]}"),
|
|
|
|
%q("#{true}"),
|
|
|
|
%q("#{false}"),
|
|
|
|
%q("here are #{4} cats"),
|
|
|
|
].each do |str|
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(Source.new str).should_not be_valid
|
2017-11-01 12:18:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, pos and message" do
|
2017-11-07 20:02:51 +00:00
|
|
|
s = Source.new %q("#{4}"), "source.cr"
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(s).should_not be_valid
|
2017-11-01 12:18:28 +00:00
|
|
|
|
|
|
|
error = s.errors.first
|
|
|
|
error.rule.should_not be_nil
|
2017-11-07 20:02:51 +00:00
|
|
|
error.location.to_s.should eq "source.cr:1:1"
|
2017-11-01 12:18:28 +00:00
|
|
|
error.message.should eq "Literal value found in interpolation"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|