Permalink
Browse files

Added a new test file that running the example given in Tree::Simple:…

…:Visitor object POD
  • Loading branch information...
1 parent ff3c84e commit 6caa82d01d009838a9ea20eef9abaf359b370a1b @Takadonet committed Dec 20, 2010
Showing with 31 additions and 0 deletions.
  1. +31 −0 t/test_visitor.t
View
31 t/test_visitor.t
@@ -0,0 +1,31 @@
+use v6;
+use Test;
+plan 1;
+BEGIN
+{
+ @*INC.push('lib');
+ @*INC.push('blib');
+}
+use Tree::Simple;
+use Tree::Simple::Visitor;
+
+# create a visitor instance
+my $visitor = Tree::Simple::Visitor.new();
+
+# create a tree to visit
+my $tree = Tree::Simple.new($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 @results= <1.0 2.0 2.1.0 3.0>;
+
+is($visitor.getResults().join(', '), @results.join(', '),'Find correct children'); # prints "1.0, 2.0, 2.1.0, 3.0"
+

0 comments on commit 6caa82d

Please sign in to comment.