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::HashDuplicatedKey
rule spec
This commit is contained in:
parent
18316eaa8b
commit
3cbb388393
1 changed files with 15 additions and 18 deletions
|
@ -5,26 +5,32 @@ module Ameba::Rule::Lint
|
||||||
subject = HashDuplicatedKey.new
|
subject = HashDuplicatedKey.new
|
||||||
|
|
||||||
it "passes if there is no duplicated keys in a hash literals" do
|
it "passes if there is no duplicated keys in a hash literals" do
|
||||||
s = Source.new %(
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
h = {"a" => 1, :a => 2, "b" => 3}
|
h = {"a" => 1, :a => 2, "b" => 3}
|
||||||
h = {"a" => 1, "b" => 2, "c" => {"a" => 3, "b" => 4}}
|
h = {"a" => 1, "b" => 2, "c" => {"a" => 3, "b" => 4}}
|
||||||
h = {} of String => String
|
h = {} of String => String
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(s).should be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if there is a duplicated key in a hash literal" do
|
it "fails if there is a duplicated key in a hash literal" do
|
||||||
s = Source.new %q(
|
expect_issue subject, <<-CRYSTAL
|
||||||
h = {"a" => 1, "b" => 2, "a" => 3}
|
h = {"a" => 1, "b" => 2, "a" => 3}
|
||||||
)
|
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Duplicated keys in hash literal: "a"
|
||||||
subject.catch(s).should_not be_valid
|
CRYSTAL
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if there is a duplicated key in the inner hash literal" do
|
it "fails if there is a duplicated key in the inner hash literal" do
|
||||||
s = Source.new %q(
|
expect_issue subject, <<-CRYSTAL
|
||||||
h = {"a" => 1, "b" => {"a" => 3, "b" => 4, "a" => 5}}
|
h = {"a" => 1, "b" => {"a" => 3, "b" => 4, "a" => 5}}
|
||||||
)
|
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Duplicated keys in hash literal: "a"
|
||||||
subject.catch(s).should_not be_valid
|
CRYSTAL
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports multiple duplicated keys" do
|
||||||
|
expect_issue subject, <<-CRYSTAL
|
||||||
|
h = {"key1" => 1, "key1" => 2, "key2" => 3, "key2" => 4}
|
||||||
|
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Duplicated keys in hash literal: "key1", "key2"
|
||||||
|
CRYSTAL
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports rule, location and message" do
|
it "reports rule, location and message" do
|
||||||
|
@ -38,14 +44,5 @@ module Ameba::Rule::Lint
|
||||||
issue.end_location.to_s.should eq "source.cr:1:24"
|
issue.end_location.to_s.should eq "source.cr:1:24"
|
||||||
issue.message.should eq %(Duplicated keys in hash literal: "a")
|
issue.message.should eq %(Duplicated keys in hash literal: "a")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports multiple duplicated keys" do
|
|
||||||
s = Source.new %q(
|
|
||||||
h = {"key1" => 1, "key1" => 2, "key2" => 3, "key2" => 4}
|
|
||||||
)
|
|
||||||
subject.catch(s).should_not be_valid
|
|
||||||
issue = s.issues.first
|
|
||||||
issue.message.should eq %(Duplicated keys in hash literal: "key1", "key2")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue