shard-ameba/spec/ameba/rule/style/type_names_spec.cr

62 lines
1.6 KiB
Crystal
Raw Normal View History

require "../../../spec_helper"
2017-11-04 16:53:21 +00:00
module Ameba
subject = Rule::Style::TypeNames.new
2017-11-04 16:53:21 +00:00
private def it_reports_name(code, expected)
2017-11-04 16:53:21 +00:00
it "reports type name #{expected}" do
s = Source.new code
Rule::Style::TypeNames.new.catch(s).should_not be_valid
2018-06-10 21:15:12 +00:00
s.issues.first.message.should contain expected
2017-11-04 16:53:21 +00:00
end
end
describe Rule::Style::TypeNames do
2017-11-04 16:53:21 +00:00
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
), "source.cr"
2017-11-04 16:53:21 +00:00
subject.catch(s).should_not be_valid
2018-06-10 21:15:12 +00:00
issue = s.issues.first
issue.rule.should_not be_nil
2018-09-07 12:07:03 +00:00
issue.location.to_s.should eq "source.cr:1:1"
2018-11-24 17:38:13 +00:00
issue.end_location.to_s.should eq "source.cr:2:3"
2018-06-10 21:15:12 +00:00
issue.message.should eq(
2017-11-04 16:53:21 +00:00
"Type name should be camelcased: MyClass, but it was My_class"
)
end
end
end