2018-06-16 11:50:59 +00:00
|
|
|
require "../../../spec_helper"
|
2017-11-27 13:35:15 +00:00
|
|
|
|
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
|
2021-11-06 18:47:16 +00:00
|
|
|
expect_no_issues subject, <<-CRYSTAL
|
|
|
|
a = 1
|
|
|
|
loop do
|
|
|
|
a += 1
|
|
|
|
break if a > 5
|
|
|
|
end
|
|
|
|
CRYSTAL
|
2017-11-27 13:35:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is `while true`" do
|
2021-11-06 18:47:16 +00:00
|
|
|
source = expect_issue subject, <<-CRYSTAL
|
|
|
|
a = 1
|
|
|
|
while true
|
|
|
|
# ^^^^^^^^ error: While statement using true literal as condition
|
|
|
|
a += 1
|
|
|
|
break if a > 5
|
|
|
|
end
|
|
|
|
CRYSTAL
|
2017-11-27 13:35:15 +00:00
|
|
|
|
2021-11-06 18:47:16 +00:00
|
|
|
expect_correction source, <<-CRYSTAL
|
|
|
|
a = 1
|
|
|
|
loop do
|
|
|
|
a += 1
|
|
|
|
break if a > 5
|
|
|
|
end
|
|
|
|
CRYSTAL
|
2017-11-27 13:35:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|