2 # Copyright (C) 2008-2010, Parrot Foundation.
7 t/op/box.t - the box opcode
15 Tests all box operators.
21 # must set these up before the hll_map calls later
22 .sub '__setup' :immediate
23 $P0 = subclass 'Integer', 'MyInt'
24 $P0 = subclass 'String', 'MyString'
25 $P0 = subclass 'Float', 'MyFloat'
29 .include 'test_more.pir'
38 .local pmc box_int_hll
39 box_int_hll = get_root_global [ 'for_test' ], 'box_int'
41 .local pmc box_num_hll
42 box_num_hll = get_root_global [ 'for_test' ], 'box_num'
44 .local pmc box_string_hll
45 box_string_hll = get_root_global [ 'for_test' ], 'box_string'
56 is( $I0, 100, 'value preserved when boxing int' )
58 isa_ok( $P0, 'Integer', 'int boxed to appropriate base type' )
63 is( $I0, 200, 'value preserved when boxing int from reg' )
64 isa_ok( $P0, 'Integer', 'int boxed to appropriate base type from reg' )
70 is( $N0, 77.7, 'value preserved when boxing num' )
72 isa_ok( $P0, 'Float', 'num boxed to appropriate base type' )
77 is( $N0, 88.8, 'value preserved when boxing num from reg' )
79 isa_ok( $P0, 'Float', 'num boxed to appropriate base type from reg' )
85 is( $S0, 'Hi, there', 'value preserved when boxing string' )
87 isa_ok( $P0, 'String', 'string boxed to appropriate base type' )
92 is( $S0, 'Hello, there', 'value preserved when boxing string from reg' )
94 isa_ok( $P0, 'String', 'string boxed to appropriate base type from reg' )
97 .sub 'box_null_string'
101 is( $S1, '', 'NULL STRING boxed to empty String PMC' )
105 is( $S1, '', '... and survives clone of boxed PMC (TT #964)' )
111 .sub anon :anon :init
113 .local pmc cint, myint
114 .local pmc cstr, mystr
115 .local pmc cnum, mynum
118 cint = get_class 'Integer'
119 myint = get_class 'MyInt'
120 interp.'hll_map'(cint,myint)
122 cstr = get_class 'String'
123 mystr = get_class 'MyString'
124 interp.'hll_map'(cstr,mystr)
126 cnum = get_class 'Float'
127 mynum = get_class 'MyFloat'
128 interp.'hll_map'(cnum,mynum)
132 .include 'test_more.pir'
136 is( $I0, -100, 'value preserved when boxing int in HLL' )
138 isa_ok( $P0, 'MyInt', 'int boxed to appropriate base type for HLL' )
143 is( $I0, -999, 'value preserved when boxing int in HLL from reg' )
145 isa_ok( $P0, 'MyInt', 'int boxed to appropriate type for HLL from reg')
151 is( $N0, -77.7, 'value preserved when boxing num in HLL' )
153 isa_ok( $P0, 'MyFloat', 'num boxed to appropriate base type for HLL' )
158 is( $N0, -222222.222222, 'value preserved when boxing num in HLL from reg' )
160 isa_ok( $P0, 'MyFloat', 'num boxed to appropriate type for HLL from reg' )
164 $P0 = box 'Bye, bye!'
166 is( $S0, 'Bye, bye!', 'value preserved when boxing string in HLL' )
168 isa_ok( $P0, 'MyString', 'string boxed to appropriate base type for HLL' )
170 $S0 = 'Hello, goodbye!'
173 is( $S0, 'Hello, goodbye!', 'value preserved when boxing string in HLL from reg' )
175 isa_ok($P0, 'MyString', 'string boxed to appropriate type for HLL from reg')
182 # vim: expandtab shiftwidth=4 ft=pir: