[svn:parrot] r47928 - branches/gsoc_past_optimization/t/library
tcurtis at svn.parrot.org
tcurtis at svn.parrot.org
Wed Jun 30 02:43:44 UTC 2010
Author: tcurtis
Date: Wed Jun 30 02:43:43 2010
New Revision: 47928
URL: https://trac.parrot.org/parrot/changeset/47928
Log:
Add some tests for :min_depth.
Modified:
branches/gsoc_past_optimization/t/library/pastpattern.t
Modified: branches/gsoc_past_optimization/t/library/pastpattern.t
==============================================================================
--- branches/gsoc_past_optimization/t/library/pastpattern.t Wed Jun 30 02:19:54 2010 (r47927)
+++ branches/gsoc_past_optimization/t/library/pastpattern.t Wed Jun 30 02:43:43 2010 (r47928)
@@ -5,7 +5,7 @@
pir::load_bytecode('PCT.pbc');
pir::load_bytecode('PAST/Pattern.pbc');
-plan(2138);
+plan(2143);
test_type_matching();
test_attribute_exact_matching();
@@ -787,6 +787,7 @@
sub test_transform () {
test_transform_sub();
+ test_transform_min_depth();
}
sub test_transform_sub () {
@@ -826,6 +827,47 @@
'Matched nodes within other matched nodes are changed.');
}
+sub test_transform_min_depth () {
+ my $pattern := PAST::Pattern::Block.new;
+ my $past := PAST::Block.new(PAST::Block.new());
+
+ my @matches := [];
+ my &transform := sub ($/) {
+ pir::push(@matches, $/.orig);
+ $/.orig;
+ };
+
+ $pattern.transform($past, &transform, :min_depth(0));
+ ok(@matches == 2 &&
+ @matches[0] =:= $past &&
+ @matches[1] =:= $past[0],
+ 'Transforming with :min_depth(0) is the same as without min_depth.');
+
+ @matches := [];
+ $pattern.transform($past, &transform, :min_depth(1));
+ ok(@matches == 1 && @matches[0] =:= $past[0],
+ 'The top node was not transformed with :min_depth(1).');
+
+ @matches := [];
+ $past := PAST::Stmts.new(PAST::Block.new());
+ $pattern.transform($past, &transform, :min_depth(1));
+ ok(@matches == 1 && @matches[0] =:= $past[0],
+ 'Non-matching top node was not transformed with :min_depth(1).');
+
+ @matches := [];
+ $past := PAST::Block.new(PAST::Block.new(PAST::Block.new()));
+ $pattern.transform($past, &transform, :min_depth(2));
+ ok(@matches == 1 && @matches[0] =:= $past[0][0],
+ 'First two levels are not transformed with :min_depth(2).');
+
+ @matches := [];
+ $past := PAST::Block.new(PAST::Block.new(),
+ PAST::Block.new(PAST::Block.new()));
+ $pattern.transform($past, &transform, :min_depth(2));
+ ok(@matches == 1 && @matches[0] =:= $past[1][0],
+ 'The second child of the top is not transformed with :min_depth(2).');
+}
+
sub test_match_method () {
my $pattern := PAST::Pattern::Block.new();
my $past := PAST::Block.new();
More information about the parrot-commits
mailing list