mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
New rule: type names
This commit is contained in:
parent
e383ec17c2
commit
20fd53682f
3 changed files with 169 additions and 14 deletions
60
spec/ameba/rules/type_names_spec.cr
Normal file
60
spec/ameba/rules/type_names_spec.cr
Normal file
|
@ -0,0 +1,60 @@
|
|||
require "../../spec_helper"
|
||||
|
||||
module Ameba
|
||||
subject = Rules::TypeNames.new
|
||||
|
||||
private def it_reports_name(content, expected)
|
||||
it "reports type name #{expected}" do
|
||||
s = Source.new content
|
||||
Rules::TypeNames.new.catch(s).should_not be_valid
|
||||
s.errors.first.message.should contain expected
|
||||
end
|
||||
end
|
||||
|
||||
describe Rules::TypeNames do
|
||||
it "passes if type names are camelcased" do
|
||||
s = Source.new %(
|
||||
class ParseError < Exception
|
||||
end
|
||||
|
||||
module HTTP
|
||||
class RequestHandler
|
||||
end
|
||||
end
|
||||
|
||||
alias NumericValue = Float32 | Float64 | Int32 | Int64
|
||||
|
||||
lib LibYAML
|
||||
end
|
||||
|
||||
struct TagDirective
|
||||
end
|
||||
|
||||
enum Time::DayOfWeek
|
||||
end
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
|
||||
it_reports_name "class My_class; end", "MyClass"
|
||||
it_reports_name "module HTT_p; end", "HTTP"
|
||||
it_reports_name "alias Numeric_value = Int32", "NumericValue"
|
||||
it_reports_name "lib Lib_YAML; end", "LibYAML"
|
||||
it_reports_name "struct Tag_directive; end", "TagDirective"
|
||||
it_reports_name "enum Time_enum::Day_of_week; end", "TimeEnum::DayOfWeek"
|
||||
|
||||
it "reports rule, pos and message" do
|
||||
s = Source.new %(
|
||||
class My_class
|
||||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.pos.should eq 2
|
||||
error.message.should eq(
|
||||
"Type name should be camelcased: MyClass, but it was My_class"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue