tagged release 0.6.4
[parrot.git] / t / pmc / fixedbooleanarray.t
blob810a866387f89899f4961c2ec86c24c9e419ca6c
1 #! perl
2 # Copyright (C) 2001-2007, The Perl Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( . lib ../lib ../../lib );
8 use Test::More;
9 use Parrot::Test tests => 13;
11 =head1 NAME
13 t/pmc/fixedbooleanarray.t - FixedBooleanArray PMC
15 =head1 SYNOPSIS
17     % prove t/pmc/FixedBooleanArray.t
19 =head1 DESCRIPTION
21 Tests C<FixedBooleanArray> PMC. Checks size, sets various elements, including
22 out-of-bounds test. Checks INT and PMC keys.
24 =cut
26 my $fp_equality_macro = pasm_fp_equality_macro();
28 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting array size" );
29     new P0, 'FixedBooleanArray'
31     set I0,P0
32     eq I0,0,OK_1
33     print "not "
34 OK_1:    print "ok 1\n"
36     set P0,1
37     set I0,P0
38     eq I0,1,OK_2
39     print "not "
40 OK_2:    print "ok 2\n"
42         end
43 CODE
44 ok 1
45 ok 2
46 OUTPUT
48 pasm_error_output_like( <<'CODE', <<'OUTPUT', "Resetting array size (and getting an exception)" );
49     new P0, 'FixedBooleanArray'
51     set I0,P0
52     set P0,1
53     set P0,2
54     print "Should have gotten an exception\n"
57         end
58 CODE
59 /FixedBooleanArray: Can't resize!
60 current instr\.:/
61 OUTPUT
63 #VIM's syntax highlighter needs this line
65 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting first element" );
66     new P0, 'FixedBooleanArray'
67     set P0, 1
69     set P0[0],-7
70     set I0,P0[0]
71     eq I0,1,OK_1
72     print "not "
73 OK_1:    print "ok 1\n"
75     set P0[0],3.7
76     set N0,P0[0]
77     eq N0,1.0,OK_2
78     print "not "
79 OK_2:    print "ok 2\n"
81     set P0[0],"17"
82     set S0,P0[0]
83     eq S0,"1",OK_3
84     print "not "
85 OK_3:    print "ok 3\n"
87     end
88 CODE
89 ok 1
90 ok 2
91 ok 3
92 OUTPUT
94 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting second element" );
95     new P0, 'FixedBooleanArray'
96     set P0, 2
98     set P0[1], -7
99     set I0, P0[1]
100     eq I0,1,OK_1
101     print "not "
102 OK_1:    print "ok 1\n"
104        set P0[1], 3.7
105     set N0, P0[1]
106     eq N0,1.0,OK_2
107     print "not "
108 OK_2:    print "ok 2\n"
110     set P0[1],"17"
111     set S0, P0[1]
112     eq S0,"1",OK_3
113     print "not "
114 OK_3:    print "ok 3\n"
116     end
117 CODE
118 ok 1
119 ok 2
120 ok 3
121 OUTPUT
123 pasm_error_output_like( <<'CODE', <<'OUTPUT', "Setting out-of-bounds elements" );
124     new P0, 'FixedBooleanArray'
125     set P0, 1
127     set P0[1], -7
129     end
130 CODE
131 /FixedBooleanArray: index out of bounds!
132 current instr\.:/
133 OUTPUT
135 pasm_error_output_like( <<'CODE', <<'OUTPUT', "Getting out-of-bounds elements" );
136     new P0, 'FixedBooleanArray'
137     set P0, 1
139     set I0, P0[1]
140     end
141 CODE
142 /FixedBooleanArray: index out of bounds!
143 current instr\.:/
144 OUTPUT
146 pasm_output_is( <<"CODE", <<'OUTPUT', "Set via PMC keys, access via INTs" );
147 @{[ $fp_equality_macro ]}
148      new P0, 'FixedBooleanArray'
149      set P0, 3
150      new P1, 'Key'
152      set P1, 0
153      set P0[P1], 25
155      set P1, 1
156      set P0[P1], 2.5
158      set P1, 2
159      set P0[P1], "17"
161      set I0, P0[0]
162      eq I0, 1, OK1
163      print "not "
164 OK1: print "ok 1\\n"
166      set N0, P0[1]
167      .fp_eq(N0, 1.0, OK2)
168      print "not "
169 OK2: print "ok 2\\n"
171      set S0, P0[2]
172      eq S0, "1", OK3
173      print "not "
174 OK3: print "ok 3\\n"
176      end
177 CODE
178 ok 1
179 ok 2
180 ok 3
181 OUTPUT
183 pasm_output_is( <<"CODE", <<'OUTPUT', "Set via INTs, access via PMC Keys" );
184 @{[ $fp_equality_macro ]}
185      new P0, 'FixedBooleanArray'
186      set P0, 1024
188      set P0[25], 125
189      set P0[128], 10.2
190      set P0[513], "17"
191      new P1, 'Integer'
192      set P1, 123456
193      set P0[1023], P1
195      new P2, 'Key'
196      set P2, 25
197      set I0, P0[P2]
198      eq I0, 1, OK1
199      print "not "
200 OK1: print "ok 1\\n"
202      set P2, 128
203      set N0, P0[P2]
204      .fp_eq(N0, 1.0, OK2)
205      print "not "
206 OK2: print "ok 2\\n"
208      set P2, 513
209      set S0, P0[P2]
210      eq S0, "1", OK3
211      print "not "
212 OK3: print "ok 3\\n"
214      set P2, 1023
215      set P3, P0[P2]
216      set I1, P3
217      eq I1, 1, OK4
218      print "not "
219 OK4: print "ok 4\\n"
221      end
222 CODE
223 ok 1
224 ok 2
225 ok 3
226 ok 4
227 OUTPUT
229 pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" );
231 .sub _main
232     .local pmc pmc1
233     pmc1 = new 'FixedBooleanArray'
234     .local int bool1
235     does bool1, pmc1, "scalar"
236     print bool1
237     print "\n"
238     does bool1, pmc1, "array"
239     print bool1
240     print "\n"
241     does bool1, pmc1, "no_interface"
242     print bool1
243     print "\n"
244     end
245 .end
246 CODE
250 OUTPUT
252 pasm_output_is( << 'CODE', << 'OUTPUT', "Truth" );
253      new P0, 'FixedBooleanArray'
254      unless P0, OK1
255      print "not "
256 OK1: print "ok 1\n"
257      set P0, 1
258      if P0, OK2
259      print "not "
260 OK2: print "ok 2\n"
261      set P0[0], 0
262      if P0, OK3
263      print "not "
264 OK3: print "ok 3\n"
265      end
266 CODE
267 ok 1
268 ok 2
269 ok 3
270 OUTPUT
272 pasm_output_is( << 'CODE', << 'OUTPUT', "PMC keys & values" );
273      new P0, 'FixedBooleanArray'
274      set P0, 2
275      new P1, 'Key'
276      set P1, 1
277      new P2, 'Integer'
278      set P2, 1
279      set P0[P1], P2
280      set I0, P0[P1]
281      print I0
282      print "\n"
283      end
284 CODE
286 OUTPUT
288 pir_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw" );
289 .sub main :main
290     .local pmc fba
291     .local int i
292     .local string s
294     fba = new 'FixedBooleanArray'
295     fba = 17
297     fba[1]  = 1
298     fba[4]  = 1
299     fba[8]  = 1
300     fba[12] = 1
301     fba[15] = 1
303     say fba
304     s = freeze fba
305     fba.'fill'(0)
306     fba = thaw s
307     say fba
309 .end    
311 CODE
312 01001000100010010
313 01001000100010010
314 OUTPUT
316 pir_output_is( <<'CODE', <<'OUTPUT', "clone" );
317 .sub main :main
318     .local pmc fba1, fba2
319     .local int i
320     .local string s
322     fba1 = new 'FixedBooleanArray'
323     fba1 = 17
325     fba1[1]  = 1
326     fba1[4]  = 1
327     fba1[8]  = 1
328     fba1[12] = 1
329     fba1[15] = 1
331     say fba1
332     fba2 = clone fba1
333     say fba2
335 .end    
337 CODE
338 01001000100010010
339 01001000100010010
340 OUTPUT
345 # Local Variables:
346 #   mode: cperl
347 #   cperl-indent-level: 4
348 #   fill-column: 100
349 # End:
350 # vim: expandtab shiftwidth=4: