2 # Copyright (C) 2007-2008, Parrot Foundation.
7 t/oo/isa.t - Test OO inheritance
15 Tests OO features related to the isa opcode, comparing for inheritance and
21 .include 'test_more.pir'
27 subclass_isa_by_string_name()
28 subclass_isa_by_class_object()
29 string_isa_and_pmc_isa_have_same_result()
30 string_register_and_string_pmc_isa_have_same_result()
35 .sub isa_by_string_name
39 is( 'Class', $S1, 'typeof newclass retval')
41 $I3 = isa $P1, "Class"
42 ok( $I3, 'isa newclass retval a Class')
46 is ( 'Foo', $S1, 'typeof instance of our class')
49 ok ( $I3, 'isa instance of our class')
51 $I3 = isa $P2, "Object"
52 ok ( $I3, 'isa instance of object')
55 .sub isa_by_class_object
57 foo_class = newclass "Foo2"
58 $S1 = typeof foo_class
60 is( 'Class', $S1, 'typeof newclass retval')
62 .local pmc class_class
63 class_class = get_class "Class"
64 $I3 = isa foo_class, class_class
65 ok ($I3, 'isa newclass retval a Class')
69 is ( 'Foo2', $S1, 'typeof new our class?')
71 $I3 = isa $P2, foo_class
72 ok ( $I3, 'isa instance of our class')
74 .local pmc object_class
75 object_class = get_class "Object"
76 $I3 = isa $P2, object_class
77 ok ( $I3, 'isa instance of Object')
80 .sub subclass_isa_by_string_name
81 .local pmc foo_class, bar_class
82 foo_class = newclass "Foo3"
83 bar_class = subclass "Foo3", "Bar3"
85 $I3 = isa bar_class, "Class"
86 ok ($I3, 'does subclass generate class objects')
90 is ('Bar3', $S1, 'does new give us an obj of our type')
93 ok ($I3, 'does new give us an obj that isa our type')
96 ok ($I3, 'does new give us an obj that isa our parent type')
98 $I3 = isa $P2, "Object"
99 ok ($I3, 'does new give us an obj that isa Object')
102 .sub subclass_isa_by_class_object
103 .local pmc foo_class, bar_class, sub_sub_class, my_sub_class
104 foo_class = newclass "Foo4"
105 bar_class = subclass "Foo4", "Bar4"
106 sub_sub_class = subclass 'Sub', 'SubSub'
107 my_sub_class = subclass 'SubSub', 'MySub'
109 .local pmc class_class
110 class_class = get_class "Class"
111 $I3 = isa bar_class, class_class
112 ok ($I3, 'is the class of a subclass Class')
116 is ('Bar4', $S1, 'typeof new class our class')
118 $I3 = isa $P2, bar_class
119 ok ($I3, 'new class isa our class')
121 $I3 = isa $P2, foo_class
122 ok ($I3, 'new class isa our parent class')
124 .local pmc object_class
125 object_class = get_class "Object"
126 $I3 = isa $P2, object_class
127 ok ($I3, 'new class isa Object')
130 sub_class = get_class 'Sub'
131 $P2 = new sub_sub_class
132 $I3 = isa $P2, sub_class
133 ok( $I3, 'new class isa Sub' )
135 $P2 = new my_sub_class
136 $I3 = isa $P2, sub_class
137 ok( $I3, 'new subclass isa Sub' )
141 .sub string_isa_and_pmc_isa_have_same_result
142 .local pmc class, obj
145 $I0 = isa obj, 'Object'
146 ok ($I0, 'isa Class instance an Object')
152 ok ($I1, 'isa String instance an Object')
155 .sub string_register_and_string_pmc_isa_have_same_result
156 .local pmc xyzns, xyzclass, xyzobj
158 xyzns = get_root_namespace ['foo';'XYZ']
159 xyzclass = newclass xyzns
160 xyzobj = new xyzclass
162 # prove that it's the correct type
164 is( $S0, 'XYZ::abc', 'sanity check for correct method and type' )
166 # test two forms of isa
169 $I0 = isa xyzobj, 'XYZ'
170 ok( $I0, 'isa given string register should return true when it isa' )
172 $I0 = isa xyzobj, 'ZYX'
174 ok( $I0, '... and false when it is not' )
176 $I0 = isa xyzobj, $P0
177 ok( $I0, 'isa given string PMC should return true when it isa' )
180 $I0 = isa xyzobj, $P0
182 ok( $I0, '... and false when it is not' )
186 $P0 = newclass ['Foo';'Buz']
188 $P0 = split "::", "Foo::Buz"
190 ok($I0, "isa accepts a ResizablePMCArray")
197 .return( 'XYZ::abc' )
204 # vim: expandtab shiftwidth=4 ft=pir: