[svn:parrot] r46907 - in branches/gsoc_past_optimization: . t/library

tcurtis at svn.parrot.org tcurtis at svn.parrot.org
Sun May 23 04:23:16 UTC 2010


Author: tcurtis
Date: Sun May 23 04:23:13 2010
New Revision: 46907
URL: https://trac.parrot.org/parrot/changeset/46907

Log:
Clean up PAST::Walker test a little and write one test for PAST::Transformer.

Added:
   branches/gsoc_past_optimization/t/library/pasttransformer.t   (contents, props changed)
Modified:
   branches/gsoc_past_optimization/MANIFEST
   branches/gsoc_past_optimization/MANIFEST.SKIP
   branches/gsoc_past_optimization/t/library/pastwalker.t

Modified: branches/gsoc_past_optimization/MANIFEST
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST	Sun May 23 03:48:40 2010	(r46906)
+++ branches/gsoc_past_optimization/MANIFEST	Sun May 23 04:23:13 2010	(r46907)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Sat May 22 19:48:00 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Sun May 23 04:15:21 2010 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -1673,6 +1673,7 @@
 t/library/osutils.t                                         [test]
 t/library/p6object.t                                        [test]
 t/library/parrotlib.t                                       [test]
+t/library/pasttransformer.t                                 [test]
 t/library/pastwalker.t                                      [test]
 t/library/pcre.t                                            [test]
 t/library/perlhist.txt                                      [test]

Modified: branches/gsoc_past_optimization/MANIFEST.SKIP
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST.SKIP	Sun May 23 03:48:40 2010	(r46906)
+++ branches/gsoc_past_optimization/MANIFEST.SKIP	Sun May 23 04:23:13 2010	(r46907)
@@ -1,6 +1,6 @@
 # ex: set ro:
 # $Id$
-# generated by tools/dev/mk_manifest_and_skip.pl Thu May 20 08:04:31 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Sun May 23 04:15:21 2010 UT
 #
 # This file should contain a transcript of the svn:ignore properties
 # of the directories in the Parrot subversion repository. (Needed for
@@ -577,8 +577,8 @@
 ^runtime/parrot/library/OpenGL/.*\.pbc$
 ^runtime/parrot/library/OpenGL/.*\.pbc/
 # generated from svn:ignore of 'runtime/parrot/library/PAST/'
-^runtime/parrot/library/PAST/Walker\.pbc$
-^runtime/parrot/library/PAST/Walker\.pbc/
+^runtime/parrot/library/PAST/.*\.pbc$
+^runtime/parrot/library/PAST/.*\.pbc/
 # generated from svn:ignore of 'runtime/parrot/library/PCT/'
 ^runtime/parrot/library/PCT/.*\.pbc$
 ^runtime/parrot/library/PCT/.*\.pbc/

