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::AmbiguousAssignment
rule spec
This commit is contained in:
parent
caeb1609c9
commit
390b26d7f1
1 changed files with 54 additions and 102 deletions
|
@ -6,51 +6,35 @@ module Ameba::Rule::Lint
|
||||||
|
|
||||||
context "when using `-`" do
|
context "when using `-`" do
|
||||||
it "registers an offense with `x`" do
|
it "registers an offense with `x`" do
|
||||||
source = Source.new("x =- y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
x =- y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `-=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `-=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:3"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:4"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense with `@x`" do
|
it "registers an offense with `@x`" do
|
||||||
source = Source.new("@x =- y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
@x =- y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `-=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `-=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:4"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:5"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense with `@@x`" do
|
it "registers an offense with `@@x`" do
|
||||||
source = Source.new("@@x =- y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
@@x =- y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `-=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `-=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:5"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:6"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense with `X`" do
|
it "registers an offense with `X`" do
|
||||||
source = Source.new("X =- y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
X =- y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `-=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `-=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:3"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:4"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not register an offense when no mistype assignments" do
|
it "does not register an offense when no mistype assignments" do
|
||||||
subject.catch(Source.new(<<-CRYSTAL)).should be_valid
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
x = 1
|
x = 1
|
||||||
x -= y
|
x -= y
|
||||||
x = -y
|
x = -y
|
||||||
|
@ -60,51 +44,35 @@ module Ameba::Rule::Lint
|
||||||
|
|
||||||
context "when using `+`" do
|
context "when using `+`" do
|
||||||
it "registers an offense with `x`" do
|
it "registers an offense with `x`" do
|
||||||
source = Source.new("x =+ y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
x =+ y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `+=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `+=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:3"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:4"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense with `@x`" do
|
it "registers an offense with `@x`" do
|
||||||
source = Source.new("@x =+ y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
@x =+ y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `+=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `+=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:4"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:5"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense with `@@x`" do
|
it "registers an offense with `@@x`" do
|
||||||
source = Source.new("@@x =+ y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
@@x =+ y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `+=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `+=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:5"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:6"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense with `X`" do
|
it "registers an offense with `X`" do
|
||||||
source = Source.new("X =+ y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
X =+ y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `+=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `+=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:3"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:4"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not register an offense when no mistype assignments" do
|
it "does not register an offense when no mistype assignments" do
|
||||||
subject.catch(Source.new(<<-CRYSTAL)).should be_valid
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
x = 1
|
x = 1
|
||||||
x += y
|
x += y
|
||||||
x = +y
|
x = +y
|
||||||
|
@ -114,51 +82,35 @@ module Ameba::Rule::Lint
|
||||||
|
|
||||||
context "when using `!`" do
|
context "when using `!`" do
|
||||||
it "registers an offense with `x`" do
|
it "registers an offense with `x`" do
|
||||||
source = Source.new("x =! y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
x =! y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `!=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `!=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:3"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:4"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense with `@x`" do
|
it "registers an offense with `@x`" do
|
||||||
source = Source.new("@x =! y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
@x =! y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `!=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `!=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:4"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:5"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense with `@@x`" do
|
it "registers an offense with `@@x`" do
|
||||||
source = Source.new("@@x =! y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
@@x =! y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `!=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `!=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:5"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:6"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense with `X`" do
|
it "registers an offense with `X`" do
|
||||||
source = Source.new("X =! y", "source.cr")
|
expect_issue subject, <<-CRYSTAL
|
||||||
subject.catch(source).should_not be_valid
|
X =! y
|
||||||
source.issues.size.should eq 1
|
# ^^ error: Suspicious assignment detected. Did you mean `!=`?
|
||||||
|
CRYSTAL
|
||||||
issue = source.issues.first
|
|
||||||
issue.message.should eq "Suspicious assignment detected. Did you mean `!=`?"
|
|
||||||
issue.location.to_s.should eq "source.cr:1:3"
|
|
||||||
issue.end_location.to_s.should eq "source.cr:1:4"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not register an offense when no mistype assignments" do
|
it "does not register an offense when no mistype assignments" do
|
||||||
subject.catch(Source.new(<<-CRYSTAL)).should be_valid
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
x = false
|
x = false
|
||||||
x != y
|
x != y
|
||||||
x = !y
|
x = !y
|
||||||
|
|
Loading…
Reference in a new issue