[cage] Fix pgegrep, which was merely an innocent bystander in the Great Namespace...
[parrot.git] / t / op / box.t
blobc98c48502db2d683b7a17c1ea6a62652ff580de2
1 #!parrot
2 # Copyright (C) 2008-2009, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/op/box.t - the box opcode
9 =head1 SYNOPSIS
11     % prove t/op/box.t
13 =head1 DESCRIPTION
15 Tests all box operators.
17 =cut
19 .const int TESTS = 26
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'
26 .end
28 .sub 'main' :main
29     .include 'test_more.pir'
31     'plan'(TESTS)
33     'box_int'()
34     'box_num'()
35     'box_string'()
36     'box_null_string'()
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'
47     box_int_hll()
48     box_num_hll()
49     box_string_hll()
50 .end
52 .sub 'box_int'
54     $P0 = box 100
55     $I0 = $P0
56     is( $I0, 100, 'value preserved when boxing int' )
58     isa_ok( $P0, 'Integer', 'int boxed to appropriate base type' )
60     $I0 = 200
61     $P0 = box $I0
62     $I0 = $P0
63     is( $I0, 200, 'value preserved when boxing int from reg' )
64     isa_ok( $P0, 'Integer', 'int boxed to appropriate base type from reg' )
65 .end
67 .sub 'box_num'
68     $P0 = box 77.7
69     $N0 = $P0
70     is( $N0, 77.7, 'value preserved when boxing num' )
72     isa_ok( $P0, 'Float', 'num boxed to appropriate base type' )
74     $N0 = 88.8
75     $P0 = box $N0
76     $N0 = $P0
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' )
80 .end
82 .sub 'box_string'
83     $P0 = box 'Hi, there'
84     $S0 = $P0
85     is( $S0, 'Hi, there', 'value preserved when boxing string' )
87     isa_ok( $P0, 'String', 'string boxed to appropriate base type' )
89     $S0 = 'Hello, there'
90     $P0 = box $S0
91     $S0 = $P0
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' )
95 .end
97 .sub 'box_null_string'
98     null $S0
99     $P0 = box $S0
100     $S1 = $P0
101     is( $S1, '', 'NULL STRING boxed to empty String PMC' )
103     $P1 = clone $P0
104     $S1 = $P0
105     is( $S1, '', '... and survives clone of boxed PMC (TT #964)' )
107 .end
109 .HLL 'for_test'
111 .sub anon :anon :init
112   .local pmc interp
113   .local pmc cint, myint
114   .local pmc cstr, mystr
115   .local pmc cnum, mynum
116   interp = getinterp
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)
129 .end
131 .sub 'box_int'
132     .include 'test_more.pir'
134     $P0 = box -100
135     $I0 = $P0
136     is( $I0, -100, 'value preserved when boxing int in HLL' )
138     isa_ok( $P0, 'MyInt', 'int boxed to appropriate base type for HLL' )
140     $I0 = -999
141     $P0 = box $I0
142     $I0 = $P0
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')
146 .end
148 .sub 'box_num'
149     $P0 = box -77.7
150     $N0 = $P0
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' )
155     $N0 = -222222.222222
156     $P0 = box $N0
157     $N0 = $P0
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' )
161 .end
163 .sub 'box_string'
164     $P0 = box 'Bye, bye!'
165     $S0 = $P0
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!'
171     $P0 = box $S0
172     $S0 = $P0
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')
176 .end
178 # Local Variables:
179 #   mode: cperl
180 #   cperl-indent-level: 4
181 #   fill-column: 100
182 # End:
183 # vim: expandtab shiftwidth=4: