mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
122 lines
3.2 KiB
Crystal
122 lines
3.2 KiB
Crystal
require "../../../spec_helper"
|
|
|
|
module Ameba::Rule::Lint
|
|
describe AmbiguousAssignment do
|
|
subject = AmbiguousAssignment.new
|
|
|
|
context "when using `-`" do
|
|
it "registers an offense with `x`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
x =- y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `-=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "registers an offense with `@x`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
@x =- y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `-=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "registers an offense with `@@x`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
@@x =- y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `-=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "registers an offense with `X`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
X =- y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `-=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "does not register an offense when no mistype assignments" do
|
|
expect_no_issues subject, <<-CRYSTAL
|
|
x = 1
|
|
x -= y
|
|
x = -y
|
|
CRYSTAL
|
|
end
|
|
end
|
|
|
|
context "when using `+`" do
|
|
it "registers an offense with `x`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
x =+ y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `+=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "registers an offense with `@x`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
@x =+ y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `+=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "registers an offense with `@@x`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
@@x =+ y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `+=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "registers an offense with `X`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
X =+ y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `+=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "does not register an offense when no mistype assignments" do
|
|
expect_no_issues subject, <<-CRYSTAL
|
|
x = 1
|
|
x += y
|
|
x = +y
|
|
CRYSTAL
|
|
end
|
|
end
|
|
|
|
context "when using `!`" do
|
|
it "registers an offense with `x`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
x =! y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `!=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "registers an offense with `@x`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
@x =! y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `!=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "registers an offense with `@@x`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
@@x =! y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `!=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "registers an offense with `X`" do
|
|
expect_issue subject, <<-CRYSTAL
|
|
X =! y
|
|
# ^^ error: Suspicious assignment detected. Did you mean `!=`?
|
|
CRYSTAL
|
|
end
|
|
|
|
it "does not register an offense when no mistype assignments" do
|
|
expect_no_issues subject, <<-CRYSTAL
|
|
x = false
|
|
x != y
|
|
x = !y
|
|
CRYSTAL
|
|
end
|
|
end
|
|
end
|
|
end
|