Permalink
Browse files

[pmc]: Exporter is complete

~ source namespace is now initialized to PMCNULL
~ added tests for 'import' method

git-svn-id: https://svn.parrot.org/parrot/trunk@18121 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 5b941ad commit 5b556ee85f36a2332b60a626f554b9e407ba36e0 @particle particle committed Apr 10, 2007
Showing with 100 additions and 9 deletions.
  1. +2 −4 src/pmc/exporter.pmc
  2. +98 −5 t/pmc/exporter.t
View
@@ -24,7 +24,7 @@ The Exporter PMC structure (C<Parrot_Exporter>) consists of three items:
=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 @@ Instantiates an Exporter.
/* 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 @@ Throws an exception if a non-NameSpace PMC is passed.
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 @@ Throws an exception if a non-NameSpace PMC is passed.
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,
View
@@ -6,7 +6,7 @@ use strict;
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 @@ pir_output_is( <<'CODE', <<'OUT', 'source' );
.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 @@ pir_output_is( <<'CODE', <<'OUT', 'source' );
.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 @@ OUT
## 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 @@ CODE
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:

0 comments on commit 5b556ee

Please sign in to comment.