Permalink
Browse files

Add tests for adding dependencies when using a pass directly as argum…

…ent to Tree::Optimizer.register.
  • Loading branch information...
1 parent eb54e94 commit 25f33c2bb2cc3721e403eb09603b2000fdad976c tcurtis committed Aug 6, 2010
Showing with 21 additions and 2 deletions.
  1. +21 −2 t/tree-optimizer.t
View
@@ -2,7 +2,7 @@
pir::load_bytecode('Tree/Optimizer.pbc');
-plan(30);
+plan(32);
{
my $opt := Tree::Optimizer.new;
@@ -278,7 +278,7 @@ pir::load_bytecode('PAST/Pattern.pbc');
};
my $pass := Tree::Optimizer::Pass.new(&inc, :name<inc>);
$opt.register($pass);
- ok($opt.find-pass('inc') =:= $pass,
+ ok(pir::defined__IP($opt.find-pass('inc')),
'.register with a pass correctly stores the pass by name.');
ok($opt.run(5) == 6,
'Passes that were directly .registered are ran.');
@@ -307,6 +307,25 @@ pir::load_bytecode('PAST/Pattern.pbc');
}
}
+{
+ my $inc := Tree::Optimizer::Pass.new(-> $n { $n + 1; }, :name<inc>);
+ my $double := Tree::Optimizer::Pass.new(-> $n { $n * 2; }, :name<double>);
+ {
+ my $opt := Tree::Optimizer.new;
+ $opt.register($inc);
+ $opt.register($double, :depends-on<inc>);
+ ok($opt.run(5) == 12,
+ 'Adding dependencies after pass-creation with .register 1.');
+ }
+ {
+ my $opt := Tree::Optimizer.new;
+ $opt.register($inc, :depends-on<double>);
+ $opt.register($double);
+ ok($opt.run(5) == 11,
+ 'Adding dependencies after pass-creation with .register 2.');
+ }
+}
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4

0 comments on commit 25f33c2

Please sign in to comment.