mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Use issue expectation helpers in Lint::EmptyLoop
rule spec
This commit is contained in:
parent
3cbb388393
commit
5283ae4a96
1 changed files with 15 additions and 19 deletions
|
@ -5,7 +5,7 @@ module Ameba::Rule::Lint
|
|||
subject = EmptyLoop.new
|
||||
|
||||
it "does not report if there are not empty loops" do
|
||||
s = Source.new %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
a = 1
|
||||
|
||||
while a < 10
|
||||
|
@ -19,54 +19,50 @@ module Ameba::Rule::Lint
|
|||
loop do
|
||||
a += 1
|
||||
end
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there is an empty while loop" do
|
||||
s = Source.new %(
|
||||
expect_issue subject, <<-CRYSTAL
|
||||
a = 1
|
||||
while true
|
||||
# ^^^^^^^^ error: Empty loop detected
|
||||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report if while loop has non-literals in cond block" do
|
||||
s = Source.new %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
a = 1
|
||||
while a = gets.to_s
|
||||
# nothing here
|
||||
end
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there is an empty until loop" do
|
||||
s = Source.new %(
|
||||
expect_issue subject, <<-CRYSTAL
|
||||
do_something
|
||||
until false
|
||||
# ^^^^^^^^^ error: Empty loop detected
|
||||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report if until loop has non-literals in cond block" do
|
||||
s = Source.new %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
until socket_open?
|
||||
end
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there an empty loop" do
|
||||
s = Source.new %(
|
||||
expect_issue subject, <<-CRYSTAL
|
||||
a = 1
|
||||
loop do
|
||||
|
||||
# ^^^^^ error: Empty loop detected
|
||||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports rule, message and location" do
|
||||
|
|
Loading…
Reference in a new issue