summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGianni Ceccarelli <dakkar@dechirico.(none)>2009-03-27 15:46:06 +0100
committerGianni Ceccarelli <dakkar@dechirico.(none)>2009-03-27 15:46:06 +0100
commitbc862a99313ee149f531c1e00d800c870b9b783c (patch)
tree8f013a826b06495852b73127153ce5413b641dc3
parentremove no_plan (diff)
downloadTree-Template-Declare-bc862a99313ee149f531c1e00d800c870b9b783c.tar.gz
Tree-Template-Declare-bc862a99313ee149f531c1e00d800c870b9b783c.tar.bz2
Tree-Template-Declare-bc862a99313ee149f531c1e00d800c870b9b783c.zip
test tree generation across subroutines
-rw-r--r--t/06-code.t56
1 files changed, 56 insertions, 0 deletions
diff --git a/t/06-code.t b/t/06-code.t
new file mode 100644
index 0000000..aa77ef3
--- /dev/null
+++ b/t/06-code.t
@@ -0,0 +1,56 @@
+#!perl
+use Test::Most 'no_plan','die';
+use strict;
+use warnings;
+use Tree::Template::Declare options => {builder => '+DAG_Node'};
+use Data::Dumper;
+
+sub make_item {
+ my ($name,$id)=@_;
+
+ return node {
+ name 'item';
+ attribs id => $id;
+ node {
+ name 'description';
+ attribs name => $name;
+ };
+ };
+}
+
+sub make_list {
+ my (@items)=@_;
+
+ return node {
+ name 'list';
+ make_item(@$_) for @items;
+ };
+}
+
+my $tree=tree {
+ make_list([gino => 1],
+ [pino => 2],
+ [rino => 3],
+ );
+};
+
+is_deeply($tree->tree_to_lol(),
+ [
+ [['description'],'item'],
+ [['description'],'item'],
+ [['description'],'item'],
+ 'list'],
+ 'tree with code');
+
+my @attrs;
+$tree->walk_down({callback=>sub{
+ push @attrs,$_[0]->attributes;
+ 1
+ }});
+is_deeply(\@attrs,
+ [{},
+ {id=>1},{name=>'gino'},
+ {id=>2},{name=>'pino'},
+ {id=>3},{name=>'rino'},
+ ],
+ 'attributes');