Only wrap followed_by nodes in begin/end

This commit is contained in:
Yorick Peterse 2015-08-18 17:35:23 +02:00
parent a661bf8c12
commit f41f6ff0c8
3 changed files with 19 additions and 7 deletions

View File

@ -63,7 +63,11 @@ module Oga
# @return [Oga::Ruby::Node]
#
def assign(other)
Node.new(:assign, [self, other.wrap])
if other.type == :followed_by
other = other.wrap
end
Node.new(:assign, [self, other])
end
##

View File

@ -21,11 +21,23 @@ describe Oga::Ruby::Generator do
val = Oga::Ruby::Node.new(:lit, %w{10})
assign = var.assign(val)
@generator.on_assign(assign).should == 'number = 10'
end
describe 'using a followed_by node' do
it 'returns a String' do
var = Oga::Ruby::Node.new(:lit, %w{number})
val = Oga::Ruby::Node.new(:lit, %w{10})
assign = var.assign(val.followed_by(val))
@generator.on_assign(assign).should == <<-EOF
number = begin
10
10
end
EOF
EOF
end
end
end

View File

@ -34,11 +34,7 @@ describe Oga::Ruby::Node do
node = left.assign(right)
node.type.should == :assign
node.to_a[0].should == left
node.to_a[1].type.should == :begin
node.to_a[1].to_a[0].should == right
node.to_a.should == [left, right]
end
end