Decl
view release on metacpan or search on metacpan
t/06-macros.t view on Meta::CPAN
#!perl -T
use Test::More tests => 20;
# --------------------------------------------------------------------------------------
# This first bit tests the macro insertion code. Macro insertions are nodes that are
# added to the tree "invisibly", that is, they're there but don't appear in the code's
# self-dump. This is because they're presumed to have been added at runtime based on
# specifications already present in the defined code, and will be added on the next
# runtime based on those same specifications.
# --------------------------------------------------------------------------------------
use Decl qw(-nofilter Decl::Semantics);
use Data::Dumper;
$tree = Decl->new();
$code = <<'EOF';
pod head1 "HEADING"
This is a POD element.
value basevar "0" {
if (defined $value) {
$^variable = -$value;
$this->{$key} = $value;
}
$this->{$key}
}
thing nolabel { single-line body }
something (with=parameters, borders, numeric=0, boing=boing) [with_options, something here] "and a label"
with children
and grandchildren
multiple ones
and yet "more kids"
a "plethora of'em"
EOF
$tree->load($code);
$with = $tree->first('with');
isa_ok ($with, 'Decl::Node');
$with->macroinsert (<<EOF);
! macro_expansion
! macro_expansion2
! with a child
! macro_expansion3
EOF
# Check that it all got added.
$me = $tree->first('macro_expansion');
isa_ok ($me, 'Decl::Node');
$me2 = $tree->first('macro_expansion2');
isa_ok ($me2, 'Decl::Node');
$child = $me2->find('with');
isa_ok ($child, 'Decl::Node');
$me3 = $tree->first('macro_expansion2');
isa_ok ($me3, 'Decl::Node');
$dump = $tree->describe; # Normal description does not include macro expansions.
ok ($dump !~ /with a child/);
ok ($dump !~ /macro_expansion3/);
( run in 3.001 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )