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
|
subject = EmptyLoop.new
|
||||||
|
|
||||||
it "does not report if there are not empty loops" do
|
it "does not report if there are not empty loops" do
|
||||||
s = Source.new %(
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
a = 1
|
a = 1
|
||||||
|
|
||||||
while a < 10
|
while a < 10
|
||||||
|
@ -19,54 +19,50 @@ module Ameba::Rule::Lint
|
||||||
loop do
|
loop do
|
||||||
a += 1
|
a += 1
|
||||||
end
|
end
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(s).should be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports if there is an empty while loop" do
|
it "reports if there is an empty while loop" do
|
||||||
s = Source.new %(
|
expect_issue subject, <<-CRYSTAL
|
||||||
a = 1
|
a = 1
|
||||||
while true
|
while true
|
||||||
|
# ^^^^^^^^ error: Empty loop detected
|
||||||
end
|
end
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(s).should_not be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't report if while loop has non-literals in cond block" do
|
it "doesn't report if while loop has non-literals in cond block" do
|
||||||
s = Source.new %(
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
a = 1
|
a = 1
|
||||||
while a = gets.to_s
|
while a = gets.to_s
|
||||||
# nothing here
|
# nothing here
|
||||||
end
|
end
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(s).should be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports if there is an empty until loop" do
|
it "reports if there is an empty until loop" do
|
||||||
s = Source.new %(
|
expect_issue subject, <<-CRYSTAL
|
||||||
do_something
|
do_something
|
||||||
until false
|
until false
|
||||||
|
# ^^^^^^^^^ error: Empty loop detected
|
||||||
end
|
end
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(s).should_not be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't report if until loop has non-literals in cond block" do
|
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?
|
until socket_open?
|
||||||
end
|
end
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(s).should be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports if there an empty loop" do
|
it "reports if there an empty loop" do
|
||||||
s = Source.new %(
|
expect_issue subject, <<-CRYSTAL
|
||||||
a = 1
|
a = 1
|
||||||
loop do
|
loop do
|
||||||
|
# ^^^^^ error: Empty loop detected
|
||||||
end
|
end
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(s).should_not be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports rule, message and location" do
|
it "reports rule, message and location" do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue