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::FlattenAfterMap
rule spec
This commit is contained in:
parent
931dc3d2dc
commit
6f30881ae6
1 changed files with 9 additions and 12 deletions
|
@ -5,32 +5,29 @@ module Ameba::Rule::Performance
|
||||||
|
|
||||||
describe FlattenAfterMap do
|
describe FlattenAfterMap 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
|
||||||
%w[Alice Bob].flat_map(&.chars)
|
%w[Alice Bob].flat_map(&.chars)
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(source).should be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports if there is map followed by flatten call" do
|
it "reports if there is map followed by flatten call" do
|
||||||
source = Source.new %(
|
expect_issue subject, <<-CRYSTAL
|
||||||
%w[Alice Bob].map(&.chars).flatten
|
%w[Alice Bob].map(&.chars).flatten
|
||||||
)
|
# ^^^^^^^^^^^^^^^^^^^^^ error: Use `flat_map {...}` instead of `map {...}.flatten`
|
||||||
subject.catch(source).should_not be_valid
|
CRYSTAL
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not report is source is a spec" do
|
it "does not report is source is a spec" do
|
||||||
source = Source.new %(
|
expect_no_issues subject, path: "source_spec.cr", code: <<-CRYSTAL
|
||||||
%w[Alice Bob].map(&.chars).flatten
|
%w[Alice Bob].map(&.chars).flatten
|
||||||
), "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
|
||||||
{{ %w[Alice Bob].map(&.chars).flatten }}
|
{{ %w[Alice Bob].map(&.chars).flatten }}
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(source).should be_valid
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue