2 # Copyright (C) 2010, Parrot Foundation.
7 t/pmc/namepspace-subs.t - test NameSpace PMC
11 % prove t/pmc/namespace-subs.t
15 Tests subroutines stored in the NameSpace PMC, specifically focusing on the
16 specified behavior for :method, :vtable, :nsentry, and :anon.
23 .include 'test_more.pir'
33 # Subs marked with :anon should not be stored in the namespace. Methods marked
34 # with :anon should not be stored in the class.
36 .sub 'anon_sub_and_method'
37 $P2 = get_hll_global ['AnonTest'], 'anonsub'
38 is_null($P2, "Anon sub not stored in namespace")
40 $P0 = newclass 'AnonTest'
43 push_eh method_not_in_namespace
44 $I1 = $P1.'anonmethod'()
45 ok(0, "Anon method not stored in class")
48 method_not_in_namespace:
49 ok(1, "Anon method not stored in class")
52 $P2 = get_hll_global ['AnonTest'], 'anonmethod'
53 is_null($P2, "Anon method not stored in namespace")
57 # Vtable overrides marked with :anon should be stored in the class anyway. See
63 is($I0, 414, "Anon vtable override stored in class")
67 # Methods should not be stored in the namespace. See TT #389.
69 $P0 = newclass 'MethodTest'
70 $P1 = new 'MethodTest'
72 $I1 = $P1.'methodtest'()
73 is($I1, 75, "Invoked stored method")
75 $P2 = get_hll_global ['MethodTest'], 'methodtest'
76 is_null($P2, "Method not stored in namespace")
80 $P0 = newclass 'NsentryTest'
81 $P1 = new 'NsentryTest'
83 $I1 = $P1.'nsentrymethodtest'()
84 is($I1, 63, "Invoked nsentry method")
86 $P2 = get_hll_global ['NsentryTest'], 'renamedmethod'
87 isa_ok($P2, "Sub", "Nsentry method stored in namespace")
90 is($I2, 63, "Invoked nsentry method from namespace")
92 $P3 = get_hll_global ['NsentryTest'], 'renamedsub'
93 isa_ok($P3, "Sub", "Nsentry sub stored in namespace")
96 is($I3, 36, "Invoked nsentry sub from namespace")
98 $P4 = get_hll_global ['NsentryTest'], 'renamedvtable'
99 isa_ok($P4, "Sub", "Nsentry vtable stored in namespace")
102 is($I4, 363, "Invoked nsentry vtable from namespace")
105 .sub 'store_multisub'
106 $P1 = get_hll_global ['MultiSubTest'], 'multisubtest'
107 isa_ok($P1, "MultiSub", "Multi sub stored in namespace")
110 is($S1, "called int variant", "Multi sub int stored in namespace")
113 is($S2, "called string variant", "Multi sub string stored in namespace")
116 is($S3, "called num variant", "Anon multi sub num stored in namespace")
120 .namespace ['AnonTest']
125 .sub 'anonmethod' :anon :method
129 .sub 'get_integer' :anon :vtable
134 .namespace ['MethodTest']
135 .sub 'methodtest' :method
139 .namespace ['NsentryTest']
140 .sub 'nsentrymethodtest' :method :nsentry('renamedmethod')
143 .sub 'nsentrysubtest' :nsentry('renamedsub')
146 .sub 'nsentryvtabletest' :nsentry('renamedvtable')
150 .namespace ['MultiSubTest']
151 .sub 'multisubtest' :multi(int)
152 .return("called int variant")
154 .sub 'multisubtest' :multi(string)
155 .return("called string variant")
157 .sub 'multisubtest' :anon :multi(num)
158 .return("called num variant")
166 # vim: expandtab shiftwidth=4 ft=pir: