2017-11-04 16:53:21 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
|
|
|
module Ameba
|
2017-11-07 21:50:25 +00:00
|
|
|
subject = Rule::TypeNames.new
|
2017-11-04 16:53:21 +00:00
|
|
|
|
2017-11-07 20:02:51 +00:00
|
|
|
private def it_reports_name(code, expected)
|
2017-11-04 16:53:21 +00:00
|
|
|
it "reports type name #{expected}" do
|
2017-11-07 20:02:51 +00:00
|
|
|
s = Source.new code
|
2017-11-07 21:50:25 +00:00
|
|
|
Rule::TypeNames.new.catch(s).should_not be_valid
|
2017-11-04 16:53:21 +00:00
|
|
|
s.errors.first.message.should contain expected
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-07 21:50:25 +00:00
|
|
|
describe Rule::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
|
2017-11-07 20:02:51 +00:00
|
|
|
), "source.cr"
|
2017-11-04 16:53:21 +00:00
|
|
|
subject.catch(s).should_not be_valid
|
|
|
|
error = s.errors.first
|
|
|
|
error.rule.should_not be_nil
|
2017-11-07 20:02:51 +00:00
|
|
|
error.location.to_s.should eq "source.cr:2:9"
|
2017-11-04 16:53:21 +00:00
|
|
|
error.message.should eq(
|
|
|
|
"Type name should be camelcased: MyClass, but it was My_class"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|