Author: particle
Date: Tue Apr 10 09:54:25 2007
New Revision: 18121

Modified:
   trunk/src/pmc/exporter.pmc
   trunk/t/pmc/exporter.t

Log:
[pmc]: Exporter is complete
~ source namespace is now initialized to PMCNULL
~ added tests for 'import' method

Modified: trunk/src/pmc/exporter.pmc
==============================================================================
--- trunk/src/pmc/exporter.pmc  (original)
+++ trunk/src/pmc/exporter.pmc  Tue Apr 10 09:54:25 2007
@@ -24,7 +24,7 @@
 =item C<ns_src>
 
 The source namespace -- a NameSpace PMC.
-An empty PMC of this type is allocated upon initialization.
+A Null PMC is allocated during initialization.
 
 =item C<ns_dest>
 
@@ -85,7 +85,7 @@
 
         /* Set up the object. */
         exp = mem_sys_allocate_zeroed(sizeof (Parrot_Exporter));
-        exp->ns_src  = pmc_new(interp, enum_class_NameSpace);
+        exp->ns_src  = PMCNULL;
         exp->ns_dest = CONTEXT(interp->ctx)->current_namespace;
         exp->globals = PMCNULL;
         PMC_data(SELF) = exp;
@@ -150,7 +150,6 @@
     PCCMETHOD void source(PMC *src :optional, int got_src :opt_flag) {
         Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
 
-        /* TODO deal with non-namespace pmcs */
         if (got_src) {
             if (src->vtable->base_type != enum_class_NameSpace) {
                 real_exception(interp, NULL, 0,
@@ -184,7 +183,6 @@
     PCCMETHOD void destination(PMC *dest :optional, int got_dest :opt_flag) {
         Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
 
-        /* TODO deal with non-namespace pmcs */
         if (got_dest) {
             if (dest->vtable->base_type != enum_class_NameSpace) {
                 real_exception(interp, NULL, 0,

Modified: trunk/t/pmc/exporter.t
==============================================================================
--- trunk/t/pmc/exporter.t      (original)
+++ trunk/t/pmc/exporter.t      Tue Apr 10 09:54:25 2007
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 6;
+use Parrot::Test tests => 10;
 
 =head1 NAME
 
@@ -45,10 +45,10 @@
 .sub 'test' :main
     new $P0, .Exporter
     $P1 = $P0.'source'()
-    if $P1 == '' goto ok_1
+    if null $P1 goto ok_1
     print 'not '
   ok_1:
-    say 'ok 1 - source() with no args returns source namespace, which is empty 
at first'
+    say 'ok 1 - source() returns PMCNULL upon Exporter init'
 
     # get a NameSpace PMC for testing
     # TODO replace with make_namespace, when implemented
@@ -87,7 +87,7 @@
 .sub 'Eponymous' :anon
 .end
 CODE
-ok 1 - source() with no args returns source namespace, which is empty at first
+ok 1 - source() returns PMCNULL upon Exporter init
 ok 2 - source() with args sets source namespace
 ok 3 - source() with too many args fails
 ok 4 - source() with non-namespace arg throws exception
@@ -276,7 +276,7 @@
 
 
 ## TODO import
-pir_output_like( <<'CODE', <<'OUT', 'import - no args', todo => 'not yet 
implemented' );
+pir_output_like( <<'CODE', <<'OUT', 'import - no args' );
 .sub 'test' :main
     $P0 = new .Exporter
 
@@ -289,6 +289,99 @@
 OUT
 
 
+pir_output_is( <<'CODE', <<'OUT', 'import - same source and destination 
namespaces' );
+.sub 'test' :main
+    .local pmc exporter, src
+
+    src     = get_namespace
+
+    exporter = new .Exporter
+    exporter.'import'( src :named('source'), src :named('destination'), 'plan 
ok' :named('globals') )
+    plan(1)
+    ok(1)
+.end
+
+.sub 'plan'
+    .param int one
+    say '1..1'
+.end
+
+.sub 'ok'
+    .param int one
+    say 'ok 1'
+.end
+CODE
+1..1
+ok 1
+OUT
+
+
+pir_output_is( <<'CODE', <<'OUT', 'import - globals as string' );
+.sub 'test' :main
+    load_bytecode 'Test/More.pir'
+    .local pmc exporter, src
+
+    src     = get_namespace ['Test::More']
+
+    exporter = new .Exporter
+    exporter.'import'( src :named('source'), 'plan ok' :named('globals') )
+    plan(1)
+    ok(1)
+.end
+CODE
+1..1
+ok 1
+OUT
+
+
+pir_output_is( <<'CODE', <<'OUT', 'import - globals as array' );
+.sub 'test' :main
+    load_bytecode 'Test/More.pir'
+    .local pmc exporter, src, globals
+
+    src     = get_namespace ['Test::More']
+    globals = new .ResizableStringArray
+    globals = push 'ok'
+    globals = push 'plan'
+
+    exporter = new .Exporter
+    exporter.'import'( src :named('source'), globals :named('globals') )
+    plan(1)
+    ok(1)
+.end
+CODE
+1..1
+ok 1
+OUT
+
+
+pir_output_is( <<'CODE', <<'OUT', 'import - globals with destination' );
+.sub 'test' :main
+    load_bytecode 'Test/More.pir'
+    .local pmc exporter, src, dest, globals
+
+    src     = get_namespace ['Test::More']
+    dest    = get_namespace ['foo']
+    globals = new .ResizableStringArray
+    globals = push 'ok'
+    globals = push 'plan'
+
+    exporter = new .Exporter
+    exporter.'import'( src :named('source'), dest :named('destination'), 
globals :named('globals') )
+
+    $P0 = find_global ['foo'], 'bar'
+    $P0()
+.end
+
+.namespace ['foo']
+.sub 'bar'
+    plan(1)
+    ok(1)
+.end
+CODE
+1..1
+ok 1
+OUT
 
 
 # Local Variables:

Reply via email to