2 # Copyright (C) 2009-2010, Parrot Foundation.
7 t/op/fetch.t - the fetch opcode
15 Tests Parrot's experimental fetch opcode.
20 .include 'test_more.pir'
24 test_fetch_keyed_pmc()
25 test_fetch_keyed_int()
26 test_fetch_keyed_str()
30 .sub 'test_fetch_keyed_int'
36 $P3 = fetch $P0, 1, [ 'Integer' ]
37 is( $P3, 111, 'fetch should return existing element unmodified' )
39 is( $P3, 123, '... the exact PMC itself' )
41 $P3 = fetch $P0, 3, [ 'Integer' ]
42 is( $P3, 123, '... even if stored in multiple locations' )
44 $P3 = fetch $P0, 2, [ 'Integer' ]
45 is( $P3, 0, 'fetch should create new PMC if not-existent' )
46 isa_ok( $P3, 'Integer', 'new PMC should have type Integer' )
49 .sub 'test_fetch_keyed_str'
55 $P3 = fetch $P0, 'one', [ 'Integer' ]
56 is( $P3, 111, 'fetch should return existing element unmodified' )
58 is( $P3, 123, '... the exact PMC itself' )
60 $P3 = fetch $P0, 'three', [ 'Integer' ]
61 is( $P3, 123, '... even if stored in multiple locations' )
63 $P3 = fetch $P0, 'two', [ 'Integer' ]
64 is( $P3, 0, 'fetch should create new PMC if not-existent' )
65 isa_ok( $P3, 'Integer', 'new PMC should have type Integer' )
68 .sub 'test_fetch_keyed_pmc'
80 $P3 = fetch $P0, str_key, [ 'String' ]
81 is( $P3, 111, 'fetch should return existing element unmodified' )
84 is( $P3, 123, '... the exact PMC itself' )
86 $P3 = fetch $P0, int_key, [ 'String' ]
87 is( $P3, 123, '... even if stored in multiple locations' )
90 $P3 = fetch $P0, str_key, [ 'String' ]
91 is( $P3, '', 'fetch should return new PMC if keyed PMC is not there' )
92 isa_ok( $P3, 'String', 'new PMC should have given type' )
95 $P3 = fetch $P0, str_key, [ 'String' ]
96 is( $P3, '', 'fetch should return new PMC if keyed PMC is not there' )
97 isa_ok( $P3, 'String', 'new PMC should have given type' )
104 # vim: expandtab shiftwidth=4 ft=pir: