mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Disallows while true
(#22)
* Disallows `while true` * Add syntax highlighting in documentation * Replace `while true` occurrencies * Add WhileTrue rule to config sample
This commit is contained in:
parent
21abce63bd
commit
b023ae0baa
6 changed files with 94 additions and 4 deletions
42
spec/ameba/rule/while_true_spec.cr
Normal file
42
spec/ameba/rule/while_true_spec.cr
Normal file
|
@ -0,0 +1,42 @@
|
|||
require "../../spec_helper"
|
||||
|
||||
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
|
||||
|
||||
module Ameba::Rule
|
||||
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
|
||||
|
||||
error = source.errors.first
|
||||
error.location.to_s.should eq "source.cr:2:1"
|
||||
error.message.should eq "While statement using true literal as condition"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue