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 Performance::CompactAfterMap
rule spec
This commit is contained in:
parent
b54f0f0738
commit
931dc3d2dc
1 changed files with 11 additions and 15 deletions
|
@ -5,39 +5,35 @@ module Ameba::Rule::Performance
|
||||||
|
|
||||||
describe CompactAfterMap do
|
describe CompactAfterMap do
|
||||||
it "passes if there is no potential performance improvements" do
|
it "passes if there is no potential performance improvements" do
|
||||||
source = Source.new %(
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
(1..3).compact_map(&.itself)
|
(1..3).compact_map(&.itself)
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(source).should be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "passes if there is map followed by a bang call" do
|
it "passes if there is map followed by a bang call" do
|
||||||
source = Source.new %(
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
(1..3).map(&.itself).compact!
|
(1..3).map(&.itself).compact!
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(source).should be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports if there is map followed by compact call" do
|
it "reports if there is map followed by compact call" do
|
||||||
source = Source.new %(
|
expect_issue subject, <<-CRYSTAL
|
||||||
(1..3).map(&.itself).compact
|
(1..3).map(&.itself).compact
|
||||||
)
|
# ^^^^^^^^^^^^^^^^^^^^^^ error: Use `compact_map {...}` instead of `map {...}.compact`
|
||||||
subject.catch(source).should_not be_valid
|
CRYSTAL
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not report if source is a spec" do
|
it "does not report if source is a spec" do
|
||||||
source = Source.new %(
|
expect_no_issues subject, path: "source_spec.cr", code: <<-CRYSTAL
|
||||||
(1..3).map(&.itself).compact
|
(1..3).map(&.itself).compact
|
||||||
), "source_spec.cr"
|
CRYSTAL
|
||||||
subject.catch(source).should be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "macro" do
|
context "macro" do
|
||||||
it "doesn't report in macro scope" do
|
it "doesn't report in macro scope" do
|
||||||
source = Source.new %(
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
{{ [1, 2, 3].map(&.to_s).compact }}
|
{{ [1, 2, 3].map(&.to_s).compact }}
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(source).should be_valid
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue