tagged release 0.6.4
[parrot.git] / t / pmc / boolean.t
blobaa26efd86ee3b1c98ef97c872262b9c71a165703
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 => 8;
11 =head1 NAME
13 t/pmc/boolean.t - Boolean Ops
15 =head1 SYNOPSIS
17     % prove t/pmc/boolean.t
19 =head1 DESCRIPTION
21 Tests C<Boolean> PMC. Checks comparison and logic operations for various
22 type combinations.
24 =cut
26 pasm_output_is( <<'CODE', <<'OUTPUT', "Initialization, and integer tests" );
27     new P0, 'Boolean'
29     set I0, P0
30     eq I0,0,OK_1
31     print "not "
32 OK_1:    print "ok 1\n"
34         set I0, 1
35         set P0, I0
36         set I1, P0
37         eq I1,1,OK_2
38         print "not "
39 OK_2:   print "ok 2\n"
41         set P0, -4
42         set I0, P0
43         eq I0,1,OK_3
44         print "not "
45 OK_3:   print "ok 3\n"
47         end
48 CODE
49 ok 1
50 ok 2
51 ok 3
52 OUTPUT
54 pasm_output_is( <<'CODE', <<'OUTPUT', "Number tests" );
55         new P0, 'Boolean'
57         set N0, 0
58         set P0, N0
59         set I0, P0
60         eq I0, 0, OK_1
61         print "not "
62 OK_1:   print "ok 1\n"
65         set N0, 0.001
66         set P0, N0
67         set I0, P0
68         eq I0, 1, OK_2
69         print "not "
70 OK_2:   print "ok 2\n"
72         end
73 CODE
74 ok 1
75 ok 2
76 OUTPUT
78 pasm_output_is( <<'CODE', <<'OUTPUT', "String tests" );
79         new P0, 'Boolean'
81         set S0, "0"
82         set P0, S0
83         set I0, P0
84         eq I0, 0, OK_1
85         print "not "
86 OK_1:   print "ok 1\n"
89         set S0, "foo"
90         set P0, S0
91         set I0, P0
92         eq I0, 1, OK_2
93         print "not "
94 OK_2:   print "ok 2\n"
96         set S0, ""
97         set P0, S0
98         set I0, P0
99         eq I0, 0, OK_3
100         print "not "
101 OK_3:   print "ok 3\n"
103         end
104 CODE
105 ok 1
106 ok 2
107 ok 3
108 OUTPUT
110 pasm_output_is( <<'CODE', <<'OUTPUT', "PMC to PMC" );
111         new P0, 'Boolean'
112         new P1, 'Boolean'
114         set P0, 1
115         clone P1, P0
116         set I0, P1
117         eq I0, 1, OK_1
118         print "not "
119 OK_1:   print "ok 1\n"
121         set P0, 0
122         set I0, P1
123         eq I0, 1, OK_2
124         print "not "
125 OK_2:   print "ok 2\n"
127         set P1, 0
128         set I0, P1
129         eq I0, 0, OK_3
130         print "not "
131 OK_3:   print "ok 3\n"
133         end
134 CODE
135 ok 1
136 ok 2
137 ok 3
138 OUTPUT
140 pasm_output_is( <<'CODE', <<'OUTPUT', "As boolean" );
141         new P0, 'Boolean'
143         set P0, 1
144         if P0, OK_1
145         print "not "
146 OK_1:   print "ok 1\n"
148         end
149 CODE
150 ok 1
151 OUTPUT
153 pasm_output_is( <<'CODE', <<'OUTPUT', "Logic operations" );
154         new P0, 'Boolean'
155         new P1, 'Boolean'
156         new P2, 'Boolean'
158         set P0, 1
159         set P1, 0
160         or P2, P0, P1
161         set I0, P2
162         eq I0, 1, OK_1
163         print "not "
164 OK_1:   print "ok 1\n"
166         or P2, P1, P1
167         set I0, P2
168         eq I0, 0, OK_2
169         print "not "
170 OK_2:   print "ok 2\n"
172         and P2, P0, P1
173         set I0, P2
174         eq I0, 0, OK_3
175         print "not "
176 OK_3:   print "ok 3\n"
178         set P0, 0
179         set P1, 0
180         and P2, P0, P1
181         set I0, P2
182         eq I0, 0, OK_4
183         print "not "
184 OK_4:   print "ok 4\n"
186         not P1, P1
187         set I0, P1
188         eq I0, 1, OK_5
189         print "not "
190 OK_5:   print "ok 5\n"
192         not P0, P0
193         and P2, P0, P1
194         set I0, P2
195         eq I0, 1, OK_6
196         print "not "
197 OK_6:   print "ok 6\n"
199         xor P2, P0, P1
200         set I0, P2
201         eq I0, 0, OK_7
202         print "not "
203 OK_7:   print "ok 7\n"
205         not P0, P0
206         xor P2, P0, P1
207         set I0, P2
208         eq I0, 1, OK_8
209         print "not "
210 OK_8:   print "ok 8\n"
212         not P1, P1
213         xor P2, P0, P1
214         set I0, P2
215         eq I0, 0, OK_9
216         print "not "
217 OK_9:   print "ok 9\n"
219         end
220 CODE
221 ok 1
222 ok 2
223 ok 3
224 ok 4
225 ok 5
226 ok 6
227 ok 7
228 ok 8
229 ok 9
230 OUTPUT
232 pasm_output_is( <<'CODE', <<'OUTPUT', "neg" );
233         new P0, 'Boolean'
234         new P1, 'Boolean'
236         set P0, 1
237         neg P1, P0
238         if P1, OK1
239         print "not "
240 OK1:    print "ok 1\n"
242         set P0, 0
243         neg P1, P0
244         unless P1, OK2
245         print "not "
246 OK2:    print "ok 2\n"
248         set P0, 1
249         neg P0
250         if P0, OK3
251         print "not "
252 OK3:    print "ok 3\n"
254         set P0, 0
255         neg P0
256         unless P0, OK4
257         print "not "
258 OK4:    print "ok 4\n"
260         end
261 CODE
262 ok 1
263 ok 2
264 ok 3
265 ok 4
266 OUTPUT
268 pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" );
270 .sub _main
271     .local pmc pmc1
272     pmc1 = new 'Boolean'
273     .local int bool1
274     does bool1, pmc1, "scalar"
275     print bool1
276     print "\n"
277     does bool1, pmc1, "boolean"
278     print bool1
279     print "\n"
280     does bool1, pmc1, "no_interface"
281     print bool1
282     print "\n"
283     end
284 .end
285 CODE
289 OUTPUT
291 # Local Variables:
292 #   mode: cperl
293 #   cperl-indent-level: 4
294 #   fill-column: 100
295 # End:
296 # vim: expandtab shiftwidth=4: