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