shard-ameba/spec/ameba/rule/lint/rand_zero_spec.cr

30 lines
615 B
Crystal
Raw Normal View History

require "../../../spec_helper"
2018-03-08 16:55:35 +00:00
module Ameba::Rule::Lint
2018-03-08 16:55:35 +00:00
describe RandZero do
subject = RandZero.new
it "passes if it is not rand(1) or rand(0)" do
expect_no_issues subject, <<-CRYSTAL
2018-03-08 16:55:35 +00:00
rand(1.0)
rand(0.11)
rand(2)
CRYSTAL
2018-03-08 16:55:35 +00:00
end
it "fails if it is rand(0)" do
expect_issue subject, <<-CRYSTAL
rand(0)
# ^^^^^ error: rand(0) always returns 0
CRYSTAL
2018-03-08 16:55:35 +00:00
end
it "fails if it is rand(1)" do
expect_issue subject, <<-CRYSTAL
rand(1)
# ^^^^^ error: rand(1) always returns 0
CRYSTAL
2018-03-08 16:55:35 +00:00
end
end
end