shard-ameba/spec/ameba/rule/layout/line_length_spec.cr

46 lines
1.2 KiB
Crystal
Raw Normal View History

require "../../../spec_helper"
2017-10-30 20:00:01 +00:00
module Ameba::Rule::Layout
2017-10-30 20:00:01 +00:00
subject = LineLength.new
long_line = "*" * (subject.max_length + 1)
2017-10-30 20:00:01 +00:00
describe LineLength do
it "passes if all lines are shorter than MaxLength symbols" do
expect_no_issues subject, <<-CRYSTAL
short line
CRYSTAL
2017-10-30 20:00:01 +00:00
end
it "passes if line consists of MaxLength symbols" do
expect_no_issues subject, <<-CRYSTAL
#{"*" * subject.max_length}
CRYSTAL
2017-11-01 10:23:12 +00:00
end
it "fails if there is at least one line longer than MaxLength symbols" do
2017-10-31 18:29:30 +00:00
source = Source.new long_line
2017-11-01 20:05:41 +00:00
subject.catch(source).should_not be_valid
2017-10-30 20:00:01 +00:00
end
it "reports rule, pos and message" do
source = Source.new long_line, "source.cr"
2017-11-01 20:05:41 +00:00
subject.catch(source).should_not be_valid
2017-10-30 20:00:01 +00:00
2018-06-10 21:15:12 +00:00
issue = source.issues.first
issue.rule.should eq subject
issue.location.to_s.should eq "source.cr:1:#{subject.max_length + 1}"
2018-11-24 17:38:13 +00:00
issue.end_location.should be_nil
2018-06-10 21:15:12 +00:00
issue.message.should eq "Line too long"
2017-10-30 20:00:01 +00:00
end
2017-11-22 06:44:29 +00:00
context "properties" do
it "#max_length" do
2017-11-22 06:44:29 +00:00
rule = LineLength.new
rule.max_length = long_line.size
expect_no_issues rule, long_line
2017-11-22 06:44:29 +00:00
end
end
2017-10-30 20:00:01 +00:00
end
end