2 # Copyright (C) 2007, The Perl Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use Parrot::Test tests => 8;
13 t/oo/ops.t - test OO related ops
21 Tests opcodes related to the OO implementation.
25 pir_output_is( <<'CODE', <<'OUT', 'addrole_p_p' );
30 print "ok 1 - addrole op executed\n"
37 print "ok 2 - addrole op actually added the role\n"
40 ok 1 - addrole op executed
41 ok 2 - addrole op actually added the role
44 pir_output_is( <<'CODE', <<'OUT', 'inspect_p_p' );
49 print "ok 1 - inspect_p_p op executed\n"
55 print "ok 2 - returned hash had correct number of elements\n"
58 ok 1 - inspect_p_p op executed
59 ok 2 - returned hash had correct number of elements
62 pir_output_is( <<'CODE', <<'OUT', 'inspect_p_p_s' );
66 $P0.add_attribute('a')
68 $P1 = inspect $P0, 'name'
70 print "ok 1 - inspect_p_p_s with $3='name'\n"
72 $P1 = inspect $P0, 'flags'
74 $I1 = 1 << 29 # flag 29 is PObj_is_class_FLAG
80 print "ok 2 - inspect_p_p_s with $3='flags'\n"
82 $P1 = inspect $P0, 'attributes'
87 print "ok 3 - inspect_p_p_s with $3='attributes'\n"
91 ok 1 - inspect_p_p_s with $3='name'
92 ok 2 - inspect_p_p_s with $3='flags'
93 ok 3 - inspect_p_p_s with $3='attributes'
96 pir_output_is( <<'CODE', <<'OUT', 'get_class_p_s' );
103 $P1 = new 'Class', $P0
104 print "ok 1 - created new class named Monkey\n"
107 $P2 = get_class 'Monkey'
113 print "ok 2 - get_class found a class\n"
115 $P3 = $P2.'inspect'('name')
117 print "\nok 3 - got name of found class\n"
120 ok 1 - created new class named Monkey
121 ok 2 - get_class found a class
123 ok 3 - got name of found class
126 pir_output_is( <<'CODE', <<'OUT', 'get_class_p_p' );
133 $P1 = new 'Class', $P0
134 print "ok 1 - created new class named Monkey\n"
137 $P2 = get_class [ 'Monkey' ]
143 print "ok 2 - get_class with a Key found a class\n"
145 $P3 = $P2.'inspect'('name')
147 print "\nok 3 - got name of found class\n"
150 $P3 = get_namespace [ 'Monkey' ]
157 print "ok 4 - get_class with a NameSpace found a class\n"
159 $P3 = $P2.'inspect'('name')
161 print "\nok 5 - got name of found class\n"
164 ok 1 - created new class named Monkey
165 ok 2 - get_class with a Key found a class
167 ok 3 - got name of found class
168 ok 4 - get_class with a NameSpace found a class
170 ok 5 - got name of found class
173 pir_error_output_like( <<'CODE', <<'OUT', 'addattribute_p_s' );
176 addattribute $P0, 'foo'
182 setattribute $P1, 'foo', $P2
183 getattribute $P2, $P1, 'foo'
189 addattribute $P0, 'oops'
194 Cannot add attribute to non-class
195 current instr\.: 'main'/
198 pir_output_is( <<'CODE', <<'OUT', 'new_p_s works with string register arg' );
200 # $P0 = newclass "Foo"
202 addattribute $P0, 'foo'
209 setattribute $P1, 'foo', $P2
210 getattribute $P2, $P1, 'foo'
220 pir_output_is( <<'CODE', <<'OUT', 'can_i_p_s' );
247 # cperl-indent-level: 4
250 # vim: expandtab shiftwidth=4: