2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/pmc/capture.t - Test the Capture PMC
11 % parrot t/pmc/capture.t
15 Tests the C<Capture> PMC. Checks integer and key access using
16 a variety of keys and values.
23 .include 'test_more.pir'
30 test_defined_delete_exists()
34 test_keyed_int_delegation()
35 test_list_delegation()
38 .sub 'test_new_capture'
41 capt = new ['Capture']
45 .sub 'empty_capture_tests'
48 capt = new ['Capture']
51 is($I0, 0, 'elements on empty Capture')
54 is($N0, 0.0, 'get_number_keyed_int on empty Capture')
56 is($I0, 0, 'get_integer_keyed_int on empty Capture')
58 is($S0, '', 'get_string_keyed_int on empty Capture')
61 is($N0, 0.0, 'get_number_keyed on empty Capture')
64 $S1 = 'get_string on empty Capture - ' . $S0
65 substring($S0, 'Capture[', $S1)
68 .sub 'basic_capture_tests'
71 capt = new ['Capture']
96 capt['gamma'] = 'fourteen'
102 is($I0, 12, 'elements')
105 is($I0, 7, 'get_integer_keyed_int')
108 is($P0, 'six', 'get_pmc_keyed_int')
111 is($N0, 5.5, 'get_number_keyed_int')
114 is($S0, '4', 'get_string_keyed_int')
117 is($I0, 7, 'pop an integer')
120 is($P0, 'six', 'pop a PMC')
123 is($N0, 5.5, 'pop a number')
126 is($S0, '4', 'pop a string')
129 is($I0, 8, 'elements after pop')
132 is($I0, 11, 'shift an integer')
135 is($P0, 'ten', 'shift a PMC')
138 is($N0, 9.5, 'shift a number')
141 is($S0, '8', 'shift a string')
144 is($I0, 4, 'elements after shift')
147 is($P0, 3, 'pop 1 out of 4')
150 is($P0, 'two', 'pop 2 out of 4')
153 is($P0, 1.5, 'pop 3 out of 4')
156 is($P0, 0, 'pop 4 out of 4')
159 is($I0, 15, 'get_integer_keyed_str')
162 is($P0, 'fourteen', 'get_pmc_keyed_str')
165 is($N0, 13.5, 'get_number_keyed_str')
168 is($S0, '12', 'get_string_keyed_str')
171 .sub 'test_defined_delete_exists'
173 capt = new ['Capture']
175 $I0 = defined capt[2]
176 nok($I0, 'defined_i initially false')
179 nok($I1, 'exists_i initially false')
181 $I0 = defined capt['alpha']
182 nok($I0, 'defined_s initially false')
184 $I1 = exists capt['alpha']
185 nok($I1, 'exists_s initially false')
192 $I0 = defined capt[2]
193 ok($I0, 'defined_i true after set')
196 ok($I1, 'exists_i true after set')
198 $I0 = defined capt['alpha']
199 ok($I0, 'defined_s true after set')
201 $I1 = exists capt['alpha']
202 ok($I1, 'exists_s true after set')
204 $I0 = defined capt[1]
205 nok($I0, 'defined_i - no intermediate element created')
208 nok($I1, 'exists_i - no intermediate element created')
210 $I0 = defined capt['beta']
211 nok($I0, 'defined_s checks for Undef values...')
213 $I1 = exists capt['beta']
214 ok($I1, 'but exists_s does not care')
219 $I0 = defined capt[2]
220 nok($I0, 'defined_i false after delete')
222 nok($I1, 'exists_i false after delete')
224 $I0 = defined capt['alpha']
225 nok($I0, 'defined_s false after delete')
226 $I1 = exists capt['alpha']
227 nok($I1, 'exists_s false after delete')
230 .sub 'test_hash_list'
233 capt = new ['Capture']
238 isa_ok($P0, 'ResizablePMCArray', "capt.'list'")
239 isa_ok($P1, 'Hash', "capt.'hash'")
242 .sub 'test_get_integer'
245 capt = new ['Capture']
246 push_eh test_get_integer_catch
249 nok(1, 'get_integer not implemented')
252 test_get_integer_catch:
255 .local string message
256 .get_results (exception)
258 message = exception['message']
259 message = substr message, 0, 29
260 is(message, 'get_integer() not implemented', 'get_integer not implemented')
264 .sub 'test_get_number'
267 capt = new ['Capture']
268 push_eh test_get_number_catch
271 nok(1, 'get_number not implemented')
274 test_get_number_catch:
276 .local string message
277 .get_results (exception)
279 message = exception['message']
280 message = substr message, 0, 28
281 is(message, 'get_number() not implemented', 'get_number not implemented')
286 .sub 'test_keyed_int_delegation'
287 $P99 = subclass ['Capture'], ['Match']
291 is($I1, 2, 'elements - delegated to parent class')
293 $P99 = subclass ['Match'], ['Exp']
297 is($I2, 2, 'elements - delegated twice')
300 .sub 'test_list_delegation'
301 $P0 = subclass ['Capture'], ['Match2']
302 addattribute $P0, '$.abc'
303 addattribute $P0, '$.xyz'
308 setattribute $P1, '$.abc', $P2
310 setattribute $P1, '$.xyz', $P2
315 is($I0, 0, 'list method delegation')
322 # vim: expandtab shiftwidth=4 ft=pir: