2 # Copyright (C) 2009-2010, Parrot Foundation.
7 t/op/vivify.t - the vivify opcode
15 Tests Parrot's experimental vivify opcode.
20 .include 'test_more.pir'
24 test_vivify_keyed_pmc()
25 test_vivify_keyed_int()
26 test_vivify_keyed_str()
30 .sub 'test_vivify_keyed_int'
36 $P3 = vivify $P0, 1, [ 'Integer' ]
37 is( $P3, 111, 'vivify should return existing element unmodified' )
39 is( $P3, 123, '... the exact PMC itself' )
43 ok( $I0, ' ... existing entry in Hash should be unmodified')
45 $P3 = vivify $P0, 3, [ 'Integer' ]
46 is( $P3, 123, '... even if stored in multiple locations' )
48 $P3 = vivify $P0, 2, [ 'Integer' ]
49 is( $P3, 0, 'vivify should create new PMC if not-existent' )
50 isa_ok( $P3, 'Integer', 'new PMC should have requested type' )
54 ok( $I0, ' ... and should be bound in Hash')
57 .sub 'test_vivify_keyed_str'
63 $P3 = vivify $P0, 'one', [ 'Integer' ]
64 is( $P3, 111, 'vivify should return existing element unmodified' )
66 is( $P3, 123, '... the exact PMC itself' )
70 ok( $I0, ' ... existing entry in Hash should be unmodified')
72 $P3 = vivify $P0, 'three', [ 'Integer' ]
73 is( $P3, 123, '... even if stored in multiple locations' )
75 $P3 = vivify $P0, 'two', [ 'Integer' ]
76 is( $P3, 0, 'vivify should create new PMC if not-existent' )
77 isa_ok( $P3, 'Integer', 'new PMC should have requested type' )
81 ok( $I0, ' ... and should be bound in Hash')
84 .sub 'test_vivify_keyed_pmc'
96 $P3 = vivify $P0, str_key, [ 'String' ]
97 is( $P3, 111, 'vivify should return existing element unmodified' )
100 is( $P3, 123, '... the exact PMC itself' )
103 $I0 = issame $P1, $P4
104 ok( $I0, ' ... existing entry in Hash should be unmodified')
106 $P3 = vivify $P0, int_key, [ 'String' ]
107 is( $P3, 123, '... even if stored in multiple locations' )
110 $I0 = issame $P1, $P4
111 ok( $I0, ' ... existing entry in Hash should be unmodified')
114 $P3 = vivify $P0, str_key, [ 'String' ]
115 is( $P3, '', 'vivify should return new PMC if keyed PMC is not there' )
116 isa_ok( $P3, 'String', 'new PMC should have given type' )
119 $I0 = issame $P3, $P4
120 ok( $I0, ' ... and should be bound in Hash')
123 $P3 = vivify $P0, int_key, [ 'String' ]
124 is( $P3, '', 'vivify should return new PMC if keyed PMC is not there' )
125 isa_ok( $P3, 'String', 'new PMC should have given type' )
128 $I0 = issame $P3, $P4
129 ok( $I0, ' ... and should be bound in Hash')
136 # vim: expandtab shiftwidth=4 ft=pir: