tests: Port avmplus as3 for-each-in tests
This commit is contained in:
parent
d6f83ce9c3
commit
cc302a56de
|
@ -0,0 +1,325 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package {
|
||||
import flash.display.MovieClip; public class Test extends MovieClip {}
|
||||
}
|
||||
|
||||
import com.adobe.test.Assert;
|
||||
// TODO: REVIEW AS4 CONVERSION ISSUE
|
||||
// var SECTION = "forin-001";
|
||||
// var VERSION = "ECMA_2";
|
||||
// var TITLE = "The for each in statement";
|
||||
var BUGNUMBER="";
|
||||
|
||||
|
||||
var tc = 0;
|
||||
var testcases = new Array();
|
||||
|
||||
ForIn_1( { length:4, company:"netscape", year:2000, 0:"zero" } );
|
||||
ForIn_2( { length:4, company:"netscape", year:2000, 0:"zero" } );
|
||||
ForIn_3( { length:4, company:"netscape", year:2000, 0:"zero" } );
|
||||
|
||||
// ForIn_6({ length:4, company:"netscape", year:2000, 0:"zero" });
|
||||
ForIn_8({ length:4, company:"netscape", year:2000, 0:"zero" });
|
||||
|
||||
|
||||
function ForIn_1( object ) {
|
||||
PropertyArray = new Array();
|
||||
ValueArray = new Array();
|
||||
|
||||
for each ( PropertyArray[PropertyArray.length] in object ) {
|
||||
ValueArray[ValueArray.length] =
|
||||
object[PropertyArray[PropertyArray.length-1]];
|
||||
}
|
||||
|
||||
tcCompany = tc+0;
|
||||
tcLength = tc+1;
|
||||
tcZero = tc+2;
|
||||
tcYear = tc+3;
|
||||
|
||||
// need a hack to make sure that the order of test cases
|
||||
// is constant... ecma stats that the order that for-each-in
|
||||
// is run does not have to be constant
|
||||
for ( var i = 0; i < PropertyArray.length; i++ ) {
|
||||
switch( PropertyArray[i] ) {
|
||||
case "company":
|
||||
testcases[tcCompany] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object[" + PropertyArray[i] +"]",
|
||||
object[PropertyArray[i]],
|
||||
ValueArray[i]
|
||||
);
|
||||
tc++
|
||||
break;
|
||||
|
||||
case "length":
|
||||
testcases[tcLength] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object[" + PropertyArray[i] +"]",
|
||||
object[PropertyArray[i]],
|
||||
ValueArray[i]
|
||||
);
|
||||
tc++
|
||||
break;
|
||||
|
||||
case "year":
|
||||
testcases[tcYear] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object[" + PropertyArray[i] +"]",
|
||||
object[PropertyArray[i]],
|
||||
ValueArray[i]
|
||||
);
|
||||
tc++
|
||||
break;
|
||||
|
||||
case "0":
|
||||
testcases[tcZero] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object[" + PropertyArray[i] +"]",
|
||||
object[PropertyArray[i]],
|
||||
ValueArray[i]
|
||||
);
|
||||
tc++
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object.length",
|
||||
PropertyArray.length,
|
||||
object.length );
|
||||
}
|
||||
|
||||
function ForIn_2( object ) {
|
||||
PropertyArray = new Array();
|
||||
ValueArray = new Array();
|
||||
var i = 0;
|
||||
|
||||
for each ( PropertyArray[i++] in object ) {
|
||||
ValueArray[ValueArray.length] =
|
||||
object[PropertyArray[PropertyArray.length-1]];
|
||||
}
|
||||
|
||||
tcCompany = tc+0;
|
||||
tcLength = tc+1;
|
||||
tcZero = tc+2;
|
||||
tcYear = tc+3;
|
||||
|
||||
// need a hack to make sure that the order of test cases
|
||||
// is constant... ecma stats that the order that for-each-in
|
||||
// is run does not have to be constant
|
||||
for ( var i = 0; i < PropertyArray.length; i++ ) {
|
||||
switch( PropertyArray[i] ) {
|
||||
case "company":
|
||||
testcases[tcCompany] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object[" + PropertyArray[i] +"]",
|
||||
object[PropertyArray[i]],
|
||||
ValueArray[i]
|
||||
);
|
||||
tc++
|
||||
break;
|
||||
|
||||
case "length":
|
||||
testcases[tcLength] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object[" + PropertyArray[i] +"]",
|
||||
object[PropertyArray[i]],
|
||||
ValueArray[i]
|
||||
);
|
||||
tc++
|
||||
break;
|
||||
|
||||
case "year":
|
||||
testcases[tcYear] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object[" + PropertyArray[i] +"]",
|
||||
object[PropertyArray[i]],
|
||||
ValueArray[i]
|
||||
);
|
||||
tc++
|
||||
break;
|
||||
|
||||
case "0":
|
||||
testcases[tcZero] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object[" + PropertyArray[i] +"]",
|
||||
object[PropertyArray[i]],
|
||||
ValueArray[i]
|
||||
);
|
||||
tc++
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object.length",
|
||||
PropertyArray.length,
|
||||
object.length );
|
||||
}
|
||||
|
||||
function ForIn_3( object ) {
|
||||
var checkBreak = "pass";
|
||||
var properties = new Array();
|
||||
var values = new Array();
|
||||
|
||||
for each ( properties[properties.length] in object ) {
|
||||
values[values.length] = object[properties[properties.length-1]];
|
||||
break;
|
||||
checkBreak = "fail";
|
||||
}
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"check break out of for...in",
|
||||
"pass",
|
||||
checkBreak );
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"properties.length",
|
||||
1,
|
||||
properties.length );
|
||||
|
||||
// we don't know which one of the properties
|
||||
// because we can't predict order
|
||||
var myTest = "PASSED";
|
||||
if( values[0] != object[properties[0]] )
|
||||
myTest = "FAILED";
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object[properties[0]] == values[0]",
|
||||
"PASSED",
|
||||
myTest );
|
||||
}
|
||||
|
||||
function ForIn_4( object ) {
|
||||
var result1 = 0;
|
||||
var result2 = 0;
|
||||
var result3 = 0;
|
||||
var result4 = 0;
|
||||
var i = 0;
|
||||
var property = new Array();
|
||||
|
||||
butterbean: {
|
||||
result1++;
|
||||
|
||||
for each ( property[i++] in object ) {
|
||||
result2++;
|
||||
break;
|
||||
result4++;
|
||||
}
|
||||
result3++;
|
||||
}
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"verify labeled statement is only executed once",
|
||||
true,
|
||||
result1 == 1 );
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"verify statements in for loop are evaluated",
|
||||
true,
|
||||
result2 == i );
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"verify break out of labeled for each in loop",
|
||||
true,
|
||||
result4 == 0 );
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"verify break out of labeled block",
|
||||
true,
|
||||
result3 == 0 );
|
||||
}
|
||||
|
||||
function ForIn_5 (object) {
|
||||
var result1 = 0;
|
||||
var result2 = 0;
|
||||
var result3 = 0;
|
||||
var result4 = 0;
|
||||
var i = 0;
|
||||
var property = new Array();
|
||||
|
||||
bigredbird: {
|
||||
result1++;
|
||||
for ( property[i++] in object ) {
|
||||
result2++;
|
||||
break bigredbird;
|
||||
result4++;
|
||||
}
|
||||
result3++;
|
||||
}
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"verify labeled statement is only executed once",
|
||||
true,
|
||||
result1 == 1 );
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"verify statements in for loop are evaluated",
|
||||
true,
|
||||
result2 == i );
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"verify break out of labeled for each in loop",
|
||||
true,
|
||||
result4 == 0 );
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"verify break out of labeled block",
|
||||
true,
|
||||
result3 == 0 );
|
||||
}
|
||||
|
||||
function ForIn_8( object ) {
|
||||
var checkBreak = "pass";
|
||||
var properties = new Array();
|
||||
var values = new Array();
|
||||
|
||||
for each ( properties[properties.length] in object ) {
|
||||
values[values.length] = object[properties[properties.length-1]];
|
||||
break;
|
||||
checkBreak = "fail";
|
||||
}
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"check break out of for each in",
|
||||
"pass",
|
||||
checkBreak );
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"properties.length",
|
||||
1,
|
||||
properties.length );
|
||||
|
||||
// we don't know which one of the properties
|
||||
// because we can't predict order
|
||||
var myTest = "PASSED";
|
||||
if( values[0] != object[properties[0]] )
|
||||
myTest = "FAILED";
|
||||
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"object[properties[0]] == object[properties[0]]",
|
||||
"PASSED",
|
||||
myTest );
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<flex-config>
|
||||
<compiler>
|
||||
<source-path>
|
||||
<path-element>.</path-element>
|
||||
<path-element>../../../../lib</path-element>
|
||||
</source-path>
|
||||
<debug>false</debug>
|
||||
<omit-trace-statements>false</omit-trace-statements>
|
||||
<show-actionscript-warnings>false</show-actionscript-warnings>
|
||||
<strict>false</strict>
|
||||
</compiler>
|
||||
<output>test.swf</output>
|
||||
</flex-config>
|
|
@ -0,0 +1,8 @@
|
|||
object.length PASSED!
|
||||
object.length PASSED!
|
||||
check break out of for...in PASSED!
|
||||
properties.length PASSED!
|
||||
object[properties[0]] == values[0] PASSED!
|
||||
check break out of for each in PASSED!
|
||||
properties.length PASSED!
|
||||
object[properties[0]] == object[properties[0]] PASSED!
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
num_ticks = 1
|
|
@ -0,0 +1,49 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package {
|
||||
import flash.display.MovieClip; public class Test extends MovieClip {}
|
||||
}
|
||||
|
||||
import com.adobe.test.Assert;
|
||||
// TODO: REVIEW AS4 CONVERSION ISSUE
|
||||
// var SECTION = "forin-001";
|
||||
// var VERSION = "ECMA_2";
|
||||
// var TITLE = "The for each in statement";
|
||||
var BUGNUMBER="https://bugzilla.mozilla.org/show_bug.cgi?id=500476";
|
||||
|
||||
|
||||
var tc = 0;
|
||||
var testcases = new Array();
|
||||
|
||||
ForIn_7({ length:4, company:"netscape", year:2000, 0:"zero" });
|
||||
|
||||
|
||||
function ForIn_7( object ) {
|
||||
var result1 = 0;
|
||||
var result2 = 0;
|
||||
var result3 = 0;
|
||||
var result4 = 0;
|
||||
var i = 0;
|
||||
var property = new Array();
|
||||
|
||||
//bigredbird:
|
||||
for each( property[i++] in object ) {
|
||||
result2++;
|
||||
continue;
|
||||
result4++;
|
||||
}
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"verify statements in for loop are evaluated",
|
||||
true,
|
||||
result2 == i );
|
||||
|
||||
testcases[tc++] = Assert.expectEq(
|
||||
//SECTION,
|
||||
"verify continue of labeled for each in loop",
|
||||
true,
|
||||
result4 == 0 );
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<flex-config>
|
||||
<compiler>
|
||||
<source-path>
|
||||
<path-element>.</path-element>
|
||||
<path-element>../../../../lib</path-element>
|
||||
</source-path>
|
||||
<debug>false</debug>
|
||||
<omit-trace-statements>false</omit-trace-statements>
|
||||
<show-actionscript-warnings>false</show-actionscript-warnings>
|
||||
<strict>false</strict>
|
||||
</compiler>
|
||||
<output>test.swf</output>
|
||||
</flex-config>
|
|
@ -0,0 +1,2 @@
|
|||
verify statements in for loop are evaluated PASSED!
|
||||
verify continue of labeled for each in loop PASSED!
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
num_ticks = 1
|
|
@ -0,0 +1,49 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package {
|
||||
import flash.display.MovieClip; public class Test extends MovieClip {}
|
||||
}
|
||||
|
||||
import com.adobe.test.Assert;
|
||||
|
||||
// var SECTION = "Statements"; // provide a document reference (ie, ECMA section)
|
||||
// var VERSION = "AS3"; // Version of JavaScript or ECMA
|
||||
// var TITLE = "for each in"; // Provide ECMA section title or a description
|
||||
var BUGNUMBER = "";
|
||||
|
||||
|
||||
|
||||
// XML Object
|
||||
|
||||
var i, s="";
|
||||
|
||||
obj1 = {};
|
||||
obj1.A = 1;
|
||||
|
||||
obj2 = {};
|
||||
obj2.A = 2;
|
||||
obj3 = {};
|
||||
obj3.A = 3;
|
||||
|
||||
x1 = {};
|
||||
x1.z = [obj1,obj2,obj3];
|
||||
|
||||
// var xmlDoc = "<L><z><A>1</A></z><z><A>2</A></z><z><A>3</A></z></L>";
|
||||
// var x1 = new XML(xmlDoc);
|
||||
|
||||
for each(var i in x1.z) {
|
||||
s += i.A;
|
||||
}
|
||||
|
||||
Assert.expectEq( "for-each-in (var) :", true, (s=="123") );
|
||||
|
||||
s = 0;
|
||||
|
||||
for each ( i in x1.z )
|
||||
s += i.A;
|
||||
|
||||
Assert.expectEq( "for-each-in :", true, (s==6) );
|
||||
|
||||
|
||||
// displays results.
|
|
@ -0,0 +1,13 @@
|
|||
<flex-config>
|
||||
<compiler>
|
||||
<source-path>
|
||||
<path-element>.</path-element>
|
||||
<path-element>../../../../lib</path-element>
|
||||
</source-path>
|
||||
<debug>false</debug>
|
||||
<omit-trace-statements>false</omit-trace-statements>
|
||||
<show-actionscript-warnings>false</show-actionscript-warnings>
|
||||
<strict>false</strict>
|
||||
</compiler>
|
||||
<output>test.swf</output>
|
||||
</flex-config>
|
|
@ -0,0 +1,2 @@
|
|||
for-each-in (var) : PASSED!
|
||||
for-each-in : PASSED!
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
num_ticks = 1
|
Loading…
Reference in New Issue