2 # Copyright (C) 2001-2007, Parrot Foundation.
7 t/pmc/boolean.t - Boolean Ops
11 % prove t/pmc/boolean.t
15 Tests C<Boolean> PMC. Checks comparison and logic operations for various
21 .include 'test_more.pir'
29 boolean_as_conditional()
37 $P1 = new ['Boolean'], $P0
39 is($I0, 0, "init with null pmc gives false")
46 is($I0, 0, "Boolean defaults to false")
51 is($I1, 1, "Boolean converts 1 to true")
55 is($I0, 1, "Boolean converts negative int to true")
58 .sub instantiate_tests
62 $P2 = get_class ['Boolean']
65 is($I0, 1, "Boolean instantiated to true")
68 $P1 = new ['Boolean'], $P0
70 is($I0, 0, "Boolean instantiated to false")
79 is($I0, 0, "Boolean converts num 0 to false")
84 is($I0, 1, "Boolean converts non-0 num to true")
93 is($I0, 0, "Boolean converts string '0' to false")
98 is($I0, 1, "Boolean converts string 'foo' to true")
103 is($I0, 0, "Boolean converts empty string to false")
106 .sub pmc_to_pmc_tests
107 $P0 = new ['Boolean']
108 $P1 = new ['Boolean']
113 is($I0, 1, "cloned Boolean has correct value")
117 is($I0, 1, "cloned Boolean is not a reference")
121 is($I0, 0, "cloned Boolean can change value")
124 .sub boolean_as_conditional
125 $P0 = new ['Boolean']
129 ok(0, "Boolean is broken as a conditional")
132 ok(1, "Boolean works as a conditional")
136 .sub logic_operations
137 $P0 = new ['Boolean']
138 $P1 = new ['Boolean']
139 $P2 = new ['Boolean']
144 is($P2, 1, "1|0 == 1 for Booleans")
146 #$P0 = 0, $P1 = 1, $P2 = 1
148 is($P2, 0, "0|0 == 0 for Booleans")
150 #$P0 = 0, $P1 = 1, $P2 = 0
152 is($P2, 0, "0&1 == 0 for Booleans")
157 is($P2, 0, "0&0 == 0 for Booleans")
159 #$P0 = 0, $P1 = 0, $P2 = 0
161 is($P1, 1, "!0 == 1 for Booleans")
163 #$P0 = 0, $P1 = 1, $P2 = 0
166 is($P2, 1, "1&1 == 1 for Booleans")
168 #$P0 = 1, $P1 = 1, $P2 = 1
170 is($P2, 0, "1xor1 == 0 for Booleans")
172 #$P0 = 1, $P1 = 1, $P2 = 0
175 is($P2, 1, "0xor1 == 1 for Booleans")
177 #$P0 = 0, $P1 = 1, $P2 = 1
180 is($P2, 0, "0xor0 == 0 for Booleans")
185 $P0 = new ['Boolean']
186 $P1 = new ['Boolean']
190 is($P1, 1, "negated Boolean true is still true")
194 is($P1, 0, "negated Boolean false is still false")
198 is($P0, 1, "in-place negated Boolean true is still true")
202 is($P0, 0, "in-place negated Boolean false is still false")
211 is(b, 1, "Boolean does scalar")
213 is(b, 1, "Boolean does boolean (big surprise there)")
214 does b, p, "no_interface"
215 is(b, 0, "Boolean doesn't do no_interface")
222 # vim: expandtab shiftwidth=4 ft=pir: