2017-10-30 20:00:01 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
|
|
|
module Ameba
|
|
|
|
describe Source do
|
|
|
|
describe ".new" do
|
2017-11-07 20:02:51 +00:00
|
|
|
it "allows to create a source by code and path" do
|
|
|
|
s = Source.new("code", "path")
|
2017-10-31 18:29:30 +00:00
|
|
|
s.path.should eq "path"
|
2017-11-07 20:02:51 +00:00
|
|
|
s.code.should eq "code"
|
|
|
|
s.lines.should eq ["code"]
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#error" do
|
|
|
|
it "adds and error" do
|
2017-11-07 20:02:51 +00:00
|
|
|
s = Source.new "", "source.cr"
|
|
|
|
s.error(DummyRule.new, s.location(23, 2), "Error!")
|
|
|
|
s.should_not be_valid
|
|
|
|
|
|
|
|
error = s.errors.first
|
|
|
|
error.rule.should_not be_nil
|
|
|
|
error.location.to_s.should eq "source.cr:23:2"
|
|
|
|
error.message.should eq "Error!"
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
|
|
|
end
|
2017-12-18 11:06:19 +00:00
|
|
|
|
|
|
|
describe "#fullpath" do
|
|
|
|
it "returns a relative path of the source" do
|
|
|
|
s = Source.new "", "./source_spec.cr"
|
|
|
|
s.fullpath.should contain "source_spec.cr"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns fullpath if path is blank" do
|
|
|
|
s = Source.new "", ""
|
|
|
|
s.fullpath.should_not be_nil
|
|
|
|
end
|
|
|
|
end
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
|
|
|
end
|