Skip to content

Commit

Permalink
Add tests for :when.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcurtis committed Jul 29, 2010
1 parent b05292d commit 3bf0507
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion t/tree-optimizer.t
Expand Up @@ -2,7 +2,7 @@

pir::load_bytecode('Tree/Optimizer.pbc');

plan(10);
plan(12);

{
my $opt := Tree::Optimizer.new;
Expand Down Expand Up @@ -74,6 +74,25 @@ plan(10);
'Multipled unnamed passes are allowed.');
}

{
class Even {
method ACCEPTS ($n) { $n % 2 == 0; }
}
my &inc := sub ($n) { $n + 1; };
{
my $opt := Tree::Optimizer.new;
$opt.register(&inc, :when(Even.new));
ok($opt.run(2) == 3,
'A pass with :when runs correctly when matching.');
}
{
my $opt := Tree::Optimizer.new;
$opt.register(&inc, :when(Even.new));
ok($opt.run(1) == 1,
'A pass with :when correctly does nothing when not matching.');
}
}

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down

0 comments on commit 3bf0507

Please sign in to comment.