2 # Copyright (C) 2007-2010, Parrot Foundation.
7 t/oo/ops.t - test OO related ops
15 Tests opcodes related to the OO implementation.
20 .include 'except_types.pasm'
21 .include 'test_more.pir'
43 is ($I1, 1, 'addrole op executed and verified')
52 is ($I1, 7, 'inspect op executed and hash count verified')
59 $P0.'add_attribute'('a')
61 $P1 = inspect $P0, 'name'
62 is ($P1, 'foo', 'inspect_p_p_s with name')
64 $P1 = inspect $P0, 'flags'
66 $I1 = 1 << 29 # flag 29 is PObj_is_class_FLAG
68 ok ($I2, 'inspect_p_p_s with flags')
70 $P1 = inspect $P0, 'attributes'
72 is ($I0, 1, 'inspect_p_p_s with attributes')
81 $P1 = new 'Class', $P0
82 $I0 = isa $P1 , 'Class'
83 ok ($I0, 'created new class named Monkey')
85 $P2 = get_class 'Monkey'
86 $I1 = isa $P2 , 'Class'
87 ok ($I1, 'get_class found a class')
89 $P3 = $P2.'inspect'('name')
90 is ($P3, 'Monkey', 'got name of found class')
95 is ($I2, 1, 'null p gives null p')
104 $P1 = new 'Class', $P0
105 $I0 = isa $P1 , 'Class'
106 ok ($I0, 'created new class named Ape')
108 $P2 = get_class [ 'Ape' ]
109 $I1 = isa $P2 , 'Class'
110 ok ($I1, 'get_class with a key found a class')
112 $P3 = $P2.'inspect'('name')
113 is ($P3, 'Ape', 'got name of found class')
115 $P3 = get_namespace [ 'Monkey' ]
117 $I1 = isa $P2 , 'Class'
118 ok ($I1, 'get_class with a namespace found a class')
119 is ($P3, 'Monkey', 'got name of found class')
124 is ($I2, 1, 'null s gives null p')
127 .sub op_addattribute_p_s
130 addattribute $P0, 'foo'
136 setattribute $P1, 'foo', $P2
137 getattribute $P2, $P1, 'foo'
142 eh = new 'ExceptionHandler'
143 eh.'handle_types'(.EXCEPTION_INVALID_OPERATION)
147 addattribute $P0, 'oops'
148 $I0 = 1 # add attribute success flag
152 $I0 = 0 # add attribute failure flag
156 is ($P2, 100, 'reading assigned attribute')
157 nok ($I0,'attempt to add attribute to non-class')
163 addattribute $P0, 'foo'
170 setattribute $P1, 'foo', $P2
171 getattribute $P2, $P1, 'foo'
173 is ($P2, 100, 'reading assigned attribute')
182 ok ($I0, 'PMC has method bar')
184 ok ($I1, 'called bar method on PMC')
196 # vim: expandtab shiftwidth=4 ft=pir: