Fix specs on Crystal nightly (soon to be v1.7.0)

This commit is contained in:
Sijawusz Pur Rahnama 2022-12-21 16:23:36 +01:00
parent a091af14a8
commit d31e41b8a7
10 changed files with 21 additions and 21 deletions

View file

@ -17,7 +17,7 @@ module Ameba::Rule::Lint
require "big"
require "math"
require "big"
# ^{} error: Duplicated require of `big`
# ^^^^^^^^^^^ error: Duplicated require of `big`
CRYSTAL
expect_no_corrections source

View file

@ -77,7 +77,7 @@ module Ameba::Rule::Lint
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:19"
issue.end_location.to_s.should eq "source.cr:2:29"
issue.end_location.to_s.should eq "source.cr:2:28"
issue.message.should eq "Remove redundant with_index"
end
end
@ -155,7 +155,7 @@ module Ameba::Rule::Lint
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:14"
issue.end_location.to_s.should eq "source.cr:2:29"
issue.end_location.to_s.should eq "source.cr:2:28"
issue.message.should eq "Use each instead of each_with_index"
end
end

View file

@ -76,7 +76,7 @@ module Ameba::Rule::Lint
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:14"
issue.end_location.to_s.should eq "source.cr:2:30"
issue.end_location.to_s.should eq "source.cr:2:29"
issue.message.should eq "Use `each` instead of `each_with_object`"
end
end

View file

@ -17,7 +17,7 @@ module Ameba::Rule::Performance
it "reports if there is select followed by any? without a block" do
source = expect_issue subject, <<-CRYSTAL
[1, 2, 3].select { |e| e > 2 }.any?
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `select {...}.any?`
# ^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `select {...}.any?`
CRYSTAL
expect_no_corrections source
@ -32,7 +32,7 @@ module Ameba::Rule::Performance
it "reports if there is reject followed by any? without a block" do
source = expect_issue subject, <<-CRYSTAL
[1, 2, 3].reject { |e| e > 2 }.any?
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `reject {...}.any?`
# ^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `reject {...}.any?`
CRYSTAL
expect_no_corrections source
@ -60,7 +60,7 @@ module Ameba::Rule::Performance
it "reports in macro scope" do
source = expect_issue subject, <<-CRYSTAL
{{ [1, 2, 3].reject { |e| e > 2 }.any? }}
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `reject {...}.any?`
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `reject {...}.any?`
CRYSTAL
expect_no_corrections source

View file

@ -19,7 +19,7 @@ module Ameba::Rule::Performance
it "reports if there is map followed by compact call" do
expect_issue subject, <<-CRYSTAL
(1..3).map(&.itself).compact
# ^^^^^^^^^^^^^^^^^^^^^^ error: Use `compact_map {...}` instead of `map {...}.compact`
# ^^^^^^^^^^^^^^^^^^^^^ error: Use `compact_map {...}` instead of `map {...}.compact`
CRYSTAL
end

View file

@ -17,7 +17,7 @@ module Ameba::Rule::Performance
it "reports if there is select followed by last" do
expect_issue subject, <<-CRYSTAL
[1, 2, 3].select { |e| e > 2 }.last
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `reverse_each.find {...}` instead of `select {...}.last`
# ^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `reverse_each.find {...}` instead of `select {...}.last`
CRYSTAL
end
@ -30,14 +30,14 @@ module Ameba::Rule::Performance
it "reports if there is select followed by last?" do
expect_issue subject, <<-CRYSTAL
[1, 2, 3].select { |e| e > 2 }.last?
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `reverse_each.find {...}` instead of `select {...}.last?`
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `reverse_each.find {...}` instead of `select {...}.last?`
CRYSTAL
end
it "reports if there is select followed by first" do
expect_issue subject, <<-CRYSTAL
[1, 2, 3].select { |e| e > 2 }.first
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `find {...}` instead of `select {...}.first`
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `find {...}` instead of `select {...}.first`
CRYSTAL
end
@ -50,7 +50,7 @@ module Ameba::Rule::Performance
it "reports if there is select followed by first?" do
expect_issue subject, <<-CRYSTAL
[1, 2, 3].select { |e| e > 2 }.first?
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `find {...}` instead of `select {...}.first?`
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `find {...}` instead of `select {...}.first?`
CRYSTAL
end

View file

@ -13,7 +13,7 @@ module Ameba::Rule::Performance
it "reports if there is map followed by flatten call" do
expect_issue subject, <<-CRYSTAL
%w[Alice Bob].map(&.chars).flatten
# ^^^^^^^^^^^^^^^^^^^^^ error: Use `flat_map {...}` instead of `map {...}.flatten`
# ^^^^^^^^^^^^^^^^^^^^ error: Use `flat_map {...}` instead of `map {...}.flatten`
CRYSTAL
end

View file

@ -14,7 +14,7 @@ module Ameba::Rule::Performance
it "reports if there is map followed by sum without a block" do
expect_issue subject, <<-CRYSTAL
(1..3).map(&.to_u64).sum
# ^^^^^^^^^^^^^^^^^^ error: Use `sum {...}` instead of `map {...}.sum`
# ^^^^^^^^^^^^^^^^^ error: Use `sum {...}` instead of `map {...}.sum`
CRYSTAL
end
@ -27,14 +27,14 @@ module Ameba::Rule::Performance
it "reports if there is map followed by sum without a block (with argument)" do
expect_issue subject, <<-CRYSTAL
(1..3).map(&.to_u64).sum(0)
# ^^^^^^^^^^^^^^^^^^ error: Use `sum {...}` instead of `map {...}.sum`
# ^^^^^^^^^^^^^^^^^ error: Use `sum {...}` instead of `map {...}.sum`
CRYSTAL
end
it "reports if there is map followed by sum with a block" do
expect_issue subject, <<-CRYSTAL
(1..3).map(&.to_u64).sum(&.itself)
# ^^^^^^^^^^^^^^^^^^ error: Use `sum {...}` instead of `map {...}.sum`
# ^^^^^^^^^^^^^^^^^ error: Use `sum {...}` instead of `map {...}.sum`
CRYSTAL
end

View file

@ -19,7 +19,7 @@ module Ameba::Rule::Performance
it "reports if there is a select followed by size" do
expect_issue subject, <<-CRYSTAL
[1, 2, 3].select { |e| e > 2 }.size
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `count {...}` instead of `select {...}.size`.
# ^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `count {...}` instead of `select {...}.size`.
CRYSTAL
end
@ -32,14 +32,14 @@ module Ameba::Rule::Performance
it "reports if there is a reject followed by size" do
expect_issue subject, <<-CRYSTAL
[1, 2, 3].reject { |e| e < 2 }.size
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `count {...}` instead of `reject {...}.size`.
# ^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `count {...}` instead of `reject {...}.size`.
CRYSTAL
end
it "reports if a block shorthand used" do
expect_issue subject, <<-CRYSTAL
[1, 2, 3].reject(&.empty?).size
# ^^^^^^^^^^^^^^^^^^^^^^ error: Use `count {...}` instead of `reject {...}.size`.
# ^^^^^^^^^^^^^^^^^^^^^ error: Use `count {...}` instead of `reject {...}.size`.
CRYSTAL
end

View file

@ -51,7 +51,7 @@ module Ameba::Rule::Style
expect_issue subject, <<-CRYSTAL, call: {{ call }}
class Foo
%{call} foo : Bool = true
_{call} # ^ error: Consider using '%{call}?' for 'foo'
_{call} # ^^^ error: Consider using '%{call}?' for 'foo'
end
CRYSTAL
end
@ -60,7 +60,7 @@ module Ameba::Rule::Style
expect_issue subject, <<-CRYSTAL, call: {{ call }}
class Foo
%{call} foo : Bool
_{call} # ^ error: Consider using '%{call}?' for 'foo'
_{call} # ^^^ error: Consider using '%{call}?' for 'foo'
def initialize(@foo = true)
end