2 # Copyright (C) 2006-2010, Parrot Foundation.
7 t/pmc/callcontext.t - test CallContext PMC
11 % prove t/pmc/callcontext.t
15 Tests the CallContext PMC.
20 .include 'test_more.pir'
34 .sub 'test_instantiate'
35 $P0 = new ['CallContext']
36 ok(1, 'Instantiated CallContext')
39 .sub 'test_get_set_attrs'
40 $P0 = new ['CallContext']
44 setattribute $P0, 'return_flags', $P5
45 ok(1, 'set return_flags attribute')
46 getattribute $P1, $P0, 'return_flags'
47 is($P5,'moonbomb', 'got return_flags attribute')
50 setattribute $P0, 'arg_flags', $P5
51 ok(1, 'set arg_flags attribute')
52 getattribute $P1, $P0, 'arg_flags'
53 is($P5,'cheese', 'got arg_flags attribute')
56 .sub 'test_indexed_access'
57 $P0 = new [ 'CallContext' ]
61 is( $I0, 1, 'elements after set_*_indexed' )
66 is( $I0, 2, 'elements after set_*_indexed' )
72 is( $I0, 3, 'elements after set_*_indexed' )
79 is( $I0, 4, 'elements after set_*_indexed' )
82 is( $I1, 100, 'set_integer_keyed_int/get_integer_keyed_int pair' )
85 is( $N1, 1.11, 'set_number_keyed_int/get_number_keyed_int pair' )
88 is( $S1, '2.22', 'set_string_keyed_int/get_string_keyed_int pair' )
91 is( $P1, 3.33, 'set_pmc_keyed_int/get_pmc_keyed_int pair' )
95 .sub 'test_indexed_boxing'
96 $P0 = new [ 'CallContext' ]
103 $P1 = new [ 'Float' ]
108 is( $I0, 1, 'indexed float converted to int on get_integer_keyed_int' )
110 is( $I0, 2, 'indexed string converted to int on get_integer_keyed_int' )
112 is( $I0, 3, 'indexed PMC converted to int on get_integer_keyed_int' )
115 is( $N0, 100.0, 'indexed integer converted to num on get_number_keyed_int' )
117 is( $N0, 2.22, 'indexed string converted to num on get_number_keyed_int' )
119 is( $N0, 3.33, 'indexed PMC converted to int num get_number_keyed_int' )
122 is( $S0, '100', 'indexed int converted to string on get_string_keyed_int' )
124 is( $S0, '1.11', 'indexed num converted to string on get_string_keyed_int' )
126 is( $S0, '3.33', 'indexed PMC converted to string get_string_keyed_int' )
129 is( $P1, 100, 'indexed int converted to PMC on get_pmc_keyed_int' )
131 is( $P1, 1.11, 'indexed float converted to PMC on get_pmc_keyed_int' )
133 is( $P1, 2.22, 'indexed string converted to PMC on get_pmc_keyed_int' )
136 .sub 'test_keyed_access'
137 $P0 = new [ 'CallContext' ]
142 $P1 = new [ 'Float' ]
148 is( $I0, 100, 'set/get_intval_keyed_str' )
151 is( $N0, 1.11, 'set/get_number_keyed_str' )
154 is( $S0, '2.22', 'set/get_string_keyed_str' )
157 is( $P2, 3.33, 'set/get_pmc_keyed_str' )
159 $P1 = getattribute $P0, 'named'
161 is( $I0, 4, 'elements after set_*_keyed' )
165 $P0 = new [ 'CallContext' ]
171 ok( $I0, 'exists_keyed_int' )
173 $I0 = exists $P0['foo']
174 ok( $I0, 'exists_keyed_str' )
176 $I0 = exists $P0[100]
177 nok( $I0, 'exists_keyed_int -- non-existant' )
179 $I0 = exists $P0['bar']
180 nok( $I0, 'exists_keyed_str -- non-existant' )
184 $P0 = new ['CallContext']
186 $P0[1] = "Hello Parrot"
187 $P0['floatval'] = 3.14159
192 is($I2, 42, 'clone - integer positional cloned')
194 is($S2, "Hello Parrot", 'clone - string positional cloned')
195 $N2 = $P1['floatval']
196 is($N2, 3.14159, 'clone - named number cloned')
199 .sub 'test_shift_access'
200 $P0 = new ['CallContext']
201 $P1 = new [ 'String' ]
207 is($S1, 'derF', 'shift should convert to proper type (PMC -> STRING)')
212 is($P2, 'derF', '... but not convert when unneccesary')
213 $I0 = issame $P1, $P2
214 ok($I0, '... returning the same item' )
216 # no unshift_string for now
220 is($P2, 'Fred', 'shift should convert to proper type (STRING -> PMC)')
225 is($S2, 'Fred', '... but not convert when unnecessary')
232 # vim: expandtab shiftwidth=4 ft=pir: