2018-06-16 11:50:59 +00:00
|
|
|
require "../../../spec_helper"
|
2017-11-27 13:35:15 +00:00
|
|
|
|
|
|
|
valid_source = <<-EOF
|
|
|
|
a = 1
|
|
|
|
loop do
|
|
|
|
a += 1
|
|
|
|
break if a > 5
|
|
|
|
end
|
|
|
|
EOF
|
|
|
|
|
|
|
|
invalid_source = <<-EOF
|
|
|
|
a = 1
|
|
|
|
while true
|
|
|
|
a += 1
|
|
|
|
break if a > 5
|
|
|
|
end
|
|
|
|
EOF
|
|
|
|
|
2018-06-16 11:50:59 +00:00
|
|
|
module Ameba::Rule::Style
|
2017-11-27 13:35:15 +00:00
|
|
|
subject = WhileTrue.new
|
|
|
|
|
|
|
|
describe WhileTrue do
|
|
|
|
it "passes if there is no `while true`" do
|
|
|
|
source = Source.new valid_source
|
|
|
|
subject.catch(source).should be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is `while true`" do
|
|
|
|
source = Source.new invalid_source
|
|
|
|
subject.catch(source).should_not be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, pos and message" do
|
|
|
|
source = Source.new invalid_source, "source.cr"
|
|
|
|
subject.catch(source).should_not be_valid
|
|
|
|
|
2018-06-10 21:15:12 +00:00
|
|
|
issue = source.issues.first
|
|
|
|
issue.location.to_s.should eq "source.cr:2:1"
|
2018-11-24 17:38:13 +00:00
|
|
|
issue.end_location.to_s.should eq "source.cr:5:3"
|
2018-06-10 21:15:12 +00:00
|
|
|
issue.message.should eq "While statement using true literal as condition"
|
2017-11-27 13:35:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|