2 # Copyright (C) 2001-2008, The Perl Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use Parrot::Test tests => 65;
14 t/pmc/namespace.t - test the NameSpace PMC as described in PDD21.
18 % prove t/pmc/namespace.t
22 Test the NameSpace PMC as described in PDD21.
26 # L<PDD21/Namespace PMC API/>
27 pir_output_is( <<'CODE', <<'OUT', 'new' );
30 say "ok 1 - $P0 = new 'NameSpace'"
33 ok 1 - $P0 = new 'NameSpace'
36 # L<PDD21/Namespace PMC API/=head4 Untyped Interface>
37 pir_output_is( <<'CODE', <<'OUT', 'NameSpace does "hash"' );
40 $I0 = does $P0, 'hash'
44 say 'ok 1 - NameSpace does "hash"'
47 ok 1 - NameSpace does "hash"
51 pir_output_is( <<'CODE', <<'OUTPUT', "get_global bar" );
53 $P0 = get_global "bar"
66 pir_output_is( <<'CODE', <<'OUTPUT', "verify NameSpace type" );
68 $P0 = get_global "Foo"
82 pir_output_is( <<'CODE', <<'OUTPUT', "get_global Foo::bar" );
84 $P0 = get_global ["Foo"], "bar"
98 pir_output_is( <<'CODE', <<'OUTPUT', "get_namespace Foo::bar" );
100 $P0 = get_global ["Foo"], "bar"
102 $P1 = $P0."get_namespace"()
115 pir_output_is( <<'CODE', <<'OUTPUT', "get_global Foo::bar ns" );
117 $P1 = get_global ["Foo"], "bar"
131 pir_output_is( <<'CODE', <<'OUTPUT', "get_global Foo::bar hash" );
133 $P0 = get_global "Foo"
148 pir_output_is( <<'CODE', <<'OUTPUT', "get_global Foo::Bar::baz" );
150 $P2 = get_global ["Foo";"Bar"], "baz"
155 .namespace ["Foo" ; "Bar"]
164 pir_error_output_like( <<'CODE', <<'OUTPUT', "get_global Foo::bazz not found" );
166 $P2 = get_global ["Foo"], "bazz"
171 /Null PMC access in invoke\(\)/
174 # [this used to behave differently from the previous case.]
175 pir_error_output_like( <<'CODE', <<'OUTPUT', "get_global Foo::Bar::bazz not found" );
177 $P2 = get_global ["Foo";"Bar"], "bazz"
182 /Null PMC access in invoke\(\)/
185 pir_output_is( <<'CODE', <<'OUTPUT', "get_global Foo::Bar::baz hash" );
187 $P0 = get_global "Foo"
194 .namespace ["Foo"; "Bar"]
203 pir_output_is( <<'CODE', <<'OUTPUT', "get_global Foo::Bar::baz hash 2" );
205 $P0 = get_global "Foo"
206 $P1 = $P0["Bar" ; "baz"]
211 .namespace ["Foo"; "Bar"]
220 pir_output_is( <<'CODE', <<'OUTPUT', "get_global Foo::Bar::baz alias" );
222 $P0 = get_global "Foo"
224 set_global "TopBar", $P1
225 $P2 = get_global ["TopBar"], "baz"
230 .namespace ["Foo"; "Bar"]
239 pir_error_output_like( <<'CODE', <<'OUTPUT', "func() namespace resolution" );
241 print "calling foo\n"
243 print "calling Foo::foo\n"
244 $P0 = get_global ["Foo"], "foo"
246 print "calling baz\n"
287 Could not find non-existent sub baz/
290 pir_output_is( <<'CODE', <<'OUTPUT', 'get namespace of :anon .sub' );
292 .sub main :main :anon
294 $P0 = $P0.'get_name'()
303 pir_output_is( <<'CODE', <<'OUTPUT', "get namespace in Foo::bar" );
305 $P0 = get_global ["Foo"], "bar"
313 .include "interpinfo.pasm"
314 $P0 = interpinfo .INTERPINFO_CURRENT_SUB
315 $P1 = $P0."get_namespace"()
325 pir_output_is( <<'CODE', <<'OUTPUT', "get namespace in Foo::Bar::baz" );
327 $P0 = get_global "Foo"
334 .namespace ["Foo" ; "Bar"]
337 .include "interpinfo.pasm"
338 .include "pmctypes.pasm"
339 $P0 = interpinfo .INTERPINFO_CURRENT_SUB
340 $P1 = $P0."get_namespace"()
341 $P2 = $P1.'get_name'()
352 pir_output_is( <<'CODE', <<'OUTPUT', "segv in get_name" );
353 .namespace ['pugs';'main']
355 $P0 = find_name "&say"
365 pir_output_is( <<'CODE', <<'OUT', "latin1 namespace, global" );
366 .namespace [ iso-8859-1:"François" ]
369 print "latin1 namespaces are fun\n"
375 $P0 = get_global [iso-8859-1:"François"], 'test'
379 latin1 namespaces are fun
382 pir_output_is( <<'CODE', <<'OUT', "unicode namespace, global" );
383 .namespace [ unicode:"Fran\xe7ois" ]
386 print "unicode namespaces are fun\n"
392 $P0 = get_global [unicode:"Fran\xe7ois"], 'test'
396 unicode namespaces are fun
399 pir_output_is( <<'CODE', <<'OUTPUT', "verify root and parrot namespaces" );
400 # name may change though
403 $P0 = get_root_namespace
424 pir_output_is( <<'CODE', <<'OUTPUT', "ns.name()" );
426 .include "interpinfo.pasm"
427 $P0 = get_root_namespace
429 $P3 = new 'NameSpace'
431 $P2 = $P3.'get_name'()
444 pir_output_is( <<'CODE', <<'OUTPUT', "get_namespace_p_p, getnamespace_p_kc" );
446 .include "interpinfo.pasm"
447 $P3 = new 'NameSpace'
448 set_hll_global "Foo", $P3
450 $P4 = new 'FixedStringArray'
453 $P0 = get_hll_namespace $P4
454 $P2 = $P0.'get_name'()
462 $P2 = get_hll_namespace ["Foo"]
463 $P2 = $P2.'get_name'()
478 pir_output_is( <<'CODE', <<'OUTPUT', "Sub.get_namespace, get_namespace" );
480 $P0 = get_global ["Foo"], "bar"
482 $P1 = $P0."get_namespace"()
483 $P2 = $P1.'get_name'()
502 pir_output_is( <<'CODE', <<'OUTPUT', "check parrot ns" );
504 $P0 = get_global ["String"], "lower"
512 my $temp_a = "temp_a";
513 my $temp_b = "temp_b";
516 unlink( "$temp_a.pir", "$temp_a.pbc", "$temp_b.pir", "$temp_b.pbc" );
519 open my $S, '>', "$temp_a.pir" or die "Can't write $temp_a.pir";
524 $P0 = get_global ["Foo_A"], "A"
526 load_bytecode "temp_b.pbc"
534 open $S, '>', "$temp_b.pir" or die "Can't write $temp_b.pir";
538 $P0 = get_global ["Foo_B"], "B"
548 system(".$PConfig{slash}parrot$PConfig{exe} -o $temp_a.pbc $temp_a.pir");
549 system(".$PConfig{slash}parrot$PConfig{exe} -o $temp_b.pbc $temp_b.pir");
551 pir_output_is( <<'CODE', <<'OUTPUT', "HLL and load_bytecode - #38888" );
553 load_bytecode "temp_a.pbc"
562 pir_output_is( <<'CODE', <<'OUTPUT', "HLL and vars" );
563 # initial storage of _tcl global variable...
570 set_global '$variable', $P0
573 # start running HLL language
578 $P1 = get_root_namespace ['_tcl']
579 $P2 = $P1['$variable']
587 pir_output_is( <<'CODE', <<'OUTPUT', "HLL and namespace directives" );
589 .namespace ['Foo'; 'Bar']
595 $P1 = $P0.'get_name'()
606 my $temp_a = "temp_a.pir";
612 open $S, '>', $temp_a or die "Can't write $temp_a";
619 set_global '$whee', $P1
623 $P0 = get_global '$whee'
629 pir_output_is( <<'CODE', <<'OUTPUT', ":anon subs still get default namespace" );
633 load_bytecode 'temp_a.pir'
635 var = get_root_namespace
648 skip( "immediate test, doesn't with -r (from .pbc)", 1 )
649 if ( exists $ENV{TEST_PROG_ARGS} and $ENV{TEST_PROG_ARGS} =~ m/-r/ );
651 pir_output_is( <<'CODE', <<'OUTPUT', "get_global in current" );
658 set_global ['sub_namespace'], "eek", $P1
661 .namespace [ 'sub_namespace' ]
664 $P1 = get_global 'eek'
672 open $S, '>', "$temp_b.pir" or die "Can't write $temp_b.pir";
681 pir_error_output_like( <<'CODE', <<'OUTPUT', 'export_to() with null destination throws exception' );
683 .local pmc nsa, nsb, ar
685 ar = new 'ResizableStringArray'
688 nsb = get_namespace ['B']
689 nsb.'export_to'(nsa, ar)
696 /^destination namespace not specified\n/
699 pir_error_output_like(
700 <<'CODE', <<'OUTPUT', 'export_to() with null exports default object set !!!UNSPECIFIED!!!' );
702 .local pmc nsa, nsb, ar
706 nsb = get_namespace ['B']
707 nsb.'export_to'(nsa, ar)
714 /^exporting default object set not yet implemented\n/
717 pir_error_output_like(
718 <<'CODE', <<'OUTPUT', 'export_to() with empty array exports default object set !!!UNSPECIFIED!!!' );
720 .local pmc nsa, nsb, ar
722 ar = new 'ResizableStringArray'
724 nsb = get_namespace ['B']
725 nsb.'export_to'(nsa, ar)
732 /^exporting default object set not yet implemented\n/
735 pir_error_output_like(
736 <<'CODE', <<'OUTPUT', 'export_to() with empty hash exports default object set !!!UNSPECIFIED!!!' );
738 .local pmc nsa, nsb, ar
742 nsb = get_namespace ['B']
743 nsb.'export_to'(nsa, ar)
750 /^exporting default object set not yet implemented\n/
753 pir_output_is( <<"CODE", <<'OUTPUT', "export_to -- success with array" );
757 load_bytecode "$temp_b.pir"
758 .local pmc nsr, nsa, nsb, ar
759 ar = new 'ResizableStringArray'
761 nsr = get_root_namespace
764 nsb."export_to"(nsa, ar)
776 pir_output_is( <<"CODE", <<'OUTPUT', "export_to -- success with hash (empty value)" );
780 load_bytecode "$temp_b.pir"
781 .local pmc nsr, nsa, nsb, ar
784 nsr = get_root_namespace
787 nsb."export_to"(nsa, ar)
799 pir_output_is( <<"CODE", <<'OUTPUT', "export_to -- success with hash (null value)" );
803 load_bytecode "$temp_b.pir"
804 .local pmc nsr, nsa, nsb, ar, nul
808 nsr = get_root_namespace
811 nsb."export_to"(nsa, ar)
823 pir_error_output_like( <<"CODE", <<'OUTPUT', "export_to -- success with hash (and value)" );
827 load_bytecode "$temp_b.pir"
828 .local pmc nsr, nsa, nsb, ar
830 ar["b_foo"] = "c_foo"
831 nsr = get_root_namespace
834 nsb."export_to"(nsa, ar)
845 Could not find non-existent sub b_foo/
848 pir_output_is( <<'CODE', <<'OUTPUT', "get_parent" );
851 ns = get_hll_namespace ['Foo']
852 ns = ns.'get_parent'()
863 pir_output_is( <<'CODE', <<'OUTPUT', "get_global [''], \"print_ok\"" );
874 $P0 = get_hll_global [''], 'print_ok'
882 pir_output_is( <<'CODE', <<'OUTPUT', "get_global with array ('')" );
893 $P0 = new 'ResizableStringArray'
895 $P0 = get_hll_global $P0, 'print_ok'
903 pir_output_is( <<'CODE', <<'OUTPUT', "get_global with empty array" );
914 $P0 = new 'ResizablePMCArray'
916 $P0 = get_hll_global $P0, 'print_ok'
924 pir_output_is( <<'CODE', <<'OUTPUT', "Namespace.get_global() with array ('')" );
935 $P1 = new 'ResizableStringArray'
937 $P1 = get_hll_global $P1, 'print_ok'
945 pir_output_is( <<'CODE', <<'OUTPUT', "Namespace introspection" );
948 f = get_hll_global ['Foo'], 'dummy'
953 .local pmc interp, ns_caller
955 ns_caller = interp['namespace'; 1]
963 pir_output_is( <<'CODE', <<'OUTPUT', "Nested namespace introspection" );
965 .local string no_symbol
968 foo_ns = get_hll_namespace [ 'Foo' ]
970 print "Found namespace: "
975 bar_ns = foo_ns.find_namespace( 'Bar' )
977 print "Found nested namespace: "
982 baz_ns = bar_ns.find_namespace( 'Baz' )
985 .local int is_defined
986 is_defined = defined baz_ns
987 if is_defined goto oops
991 print "Found non-null '"
998 a_sub = bar_ns.find_sub( 'a_sub' )
1006 some_sub = bar_ns.find_sub( 'some_sub' )
1007 no_symbol = 'some_sub'
1009 is_defined = defined some_sub
1010 if is_defined goto oops
1013 a_var = bar_ns.find_var( 'a_var' )
1019 some_var = bar_ns.find_var( 'some_var' )
1020 no_symbol = 'some_var'
1022 is_defined = defined some_var
1023 if is_defined goto oops
1032 .namespace [ 'Foo'; 'Bar' ]
1036 some_var = new 'String'
1037 some_var = 'a string PMC'
1038 set_hll_global [ 'Foo'; 'Bar' ], 'a_var', some_var
1041 Found namespace: Foo
1042 Found nested namespace: Bar
1044 Found var: a string PMC
1047 pir_output_is( <<'CODE', <<'OUTPUT', 'get_root_namespace' );
1050 root_ns = get_root_namespace
1051 .local int is_defined
1052 is_defined = defined root_ns
1053 unless is_defined goto NO_NAMESPACE_FOUND
1054 print "Found root namespace.\n"
1058 Found root namespace.
1061 pir_output_is( <<'CODE', <<'OUTPUT', 'root namespace is not a class' );
1064 root_ns = get_root_namespace
1065 .local pmc root_class
1066 root_class = get_class root_ns
1068 is_class = defined root_class
1075 pir_output_is( <<'CODE', <<'OUTPUT', 'get_root_namespace "Foo"' );
1078 foo_ns = get_root_namespace [ "foo" ]
1079 .local int is_defined
1080 is_defined = defined foo_ns
1081 unless is_defined goto NO_NAMESPACE_FOUND
1082 print "Found root namespace 'foo'.\n"
1089 Found root namespace 'foo'.
1092 pir_output_is( <<'CODE', <<'OUTPUT', 'get_root_namespace "Foo", not there' );
1095 foo_ns = get_root_namespace [ "Foo" ]
1096 .local int is_defined
1097 is_defined = defined foo_ns
1098 if is_defined goto NAMESPACE_FOUND
1099 print "Didn't find root namespace 'Foo'.\n"
1103 .namespace [ "NotFoo" ]
1105 Didn't find root namespace 'Foo'.
1108 my $create_nested_key = <<'CREATE_NESTED_KEY';
1109 .sub create_nested_key
1111 .param pmc other_names :slurpy
1125 tail = create_nested_key(other_names :flat)
1132 pir_output_is( <<"CODE", <<'OUTPUT', 'get_name()' );
1137 key = create_nested_key( 'SingleName' )
1138 print_namespace( key )
1140 key = create_nested_key( 'Nested', 'Name', 'Space' )
1141 print_namespace( key )
1146 ns = key.'get_name'()
1148 .local string ns_name
1149 ns_name = join ';', ns
1154 .sub 'print_namespace'
1158 get_ns = get_global key, 'get_namespace'
1163 .local pmc name_array
1164 name_array = ns.'get_name'()
1167 name = join ';', name_array
1179 .namespace [ 'SingleName' ]
1187 .namespace [ 'Nested'; 'Name'; 'Space' ]
1197 parrot;Nested;Name;Space
1201 pir_output_is( <<"CODE", <<'OUTPUT', 'add_namespace()' );
1206 root_ns = get_namespace
1209 child_ns = new 'NameSpace'
1210 root_ns.'add_namespace'( 'Nested', child_ns )
1212 .local pmc grandchild_ns
1213 grandchild_ns = new 'NameSpace'
1214 child_ns.'add_namespace'( 'Grandkid', grandchild_ns )
1216 .local pmc great_grandchild_ns
1217 great_grandchild_ns = new 'NameSpace'
1218 grandchild_ns.'add_namespace'( 'Greatgrandkid', great_grandchild_ns )
1221 parent = great_grandchild_ns.'get_parent'()
1222 print_ns_name( parent )
1224 parent = parent.'get_parent'()
1225 print_ns_name( parent )
1227 parent = parent.'get_parent'()
1228 print_ns_name( parent )
1232 .param pmc namespace
1235 ns = namespace.'get_name'()
1237 .local string ns_name
1238 ns_name = join ';', ns
1243 parrot;Nested;Grandkid
1248 pir_output_like( <<'CODE', <<'OUTPUT', 'add_namespace() with error' );
1251 ns_child = subclass 'NameSpace', 'NSChild'
1254 child = new 'NSChild'
1257 root_ns = get_namespace
1259 root_ns.'add_namespace'( 'Really nested', child )
1262 not_a_ns = new 'Integer'
1265 root_ns.'add_namespace'( 'Nested', not_a_ns )
1269 .local pmc exception
1270 .local string message
1271 .get_results( exception, message )
1277 /Invalid type \d+ in add_namespace\(\)/
1280 pir_output_is( <<"CODE", <<'OUTPUT', 'add_sub()' );
1284 .local pmc report_ns
1285 report_ns = get_global 'report_namespace'
1288 key = create_nested_key( 'Parent' )
1290 .local pmc parent_ns
1291 parent_ns = get_namespace key
1292 parent_ns.'add_sub'( 'report_ns', report_ns )
1294 key = create_nested_key( 'Parent', 'Child' )
1297 child_ns = get_namespace key
1298 child_ns.'add_sub'( 'report_ns', report_ns )
1300 .local pmc report_namespace
1301 report_namespace = get_global [ 'Parent' ], 'report_ns'
1304 report_namespace = get_global [ 'Parent'; 'Child' ], 'report_ns'
1308 .sub 'report_namespace'
1309 .local pmc namespace
1310 namespace = get_namespace
1313 ns = namespace.'get_name'()
1315 .local string ns_name
1316 ns_name = join ';', ns
1321 .namespace [ 'Parent' ]
1326 .namespace [ 'Parent'; 'Child' ]
1335 pir_error_output_like( <<'CODE', <<'OUTPUT', 'add_sub() with error', todo => 'needs full implementation of PDD 17' );
1338 s_child = subclass 'Sub', 'SubChild'
1341 e_child = subclass 'Closure', 'ClosureChild'
1344 child = new 'SubChild'
1347 root_ns = get_namespace
1349 root_ns.'add_sub'( 'child', child )
1350 print "Added sub child\n"
1352 child = new 'Closure'
1353 root_ns.'add_sub'( 'closure', child )
1354 print "Added closure\n"
1356 child = new 'Coroutine'
1357 root_ns.'add_sub'( 'coroutine', child )
1358 print "Added coroutine\n"
1361 root_ns.'add_sub'( 'eval', child )
1362 print "Added eval\n"
1364 child = new 'ClosureChild'
1365 root_ns.'add_sub'( 'closure_child', child )
1366 print "Added closure child\n"
1368 .local pmc not_a_sub
1369 not_a_sub = new 'Integer'
1371 push_eh _invalid_sub
1372 root_ns.'add_sub'( 'Nested', not_a_sub )
1376 .local pmc exception
1377 .local string message
1378 .get_results( exception, message )
1389 Invalid type \d+ in add_sub\(\)/
1392 pir_output_is( <<"CODE", <<'OUTPUT', 'add_var()' );
1405 key = create_nested_key( 'Parent' )
1407 .local pmc parent_ns
1408 parent_ns = get_namespace key
1409 parent_ns.'add_var'( 'foo', foo )
1411 key = create_nested_key( 'Parent', 'Child' )
1414 child_ns = get_namespace key
1415 child_ns.'add_var'( 'bar', bar )
1418 my_var = get_global [ 'Parent' ], 'foo'
1423 my_var = get_global [ 'Parent'; 'Child' ], 'bar'
1429 .namespace [ 'Parent' ]
1434 .namespace [ 'Parent'; 'Child' ]
1443 pir_output_is( <<"CODE", <<'OUTPUT', 'del_namespace()' );
1448 root_ns = get_namespace
1451 key = create_nested_key( 'Parent' )
1454 child_ns = root_ns.'find_namespace'( key )
1456 key = create_nested_key( 'Child' )
1458 .local pmc grandchild_ns
1459 grandchild_ns = child_ns.'find_namespace'( key )
1461 child_ns.'del_namespace'( 'Child' )
1463 key = create_nested_key( 'Child' )
1465 .local pmc grandchild_ns
1466 grandchild_ns = child_ns.'find_namespace'( key )
1467 if_null grandchild_ns, CHECK_SIBLING
1468 print "Grandchild still exists\\n"
1471 key = create_nested_key( 'Sibling' )
1472 grandchild_ns = child_ns.'find_namespace'( key )
1473 if_null grandchild_ns, DELETE_PARENT
1474 print "Sibling not deleted\\n"
1477 key = create_nested_key( 'Parent' )
1478 root_ns.'del_namespace'( 'Parent' )
1479 child_ns = root_ns.'find_namespace'( key )
1480 if_null child_ns, CHECK_UNCLE
1481 print "Child still exists\\n"
1484 key = create_nested_key( 'FunUncle' )
1485 grandchild_ns = root_ns.'find_namespace'( key )
1486 if_null grandchild_ns, DELETE_PARENT
1487 print "Fun uncle stuck around\\n"
1492 .namespace [ 'FunUncle' ]
1497 .namespace [ 'Parent' ]
1502 .namespace [ 'Parent'; 'Child' ]
1507 .namespace [ 'Parent'; 'Sibling' ]
1513 Fun uncle stuck around
1516 pir_output_like( <<'CODE', <<'OUTPUT', 'del_namespace() with error' );
1522 not_a_ns = new 'Array'
1524 set_global 'Not_A_NS', not_a_ns
1527 root_ns = get_namespace
1528 delete_namespace( root_ns, 'dummy' )
1529 delete_namespace( root_ns, 'Not_A_NS' )
1532 .sub delete_namespace
1536 root_ns.'del_namespace'( name )
1539 .local pmc exception
1540 .local string message
1541 .get_results( exception, message )
1548 /Invalid type \d+ for 'dummy' in del_namespace\(\)
1549 Invalid type \d+ for 'Not_A_NS' in del_namespace\(\)/
1552 pir_output_is( <<"CODE", <<'OUTPUT', 'del_sub()' );
1555 root_ns = get_namespace
1557 .local pmc parent_ns
1558 parent_ns = root_ns.'find_namespace'( 'Parent' )
1559 parent_ns.'del_sub'( 'dummy' )
1562 my_sub = get_global [ 'Parent' ], 'dummy'
1563 if_null my_sub, PARENT_NO_DUMMY
1564 print "Parent did not delete dummy\\n"
1567 my_sub = get_global [ 'Parent' ], 'no_dummy'
1571 child_ns = parent_ns.'find_namespace'( 'Child' )
1572 child_ns.'del_sub'( 'dummy' )
1575 my_sub = get_global [ 'Parent'; 'Child' ], 'dummy'
1576 if_null my_sub, CHILD_NO_DUMMY
1577 print "Child did not delete dummy\\n"
1581 my_sub = get_global [ 'Parent'; 'Child' ], 'no_dummy'
1585 .namespace [ 'Parent' ]
1591 print "Parent is no dummy\\n"
1594 .namespace [ 'Parent'; 'Child' ]
1597 print "Dummy sub!\\n"
1601 print "Child is no dummy\\n"
1609 pir_output_like( <<'CODE', <<'OUTPUT', 'del_sub() with error' );
1612 not_a_ns = new 'Array'
1614 set_global 'Not_A_Sub', not_a_ns
1617 root_ns = get_namespace
1619 push_eh _invalid_sub
1620 root_ns.'del_sub'( 'Not_A_Sub' )
1623 .local pmc exception
1624 .local string message
1625 .get_results( exception, message )
1632 /Invalid type \d+ for 'Not_A_Sub' in del_sub\(\)/
1635 pir_output_is( <<"CODE", <<'OUTPUT', 'del_var()' );
1645 set_global [ 'Parent' ], 'Foo', foo
1646 set_global [ 'Parent'; 'Child' ], 'Bar', bar
1649 root_ns = get_namespace
1651 .local pmc parent_ns
1652 parent_ns = root_ns.'find_namespace'( 'Parent' )
1653 parent_ns.'del_var'( 'Foo' )
1656 child_ns = parent_ns.'find_namespace'( 'Child' )
1657 child_ns.'del_var'( 'Bar' )
1660 my_var = get_global [ 'Parent' ], 'Foo'
1661 if_null my_var, TEST_CHILD_VAR
1662 print "Parent Foo exists: "
1667 my_var = get_global [ 'Parent'; 'Child' ], 'Bar'
1668 if_null my_var, ALL_DONE
1669 print "Child Bar exists: "
1676 .namespace [ 'Parent' ]
1681 .namespace [ 'Parent'; 'Child' ]
1686 pir_error_output_like( <<'CODE', <<'OUTPUT', 'overriding find_method()' );
1688 $P0 = newclass 'Override'
1689 $P1 = new 'Override'
1690 $P2 = find_method $P1, 'foo'
1693 .namespace [ 'Override' ]
1695 .sub 'find_method' :vtable
1696 say "Finding method"
1702 pir_output_is( <<'CODE', <<OUT, "iterate through a NameSpace PMC, RT #39978" );
1705 $P0 = "Ook...BANG!\n"
1706 set_root_global [ "DUMMY"; "X"; "Y" ], "Explosion", $P0
1710 set_root_global [ "DUMMY"; "X"; "Y" ], "T0", $P0
1712 .local pmc dummy_x_y_ns, iter
1713 dummy_x_y_ns = get_root_namespace [ "DUMMY"; "X"; "Y" ]
1714 iter = new 'Iterator', dummy_x_y_ns
1716 unless iter goto loop_end
1729 pir_error_output_like( <<'CODE', <<OUT, "NameSpace with no class, RT #55620" );
1731 $P1 = new 'NameSpace'
1733 tailcallmethod $P1, 'bob'
1736 /Null PMC access in get_string()/
1739 pir_output_is( <<'CODE', <<OUT, "iterate through a NameSpace PMC" );
1740 .namespace [ 'bar' ]
1747 new $P1 , 'Iterator', $P0
1771 # cperl-indent-level: 4
1774 # vim: expandtab shiftwidth=4: