shard-ameba/spec/ameba/rule/trailing_blank_lines_spec.cr

38 lines
1 KiB
Crystal
Raw Normal View History

2017-10-31 15:50:05 +00:00
require "../../spec_helper"
2017-11-07 21:50:25 +00:00
module Ameba::Rule
2017-10-31 15:50:05 +00:00
subject = TrailingBlankLines.new
describe TrailingBlankLines do
it "passes if there is no blank lines at the end" do
2017-10-31 18:29:30 +00:00
source = Source.new "no-blankline"
2017-11-01 20:05:41 +00:00
subject.catch(source).should be_valid
2017-10-31 15:50:05 +00:00
end
it "fails if there is a blank line at the end of a source" do
2017-10-31 18:29:30 +00:00
source = Source.new "a = 1\n \n "
2017-11-01 20:05:41 +00:00
subject.catch(source).should_not be_valid
2017-10-31 15:50:05 +00:00
end
it "passes if source is empty" do
2017-10-31 18:29:30 +00:00
source = Source.new ""
2017-11-01 20:05:41 +00:00
subject.catch(source).should be_valid
2017-10-31 15:50:05 +00:00
end
it "passes if last line is not blank" do
2017-10-31 18:29:30 +00:00
source = Source.new "\n\n\n puts 22"
2017-11-01 20:05:41 +00:00
subject.catch(source).should be_valid
2017-10-31 15:50:05 +00:00
end
it "reports rule, pos and message" do
source = Source.new "a = 1\n\n ", "source.cr"
2017-11-01 20:05:41 +00:00
subject.catch(source).should_not be_valid
2017-10-31 15:50:05 +00:00
error = source.errors.first
error.rule.should_not be_nil
error.location.to_s.should eq "source.cr:3:1"
2017-10-31 15:50:05 +00:00
error.message.should eq "Blank lines detected at the end of the file"
end
end
end