AST node source code

This commit is contained in:
Vitalii Elenhaupt 2017-11-07 13:28:33 +02:00
parent adfe654733
commit a9421ee79b
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
2 changed files with 49 additions and 0 deletions

View file

@ -45,5 +45,31 @@ module Ameba::AST
subject.string_literal?(Crystal::Nop.new).should be_false
end
end
describe "#node_source" do
it "returns original source of the node" do
s = %(
a = 1
)
node = Crystal::Parser.new(s).parse
source = subject.node_source node, s.split("\n")
source.should eq ["a = 1"]
end
it "returns original source of multiline node" do
s = %(
if ()
:ok
end
)
node = Crystal::Parser.new(s).parse
source = subject.node_source node, s.split("\n")
source.should eq([
"if ()",
" :ok",
" end",
])
end
end
end
end