Added: branches/gsoc_past_optimization/t/library/pasttransformer.t
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gsoc_past_optimization/t/library/pasttransformer.t	Sun May 23 04:23:13 2010	(r46907)
@@ -0,0 +1,138 @@
+#!./parrot
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+=head1 NAME
+
+t/library/pasttransformer.t
+
+=head1 DESCRIPTION
+
+Test PAST::Transformer.
+
+=head1 SYNOPSIS
+
+    % prove t/library/pasttransformer.t
+
+=cut
+
+.sub 'main' :main
+    .include 'test_more.pir'
+
+    load_bytecode 'PCT.pbc'
+    load_bytecode 'PAST/Transformer.pbc'
+    load_bytecode 'PAST/Walker.pbc'
+    register_classes()
+
+    plan(4)
+    test_change_node_attributes()
+.end
+
+=head1 Tests
+
+=over 4
+
+=item test_change_node_attributes()
+
+Uses PAST::Transformer::Increment to add 1 to each PAST::Value node. It tests that modifying attributes with a PAST::Transformer works. PAST::Walker::SumVals is used to verify that the transformation has occured correctly.
+
+=cut
+
+.sub test_change_node_attributes
+    .local pmc past, result, summer, transformer
+    past = build_test_change_node_attributes_past()
+    summer = new ['PAST'; 'Walker'; 'SumVals']
+    transformer = new ['PAST'; 'Transformer'; 'Increment']
+
+    summer.'reset'()
+    summer.'walk'(past)
+    $P0 = getattribute summer, 'sum'
+    is($P0, 78, "Initial sum worked correctly.")
+    $P1 = getattribute summer, 'count'
+    is($P1, 4, "Initial count worked correctly.")
+
+    result = transformer.'walk'(past)
+
+    summer.'reset'()
+    summer.'walk'(result)
+    $P0 = getattribute summer, 'sum'
+    is($P0, 82, "The sum changed correctly.")
+    $P1 = getattribute summer, 'count'
+    is($P1, 4, "The count stayed the same correctly.")
+.end
+
+.sub build_test_change_node_attributes_past
+    .local pmc result
+    result = new ['PAST'; 'Block']
+    $P0 = new ['PAST'; 'Var']
+    $P1 = new ['PAST'; 'Val']
+    $P1.'value'(37)
+    push $P0, $P1
+    push result, $P0
+    $P0 = new ['PAST'; 'Val']
+    $P0.'value'(24)
+    push result, $P0
+    $P0 = new ['PAST'; 'Block']
+    $P1 = new ['PAST'; 'Val']
+    $P1.'value'(5)
+    push $P0, $P1
+    $P1 = new ['PAST'; 'Val']
+    $P1.'value'(12)
+    push $P0, $P1
+    push result, $P0
+    .return (result)
+.end
+
+=back
+
+=head1 Helper classes
+
+=cut
+
+.sub register_classes
+    $P1 = get_class ['PAST'; 'Transformer']
+    $P0 = subclass $P1, ['PAST'; 'Transformer'; 'Increment']
+    $P1 = get_class ['PAST'; 'Walker']
+    $P0 = subclass $P1, ['PAST'; 'Walker'; 'SumVals']
+    addattribute $P0, 'count'
+    addattribute $P0, 'sum'
+.end
+
+.namespace ['PAST'; 'Walker']
+
+.sub 'walk' :multi(['PAST'; 'Transformer'; 'Increment'], ['PAST'; 'Val'])
+    .param pmc walker
+    .param pmc node
+    .local pmc result
+    result = clone node
+    $P0 = result.'value'()
+    inc $P0
+    result.'value'($P0)
+    .return (result)
+.end
+
+.sub 'walk' :multi(['PAST'; 'Walker'; 'SumVals'], ['PAST'; 'Val'])
+    .param pmc walker
+    .param pmc node
+    $P0 = getattribute walker, 'sum'
+    $P1 = node.'value'()
+    $P0 = $P0 + $P1
+    setattribute walker, 'sum', $P0
+    $P0 = getattribute walker, 'count'
+    inc $P0
+    setattribute walker, 'count', $P0
+.end
+
+.namespace ['PAST'; 'Walker'; 'SumVals']
+
+.sub 'reset' :method
+    $P0 = new 'Integer'
+    $P0 = 0
+    setattribute self, 'count', $P0
+    setattribute self, 'sum', $P0
+.end
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:

Modified: branches/gsoc_past_optimization/t/library/pastwalker.t
==============================================================================
--- branches/gsoc_past_optimization/t/library/pastwalker.t	Sun May 23 03:48:40 2010	(r46906)
+++ branches/gsoc_past_optimization/t/library/pastwalker.t	Sun May 23 04:23:13 2010	(r46907)
@@ -12,7 +12,7 @@
 
 =head1 SYNOPSIS
 
-    % prove t/library/configure.t
+    % prove t/library/pastwalker.t
 
 =cut
 
@@ -29,8 +29,6 @@
 
 =head1 Tests
 
-=cut
-
 =over 4
 
 =item test_count_node_types()
@@ -41,9 +39,8 @@
 
 .sub 'test_count_node_types'
     .local pmc walker, past
-    $P0 = new 'Hash'
     walker = new ['PAST';'Walker';'NodeCounter']
-    setattribute walker, 'counts', $P0
+    walker.'reset'()
 
     past = 'build_count_node_types_past'()
 
@@ -156,7 +153,12 @@
     'walkChildren'(walker, node)
 .end
 
+.namespace ['PAST'; 'Walker'; 'NodeCounter']
 
+.sub 'reset' :method
+    $P0 = new 'Hash'
+    setattribute self, 'counts', $P0
+.end
 
 # Local Variables:
 #   mode: pir


More information about the parrot-commits mailing list