2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/pmc/hashiterator.t - Test the HashIterator PMC
11 % prove t/pmc/hashiterator.t
15 Tests the C<HashIterator> PMC. Checks key access with various types of
16 normal and potentially hazardous keys. Does a bit of stress testing as
21 .include 'except_types.pasm'
24 .include 'test_more.pir'
28 iter_over_empty_hash()
29 iter_over_single_element()
30 iter_over_single_element_with_checks()
35 .sub 'iter_over_empty_hash'
38 it = new 'HashIterator', hash
40 ok($I0, "Iterator for empty Hash is empty")
42 # shift_pmc throws on empty Hash but shift_string doesn't.
45 is($S0, '', 'shift string for empty hash gives empty string')
50 eh = new 'ExceptionHandler'
51 eh.'handle_types'(.EXCEPTION_OUT_OF_BOUNDS)
61 ok(i, 'shift pmc for empty hash throws')
64 .sub 'iter_over_single_element'
68 it = new 'HashIterator', hash
70 ok($I0, "Iterator for non empty Hash is not empty")
73 ok($I0, "And contains one element")
76 .sub 'iter_over_single_element_with_checks'
81 it = new 'HashIterator', hash
83 $I0 = isa $P0, 'HashIteratorKey'
84 ok($I0, "HashIteratorKey fetched successfully")
87 is($S0, "foo", "Key fetched successfully")
89 is($S1, "bar", "Value fetched successfully")
93 .sub 'iter_invalid_type'
96 it = new 'HashIterator', hash
100 eh = new 'ExceptionHandler'
101 eh.'handle_types'(.EXCEPTION_INVALID_OPERATION)
104 it = 987 # Arbitrary value, let's hope we never use
111 ok(i, 'setting invalid type throws')
115 .local pmc oh, it, cl
120 # This chekcs the de facto behavior for code coverage purposes.
123 ok(result, 'clone of HashIterator gives null')
130 # vim: expandtab shiftwidth=4 ft=pir: