mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Convert Style/TypeNames
spec
This commit is contained in:
parent
e7cfe387d6
commit
06c0887136
1 changed files with 20 additions and 13 deletions
|
@ -3,17 +3,19 @@ require "../../../spec_helper"
|
||||||
module Ameba
|
module Ameba
|
||||||
subject = Rule::Style::TypeNames.new
|
subject = Rule::Style::TypeNames.new
|
||||||
|
|
||||||
private def it_reports_name(code, expected)
|
private def it_reports_name(type, name, expected)
|
||||||
it "reports type name #{expected}" do
|
it "reports type name #{expected}" do
|
||||||
s = Source.new code
|
rule = Rule::Style::TypeNames.new
|
||||||
Rule::Style::TypeNames.new.catch(s).should_not be_valid
|
expect_issue rule, <<-CRYSTAL, type: type, name: name
|
||||||
s.issues.first.message.should contain expected
|
%{type} %{name}; end
|
||||||
|
# ^{type}^{name}^^^^ error: Type name should be camelcased: #{expected}, but it was %{name}
|
||||||
|
CRYSTAL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Rule::Style::TypeNames do
|
describe Rule::Style::TypeNames do
|
||||||
it "passes if type names are camelcased" do
|
it "passes if type names are camelcased" do
|
||||||
s = Source.new %(
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
class ParseError < Exception
|
class ParseError < Exception
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -32,16 +34,21 @@ module Ameba
|
||||||
|
|
||||||
enum Time::DayOfWeek
|
enum Time::DayOfWeek
|
||||||
end
|
end
|
||||||
)
|
CRYSTAL
|
||||||
subject.catch(s).should be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_reports_name "class My_class; end", "MyClass"
|
it_reports_name "class", "My_class", "MyClass"
|
||||||
it_reports_name "module HTT_p; end", "HTTP"
|
it_reports_name "module", "HTT_p", "HTTP"
|
||||||
it_reports_name "alias Numeric_value = Int32", "NumericValue"
|
it_reports_name "lib", "Lib_YAML", "LibYAML"
|
||||||
it_reports_name "lib Lib_YAML; end", "LibYAML"
|
it_reports_name "struct", "Tag_directive", "TagDirective"
|
||||||
it_reports_name "struct Tag_directive; end", "TagDirective"
|
it_reports_name "enum", "Time_enum::Day_of_week", "TimeEnum::DayOfWeek"
|
||||||
it_reports_name "enum Time_enum::Day_of_week; end", "TimeEnum::DayOfWeek"
|
|
||||||
|
it "reports alias name" do
|
||||||
|
expect_issue subject, <<-CRYSTAL
|
||||||
|
alias Numeric_value = Int32
|
||||||
|
# ^{} error: Type name should be camelcased: NumericValue, but it was Numeric_value
|
||||||
|
CRYSTAL
|
||||||
|
end
|
||||||
|
|
||||||
it "reports rule, pos and message" do
|
it "reports rule, pos and message" do
|
||||||
s = Source.new %(
|
s = Source.new %(
|
||||||
|
|
Loading…
Reference in a new issue