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
|
||||
it "passes if there is no potential performance improvements" do
|
||||
source = Source.new %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
(1..3).compact_map(&.itself)
|
||||
)
|
||||
subject.catch(source).should be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
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!
|
||||
)
|
||||
subject.catch(source).should be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there is map followed by compact call" do
|
||||
source = Source.new %(
|
||||
expect_issue subject, <<-CRYSTAL
|
||||
(1..3).map(&.itself).compact
|
||||
)
|
||||
subject.catch(source).should_not be_valid
|
||||
# ^^^^^^^^^^^^^^^^^^^^^^ error: Use `compact_map {...}` instead of `map {...}.compact`
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
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
|
||||
), "source_spec.cr"
|
||||
subject.catch(source).should be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
context "macro" do
|
||||
it "doesn't report in macro scope" do
|
||||
source = Source.new %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
{{ [1, 2, 3].map(&.to_s).compact }}
|
||||
)
|
||||
subject.catch(source).should be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue