shard-ameba/spec/ameba/rule/style/while_true_spec.cr

37 lines
738 B
Crystal
Raw Normal View History

require "../../../spec_helper"
module Ameba::Rule::Style
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
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
2021-11-06 18:47:16 +00:00
expect_correction source, <<-CRYSTAL
a = 1
loop do
a += 1
break if a > 5
end
CRYSTAL
end
end
end