diff --git a/.travis.yml b/.travis.yml index fdf0384..6c3f80f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,10 @@ language: ruby rvm: - - 1.9.2 - - 1.9.3 - - 2.0 - - 2.1 - - 2.2 - - 2.3 - - 2.4.1 - - jruby-18mode - - jruby-19mode + - 2.4.10 + - 2.5.8 + - 2.6.6 + - 2.7.1 + - jruby-9.1.15.0 before_install: - gem install bundler diff --git a/lib/ast/node.rb b/lib/ast/node.rb index 51a8194..30502e8 100644 --- a/lib/ast/node.rb +++ b/lib/ast/node.rb @@ -140,7 +140,9 @@ def updated(type=nil, children=nil, properties=nil) properties.nil? self else - original_dup.send :initialize, new_type, new_children, new_properties + copy = original_dup + copy.send :initialize, new_type, new_children, new_properties + copy end end diff --git a/test/test_ast.rb b/test/test_ast.rb index 581e29f..06e02ee 100644 --- a/test/test_ast.rb +++ b/test/test_ast.rb @@ -7,9 +7,17 @@ class MetaNode < AST::Node attr_reader :meta end + class SubclassNode < AST::Node + def initialize(*) + super + nil + end + end + before do @node = AST::Node.new(:node, [ 0, 1 ]) @metanode = MetaNode.new(:node, [ 0, 1 ], :meta => 'value') + @subclass_node = SubclassNode.new(:node, [ 0, 1 ]) end it 'should have accessors for type and children' do @@ -55,6 +63,12 @@ class MetaNode < AST::Node updated.meta.should.equal 'other_value' end + it 'returns updated node for subclasses that override constructor' do + updated = @subclass_node.updated(nil, [2]) + updated.type.should.equal :node + updated.children.should.equal [2] + end + it 'should format to_sexp correctly' do AST::Node.new(:a, [ :sym, [ 1, 2 ] ]).to_sexp.should.equal '(a :sym [1, 2])' AST::Node.new(:a, [ :sym, @node ]).to_sexp.should.equal "(a :sym\n (node 0 1))"