2 # Copyright (C) 2001-2005, Parrot Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use Parrot::Test tests => 6;
13 t/pmc/object-mro.t - Object Methods Resolution Order
17 % prove t/pmc/object-mro.t
21 These are tests for the C3 MRO order
25 pir_output_is( <<'CODE', <<'OUTPUT', "print mro diamond" );
34 .local pmc A, B, C, D, E, F, mro, p, it
46 mro = F.'inspect'('all_parents')
63 pir_output_is( <<'CODE', <<'OUTPUT', "print mro 1" );
65 # example take from: http://www.python.org/2.3/mro.html
77 # Level 3 | O | (more general)
83 # Level 2 3 | D | 4| E | | F | 5 |
89 # Level 1 1 | B | | C | 2 |
94 # Level 0 0 | A | (more specialized)
98 .local pmc A, B, C, D, E, F, O
113 .local pmc mro, it, p
115 mro = A.'inspect'('all_parents')
132 pir_output_is( <<'CODE', <<'OUTPUT', "print mro 2" );
134 # example take from: http://www.python.org/2.3/mro.html
152 # Level 2 2 | E | 4 | D | | F | 5
158 # Level 1 1 | B | | C | 3
168 .local pmc A, B, C, D, E, F, O
183 .local pmc mro, it, p
185 mro = A.'inspect'('all_parents')
202 pir_output_is( <<'CODE', <<'OUTPUT', "print mro 3" );
213 .local pmc A, B, C, D
220 .local pmc mro, it, p
222 mro = D.'inspect'('all_parents')
239 pir_output_is( <<'CODE', <<'OUTPUT', "print mro 4" );
250 # Intelligent Humanoid
255 # example taken from: L<http://gauss.gwydiondylan.org/books/drm/drm_50.html>
257 # define class <sentient> (<life-form>) end class;
258 # define class <bipedal> (<life-form>) end class;
259 # define class <intelligent> (<sentient>) end class;
260 # define class <humanoid> (<bipedal>) end class;
261 # define class <vulcan> (<intelligent>, <humanoid>) end class;
264 .local pmc TestObject, LifeForm, Sentient, BiPedal, Intelligent, Humanoid, Vulcan
266 newclass TestObject, "TestObject"
268 subclass LifeForm, TestObject, "LifeForm"
270 subclass Sentient, LifeForm, "Sentient"
271 subclass Intelligent, Sentient, "Intelligent"
273 subclass BiPedal, LifeForm, "BiPedal"
274 subclass Humanoid, BiPedal, "Humanoid"
276 subclass Vulcan, Intelligent, "Vulcan"
277 addparent Vulcan, Humanoid
279 .local pmc mro, it, p
281 mro = Vulcan.'inspect'('all_parents')
295 Vulcan Intelligent Sentient Humanoid BiPedal LifeForm TestObject R
298 # ... now some tests which fail to compose the class
300 pir_error_output_like( <<'CODE', <<'OUTPUT', "mro error 1" );
302 # example take from: http://www.python.org/2.3/mro.html
304 # "Serious order disagreement" # From Guido
311 # class Z(A,B): pass # creates Z(A,B) in Python 2.2
313 # pass # Z(A,B) cannot be created in Python 2.3
316 .local pmc O, X, Y, A, B, Z
332 /ambiguous hierarchy/
337 # cperl-indent-level: 4
340 # vim: expandtab shiftwidth=4: