2 # Copyright (C) 2007-2009, Parrot Foundation.
7 t/oo/vtableoverride.t - test various vtable overrides from PIR
11 % prove t/oo/vtableoverride.t
15 Tests the behavior of VTABLE interfaces that have been overriden from PIR.
20 .include 'test_more.pir'
25 vtable_implies_self_tests()
28 get_pmc_keyed_int_Null()
32 throws_substring(<<'CODE',' but was used with ', 'invalid :vtable throws an exception')
34 .sub monkey :method :vtable("not_in_the_vtable")
46 is($S0, "[MyObject]", "get_string VTABLE override")
47 $P0 = getattribute $P1, "message"
49 is($S0, "[MyObject]", "attribute sideeffect of get_string")
52 $I0 = does $P1, 'this_dress_make...'
53 is ($I0, 1, "check first does, ok")
54 $I0 = does $P1, 'a_body_good'
55 is ($I0, 1, "check second does, ok")
56 $I0 = does $P1, 'it_better'
57 is ($I0, 0, "no it doesn't")
59 # Test morph (doesn't actually perform a morph)
60 $P2 = get_class 'String'
62 $P0 = getattribute $P1, "message"
64 is($S0, "Morphing [MyObject] to type String", "Morph VTABLE override 1")
66 $P2 = get_class 'Integer'
68 $P0 = getattribute $P1, "message"
70 is($S0, "Morphing [MyObject] to type Integer", "Morph VTABLE override 1")
72 # Test invoke. Doesn't currently work so we need to fix that.
73 #$P0 = $P1("invoked!")
75 #is($S0, "invoked!", "Invoke VTABLE override return value")
77 #$P0 = getattribute $P1, "message"
79 #is($S0, "invoked!", "Invoke VTABLE override sideeffects")
83 $P1 = new 'MySubObject'
85 # Test does, same as newclass.
86 $I0 = does $P1, 'this_dress_make...'
87 is ($I0, 1, "check first does, ok")
88 $I0 = does $P1, 'a_body_good'
89 is ($I0, 1, "check second does, ok")
90 $I0 = does $P1, 'it_better'
91 is ($I0, 0, "no it doesn't")
92 # Also verify we does what our parent does
93 $I0 = does $P1, 'array'
94 is ($I0, 1, "inherited does")
97 .sub 'vtable_implies_self_tests'
98 $P1 = get_class 'MyVtableObject'
100 $I0 = does $P2, 'frobulate'
101 ok( $I0, ':vtable should imply the self parameter' )
105 .sub 'anon_vtable_tests'
106 $P0 = newclass "AnonVtableType"
107 $P1 = new 'AnonVtableType'
108 push_eh anon_does_not_work
110 is($S0, "foo", "can have :vtable :anon")
113 ok(0, "can not have :anon :vtable")
118 .sub 'get_pmc_keyed_int_Null'
119 $P0 = newclass [ 'NoReturn_get_pmc_keyed_int' ]
123 ok($I0, "Override get_pmc_keyed_int without .return - TT #1593")
126 .namespace [ 'MyObject' ]
128 .sub '__onload' :anon :init
129 $P0 = newclass "MyObject"
130 addattribute $P0, "message"
133 .sub 'get_string' :vtable
136 setattribute self, "message", $P0
144 $S1 = "Morphing " . $S0
145 $S1 = $S1 . " to type "
146 type = class.'name'()
149 setattribute self, "message", $P0
157 setattribute self, "message", $P0
158 if query == 'this_dress_make...' goto yes
159 if query == 'a_body_good' goto yes
165 .sub 'invoke' :vtable
168 setattribute self, "message", $P0
172 .namespace [ 'MySubObject' ]
174 .sub '__onload' :anon :init
175 $P1 = get_class 'ResizablePMCArray'
176 $P0 = subclass $P1, 'MySubObject'
177 addattribute $P0, "submessage"
185 setattribute self, "submessage", $P0
186 if query == 'this_dress_make...' goto yes
187 if query == 'a_body_good' goto yes
193 .namespace [ 'MyVtableObject' ]
195 .sub '__onload' :anon :init
196 $P1 = get_class 'String'
197 $P2 = subclass $P1, 'MyVtableObject'
202 eq what, 'frobulate', true
210 .namespace [ 'AnonVtableType' ]
212 .sub '' :vtable('get_string') :method :anon
217 .namespace [ 'NoReturn_get_pmc_keyed_int' ]
219 .sub 'get_pmc_keyed_int' :vtable
228 # vim: expandtab shiftwidth=4 ft=pir: