Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add some tests for Tree::Optimizer.register with a Tree::Optimizer::P…

…ass as argument.
  • Loading branch information...
commit e36f8c9aef6be4c5d57b24c3b697dfca09814510 1 parent 826af57
tcurtis authored
Showing with 37 additions and 1 deletion.
  1. +37 −1 t/tree-optimizer.t
View
38 t/tree-optimizer.t
@@ -2,7 +2,7 @@
pir::load_bytecode('Tree/Optimizer.pbc');
-plan(26);
+plan(30);
{
my $opt := Tree::Optimizer.new;
@@ -271,6 +271,42 @@ pir::load_bytecode('PAST/Pattern.pbc');
'Null results are handled properly with :when/:recursive/:combine.');
}
+{
+ my $opt := Tree::Optimizer.new;
+ my &inc := sub ($n) {
+ $n + 1;
+ };
+ my $pass := Tree::Optimizer::Pass.new(&inc, :name<inc>);
+ $opt.register($pass);
+ ok($opt.find-pass('inc') =:= $pass,
+ '.register with a pass correctly stores the pass by name.');
+ ok($opt.run(5) == 6,
+ 'Passes that were directly .registered are ran.');
+}
+
+{
+ my &inc := sub ($n) {
+ $n + 1;
+ };
+ my &double := sub ($n) {
+ $n * 2;
+ };
+ {
+ my $opt := Tree::Optimizer.new;
+ $opt.register(Tree::Optimizer::Pass.new(&inc, :name<inc>));
+ $opt.register(Tree::Optimizer::Pass.new(&double, :depends-on<inc>));
+ ok($opt.run(5) == 12,
+ '.register(Pass) respects dependencies 1.');
+ }
+ {
+ my $opt := Tree::Optimizer.new;
+ $opt.register(Tree::Optimizer::Pass.new(&double, :name<double>));
+ $opt.register(Tree::Optimizer::Pass.new(&inc, :depends-on<double>));
+ ok($opt.run(5) == 11,
+ '.register(Pass) respects dependencies 2.');
+ }
+}
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Please sign in to comment.
Something went wrong with that request. Please try again.