1 // Boolean_as.hx: ActionScript 3 "Boolean" class, for Gnash.
3 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 // Test case for Boolean ActionScript class
22 // Migrated to haXe by Jonathan Crider
25 import flash
.display
.MovieClip
;
27 import flash
.MovieClip
;
35 // importing our testing api
39 static function main() {
41 //NOTE: These tests do not compile in swf version 9. This is due to the way
42 // in which haxe implements a Bool. Compilation in swf9 gives the error
43 // 'Unbound variable Boolean' at each place the Boolean name is used.
44 // So far I have been unable to find a workaround for this. For now we
45 // will be unable to compile these test for flash9.
47 DejaGnu
.note("These tests do not currently compile in flash version 9: see comments in Boolean_as.hx");
51 //check_equals(typeof(Boolean), 'function');
52 if ( untyped __typeof__(Boolean
) == 'function') {
53 DejaGnu
.pass("Boolean class exists");
55 DejaGnu
.fail("Boolean class does not exist");
57 //check_equals(typeof(Boolean()), 'undefined');
58 if ( untyped __typeof__(Boolean()) == 'undefined') {
59 DejaGnu
.pass("Call to Boolean() returns null");
61 DejaGnu
.fail("Call to Boolean() does not return null");
63 //check_equals(typeof(Boolean(true)), 'boolean');
64 if ( untyped __typeof__(Boolean(true)) == 'boolean') {
65 DejaGnu
.pass("Boolean(true) correctly returns a boolean value");
67 DejaGnu
.fail("Boolean(true) does not return a boolean value");
69 //check_equals(typeof(new Boolean()), 'object');
70 if (Reflect
.isObject(untyped __new__(Boolean
))) {
71 DejaGnu
.pass("new Boolean(); correctly constructs an object");
73 DejaGnu
.fail("new Boolean(); does not correctly construct an object");
76 //var boolObj = new Boolean;
77 var boolObj
= untyped __new__(Boolean
);
79 // test the Boolean constuctor
82 DejaGnu
.pass("Boolean object successfully constructed and assigned");
84 DejaGnu
.fail("Boolean object not successfully constructed or assigned");
87 //check (boolObj.toString);
88 if (untyped boolObj
.toString
) {
89 DejaGnu
.pass("boolObj.toString() inherited correctly");
91 DejaGnu
.fail("boolObj.toString() was not inherited correctly");
93 //check (boolObj.valueOf);
94 if (untyped boolObj
.valueOf
) {
95 DejaGnu
.pass("boolObj.valueOf() inherited correctly");
97 DejaGnu
.fail("boolObj.valueOf() not inherited correctly");
102 // flash6 is not case sensitive
103 //check (boolObj.tostring)
104 if (untyped boolObj
.tostring
) {
105 DejaGnu
.pass("boolObj.tostring property exists (Not Case Sensitive)");
107 DejaGnu
.fail("boolObj.tostring property does not exist");
109 //check (boolObj.valueof)
110 if (untyped boolObj
.valueof
) {
111 DejaGnu
.pass("boolObj.valueof property exists (Not Case Sensitive)");
113 DejaGnu
.fail("boolObj.valueof property does not exist");
116 // SWF7 and up is case-sensitive
117 //check_equals (boolObj.tostring, undefined);
118 if (Type
.typeof(untyped boolObj
.tostring
) == ValueType
.TNull
) {
119 DejaGnu
.pass("tostring property does not exist (Case Sensitive)");
121 DejaGnu
.fail("tostring property exists when it should not");
123 //check_equals (boolObj.valueof, undefined);
124 if (Type
.typeof(untyped boolObj
.valueof
) == ValueType
.TNull
) {
125 DejaGnu
.pass("valueof property does not exist (Case Sensitive)");
127 DejaGnu
.fail("valueof property exists when it should not");
131 //var defaultBool = new Boolean();
132 var defaultBool
= untyped __new__(Boolean
);
133 //check_equals(defaultBool.toString(), "false");
134 if (untyped defaultBool
.toString() == "false") {
135 DejaGnu
.pass("Default constructor correctly sets value to false");
137 DejaGnu
.fail("Default constructor does not set value to false");
139 //check_equals(defaultBool.valueOf(), false);
140 if (untyped defaultBool
.valueOf() == false) {
141 DejaGnu
.pass("Default valueOf() correctly returns false");
143 DejaGnu
.fail("Default valueOf() does not return false");
146 //var trueBool = new Boolean(true);
147 var trueBool
= untyped __new__(Boolean
, true);
148 //check_equals(trueBool.toString(), "true");
149 if (untyped trueBool
.toString() == "true") {
150 DejaGnu
.pass("Correctly constructed Boolean with value 'true'");
152 DejaGnu
.fail("Did not correctly construct Boolean with value 'true'");
154 //check_equals(trueBool.valueOf(), true);
155 if (untyped trueBool
.valueOf() == true) {
156 DejaGnu
.pass("trueBool.valueOf() correctly returned true");
158 DejaGnu
.fail("trueBool.valueOf() did not correctly return true");
161 //var falseBool = new Boolean(false);
162 var falseBool
= untyped __new__(Boolean
, false);
163 //check_equals(falseBool.toString(), "false");
164 if (untyped falseBool
.toString() == "false") {
165 DejaGnu
.pass("Boolean correctly constructed with argument 'false'");
167 DejaGnu
.fail("Boolean not correctly constructed with argument 'false'");
169 //check_equals(falseBool.valueOf(), false);
170 if (untyped falseBool
.valueOf() == false) {
171 DejaGnu
.pass("falseBool.valueOf() correctly returned false");
173 DejaGnu
.fail("falseBool.valueOf() did not correctly return false");
177 //---------------------------------------------------
178 // Test convertion to boolean
179 //---------------------------------------------------
180 DejaGnu
.note("*** Begin testing convertion to Boolean");
185 DejaGnu
.pass("keyword 'true' correctly evaluates to true");
187 DejaGnu
.fail("keyword 'true' does not correctly evaluate to true");
191 DejaGnu
.pass("expression '! false' correctly evaluates to true");
193 DejaGnu
.fail("expression '! false' did not evaluate to true");
199 DejaGnu
.pass("expression '1' correctly evaluates to true");
201 DejaGnu
.fail("expression '1' did not correctly evaluate to true");
205 DejaGnu
.fail("expression '0' evaluated to true");
207 DejaGnu
.pass("expression '0' evaluated to false");
211 DejaGnu
.pass("expression '!0' correctly evaluates to true");
213 DejaGnu
.fail("expression '!0' did not evaluate to true");
218 if (untyped flash
.Lib
.current
) {
219 DejaGnu
.pass("_root; (flash.lib.current in haxe) evaluated true");
221 DejaGnu
.fail("_root; (flash.lib.current in haxe) evaluated false");
227 DejaGnu
.pass("String expression '1' evaluated true");
229 DejaGnu
.fail("String expression '1' did not evaluate true");
231 //#if OUTPUT_VERSION < 7
234 if ( untyped !"0" ) {
235 DejaGnu
.pass("string expression !'0' evaluated true");
237 DejaGnu
.fail("string expression !'0' did not evaluate true");
240 if ( untyped !"true") {
241 DejaGnu
.pass("string expression !'true' evaluated true");
243 DejaGnu
.fail("string expression !'true' did not evaluate true");
245 //check( ! "false" );
246 if ( untyped !"false") {
247 DejaGnu
.pass("string expression !'false' evaluated true");
249 DejaGnu
.fail("string expression !'false' did not evaluate true");
254 DejaGnu
.pass("string expression '0' evaluated true");
256 DejaGnu
.fail("string expression '0' did not evaluate true");
259 if ( untyped "true" ) {
260 DejaGnu
.pass("string expression 'true' evaluated true");
262 DejaGnu
.fail("string expression 'true' did not evaluate true");
265 if ( untyped "false" ) {
266 DejaGnu
.pass("string expression 'false' evaluated true");
268 DejaGnu
.fail("string expression 'false' did not evaluate true");
274 //check_equals(typeOf(null), "null" );
275 if (untyped __typeof__(null) == "null") {
276 DejaGnu
.pass("typeof null is null");
278 DejaGnu
.fail("typeof null is not null");
282 DejaGnu
.pass("expression '!null' evaluates to true");
284 DejaGnu
.fail("expression '!null' did not evaluate to true");
288 //check( ! undefined );
289 if ( !(untyped undefined
) ) {
290 DejaGnu
.pass("expression '! undefined' evaluates to true");
292 DejaGnu
.fail("expression '! undefined' did not evaluate to true");
296 //var playfunc = untyped __global__["play"];
298 if ( untyped play
) {
299 DejaGnu
.pass("Global function play evaluates to true");
301 DejaGnu
.fail("Global function play does not evaluate to true");
304 // Object - conversion might depend on object type
305 //emptyArray = new Array();
306 var emptyArray
= untyped __new__(Array
);
307 //check( emptyArray );
309 DejaGnu
.pass("emptyArray object evaluates to true");
311 DejaGnu
.fail("emptyArray object does not evaluate to true");
314 #end
//end if !flash9
317 //NOTE: may need to retain Ming tests at the end of the file somehow
323 //NOTE: Haxe does not give acces to the Boolean class directly.
324 // In haXe Bool is an Enum value and does all the processing in the