Permalink
Browse files

Add a simple test for :recursive.

  • Loading branch information...
1 parent 3bf0507 commit 116e91706fc618f343d12c7063a53ca17c3173e2 tcurtis committed Jul 30, 2010
Showing with 18 additions and 1 deletion.
  1. +18 −1 t/tree-optimizer.t
View
@@ -2,7 +2,7 @@
pir::load_bytecode('Tree/Optimizer.pbc');
-plan(12);
+plan(13);
{
my $opt := Tree::Optimizer.new;
@@ -93,6 +93,23 @@ plan(12);
}
}
+pir::load_bytecode('PCT.pbc');
+pir::load_bytecode('PAST/Pattern.pbc');
+{
+ my $past := PAST::Stmts.new(PAST::Val.new(:value(6)));
+ my $target := PAST::Pattern::Stmts.new(PAST::Pattern::Val.new(:value(7)));
+ my $opt := Tree::Optimizer.new;
+ my &inc := sub transform ($node) {
+ if $node.match(PAST::Pattern::Val.new, :exact(1)) {
+ $node.value($node.value + 1);
+ }
+ $node;
+ };
+ $opt.register(&inc, :recursive(1));
+ ok($opt.run($past) ~~ $target,
+ 'A pass with :recursive correctly recurses.');
+}
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4

0 comments on commit 116e917

Please sign in to comment.