2 # Copyright (C) 2009, 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'
31 diag( 'test_fetch_keyed_int' )
37 $P3 = fetch $P0, 1, [ 'Integer' ]
38 is( $P3, 111, 'fetch should return existing element unmodified' )
40 is( $P3, 123, '... the exact PMC itself' )
42 $P3 = fetch $P0, 3, [ 'Integer' ]
43 is( $P3, 123, '... even if stored in multiple locations' )
45 $P3 = fetch $P0, 2, [ 'Integer' ]
46 is( $P3, 0, 'fetch should create new PMC if not-existent' )
47 isa_ok( $P3, 'Integer', 'new PMC should have type Integer' )
50 .sub 'test_fetch_keyed_str'
51 diag( 'test_fetch_keyed_str' )
57 $P3 = fetch $P0, 'one', [ 'Integer' ]
58 is( $P3, 111, 'fetch should return existing element unmodified' )
60 is( $P3, 123, '... the exact PMC itself' )
62 $P3 = fetch $P0, 'three', [ 'Integer' ]
63 is( $P3, 123, '... even if stored in multiple locations' )
65 $P3 = fetch $P0, 'two', [ 'Integer' ]
66 is( $P3, 0, 'fetch should create new PMC if not-existent' )
67 isa_ok( $P3, 'Integer', 'new PMC should have type Integer' )
70 .sub 'test_fetch_keyed_pmc'
71 diag( 'test_fetch_keyed_pmc' )
83 $P3 = fetch $P0, str_key, [ 'String' ]
84 is( $P3, 111, 'fetch should return existing element unmodified' )
87 is( $P3, 123, '... the exact PMC itself' )
89 $P3 = fetch $P0, int_key, [ 'String' ]
90 is( $P3, 123, '... even if stored in multiple locations' )
93 $P3 = fetch $P0, str_key, [ 'String' ]
94 is( $P3, '', 'fetch should return new PMC if keyed PMC is not there' )
95 isa_ok( $P3, 'String', 'new PMC should have given type' )
98 $P3 = fetch $P0, str_key, [ 'String' ]
99 is( $P3, '', 'fetch should return new PMC if keyed PMC is not there' )
100 isa_ok( $P3, 'String', 'new PMC should have given type' )
105 # cperl-indent-level: 4
108 # vim: expandtab shiftwidth=4 ft=pir :