From bc862a99313ee149f531c1e00d800c870b9b783c Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Fri, 27 Mar 2009 15:46:06 +0100 Subject: test tree generation across subroutines --- t/06-code.t | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 t/06-code.t 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'); -- cgit v1.2.3