Sha256: b34fa5e139f7f95aa2cc20cce1a05f11ce824f6bc6ca218c7d04e5742f86f73c

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

Contents

# -*- coding: utf-8 -*-
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")

describe "Tree Node Visitors" do

  before do
    ta = TreeNode.new( "a", nil )
    LeafNode.new("1", ta )
    LeafNode.new("2", ta )

    tb = TreeNode.new( "b", ta )
    LeafNode.new( "3", tb )

    @tree = ta
  end

  it CallbackTreeNodeVisitor2 do
    visitor = CallbackTreeNodeVisitor2.new
    visitor.on_enter_node{ |tree_node, new_parent_node|
      # puts "**** #{tree_node}"
      TreeNode.new("n" + tree_node.content, new_parent_node)
    }
    visitor.on_visit_leaf{ |leaf_node, new_parent_node|
      # puts "**** #{leaf_node}"
      LeafNode.new( "n" + leaf_node.content, new_parent_node )
    }
    @tree.accept( visitor )
    new_root = visitor.root
    new_root.content.should ==  "n" + @tree.content

    accumulator = []
    visitor = BlockTreeNodeVisitor.new { |node| accumulator << node.content}
    new_root.accept( visitor )
    accumulator.length.should == 5
    accumulator.should == %w{ na n1 n2 nb n3 }
  end

end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
tree.rb-0.3.12 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.11 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.10 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.9 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.8 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.7 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.6 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.5 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.4 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.3 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.2 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.1 spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
tree.rb-0.3.0 spec/treevisitor/visitors/callback_tree_node_visitor2_spec.rb
treevisitor-0.2.3 spec/treevisitor/visitors/callback_tree_node_visitor2_spec.rb
treevisitor-0.2.2 spec/treevisitor/visitors/callback_tree_node_visitor2_spec.rb
treevisitor-0.2.1 spec/treevisitor/visitors/callback_tree_node_visitor2_spec.rb
treevisitor-0.2.0 spec/treevisitor/visitors/callback_tree_node_visitor2_spec.rb