1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 2;
use Test::Exception;
use Tree::Simple;
use Tree::Simple::Visitor;
BEGIN {
use_ok('Tree::Simple::Visitor');
};
# create a visitor instance
my $visitor = Tree::Simple::Visitor->new();
$visitor -> includeTrunk(1);
# create a tree to visit
my $tree = Tree::Simple -> new
(
'0.0',
Tree::Simple -> ROOT
) -> addChildren
(
Tree::Simple -> new('1.0'),
Tree::Simple -> new('2.0') -> addChild
(
Tree::Simple -> new('2.1.0')
),
Tree::Simple -> new('3.0')
);
# by default this will collect all the
# node values in depth-first order into
# our results
$tree->accept($visitor);
# get our results and print them
my($result) = join ', ', $visitor->getResults();
is($result, '0.0, 1.0, 2.0, 2.1.0, 3.0', 'Visit returns correct nodes');
|