[svn:parrot] r41001 - trunk/t/pmc
whiteknight at svn.parrot.org
whiteknight at svn.parrot.org
Sat Sep 5 14:26:57 UTC 2009
Author: whiteknight
Date: Sat Sep 5 14:26:56 2009
New Revision: 41001
URL: https://trac.parrot.org/parrot/changeset/41001
Log:
[t] Convert more tests to PIR, delete a few duplicate tests, and add new tests
Modified:
trunk/t/pmc/namespace-old.t
trunk/t/pmc/namespace.t
Modified: trunk/t/pmc/namespace-old.t
==============================================================================
--- trunk/t/pmc/namespace-old.t Sat Sep 5 14:22:02 2009 (r41000)
+++ trunk/t/pmc/namespace-old.t Sat Sep 5 14:26:56 2009 (r41001)
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 56;
+use Parrot::Test tests => 51;
use Parrot::Config;
=head1 NAME
@@ -23,93 +23,7 @@
=cut
-pir_output_is( <<'CODE', <<'OUTPUT', "get_global Foo::Bar::baz hash 2" );
-.sub 'main' :main
- $P0 = get_global "Foo"
- $P1 = $P0["Bar" ; "baz"]
- print "ok\n"
- $P1()
-.end
-
-.namespace ["Foo"; "Bar"]
-.sub 'baz'
- print "baz\n"
-.end
-CODE
-ok
-baz
-OUTPUT
-
-pir_output_is( <<'CODE', <<'OUTPUT', "get_global Foo::Bar::baz alias" );
-.sub 'main' :main
- $P0 = get_global "Foo"
- $P1 = $P0["Bar"]
- set_global "TopBar", $P1
- $P2 = get_global ["TopBar"], "baz"
- print "ok\n"
- $P2()
-.end
-
-.namespace ["Foo"; "Bar"]
-.sub 'baz'
- print "baz\n"
-.end
-CODE
-ok
-baz
-OUTPUT
-
-pir_error_output_like( <<'CODE', <<'OUTPUT', "func() namespace resolution" );
-.sub 'main' :main
- print "calling foo\n"
- foo()
- print "calling Foo::foo\n"
- $P0 = get_global ["Foo"], "foo"
- $P0()
- print "calling baz\n"
- baz()
-.end
-
-.sub 'foo'
- print " foo\n"
- bar()
-.end
-
-.sub 'bar'
- print " bar\n"
-.end
-
-.sub 'fie'
- print " fie\n"
-.end
-
-.namespace ["Foo"]
-
-.sub 'foo'
- print " Foo::foo\n"
- bar()
- fie()
-.end
-
-.sub 'bar'
- print " Foo::bar\n"
-.end
-
-.sub 'baz'
- print " Foo::baz\n"
-.end
-CODE
-/calling foo
- foo
- bar
-calling Foo::foo
- Foo::foo
- Foo::bar
- fie
-calling baz
-Could not find non-existent sub baz/
-OUTPUT
-
+# How do we convert this to PIR?
pir_output_is( <<'CODE', <<'OUTPUT', 'get namespace of :anon .sub' );
.namespace ['lib']
.sub main :main :anon
@@ -123,55 +37,7 @@
parrot::lib
OUTPUT
-pir_output_is( <<'CODE', <<'OUTPUT', "get namespace in Foo::bar" );
-.sub 'main' :main
- $P0 = get_global ["Foo"], "bar"
- print "ok\n"
- $P0()
-.end
-
-.namespace ["Foo"]
-.sub 'bar'
- print "bar\n"
- .include "interpinfo.pasm"
- $P0 = interpinfo .INTERPINFO_CURRENT_SUB
- $P1 = $P0."get_namespace"()
- print $P1
- print "\n"
-.end
-CODE
-ok
-bar
-Foo
-OUTPUT
-
-pir_output_is( <<'CODE', <<'OUTPUT', "get namespace in Foo::Bar::baz" );
-.sub 'main' :main
- $P0 = get_global "Foo"
- $P1 = $P0["Bar"]
- $P2 = $P1["baz"]
- print "ok\n"
- $P2()
-.end
-
-.namespace ["Foo" ; "Bar"]
-.sub 'baz'
- print "baz\n"
- .include "interpinfo.pasm"
- .include "pmctypes.pasm"
- $P0 = interpinfo .INTERPINFO_CURRENT_SUB
- $P1 = $P0."get_namespace"()
- $P2 = $P1.'get_name'()
- $S0 = join '::', $P2
- print $S0
- print "\n"
-.end
-CODE
-ok
-baz
-parrot::Foo::Bar
-OUTPUT
-
+# How do we convert this to PIR?
pir_output_is( <<'CODE', <<'OUTPUT', "segv in get_name" );
.namespace ['pugs';'main']
.sub 'main' :main
Modified: trunk/t/pmc/namespace.t
==============================================================================
--- trunk/t/pmc/namespace.t Sat Sep 5 14:22:02 2009 (r41000)
+++ trunk/t/pmc/namespace.t Sat Sep 5 14:26:56 2009 (r41001)
@@ -18,12 +18,13 @@
.sub main :main
.include 'test_more.pir'
- plan(12)
+ plan(18)
create_namespace_pmc()
verify_namespace_type()
get_global_opcode()
get_sub_from_namespace_hash()
+ access_sub_in_namespace()
get_namespace_from_sub()
.end
@@ -100,30 +101,73 @@
.end
.sub 'get_sub_from_namespace_hash'
+ #See that a NameSpace does Hash
$P0 = get_global "Foo"
$I0 = does $P0, 'hash'
ok($I0, "Namespace does hash")
+ # Use a hash key to get a Sub in a namespace
$P1 = $P0["baz"]
$S0 = $P1()
is($S0, "Foo", "Get the Sub from the NameSpace as a Hash")
+ # Use hash keys to get Subs and nested NameSpaces in NameSpaces
$P1 = $P0["Bar"]
$P2 = $P1["baz"]
$S0 = $P2()
is($S0, "Foo::Bar", "Get the Sub from the nested NameSpace as a Hash")
+
+ # Use nested keys to access nested NameSpaces
+ $P1 = $P0[ "Bar";"baz" ]
+ $S0 = $P1()
+ is($S0, "Foo::Bar", "Get Sub from nested NameSpace with multi-key")
+
+ # Alias a namespace and access it by Key
+ $P1 = $P0["Bar"]
+ set_global "TopBar", $P1
+ $P2 = get_global ["TopBar"], "baz"
+ is($S0, "Foo::Bar", "Alias namespace")
+.end
+
+.sub 'access_sub_in_namespace'
+ $S0 = baz()
+ $P0 = get_global "baz"
+ $S1 = $P0()
+ is($S0, $S1, "Direct and Indirect Sub calls")
+
+ push_eh eh
+ 'SUB_AINT_THERE'()
+ ok(0, "Directly called a sub that doesn't exist")
+ goto _end
+ eh:
+ ok(1, "Can't direct call a sub that doesn't exist")
+ _end:
.end
.sub 'get_namespace_from_sub'
+ # root namespace is "parrot"
$P0 = get_global "baz"
$P1 = $P0."get_namespace"()
$S0 = $P1
is($S0, "parrot", "Get the root namespace from a sub in the root namespace")
+ # Get an explicit namespace
$P0 = get_global ["Foo"], "baz"
$P1 = $P0."get_namespace"()
$S0 = $P1
is($S0, "Foo", "Get the namespace from a Sub in the NameSpace")
+
+ # Get namespace from the current sub
+ .include 'interpinfo.pasm'
+ $P0 = interpinfo .INTERPINFO_CURRENT_SUB
+ $P1 = $P0."get_namespace"()
+ $S0 = $P1
+ is($S0, "parrot", "Get namespace from current sub")
+
+ # Now get the current sub again
+ $P2 = $P1["get_namespace_from_sub"]
+ $S0 = typeof $P2
+ is($S0, "Sub", "Get the current sub from namespace from current sub")
.end
More information about the parrot-commits
mailing list