From f41f6ff0c848922dbae839c898939c9abd6113d4 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 18 Aug 2015 17:35:23 +0200 Subject: [PATCH] Only wrap followed_by nodes in begin/end --- lib/oga/ruby/node.rb | 6 +++++- spec/oga/ruby/generator_spec.rb | 14 +++++++++++++- spec/oga/ruby/node_spec.rb | 6 +----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/oga/ruby/node.rb b/lib/oga/ruby/node.rb index 682b686..939d984 100644 --- a/lib/oga/ruby/node.rb +++ b/lib/oga/ruby/node.rb @@ -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 ## diff --git a/spec/oga/ruby/generator_spec.rb b/spec/oga/ruby/generator_spec.rb index 672eb15..9addba4 100644 --- a/spec/oga/ruby/generator_spec.rb +++ b/spec/oga/ruby/generator_spec.rb @@ -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 diff --git a/spec/oga/ruby/node_spec.rb b/spec/oga/ruby/node_spec.rb index 8f29617..a840419 100644 --- a/spec/oga/ruby/node_spec.rb +++ b/spec/oga/ruby/node_spec.rb @@ -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