2017-10-30 20:00:01 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
|
|
|
module Ameba
|
|
|
|
describe Source do
|
|
|
|
describe ".new" do
|
|
|
|
it "allows to create a source by content and path" do
|
2017-10-31 18:29:30 +00:00
|
|
|
s = Source.new("content", "path")
|
|
|
|
s.path.should eq "path"
|
|
|
|
s.content.should eq "content"
|
|
|
|
s.lines.should eq ["content"]
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#error" do
|
|
|
|
it "adds and error" do
|
2017-10-31 18:29:30 +00:00
|
|
|
s = Source.new ""
|
2017-10-30 20:00:01 +00:00
|
|
|
s.error(DummyRule.new, 23, "Error!")
|
|
|
|
s.errors.size.should eq 1
|
|
|
|
s.errors.first.rule.should_not be_nil
|
|
|
|
s.errors.first.pos.should eq 23
|
|
|
|
s.errors.first.message.should eq "Error!"
|
|
|
|
end
|
|
|
|
end
|
2017-10-31 18:29:30 +00:00
|
|
|
|
|
|
|
describe "#ast" do
|
|
|
|
it "returns ast nodes" do
|
|
|
|
s = Source.new %(
|
|
|
|
class A; end
|
|
|
|
class B; end
|
|
|
|
)
|
|
|
|
s.ast.to_s.should eq "class A\nend\nclass B\nend\n"
|
|
|
|
end
|
|
|
|
end
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
|
|
|
end
|