Adding ecma 2 tests to the repository.

This commit is contained in:
cbegle%netscape.com 1999-05-26 21:22:57 +00:00
Родитель 8b9c756a74
Коммит c3f9125b1d
69 изменённых файлов: 6178 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,70 @@
/**
* File Name: StrictEquality-001.js
* ECMA Section: 11.9.6.js
* Description:
*
* Author: christine@netscape.com
* Date: 4 september 1998
*/
var SECTION = "StrictEquality-001 - 11.9.6";
var VERSION = "ECMA_2";
var TITLE = "The strict equality operator ( === )";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
// 1. If Type(x) is different from Type(y) return false
StrictEquality( true, new Boolean(true), false );
StrictEquality( new Boolean(), false, false );
StrictEquality( "", new String(), false );
StrictEquality( new String("hi"), "hi", false );
// 2. If Type(x) is not Number go to step 9.
// 3. If x is NaN, return false
StrictEquality( NaN, NaN, false );
StrictEquality( NaN, 0, false );
// 4. If y is NaN, return false.
StrictEquality( 0, NaN, false );
// 5. if x is the same number value as y, return true
// 6. If x is +0 and y is -0, return true
// 7. If x is -0 and y is +0, return true
// 8. Return false.
// 9. If Type(x) is String, then return true if x and y are exactly
// the same sequence of characters ( same length and same characters
// in corresponding positions.) Otherwise return false.
// 10. If Type(x) is Boolean, return true if x and y are both true or
// both false. otherwise return false.
// Return true if x and y refer to the same object. Otherwise return
// false.
// Return false.
test();
function StrictEquality( x, y, expect ) {
result = ( x === y );
testcases[tc++] = new TestCase(
SECTION,
x +" === " + y,
expect,
result );
}

Просмотреть файл

@ -0,0 +1,117 @@
/**
* File Name: instanceof-001.js
* ECMA Section: 11.8.6
* Description:
*
* RelationalExpression instanceof Identifier
*
* Author: christine@netscape.com
* Date: 2 September 1998
*/
var SECTION = "instanceof-001";
var VERSION = "ECMA_2";
var TITLE = "instanceof"
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
function InstanceOf( object_1, object_2, expect ) {
result = object_1 instanceof object_2;
testcases[tc++] = new TestCase(
SECTION,
"(" + object_1 + ") instanceof " + object_2,
expect,
result );
}
function Gen3(value) {
this.value = value;
this.generation = 3;
this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" );
}
Gen3.name = 3;
Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\"");
function Gen2(value) {
this.value = value;
this.generation = 2;
}
Gen2.name = 2;
Gen2.prototype = new Gen3();
function Gen1(value) {
this.value = value;
this.generation = 1;
}
Gen1.name = 1;
Gen1.prototype = new Gen2();
function Gen0(value) {
this.value = value;
this.generation = 0;
}
Gen0.name = 0;
Gen0.prototype = new Gen1();
function GenA(value) {
this.value = value;
this.generation = "A";
this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
}
GenA.prototype = new Gen0();
GenA.name = "A";
function GenB(value) {
this.value = value;
this.generation = "B";
this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
}
GenB.name = "B"
GenB.prototype = void 0;
// RelationalExpression is not an object.
InstanceOf( true, Boolean, false );
InstanceOf( new Boolean(false), Boolean, true );
// Identifier is not a function
// InstanceOf( true, true, false );
// InstanceOf( new Boolean(true), false, false );
// Identifier is a function, prototype of Identifier is not an object
// InstanceOf( new GenB(), GenB, false );
// __proto__ of RelationalExpression is null. should return false
genA = new GenA();
genA.__proto__ = null;
InstanceOf( genA, GenA, false );
// RelationalExpression.__proto__ == (but not ===) Identifier.prototype
InstanceOf( new Gen2(), Gen0, false );
InstanceOf( new Gen2(), Gen1, false );
InstanceOf( new Gen2(), Gen2, true );
InstanceOf( new Gen2(), Gen3, true );
// RelationalExpression.__proto__.__proto__ === Identifier.prototype
InstanceOf( new Gen0(), Gen0, true );
InstanceOf( new Gen0(), Gen1, true );
InstanceOf( new Gen0(), Gen2, true );
InstanceOf( new Gen0(), Gen3, true );
InstanceOf( new Gen0(), Object, true );
InstanceOf( new Gen0(), Function, false );
InstanceOf( Gen0, Function, true );
InstanceOf( Gen0, Object, true );
test();

Просмотреть файл

@ -0,0 +1,124 @@
/**
File Name: instanceof-002.js
Section:
Description: Determining Instance Relationships
This test is the same as js1_3/inherit/proto-002, except that it uses
the builtin instanceof operator rather than a user-defined function
called InstanceOf.
This tests Object Hierarchy and Inheritance, as described in the document
Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97
15:19:34 on http://devedge.netscape.com/. Current URL:
http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm
This tests the syntax ObjectName.prototype = new PrototypeObject using the
Employee example in the document referenced above.
Author: christine@netscape.com
Date: 12 november 1997
*/
// onerror = err;
var SECTION = "instanceof-002";
var VERSION = "ECMA_2";
var TITLE = "Determining Instance Relationships";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
function InstanceOf( object, constructor ) {
while ( object != null ) {
if ( object == constructor.prototype ) {
return true;
}
object = object.__proto__;
}
return false;
}
function Employee ( name, dept ) {
this.name = name || "";
this.dept = dept || "general";
}
function Manager () {
this.reports = [];
}
Manager.prototype = new Employee();
function WorkerBee ( name, dept, projs ) {
this.base = Employee;
this.base( name, dept)
this.projects = projs || new Array();
}
WorkerBee.prototype = new Employee();
function SalesPerson () {
this.dept = "sales";
this.quota = 100;
}
SalesPerson.prototype = new WorkerBee();
function Engineer ( name, projs, machine ) {
this.base = WorkerBee;
this.base( name, "engineering", projs )
this.machine = machine || "";
}
Engineer.prototype = new WorkerBee();
var pat = new Engineer()
testcases[tc++] = new TestCase( SECTION,
"pat.__proto__ == Engineer.prototype",
true,
pat.__proto__ == Engineer.prototype );
testcases[tc++] = new TestCase( SECTION,
"pat.__proto__.__proto__ == WorkerBee.prototype",
true,
pat.__proto__.__proto__ == WorkerBee.prototype );
testcases[tc++] = new TestCase( SECTION,
"pat.__proto__.__proto__.__proto__ == Employee.prototype",
true,
pat.__proto__.__proto__.__proto__ == Employee.prototype );
testcases[tc++] = new TestCase( SECTION,
"pat.__proto__.__proto__.__proto__.__proto__ == Object.prototype",
true,
pat.__proto__.__proto__.__proto__.__proto__ == Object.prototype );
testcases[tc++] = new TestCase( SECTION,
"pat.__proto__.__proto__.__proto__.__proto__.__proto__ == null",
true,
pat.__proto__.__proto__.__proto__.__proto__.__proto__ == null );
testcases[tc++] = new TestCase( SECTION,
"pat instanceof Engineer",
true,
pat instanceof Engineer );
testcases[tc++] = new TestCase( SECTION,
"pat instanceof WorkerBee )",
true,
pat instanceof WorkerBee );
testcases[tc++] = new TestCase( SECTION,
"pat instanceof Employee )",
true,
pat instanceof Employee );
testcases[tc++] = new TestCase( SECTION,
"pat instanceof Object )",
true,
pat instanceof Object );
testcases[tc++] = new TestCase( SECTION,
"pat instanceof SalesPerson )",
false,
pat instanceof SalesPerson );
test();

Просмотреть файл

@ -0,0 +1,93 @@
/**
* File Name: instanceof-001.js
* ECMA Section: 11.8.6
* Description:
*
* RelationalExpression instanceof Identifier
*
* Author: christine@netscape.com
* Date: 2 September 1998
*/
var SECTION = "instanceof-001";
var VERSION = "ECMA_2";
var TITLE = "instanceof"
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
function InstanceOf( object_1, object_2, expect ) {
result = object_1 instanceof object_2;
testcases[tc++] = new TestCase(
SECTION,
"(" + object_1 + ") instanceof " + object_2,
expect,
result );
}
function Gen3(value) {
this.value = value;
this.generation = 3;
this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" );
}
Gen3.name = 3;
Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\"");
function Gen2(value) {
this.value = value;
this.generation = 2;
}
Gen2.name = 2;
Gen2.prototype = new Gen3();
function Gen1(value) {
this.value = value;
this.generation = 1;
}
Gen1.name = 1;
Gen1.prototype = new Gen2();
function Gen0(value) {
this.value = value;
this.generation = 0;
}
Gen0.name = 0;
Gen0.prototype = new Gen1();
function GenA(value) {
this.value = value;
this.generation = "A";
this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
}
GenA.prototype = new Gen0();
GenA.name = "A";
function GenB(value) {
this.value = value;
this.generation = "B";
this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
}
GenB.name = "B"
GenB.prototype = void 0;
// RelationalExpression is not an object.
InstanceOf( true, Boolean, false );
// InstanceOf( new Boolean(false), Boolean, true );
// Identifier is not a function
InstanceOf( true, true, false );
// InstanceOf( new Boolean(true), false, false );
// Identifier is a function, prototype of Identifier is not an object
// InstanceOf( new GenB(), GenB, false );
test();

Просмотреть файл

@ -0,0 +1,92 @@
/**
* File Name: instanceof-001.js
* ECMA Section: 11.8.6
* Description:
*
* RelationalExpression instanceof Identifier
*
* Author: christine@netscape.com
* Date: 2 September 1998
*/
var SECTION = "instanceof-001";
var VERSION = "ECMA_2";
var TITLE = "instanceof"
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
function InstanceOf( object_1, object_2, expect ) {
result = object_1 instanceof object_2;
testcases[tc++] = new TestCase(
SECTION,
"(" + object_1 + ") instanceof " + object_2,
expect,
result );
}
function Gen3(value) {
this.value = value;
this.generation = 3;
this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" );
}
Gen3.name = 3;
Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\"");
function Gen2(value) {
this.value = value;
this.generation = 2;
}
Gen2.name = 2;
Gen2.prototype = new Gen3();
function Gen1(value) {
this.value = value;
this.generation = 1;
}
Gen1.name = 1;
Gen1.prototype = new Gen2();
function Gen0(value) {
this.value = value;
this.generation = 0;
}
Gen0.name = 0;
Gen0.prototype = new Gen1();
function GenA(value) {
this.value = value;
this.generation = "A";
this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
}
GenA.prototype = new Gen0();
GenA.name = "A";
function GenB(value) {
this.value = value;
this.generation = "B";
this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
}
GenB.name = "B"
GenB.prototype = void 0;
// RelationalExpression is not an object.
InstanceOf( true, Boolean, false );
InstanceOf( new Boolean(false), Boolean, true );
// Identifier is not a function
InstanceOf( new Boolean(true), false, false );
// Identifier is a function, prototype of Identifier is not an object
// InstanceOf( new GenB(), GenB, false );
test();

Просмотреть файл

@ -0,0 +1,84 @@
/**
* File Name: instanceof-001.js
* ECMA Section: 11.8.6
* Description:
*
* RelationalExpression instanceof Identifier
*
* Author: christine@netscape.com
* Date: 2 September 1998
*/
var SECTION = "instanceof-001";
var VERSION = "ECMA_2";
var TITLE = "instanceof"
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
function InstanceOf( object_1, object_2, expect ) {
result = object_1 instanceof object_2;
testcases[tc++] = new TestCase(
SECTION,
"(" + object_1 + ") instanceof " + object_2,
expect,
result );
}
function Gen3(value) {
this.value = value;
this.generation = 3;
this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" );
}
Gen3.name = 3;
Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\"");
function Gen2(value) {
this.value = value;
this.generation = 2;
}
Gen2.name = 2;
Gen2.prototype = new Gen3();
function Gen1(value) {
this.value = value;
this.generation = 1;
}
Gen1.name = 1;
Gen1.prototype = new Gen2();
function Gen0(value) {
this.value = value;
this.generation = 0;
}
Gen0.name = 0;
Gen0.prototype = new Gen1();
function GenA(value) {
this.value = value;
this.generation = "A";
this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
}
GenA.prototype = new Gen0();
GenA.name = "A";
function GenB(value) {
this.value = value;
this.generation = "B";
this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
}
GenB.name = "B"
GenB.prototype = void 0;
// Identifier is a function, prototype of Identifier is not an object
InstanceOf( new GenB(), GenB, false );
test();

Просмотреть файл

Просмотреть файл

@ -0,0 +1,28 @@
/**
* File Name:
* ECMA Section:
* Description:
*
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "";
var VERSION = "ECMA_2";
var TITLE = "Keywords";
startTest();
// Regular Expression Literals may not be empty; // should be regarded
// as a comment, not a RegExp literal.
var result = "passed";
super;
AddTestCase(
"using the expression \"super\" shouldn't cause js to crash",
"passed" ,
result );
test();

Просмотреть файл

Просмотреть файл

@ -0,0 +1,38 @@
/**
* File Name: LexicalConventions/regexp-literals-001.js
* ECMA Section: 7.7.5
* Description:
*
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "LexicalConventions/regexp-literals-001.js";
var VERSION = "ECMA_2";
var TITLE = "Regular Expression Literals";
startTest();
// Regular Expression Literals may not be empty; // should be regarded
// as a comment, not a RegExp literal.
s = //;
"passed";
AddTestCase(
"// should be a comment, not a regular expression literal",
"passed",
String(s));
AddTestCase(
"// typeof object should be type of object declared on following line",
"passed",
(typeof s) == "string" ? "passed" : "failed" );
AddTestCase(
"// should not return an object of the type RegExp",
"passed",
(typeof s == "object") ? "failed" : "passed" );
test();

Просмотреть файл

@ -0,0 +1,18 @@
/**
* File Name: LexicalConventions/regexp-literals-001.js
* ECMA Section: 7.7.5
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "LexicalConventions/regexp-literals-001.js";
var VERSION = "ECMA_2";
var TITLE = "Regular Expression Literals";
startTest();
// A regular expression literal represents an object of type RegExp.
Object.prototype.getInternalClass = Object.prototype.toString;

Просмотреть файл

@ -0,0 +1,66 @@
/**
* File Name: RegExp/constructor-001.js
* ECMA Section: 15.7.3.3
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/constructor-001.js";
var VERSION = "ECMA_2";
var TITLE = "new RegExp()";
startTest();
/*
* for each test case, verify:
* - verify that [[Class]] property is RegExp
* - prototype property should be set to RegExp.prototype
* - source is set to the empty string
* - global property is set to false
* - ignoreCase property is set to false
* - multiline property is set to false
* - lastIndex property is set to 0
*/
RegExp.prototype.getClassProperty = Object.prototype.toString;
var re = new RegExp();
AddTestCase(
"new RegExp().__proto__",
RegExp.prototype,
re.__proto__
);
AddTestCase(
"RegExp.prototype.getClassProperty = Object.prototype.toString; " +
"(new RegExp()).getClassProperty()",
"[object RegExp]",
re.getClassProperty() );
AddTestCase(
"(new RegExp()).source",
"",
re.source );
AddTestCase(
"(new RegExp()).global",
false,
re.global );
AddTestCase(
"(new RegExp()).ignoreCase",
false,
re.ignoreCase );
AddTestCase(
"(new RegExp()).multiline",
false,
re.multiline );
AddTestCase(
"(new RegExp()).lastIndex",
0,
re.lastIndex );
test()

Просмотреть файл

@ -0,0 +1,29 @@
/**
* File Name: RegExp/exec-001.js
* ECMA Section: 15.7.5.3
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/exec-001.js";
var VERSION = "ECMA_2";
var TITLE = "RegExp.prototype.exec(string)";
startTest();
/*
* for each test case, verify:
* - type of object returned
* - length of the returned array
* - value of lastIndex
* - value of index
* - value of input
* - value of the array indices
*/
// test cases without subpatterns
// test cases with subpatterns
// global property is true
// global property is false
// test cases in which the exec returns null

Просмотреть файл

@ -0,0 +1,182 @@
/**
* File Name: RegExp/exec-002.js
* ECMA Section: 15.7.5.3
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Test cases provided by rogerl@netscape.com
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/exec-002.js";
var VERSION = "ECMA_2";
var TITLE = "RegExp.prototype.exec(string)";
startTest();
/*
* for each test case, verify:
* - type of object returned
* - length of the returned array
* - value of lastIndex
* - value of index
* - value of input
* - value of the array indices
*/
AddRegExpCases(
/(a|d|q|)x/i,
"bcaDxqy",
3,
["Dx", "D"] );
AddRegExpCases(
/(a|(e|q))(x|y)/,
"bcaddxqy",
6,
["qy","q","q","y"] );
AddRegExpCases(
/a+b+d/,
"aabbeeaabbs",
0,
null );
AddRegExpCases(
/a*b/,
"aaadaabaaa",
4,
["aab"] );
AddRegExpCases(
/a*b/,
"dddb",
3,
["b"] );
AddRegExpCases(
/a*b/,
"xxx",
0,
null );
AddRegExpCases(
/x\d\dy/,
"abcx45ysss235",
3,
["x45y"] );
AddRegExpCases(
/[^abc]def[abc]+/,
"abxdefbb",
2,
["xdefbb"] );
AddRegExpCases(
/(a*)baa/,
"ccdaaabaxaabaa",
9,
["aabaa", "aa"] );
AddRegExpCases(
/(a*)baa/,
"aabaa",
0,
["aabaa", "aa"] );
AddRegExpCases(
/q(a|b)*q/,
"xxqababqyy",
2,
["qababq", "b"] );
AddRegExpCases(
/(a(.|[^d])c)*/,
"adcaxc",
0,
["adcaxc", "axc", "x"] );
AddRegExpCases(
/(a*)b\1/,
"abaaaxaabaayy",
0,
["aba", "a"] );
AddRegExpCases(
/(a*)b\1/,
"abaaaxaabaayy",
0,
["aba", "a"] );
AddRegExpCases(
/(a*)b\1/,
"cccdaaabaxaabaayy",
6,
["aba", "a"] );
AddRegExpCases(
/(a*)b\1/,
"cccdaaabqxaabaayy",
7,
["b", ""] );
AddRegExpCases(
/"(.|[^"\\\\])*"/,
'xx\"makudonarudo\"yy',
2,
["\"makudonarudo\"", "o"] );
AddRegExpCases(
/"(.|[^"\\\\])*"/,
"xx\"ma\"yy",
2,
["\"ma\"", "a"] );
test();
function AddRegExpCases(
regexp, pattern, index, matches_array ) {
// prevent a runtime error
if ( regexp.exec(pattern) == null || matches_array == null ) {
AddTestCase(
regexp + ".exec(" + pattern +")",
matches_array,
regexp.exec(pattern) );
return;
}
AddTestCase(
regexp + ".exec(" + pattern +").length",
matches_array.length,
regexp.exec(pattern).length );
AddTestCase(
regexp + ".exec(" + pattern +").index",
index,
regexp.exec(pattern).index );
AddTestCase(
regexp + ".exec(" + pattern +").input",
pattern,
regexp.exec(pattern).input );
AddTestCase(
regexp + ".exec(" + pattern +").toString()",
matches_array.toString(),
regexp.exec(pattern).toString() );
/*
var limit = matches_array.length > regexp.exec(pattern).length
? matches_array.length
: regexp.exec(pattern).length;
for ( var matches = 0; matches < limit; matches++ ) {
AddTestCase(
regexp + ".exec(" + pattern +")[" + matches +"]",
matches_array[matches],
regexp.exec(pattern)[matches] );
}
*/
}

Просмотреть файл

@ -0,0 +1,66 @@
/**
* File Name: RegExp/function-001.js
* ECMA Section: 15.7.2.1
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/function-001.js";
var VERSION = "ECMA_2";
var TITLE = "RegExp( pattern, flags )";
startTest();
/*
* for each test case, verify:
* - verify that [[Class]] property is RegExp
* - prototype property should be set to RegExp.prototype
* - source is set to the empty string
* - global property is set to false
* - ignoreCase property is set to false
* - multiline property is set to false
* - lastIndex property is set to 0
*/
RegExp.prototype.getClassProperty = Object.prototype.toString;
var re = new RegExp();
AddTestCase(
"new RegExp().__proto__",
RegExp.prototype,
re.__proto__
);
AddTestCase(
"RegExp.prototype.getClassProperty = Object.prototype.toString; " +
"(new RegExp()).getClassProperty()",
"[object RegExp]",
re.getClassProperty() );
AddTestCase(
"(new RegExp()).source",
"",
re.source );
AddTestCase(
"(new RegExp()).global",
false,
re.global );
AddTestCase(
"(new RegExp()).ignoreCase",
false,
re.ignoreCase );
AddTestCase(
"(new RegExp()).multiline",
false,
re.multiline );
AddTestCase(
"(new RegExp()).lastIndex",
0,
re.lastIndex );
test()

Просмотреть файл

@ -0,0 +1,63 @@
/**
* File Name: RegExp/hex-001.js
* ECMA Section: 15.7.3.1
* Description: Based on ECMA 2 Draft 7 February 1999
* Positive test cases for constructing a RegExp object
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/hex-001.js";
var VERSION = "ECMA_2";
var TITLE = "RegExp patterns that contain HexicdecimalEscapeSequences";
startTest();
// These examples come from 15.7.1, HexidecimalEscapeSequence
AddRegExpCases( new RegExp("\x41"), "new RegExp('\\x41')", "A", "A", 1, 0, ["A"] );
AddRegExpCases( new RegExp("\x412"),"new RegExp('\\x412')", "A2", "A2", 1, 0, ["A2"] );
AddRegExpCases( new RegExp("\x1g"), "new RegExp('\\x1g')", "x1g","x1g", 1, 0, ["x1g"] );
AddRegExpCases( new RegExp("A"), "new RegExp('A')", "\x41", "\\x41", 1, 0, ["A"] );
AddRegExpCases( new RegExp("A"), "new RegExp('A')", "\x412", "\\x412", 1, 0, ["A"] );
AddRegExpCases( new RegExp("^x"), "new RegExp('^x')", "x412", "x412", 1, 0, ["x"]);
AddRegExpCases( new RegExp("A"), "new RegExp('A')", "A2", "A2", 1, 0, ["A"] );
test();
function AddRegExpCases(
regexp, str_regexp, pattern, str_pattern, length, index, matches_array ) {
// prevent a runtime error
if ( regexp.exec(pattern) == null || matches_array == null ) {
AddTestCase(
str_regexp + ".exec(" + pattern +")",
matches_array,
regexp.exec(pattern) );
return;
}
AddTestCase(
str_regexp + ".exec(" + str_pattern +").length",
length,
regexp.exec(pattern).length );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").index",
index,
regexp.exec(pattern).index );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").input",
pattern,
regexp.exec(pattern).input );
for ( var matches = 0; matches < matches_array.length; matches++ ) {
AddTestCase(
str_regexp + ".exec(" + str_pattern +")[" + matches +"]",
matches_array[matches],
regexp.exec(pattern)[matches] );
}
}

Просмотреть файл

@ -0,0 +1,62 @@
/**
* File Name: RegExp/multiline-001.js
* ECMA Section:
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Date: 19 February 1999
*/
var SECTION = "RegExp/multiline-001.js";
var VERSION = "ECMA_2";
var TITLE = "RegExp: multiline flag";
var BUGNUMBER="343901";
startTest();
var woodpeckers = "ivory-billed\ndowny\nhairy\nacorn\nyellow-bellied sapsucker\n" +
"northern flicker\npileated\n";
AddRegExpCases( /[d]$/g, woodpeckers, woodpeckers.indexOf("ivory-billed"), ["ivory-billed"] );
AddRegExpCases( /[d]$/m, woodpeckers, woodpeckers.indexOf("ivory-billed"), ["ivory-billed"] );
test();
function AddRegExpCases
( regexp, pattern, index, matches_array ) {
// prevent a runtime error
if ( regexp.exec(pattern) == null || matches_array == null ) {
AddTestCase(
regexp + ".exec(" + pattern +")",
matches_array,
regexp.exec(pattern) );
return;
}
AddTestCase(
regexp.toString() + ".exec(" + pattern +").length",
matches_array.length,
regexp.exec(pattern).length );
AddTestCase(
regexp.toString() + ".exec(" + pattern +").index",
index,
regexp.exec(pattern).index );
AddTestCase(
regexp + ".exec(" + pattern +").input",
pattern,
regexp.exec(pattern).input );
for ( var matches = 0; matches < matches_array.length; matches++ ) {
AddTestCase(
regexp + ".exec(" + pattern +")[" + matches +"]",
matches_array[matches],
regexp.exec(pattern)[matches] );
}
}

Просмотреть файл

@ -0,0 +1,94 @@
/**
* File Name: RegExp/octal-001.js
* ECMA Section: 15.7.1
* Description: Based on ECMA 2 Draft 7 February 1999
* Simple test cases for matching OctalEscapeSequences.
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/octal-001.js";
var VERSION = "ECMA_2";
var TITLE = "RegExp patterns that contain OctalEscapeSequences";
var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346196";
startTest();
// These examples come from 15.7.1, OctalEscapeSequences
// If n is exactly 1 octal digit other than “0”, and the octal value of n is
// less than or equal to the number of parenthesised subexpressions in the
// pattern, then \n is a backreference; otherwise \n is an octal value. For
// example, in the pattern “(.)\1”, “\1” is a backreference. By contrast, in
// the pattern “.\1”, “\1” is an octal value.
// backreference
AddRegExpCases(
/(.)\1/,
"/(.)\\1/",
"HI!!",
"HI!",
2,
["!!", "!"] );
// octal value
AddRegExpCases(
/.\1/,
"/.\\1/",
"HI!" + String.fromCharCode(1),
"HI!+ String.fromCharCode(1)",
1,
["!1"] );
// backreference
AddRegExpCases( /(.)\041/, "/(.)\\041/", "HI!", "HI!", 1, ["I!", "I"] );
// octal value
AddRegExpCases( /.\041/, "/.\\041/", "HI!", "HI!", 1, ["I!"] );
test();
function AddRegExpCases(
regexp, str_regexp, pattern, str_pattern, index, matches_array ) {
// prevent a runtime error
if ( regexp.exec(pattern) == null || matches_array == null ) {
AddTestCase(
regexp + ".exec(" + str_pattern +")",
matches_array,
regexp.exec(pattern) );
return;
}
AddTestCase(
str_regexp + ".exec(" + str_pattern +").length",
matches_array.length,
regexp.exec(pattern).length );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").index",
index,
regexp.exec(pattern).index );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").input",
pattern,
regexp.exec(pattern).input );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").toString()",
matches_array.toString(),
regexp.exec(pattern).toString() );
/*
var limit = matches_array.length > regexp.exec(pattern).length
? matches_array.length
: regexp.exec(pattern).length;
for ( var matches = 0; matches < limit; matches++ ) {
AddTestCase(
str_regexp + ".exec(" + str_pattern +")[" + matches +"]",
matches_array[matches],
regexp.exec(pattern)[matches] );
}
*/
}

Просмотреть файл

@ -0,0 +1,130 @@
/**
* File Name: RegExp/octal-002.js
* ECMA Section: 15.7.1
* Description: Based on ECMA 2 Draft 7 February 1999
* Simple test cases for matching OctalEscapeSequences.
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/octal-002.js";
var VERSION = "ECMA_2";
var TITLE = "RegExp patterns that contain OctalEscapeSequences";
var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346189";
startTest();
// These examples come from 15.7.1, OctalEscapeSequences
/* If n is [89], and the decimal value of n is less than or equal to the
* number of parenthesised subexpressions in the pattern, then \n is a
* backreference; otherwise \n is the literal character n. For example, in
* the pattern (.)(.)(.)(.)(.)(.)(.)(.)\8, \8 is a backreference. By
* contrast, in the pattern ..\8, \8 is the character 8.
*/
// backreference
AddRegExpCases(
/(.)(.)(.)(.)(.)(.)(.)(.)\8/,
"/(.)(.)(.)(.)(.)(.)(.)(.)\\8",
"aabbccaaabbbccc",
"aabbccaaabbbccc",
0,
["aabbccaaa", "a", "a", "b", "b", "c", "c", "a", "a"] );
AddRegExpCases(
/(.)(.)(.)(.)(.)(.)(.)(.)(.)\9/,
"/(.)(.)(.)(.)(.)(.)(.)(.)\\9",
"aabbccaabbcc",
"aabbccaabbcc",
0,
["aabbccaabb", "a", "a", "b", "b", "c", "c", "a", "a", "b"] );
AddRegExpCases(
/(.)(.)(.)(.)(.)(.)(.)(.)(.)\8/,
"/(.)(.)(.)(.)(.)(.)(.)(.)\\8",
"aabbccaababcc",
"aabbccaababcc",
0,
["aabbccaaba", "a", "a", "b", "b", "c", "c", "a", "a", "b", "a"] );
AddRegExpCases(
/(.)(.)(.)(.)(.)(.)(.)(.)(.)\9/,
"/(.)(.)(.)(.)(.)(.)(.)(.)\\9",
"aabbccddeeffgghh",
"aabbccddeeffgghh",
0,
null );
// literal
AddRegExpCases(
/(.)(.)(.)(.)(.)(.)(.)\8/,
"/(.)(.)(.)(.)(.)(.)(.)\\8",
"aabbccaaa87654321",
"aabbccaaa87654321",
2,
["bbccaaa8", "b", "b", "c", "c", "a", "a", "a"] );
AddRegExpCases(
/.......\8/,
"/.......\\8/",
"aabbccaaa87654321",
"aabbccaaa87654321",
2,
["bbccaaa8"]);
AddRegExpCases(
/........\8/,
"/........\\8/",
"aabbccaaa87654321",
"aabbccaaa87654321",
1,
["abbccaaa8"]);
test();
function AddRegExpCases(
regexp, str_regexp, pattern, str_pattern, index, matches_array ) {
// prevent a runtime error
if ( regexp.exec(pattern) == null || matches_array == null ) {
AddTestCase(
regexp + ".exec(" + str_pattern +")",
matches_array,
regexp.exec(pattern) );
return;
}
AddTestCase(
str_regexp + ".exec(" + str_pattern +").length",
matches_array.length,
regexp.exec(pattern).length );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").index",
index,
regexp.exec(pattern).index );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").input",
pattern,
regexp.exec(pattern).input );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").toString()",
matches_array.toString(),
regexp.exec(pattern).toString() );
/*
var limit = matches_array.length > regexp.exec(pattern).length
? matches_array.length
: regexp.exec(pattern).length;
for ( var matches = 0; matches < limit; matches++ ) {
AddTestCase(
str_regexp + ".exec(" + str_pattern +")[" + matches +"]",
matches_array[matches],
regexp.exec(pattern)[matches] );
}
*/
}

Просмотреть файл

@ -0,0 +1,77 @@
/**
* File Name: RegExp/octal-003.js
* ECMA Section: 15.7.1
* Description: Based on ECMA 2 Draft 7 February 1999
* Simple test cases for matching OctalEscapeSequences.
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/octal-003.js";
var VERSION = "ECMA_2";
var TITLE = "RegExp patterns that contain OctalEscapeSequences";
var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346132";
startTest();
// These examples come from 15.7.1, OctalEscapeSequences
/* If the first digit is [03], the octal value may be 1, 2, or 3 digit long.
* For example, "\11" and "\011" both match \t, while "\0111" matches "\t1.
* If the first digit is [4--7], the octal value may be 1 or 2 digits long.
* For example, "\44" matches $, while \444 matches$4.
*/
AddRegExpCases( /\11/, "/\\11/", "\t12", "\\t12", 0, ["\t"] );
AddRegExpCases( /\011/, "/\\011/", "\t12", "\\t12", 0, ["\t"] );
AddRegExpCases( /\0111/, "/\\0111/","\t12", "\\t12", 0, ["\t1"] );
AddRegExpCases( /\44/, "/\\44/", "123$456", "123$456", 3, ["$"] );
AddRegExpCases( /\444/, "/\\444/", "123$456", "123$456", 3, ["$4"] );
test();
function AddRegExpCases(
regexp, str_regexp, pattern, str_pattern, index, matches_array ) {
// prevent a runtime error
if ( regexp.exec(pattern) == null || matches_array == null ) {
AddTestCase(
regexp + ".exec(" + str_pattern +")",
matches_array,
regexp.exec(pattern) );
return;
}
AddTestCase(
str_regexp + ".exec(" + str_pattern +").length",
matches_array.length,
regexp.exec(pattern).length );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").index",
index,
regexp.exec(pattern).index );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").input",
pattern,
regexp.exec(pattern).input );
AddTestCase(
str_regexp + ".exec(" + str_pattern +").toString()",
matches_array.toString(),
regexp.exec(pattern).toString() );
/*
var limit = matches_array.length > regexp.exec(pattern).length
? matches_array.length
: regexp.exec(pattern).length;
for ( var matches = 0; matches < limit; matches++ ) {
AddTestCase(
str_regexp + ".exec(" + str_pattern +")[" + matches +"]",
matches_array[matches],
regexp.exec(pattern)[matches] );
}
*/
}

Просмотреть файл

@ -0,0 +1,78 @@
/**
* File Name: RegExp/properties-001.js
* ECMA Section: 15.7.6.js
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/properties-001.js";
var VERSION = "ECMA_2";
var TITLE = "Properties of RegExp Instances";
var BUGNUMBER ="http://scopus/bugsplat/show_bug.cgi?id=346000";
startTest();
AddRegExpCases( new RegExp, "", false, false, false, 0 );
AddRegExpCases( /.*/, ".*", false, false, false, 0 );
AddRegExpCases( /[\d]{5}/g, "[\\d]{5}", true, false, false, 0 );
AddRegExpCases( /[\S]?$/i, "[\\S]?$", false, true, false, 0 );
AddRegExpCases( /^([a-z]*)[^\w\s\f\n\r]+/m, "^([a-z]*)[^\\w\\s\\f\n\\r]+", false, false, true, 0 );
AddRegExpCases( /[\D]{1,5}[\ -][\d]/gi, "[\\D]{1,5}[\\ -][\\d]", true, true, false, 0 );
AddRegExpCases( /[a-zA-Z0-9]*/gm, "[a-zA-Z0-9]*", true, false, true, 0 );
AddRegExpCases( /x|y|z/gim, "x|y|z|", true, true, true, 0 );
AddRegExpCases( /\u0051/im, "\\u0051", false, true, true, 0 );
AddRegExpCases( /\x45/gm, "\\x45", true, false, true, 0 );
AddRegExpCases( /\097/gi, "\\097", true, true, false, 0 );
test();
function AddRegExpCases( re, s, g, i, m, l ) {
AddTestCase( re + ".test == RegExp.prototype.test",
true,
re.test == RegExp.prototype.test );
AddTestCase( re + ".toString == RegExp.prototype.toString",
true,
re.toString == RegExp.prototype.toString );
AddTestCase( re + ".contructor == RegExp.prototype.constructor",
true,
re.constructor == RegExp.prototype.constructor );
AddTestCase( re + ".compile == RegExp.prototype.compile",
true,
re.compile == RegExp.prototype.compile );
AddTestCase( re + ".exec == RegExp.prototype.exec",
true,
re.exec == RegExp.prototype.exec );
// properties
AddTestCase( re + ".source",
s,
re.source );
AddTestCase( re + ".toString()",
"/" + s +"/" + (g?"g":"") + (i?"i":"") +(m?"m":""),
re.toString() );
AddTestCase( re + ".global",
g,
re.global );
AddTestCase( re + ".ignoreCase",
i,
re.ignoreCase );
AddTestCase( re + ".multiline",
m,
re.multiline);
AddTestCase( re + ".lastIndex",
l,
re.lastIndex );
}

Просмотреть файл

@ -0,0 +1,86 @@
/**
* File Name: RegExp/properties-002.js
* ECMA Section: 15.7.6.js
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/properties-002.js";
var VERSION = "ECMA_2";
var TITLE = "Properties of RegExp Instances";
var BUGNUMBER ="http://scopus/bugsplat/show_bug.cgi?id=346032";
startTest();
re_1 = /\cA?/g;
re_1.lastIndex = Math.pow(2,32);
re_2 = /\w*/i;
re_2.lastIndex = Math.pow(2,32) -1;
re_3 = /\*{0,80}/m;
re_3.lastIndex = Math.pow(2,31) -1;
re_4 = /^./gim;
re_4.lastIndex = Math.pow(2,30) -1;
re_5 = /\B/;
re_5.lastIndex = Math.pow(2,30);
AddRegExpCases( re_1, "\\cA?", true, false, false, Math.pow(2,32) );
AddRegExpCases( re_2, "\\w*", false, true, false, Math.pow(2,32)-1 );
AddRegExpCases( re_3, "\\*{0,80}", false, false, true, Math.pow(2,31) -1 );
AddRegExpCases( re_4, "^.", true, true, true, Math.pow(2,30) -1 );
AddRegExpCases( re_5, "\\B", false, false, false, Math.pow(2,30) );
test();
function AddRegExpCases( re, s, g, i, m, l ) {
AddTestCase( re + ".test == RegExp.prototype.test",
true,
re.test == RegExp.prototype.test );
AddTestCase( re + ".toString == RegExp.prototype.toString",
true,
re.toString == RegExp.prototype.toString );
AddTestCase( re + ".contructor == RegExp.prototype.constructor",
true,
re.constructor == RegExp.prototype.constructor );
AddTestCase( re + ".compile == RegExp.prototype.compile",
true,
re.compile == RegExp.prototype.compile );
AddTestCase( re + ".exec == RegExp.prototype.exec",
true,
re.exec == RegExp.prototype.exec );
// properties
AddTestCase( re + ".source",
s,
re.source );
AddTestCase( re + ".toString()",
"/" + s +"/" + (g?"g":"") + (i?"i":"") +(m?"m":""),
re.toString() );
AddTestCase( re + ".global",
g,
re.global );
AddTestCase( re + ".ignoreCase",
i,
re.ignoreCase );
AddTestCase( re + ".multiline",
m,
re.multiline);
AddTestCase( re + ".lastIndex",
l,
re.lastIndex );
}

Просмотреть файл

@ -0,0 +1,93 @@
/**
File Name: regexp-enumerate-001.js
ECMA V2 Section:
Description: Regression Test.
If instance Native Object have properties that are enumerable,
JavaScript enumerated through the properties twice. This only
happened if objects had been instantiated, but their properties
had not been enumerated. ie, the object inherited properties
from its prototype that are enumerated.
In the core JavaScript, this is only a problem with RegExp
objects, since the inherited properties of most core JavaScript
objects are not enumerated.
Author: christine@netscape.com
Date: 12 november 1997
*/
// onerror = err;
var SECTION = "regexp-enumerate-001";
var VERSION = "ECMA_2";
var TITLE = "Regression Test for Enumerating Properties";
var BUGNUMBER="339403";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
/*
* This test expects RegExp instances to have four enumerated properties:
* source, global, ignoreCase, and lastIndex
*
* 99.01.25: now they also have a multiLine instance property.
*
*/
var r = new RegExp();
var e = new Array();
var t = new TestRegExp();
for ( p in r ) { e[e.length] = { property:p, value:r[p] }; t.addProperty( p, r[p]) };
testcases[testcases.length] = new TestCase( SECTION,
"r = new RegExp(); e = new Array(); "+
"for ( p in r ) { e[e.length] = { property:p, value:r[p] }; e.length",
5,
e.length );
test();
function TestRegExp() {
this.addProperty = addProperty;
}
function addProperty(name, value) {
var pass = false;
if ( eval("this."+name) != void 0 ) {
pass = true;
} else {
eval( "this."+ name+" = "+ false );
}
testcases[testcases.length] = new TestCase( SECTION,
"Property: " + name +" already enumerated?",
false,
pass );
if ( testcases[ testcases.length-1].passed == false ) {
testcases[testcases.length-1].reason = "property already enumerated";
}
}
function test() {
for ( tc=0; tc < testcases.length; tc++ ) {
testcases[tc].passed = writeTestCaseResult(
testcases[tc].expect,
testcases[tc].actual,
testcases[tc].description +" = "+
testcases[tc].actual );
testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
}
stopTest();
return ( testcases );
}

Просмотреть файл

@ -0,0 +1,39 @@
/**
* File Name: RegExp/regress-001.js
* ECMA Section: N/A
* Description: Regression test case:
* JS regexp anchoring on empty match bug
* http://bugzilla.mozilla.org/show_bug.cgi?id=2157
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/hex-001.js";
var VERSION = "ECMA_2";
var TITLE = "JS regexp anchoring on empty match bug";
var BUGNUMBER = "http://bugzilla.mozilla.org/show_bug.cgi?id=2157";
startTest();
AddRegExpCases( /a||b/(''),
"//a||b/('')",
1,
[''] );
test();
function AddRegExpCases( regexp, str_regexp, length, matches_array ) {
AddTestCase(
"( " + str_regexp + " ).length",
regexp.length,
regexp.length );
for ( var matches = 0; matches < matches_array.length; matches++ ) {
AddTestCase(
"( " + str_regexp + " )[" + matches +"]",
matches_array[matches],
regexp[matches] );
}
}

Просмотреть файл

@ -0,0 +1,53 @@
/**
* File Name: RegExp/unicode-001.js
* ECMA Section: 15.7.3.1
* Description: Based on ECMA 2 Draft 7 February 1999
* Positive test cases for constructing a RegExp object
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "RegExp/unicode-001.js";
var VERSION = "ECMA_2";
var TITLE = "new RegExp( pattern, flags )";
startTest();
// These examples come from 15.7.1, UnicodeEscapeSequence
AddRegExpCases( /\u0041/, "/\\u0041/", "A", "A", 1, 0, ["A"] );
AddRegExpCases( /\u00412/, "/\\u00412/", "A2", "A2", 1, 0, ["A2"] );
AddRegExpCases( /\u00412/, "/\\u00412/", "A2", "A2", 1, 0, ["A2"] );
AddRegExpCases( /\u001g/, "/\\u001g/", "u001g", "u001g", 1, 0, ["u001g"] );
AddRegExpCases( /A/, "/A/", "\u0041", "\\u0041", 1, 0, ["A"] );
AddRegExpCases( /A/, "/A/", "\u00412", "\\u00412", 1, 0, ["A"] );
AddRegExpCases( /A2/, "/A2/", "\u00412", "\\u00412", 1, 0, ["A2"]);
AddRegExpCases( /A/, "/A/", "A2", "A2", 1, 0, ["A"] );
test();
function AddRegExpCases(
regexp, str_regexp, pattern, str_pattern, length, index, matches_array ) {
AddTestCase(
str_regexp + " .exec(" + str_pattern +").length",
length,
regexp.exec(pattern).length );
AddTestCase(
str_regexp + " .exec(" + str_pattern +").index",
index,
regexp.exec(pattern).index );
AddTestCase(
str_regexp + " .exec(" + str_pattern +").input",
pattern,
regexp.exec(pattern).input );
for ( var matches = 0; matches < matches_array.length; matches++ ) {
AddTestCase(
str_regexp + " .exec(" + str_pattern +")[" + matches +"]",
matches_array[matches],
regexp.exec(pattern)[matches] );
}
}

Просмотреть файл

@ -0,0 +1,41 @@
/**
* File Name: dowhile-001
* ECMA Section:
* Description: do...while statements
*
*
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "dowhile-002";
var VERSION = "ECMA_2";
var TITLE = "do...while with a labeled continue statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
LabeledContinue( 0, 1 );
LabeledContinue( 1, 1 );
LabeledContinue( -1, 1 );
LabeledContinue( 5, 5 );
test();
function LabeledContinue( limit, expect ) {
i = 0;
woohoo:
do {
i++;
continue woohoo;
} while ( i < limit );
testcases[tc++] = new TestCase(
SECTION,
"do while ( " + i +" < " + limit +" )",
expect,
i );
}

Просмотреть файл

@ -0,0 +1,68 @@
/**
* File Name: dowhile-002
* ECMA Section:
* Description: do...while statements
*
* Verify that code after a labeled break is not executed. Verify that
* a labeled break breaks you out of the whole labeled block, and not
* just the current iteration statement.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "dowhile-002";
var VERSION = "ECMA_2";
var TITLE = "do...while with a labeled continue statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
LabeledContinue( 0, 1 );
LabeledContinue( 1, 1 );
LabeledContinue( -1, 1 );
LabeledContinue( 5, 5 );
test();
// The labeled statment contains statements after the labeled break.
// Verify that the statements after the break are not executed.
function LabeledContinue( limit, expect ) {
i = 0;
result1 = "pass";
result2 = "pass";
woohoo: {
do {
i++;
if ( ! (i < limit) ) {
break woohoo;
result1 = "fail: evaluated statement after a labeled break";
}
} while ( true );
result2 = "failed: broke out of loop, but not out of labeled block";
}
testcases[tc++] = new TestCase(
SECTION,
"do while ( " + i +" < " + limit +" )",
expect,
i );
testcases[tc++] = new TestCase(
SECTION,
"breaking out of a do... while loop",
"pass",
result1 );
testcases[tc++] = new TestCase(
SECTION,
"breaking out of a labeled do...while loop",
"pass",
result2 );
}

Просмотреть файл

@ -0,0 +1,60 @@
/**
* File Name: dowhile-003
* ECMA Section:
* Description: do...while statements
*
* Test do while, when the while expression is a JavaScript Number object.
*
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "dowhile-003";
var VERSION = "ECMA_2";
var TITLE = "do...while with a labeled continue statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
DoWhile( new DoWhileObject( 1, 1, 0 ));
DoWhile( new DoWhileObject( 1000, 1000, 0 ));
DoWhile( new DoWhileObject( 1001, 1001, 0 ));
DoWhile( new DoWhileObject( 1002, 1001, 1 ));
DoWhile( new DoWhileObject( -1, 1001, -1002 ));
test();
function DoWhileObject( value, iterations, endvalue ) {
this.value = value;
this.iterations = iterations;
this.endvalue = endvalue;
}
function DoWhile( object ) {
var i = 0;
do {
object.value = --object.value;
i++;
if ( i > 1000 )
break;
} while( object.value );
testcases[tc++] = new TestCase(
SECTION,
"loop iterations",
object.iterations,
i
);
testcases[tc++] = new TestCase(
SECTION,
"object.value",
object.endvalue,
Number( object.value )
);
}

Просмотреть файл

@ -0,0 +1,64 @@
/**
* File Name: dowhile-004
* ECMA Section:
* Description: do...while statements
*
* Test a labeled do...while. Break out of the loop with no label
* should break out of the loop, but not out of the label.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "dowhile-004";
var VERSION = "ECMA_2";
var TITLE = "do...while with a labeled continue statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
DoWhile( 0, 1 );
DoWhile( 1, 1 );
DoWhile( -1, 1 );
DoWhile( 5, 5 );
test();
function DoWhile( limit, expect ) {
i = 0;
result1 = "pass";
result2 = "failed: broke out of labeled statement unexpectedly";
foo: {
do {
i++;
if ( ! (i < limit) ) {
break;
result1 = "fail: evaluated statement after a labeled break";
}
} while ( true );
result2 = "pass";
}
testcases[tc++] = new TestCase(
SECTION,
"do while ( " + i +" < " + limit +" )",
expect,
i );
testcases[tc++] = new TestCase(
SECTION,
"breaking out of a do... while loop",
"pass",
result1 );
testcases[tc++] = new TestCase(
SECTION,
"breaking out of a labeled do...while loop",
"pass",
result2 );
}

Просмотреть файл

@ -0,0 +1,70 @@
/**
* File Name: dowhile-005
* ECMA Section:
* Description: do...while statements
*
* Test a labeled do...while. Break out of the loop with no label
* should break out of the loop, but not out of the label.
*
* Currently causes an infinite loop in the monkey. Uncomment the
* print statement below and it works OK.
*
* Author: christine@netscape.com
* Date: 26 August 1998
*/
var SECTION = "dowhile-005";
var VERSION = "ECMA_2";
var TITLE = "do...while with a labeled continue statement";
var BUGNUMBER = "316293";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
NestedLabel();
test();
function NestedLabel() {
i = 0;
result1 = "pass";
result2 = "fail: did not hit code after inner loop";
result3 = "pass";
outer: {
do {
inner: {
// print( i );
break inner;
result1 = "fail: did break out of inner label";
}
result2 = "pass";
break outer;
print (i);
} while ( i++ < 100 );
}
result3 = "fail: did not break out of outer label";
testcases[tc++] = new TestCase(
SECTION,
"number of loop iterations",
0,
i );
testcases[tc++] = new TestCase(
SECTION,
"break out of inner loop",
"pass",
result1 );
testcases[tc++] = new TestCase(
SECTION,
"break out of outer loop",
"pass",
result2 );
}

Просмотреть файл

@ -0,0 +1,86 @@
/**
* File Name: dowhile-006
* ECMA Section:
* Description: do...while statements
*
* A general do...while test.
*
* Author: christine@netscape.com
* Date: 26 August 1998
*/
var SECTION = "dowhile-006";
var VERSION = "ECMA_2";
var TITLE = "do...while";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
DoWhile( new DoWhileObject( false, false, 10 ) );
DoWhile( new DoWhileObject( true, false, 2 ) );
DoWhile( new DoWhileObject( false, true, 3 ) );
DoWhile( new DoWhileObject( true, true, 4 ) );
test();
function looping( object ) {
object.iterations--;
if ( object.iterations <= 0 ) {
return false;
} else {
return true;
}
}
function DoWhileObject( breakOut, breakIn, iterations, loops ) {
this.iterations = iterations;
this.loops = loops;
this.breakOut = breakOut;
this.breakIn = breakIn;
this.looping = looping;
}
function DoWhile( object ) {
var result1 = false;
var result2 = false;
outie: {
innie: {
do {
if ( object.breakOut )
break outie;
if ( object.breakIn )
break innie;
} while ( looping(object) );
// statements should be executed if:
// do...while exits normally
// do...while exits abruptly with no label
result1 = true;
}
// statements should be executed if:
// do...while breaks out with label "innie"
// do...while exits normally
// do...while does not break out with "outie"
result2 = true;
}
testcases[tc++] = new TestCase(
SECTION,
"hit code after loop in inner loop",
( object.breakIn || object.breakOut ) ? false : true ,
result1 );
testcases[tc++] = new TestCase(
SECTION,
"hit code after loop in outer loop",
( object.breakOut ) ? false : true,
result2 );
}

Просмотреть файл

@ -0,0 +1,94 @@
/**
* File Name: dowhile-007
* ECMA Section:
* Description: do...while statements
*
* A general do...while test.
*
* Author: christine@netscape.com
* Date: 26 August 1998
*/
var SECTION = "dowhile-007";
var VERSION = "ECMA_2";
var TITLE = "do...while";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
DoWhile( new DoWhileObject( false, false, false, false ));
DoWhile( new DoWhileObject( true, false, false, false ));
DoWhile( new DoWhileObject( true, true, false, false ));
DoWhile( new DoWhileObject( true, true, true, false ));
DoWhile( new DoWhileObject( true, true, true, true ));
DoWhile( new DoWhileObject( false, false, false, true ));
DoWhile( new DoWhileObject( false, false, true, true ));
DoWhile( new DoWhileObject( false, true, true, true ));
DoWhile( new DoWhileObject( false, false, true, false ));
test();
function DoWhileObject( out1, out2, out3, in1 ) {
this.breakOutOne = out1;
this.breakOutTwo = out2;
this.breakOutThree = out3;
this.breakIn = in1;
}
function DoWhile( object ) {
result1 = false;
result2 = false;
result3 = false;
result4 = false;
outie:
do {
if ( object.breakOutOne ) {
break outie;
}
result1 = true;
innie:
do {
if ( object.breakOutTwo ) {
break outie;
}
result2 = true;
if ( object.breakIn ) {
break innie;
}
result3 = true;
} while ( false );
if ( object.breakOutThree ) {
break outie;
}
result4 = true;
} while ( false );
testcases[tc++] = new TestCase(
SECTION,
"break one: ",
(object.breakOutOne) ? false : true,
result1 );
testcases[tc++] = new TestCase(
SECTION,
"break two: ",
(object.breakOutOne||object.breakOutTwo) ? false : true,
result2 );
testcases[tc++] = new TestCase(
SECTION,
"break three: ",
(object.breakOutOne||object.breakOutTwo||object.breakIn) ? false : true,
result3 );
testcases[tc++] = new TestCase(
SECTION,
"break four: ",
(object.breakOutOne||object.breakOutTwo||object.breakOutThree) ? false: true,
result4 );
}

Просмотреть файл

@ -0,0 +1,294 @@
/**
* File Name: forin-001.js
* ECMA Section:
* Description: The forin-001 statement
*
* Verify that the property name is assigned to the property on the left
* hand side of the for...in expression.
*
* Author: christine@netscape.com
* Date: 28 August 1998
*/
var SECTION = "forin-001";
var VERSION = "ECMA_2";
var TITLE = "The for...in statement";
var BUGNUMBER="330890";
var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=344855";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
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_7({ length:4, company:"netscape", year:2000, 0:"zero" });
ForIn_8({ length:4, company:"netscape", year:2000, 0:"zero" });
test();
/**
* Verify that the left side argument is evaluated with every iteration.
* Verify that the name of each property of the object is assigned to a
* a property.
*
*/
function ForIn_1( object ) {
PropertyArray = new Array();
ValueArray = new Array();
for ( PropertyArray[PropertyArray.length] in object ) {
ValueArray[ValueArray.length] =
object[PropertyArray[PropertyArray.length-1]];
}
for ( var i = 0; i < PropertyArray.length; i++ ) {
testcases[tc++] = new TestCase(
SECTION,
"object[" + PropertyArray[i] +"]",
object[PropertyArray[i]],
ValueArray[i]
);
}
testcases[tc++] = new TestCase(
SECTION,
"object.length",
PropertyArray.length,
object.length );
}
/**
* Similar to ForIn_1, except it should increment the counter variable
* every time the left hand expression is evaluated.
*/
function ForIn_2( object ) {
PropertyArray = new Array();
ValueArray = new Array();
var i = 0;
for ( PropertyArray[i++] in object ) {
ValueArray[ValueArray.length] =
object[PropertyArray[PropertyArray.length-1]];
}
for ( i = 0; i < PropertyArray.length; i++ ) {
testcases[tc++] = new TestCase(
SECTION,
"object[" + PropertyArray[i] +"]",
object[PropertyArray[i]],
ValueArray[i]
);
}
testcases[tc++] = new TestCase(
SECTION,
"object.length",
PropertyArray.length,
object.length );
}
/**
* Break out of a for...in loop
*
*
*/
function ForIn_3( object ) {
var checkBreak = "pass";
var properties = new Array();
var values = new Array();
for ( properties[properties.length] in object ) {
values[values.length] = object[properties[properties.length-1]];
break;
checkBreak = "fail";
}
testcases[tc++] = new TestCase(
SECTION,
"check break out of for...in",
"pass",
checkBreak );
testcases[tc++] = new TestCase(
SECTION,
"properties.length",
1,
properties.length );
testcases[tc++] = new TestCase(
SECTION,
"object["+properties[0]+"]",
values[0],
object[properties[0]] );
}
/**
* Break out of a labeled for...in loop.
*/
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 ( property[i++] in object ) {
result2++;
break;
result4++;
}
result3++;
}
testcases[tc++] = new TestCase(
SECTION,
"verify labeled statement is only executed once",
true,
result1 == 1 );
testcases[tc++] = new TestCase(
SECTION,
"verify statements in for loop are evaluated",
true,
result2 == i );
testcases[tc++] = new TestCase(
SECTION,
"verify break out of labeled for...in loop",
true,
result4 == 0 );
testcases[tc++] = new TestCase(
SECTION,
"verify break out of labeled block",
true,
result3 == 0 );
}
/**
* Labeled break out of a labeled for...in loop.
*/
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++] = new TestCase(
SECTION,
"verify labeled statement is only executed once",
true,
result1 == 1 );
testcases[tc++] = new TestCase(
SECTION,
"verify statements in for loop are evaluated",
true,
result2 == i );
testcases[tc++] = new TestCase(
SECTION,
"verify break out of labeled for...in loop",
true,
result4 == 0 );
testcases[tc++] = new TestCase(
SECTION,
"verify break out of labeled block",
true,
result3 == 0 );
}
/**
* Labeled continue from a labeled for...in loop
*/
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 ( property[i++] in object ) {
result2++;
continue bigredbird;
result4++;
}
testcases[tc++] = new TestCase(
SECTION,
"verify statements in for loop are evaluated",
true,
result2 == i );
testcases[tc++] = new TestCase(
SECTION,
"verify break out of labeled for...in loop",
true,
result4 == 0 );
testcases[tc++] = new TestCase(
SECTION,
"verify break out of labeled block",
true,
result3 == 1 );
}
/**
* continue in a for...in loop
*
*/
function ForIn_8( object ) {
var checkBreak = "pass";
var properties = new Array();
var values = new Array();
for ( properties[properties.length] in object ) {
values[values.length] = object[properties[properties.length-1]];
break;
checkBreak = "fail";
}
testcases[tc++] = new TestCase(
SECTION,
"check break out of for...in",
"pass",
checkBreak );
testcases[tc++] = new TestCase(
SECTION,
"properties.length",
1,
properties.length );
testcases[tc++] = new TestCase(
SECTION,
"object["+properties[0]+"]",
values[0],
object[properties[0]] );
}

Просмотреть файл

@ -0,0 +1,73 @@
/**
* File Name: forin-002.js
* ECMA Section:
* Description: The forin-001 statement
*
* Verify that the property name is assigned to the property on the left
* hand side of the for...in expression.
*
* Author: christine@netscape.com
* Date: 28 August 1998
*/
var SECTION = "forin-002";
var VERSION = "ECMA_2";
var TITLE = "The for...in statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
function MyObject( value ) {
this.value = value;
this.valueOf = new Function ( "return this.value" );
this.toString = new Function ( "return this.value + \"\"" );
this.toNumber = new Function ( "return this.value + 0" );
this.toBoolean = new Function ( "return Boolean( this.value )" );
}
ForIn_1(this);
ForIn_2(this);
ForIn_1(new MyObject(true));
ForIn_2(new MyObject(new Boolean(true)));
ForIn_2(3);
test();
/**
* For ... In in a With Block
*
*/
function ForIn_1( object) {
with ( object ) {
for ( property in object ) {
testcases[tc++] = new TestCase(
SECTION,
"with loop in a for...in loop. ("+object+")["+property +"] == "+
"eval ( " + property +" )",
true,
object[property] == eval(property) );
}
}
}
/**
* With block in a For...In loop
*
*/
function ForIn_2(object) {
for ( property in object ) {
with ( object ) {
testcases[tc++] = new TestCase(
SECTION,
"with loop in a for...in loop. ("+object+")["+property +"] == "+
"eval ( " + property +" )",
true,
object[property] == eval(property) );
}
}
}

Просмотреть файл

@ -0,0 +1,39 @@
/**
* File Name: if-001.js
* ECMA Section:
* Description: The if statement
*
* Verify that assignment in the if expression is evaluated correctly.
* Verifies the fix for bug http://scopus/bugsplat/show_bug.cgi?id=148822.
*
* Author: christine@netscape.com
* Date: 28 August 1998
*/
var SECTION = "for-001";
var VERSION = "ECMA_2";
var TITLE = "The if statement";
var BUGNUMBER="148822";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
var a = 0;
var b = 0;
var result = "passed";
if ( a = b ) {
result = "failed: a = b should return 0";
}
testcases[tc++] = new TestCase(
SECTION,
"if ( a = b ), where a and b are both equal to 0",
"passed",
result );
test();

Просмотреть файл

@ -0,0 +1,39 @@
/**
* File Name: label-001.js
* ECMA Section:
* Description: Labeled statements
*
* Labeled break and continue within a for loop.
*
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "label-003";
var VERSION = "ECMA_2";
var TITLE = "Labeled statements";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
LabelTest(0, 0);
LabelTest(1, 1)
LabelTest(-1, 1000);
LabelTest(false, 0);
LabelTest(true, 1);
test();
function LabelTest( limit, expect) {
woo: for ( var result = 0; result < 1000; result++ ) { if (result == limit) { break woo; } else { continue woo; } };
testcases[tc++] = new TestCase(
SECTION,
"break out of a labeled for loop: "+ limit,
expect,
result );
}

Просмотреть файл

@ -0,0 +1,53 @@
/**
* File Name: label-002.js
* ECMA Section:
* Description: Labeled statements
*
* Labeled break and continue within a for-in loop.
*
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "label-002";
var VERSION = "ECMA_2";
var TITLE = "Labeled statements";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
LabelTest( { p1:"hi,", p2:" norris" }, "hi, norris", "norrishi, " );
LabelTest( { 0:"zero", 1:"one" }, "zeroone", "onezero" );
LabelTest2( { p1:"hi,", p2:" norris" }, "hi," );
LabelTest2( { 0:"zero", 1:"one" }, "zero" );
test();
function LabelTest( object, expect1, expect2 ) {
result = "";
yoohoo: { for ( property in object ) { result += object[property]; }; break yoohoo };
testcases[tc++] = new TestCase(
SECTION,
"yoohoo: for ( property in object ) { result += object[property]; } break yoohoo }",
true,
result == expect1 || result == expect2 );
}
function LabelTest2( object, expect ) {
result = "";
yoohoo: { for ( property in object ) { result += object[property]; break yoohoo } }; ;
testcases[tc++] = new TestCase(
SECTION,
"yoohoo: for ( property in object ) { result += object[property]; break yoohoo }}",
expect,
result );
}

Просмотреть файл

@ -0,0 +1,64 @@
/**
* File Name: switch-001.js
* ECMA Section:
* Description: The switch Statement
*
* A simple switch test with no abrupt completions.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*
*/
var SECTION = "switch-001";
var VERSION = "ECMA_2";
var TITLE = "The switch statement";
var BUGNUMBER="315767";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
SwitchTest( 0, 126 );
SwitchTest( 1, 124 );
SwitchTest( 2, 120 );
SwitchTest( 3, 112 );
SwitchTest( 4, 64 );
SwitchTest( 5, 96 );
SwitchTest( true, 96 );
SwitchTest( false, 96 );
SwitchTest( null, 96 );
SwitchTest( void 0, 96 );
SwitchTest( "0", 96 );
test();
function SwitchTest( input, expect ) {
var result = 0;
switch ( input ) {
case 0:
result += 2;
case 1:
result += 4;
case 2:
result += 8;
case 3:
result += 16;
default:
result += 32;
case 4:
result +=64;
}
testcases[tc++] = new TestCase(
SECTION,
"switch with no breaks, case expressions are numbers. input is "+
input,
expect,
result );
}

Просмотреть файл

@ -0,0 +1,60 @@
/**
* File Name: switch-002.js
* ECMA Section:
* Description: The switch Statement
*
* A simple switch test with no abrupt completions.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*
*/
var SECTION = "switch-002";
var VERSION = "ECMA_2";
var TITLE = "The switch statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
SwitchTest( 0, 6 );
SwitchTest( 1, 4 );
SwitchTest( 2, 56 );
SwitchTest( 3, 48 );
SwitchTest( 4, 64 );
SwitchTest( true, 32 );
SwitchTest( false, 32 );
SwitchTest( null, 32 );
SwitchTest( void 0, 32 );
SwitchTest( "0", 32 );
test();
function SwitchTest( input, expect ) {
var result = 0;
switch ( input ) {
case 0:
result += 2;
case 1:
result += 4;
break;
case 2:
result += 8;
case 3:
result += 16;
default:
result += 32;
break;
case 4:
result += 64;
}
testcases[tc++] = new TestCase(
SECTION,
"switch with no breaks: input is " + input,
expect,
result );
}

Просмотреть файл

@ -0,0 +1,54 @@
/**
* File Name: switch-003.js
* ECMA Section:
* Description: The switch Statement
*
* Attempt to verify that case statements are evaluated in source order
*
* Author: christine@netscape.com
* Date: 11 August 1998
*
*/
var SECTION = "switch-003";
var VERSION = "ECMA_2";
var TITLE = "The switch statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
SwitchTest( "a", "abc" );
SwitchTest( "b", "bc" );
SwitchTest( "c", "c" );
SwitchTest( "d", "*abc" );
SwitchTest( "v", "*abc" );
SwitchTest( "w", "w*abc" );
SwitchTest( "x", "xw*abc" );
SwitchTest( "y", "yxw*abc" );
SwitchTest( "z", "zyxw*abc" );
// SwitchTest( new java.lang.String("z"), "*abc" );
test();
function SwitchTest( input, expect ) {
var result = "";
switch ( input ) {
case "z": result += "z";
case "y": result += "y";
case "x": result += "x";
case "w": result += "w";
default: result += "*";
case "a": result += "a";
case "b": result += "b";
case "c": result += "c";
}
testcases[tc++] = new TestCase(
SECTION,
"switch with no breaks: input is " + input,
expect,
result );
}

Просмотреть файл

@ -0,0 +1,91 @@
/**
* File Name: switch-003.js
* ECMA Section:
* Description: The switch Statement
*
* This uses variables and objects as case expressions in switch statements.
* This verifies a bunch of bugs:
*
* http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315988
* http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315975
* http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315954
*
* Author: christine@netscape.com
* Date: 11 August 1998
*
*/
var SECTION = "switch-003";
var VERSION = "ECMA_2";
var TITLE = "The switch statement";
var BUGNUMBER= "315988";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
ONE = new Number(1);
ZERO = new Number(0);
var A = new String("A");
var B = new String("B");
TRUE = new Boolean( true );
FALSE = new Boolean( false );
UNDEFINED = void 0;
NULL = null;
SwitchTest( ZERO, "ZERO" );
SwitchTest( NULL, "NULL" );
SwitchTest( UNDEFINED, "UNDEFINED" );
SwitchTest( FALSE, "FALSE" );
SwitchTest( false, "false" );
SwitchTest( 0, "0" );
SwitchTest ( TRUE, "TRUE" );
SwitchTest( 1, "1" );
SwitchTest( ONE, "ONE" );
SwitchTest( true, "true" );
SwitchTest( "a", "a" );
SwitchTest( A, "A" );
SwitchTest( "b", "b" );
SwitchTest( B, "B" );
SwitchTest( new Boolean( true ), "default" );
SwitchTest( new Boolean(false ), "default" );
SwitchTest( new String( "A" ), "default" );
SwitchTest( new Number( 0 ), "default" );
test();
function SwitchTest( input, expect ) {
var result = "";
switch ( input ) {
default: result += "default"; break;
case "a": result += "a"; break;
case "b": result += "b"; break;
case A: result += "A"; break;
case B: result += "B"; break;
case new Boolean(true): result += "new TRUE"; break;
case new Boolean(false): result += "new FALSE"; break;
case NULL: result += "NULL"; break;
case UNDEFINED: result += "UNDEFINED"; break;
case true: result += "true"; break;
case false: result += "false"; break;
case TRUE: result += "TRUE"; break;
case FALSE: result += "FALSE"; break;
case 0: result += "0"; break;
case 1: result += "1"; break;
case new Number(0) : result += "new ZERO"; break;
case new Number(1) : result += "new ONE"; break;
case ONE: result += "ONE"; break;
case ZERO: result += "ZERO"; break;
}
testcases[tc++] = new TestCase(
SECTION,
"switch with no breaks: input is " + input,
expect,
result );
}

Просмотреть файл

@ -0,0 +1,82 @@
/**
* File Name: try-001.js
* ECMA Section:
* Description: The try statement
*
* This test contains try, catch, and finally blocks. An exception is
* sometimes thrown by a function called from within the try block.
*
* This test doesn't actually make any LiveConnect calls.
*
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "";
var VERSION = "ECMA_2";
var TITLE = "The try statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
var INVALID_JAVA_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor";
TryNewJavaInteger( "3.14159", INVALID_JAVA_INTEGER_VALUE );
TryNewJavaInteger( NaN, INVALID_JAVA_INTEGER_VALUE );
TryNewJavaInteger( 0, 0 );
TryNewJavaInteger( -1, -1 );
TryNewJavaInteger( 1, 1 );
TryNewJavaInteger( Infinity, Infinity );
test();
/**
* Check to see if the input is valid for java.lang.Integer. If it is
* not valid, throw INVALID_JAVA_INTEGER_VALUE. If input is valid,
* return Number( v )
*
*/
function newJavaInteger( v ) {
value = Number( v );
if ( Math.floor(value) != value || isNaN(value) ) {
throw ( INVALID_JAVA_INTEGER_VALUE );
} else {
return value;
}
}
/**
* Call newJavaInteger( value ) from within a try block. Catch any
* exception, and store it in result. Verify that we got the right
* return value from newJavaInteger in cases in which we do not expect
* exceptions, and that we got the exception in cases where an exception
* was expected.
*/
function TryNewJavaInteger( value, expect ) {
var finalTest = false;
try {
result = newJavaInteger( value );
} catch ( e ) {
result = String( e );
} finally {
finalTest = true;
}
testcases[tc++] = new TestCase(
SECTION,
"newJavaValue( " + value +" )",
expect,
result);
testcases[tc++] = new TestCase(
SECTION,
"newJavaValue( " + value +" ) hit finally block",
true,
finalTest);
}

Просмотреть файл

@ -0,0 +1,79 @@
/**
* File Name: try-003.js
* ECMA Section:
* Description: The try statement
*
* This test has a try with no catch, and a finally.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "try-003";
var VERSION = "ECMA_2";
var TITLE = "The try statement";
var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=313585";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
// Tests start here.
TrySomething( "x = \"hi\"", false );
TrySomething( "throw \"boo\"", true );
TrySomething( "throw 3", true );
test();
/**
* This function contains a try block with no catch block,
* but it does have a finally block. Try to evaluate expressions
* that do and do not throw exceptions.
*/
function TrySomething( expression, throwing ) {
innerFinally = "FAIL: DID NOT HIT INNER FINALLY BLOCK";
if (throwing) {
outerCatch = "FAILED: NO EXCEPTION CAUGHT";
} else {
outerCatch = "PASS";
}
outerFinally = "FAIL: DID NOT HIT OUTER FINALLY BLOCK";
try {
try {
eval( expression );
} finally {
innerFinally = "PASS";
}
} catch ( e ) {
if (throwing) {
outerCatch = "PASS";
} else {
outerCatch = "FAIL: HIT OUTER CATCH BLOCK";
}
} finally {
outerFinally = "PASS";
}
testcases[tc++] = new TestCase(
SECTION,
"eval( " + expression +" )",
"PASS",
innerFinally );
testcases[tc++] = new TestCase(
SECTION,
"eval( " + expression +" )",
"PASS",
outerCatch );
testcases[tc++] = new TestCase(
SECTION,
"eval( " + expression +" )",
"PASS",
outerFinally );
}

Просмотреть файл

@ -0,0 +1,51 @@
/**
* File Name: try-004.js
* ECMA Section:
* Description: The try statement
*
* This test has a try with one catch block but no finally.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "try-004";
var VERSION = "ECMA_2";
var TITLE = "The try statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
TryToCatch( "Math.PI", Math.PI );
TryToCatch( "Thrower(5)", "Caught 5" );
TryToCatch( "Thrower(\"some random exception\")", "Caught some random exception" );
test();
function Thrower( v ) {
throw "Caught " + v;
}
/**
* Evaluate a string. Catch any exceptions thrown. If no exception is
* expected, verify the result of the evaluation. If an exception is
* expected, verify that we got the right exception.
*/
function TryToCatch( value, expect ) {
try {
result = eval( value );
} catch ( e ) {
result = e;
}
testcases[tc++] = new TestCase(
SECTION,
"eval( " + value +" )",
expect,
result );
}

Просмотреть файл

@ -0,0 +1,54 @@
/**
* File Name: try-005.js
* ECMA Section:
* Description: The try statement
*
* This test has a try with one catch block but no finally. Same
* as try-004, but the eval statement is called from a function, not
* directly from within the try block.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "try-005";
var VERSION = "ECMA_2";
var TITLE = "The try statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
TryToCatch( "Math.PI", Math.PI );
TryToCatch( "Thrower(5)", "Caught 5" );
TryToCatch( "Thrower(\"some random exception\")", "Caught some random exception" );
test();
function Thrower( v ) {
throw "Caught " + v;
}
function Eval( v ) {
return eval( v );
}
/**
* Evaluate a string. Catch any exceptions thrown. If no exception is
* expected, verify the result of the evaluation. If an exception is
* expected, verify that we got the right exception.
*/
function TryToCatch( value, expect ) {
try {
result = Eval( value );
} catch ( e ) {
result = e;
}
testcases[tc++] = new TestCase(
SECTION,
"eval( " + value +" )",
expect,
result );
}

Просмотреть файл

@ -0,0 +1,84 @@
/**
* File Name: try-006.js
* ECMA Section:
* Description: The try statement
*
* Throw an exception from within a With block in a try block. Verify
* that any expected exceptions are caught.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "try-006";
var VERSION = "ECMA_2";
var TITLE = "The try statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
/**
* This is the "check" function for test objects that will
* throw an exception.
*/
function throwException() {
throw EXCEPTION_STRING +": " + this.valueOf();
}
var EXCEPTION_STRING = "Exception thrown:";
/**
* This is the "check" function for test objects that do not
* throw an exception
*/
function noException() {
return this.valueOf();
}
/**
* Add test cases here
*/
TryWith( new TryObject( "hello", throwException, true ));
TryWith( new TryObject( "hola", noException, false ));
/**
* Run the test.
*/
test();
/**
* This is the object that will be the "this" in a with block.
*/
function TryObject( value, fun, exception ) {
this.value = value;
this.exception = exception;
this.valueOf = new Function ( "return this.value" );
this.check = fun;
}
/**
* This function has the try block that has a with block within it.
* Test cases are added in this function. Within the with block, the
* object's "check" function is called. If the test object's exception
* property is true, we expect the result to be the exception value.
* If exception is false, then we expect the result to be the value of
* the object.
*/
function TryWith( object ) {
try {
with ( object ) {
result = check();
}
} catch ( e ) {
result = e;
}
testcases[tc++] = new TestCase(
SECTION,
"TryWith( " + object.value +" )",
(object.exception ? EXCEPTION_STRING +": " + object.valueOf() : object.valueOf()),
result );
}

Просмотреть файл

@ -0,0 +1,89 @@
/**
* File Name: try-007.js
* ECMA Section:
* Description: The try statement
*
* This test has a for-in statement within a try block.
*
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "try-007";
var VERSION = "ECMA_2";
var TITLE = "The try statement: for-in";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
/**
* This is the "check" function for test objects that will
* throw an exception.
*/
function throwException() {
throw EXCEPTION_STRING +": " + this.valueOf();
}
var EXCEPTION_STRING = "Exception thrown:";
/**
* This is the "check" function for test objects that do not
* throw an exception
*/
function noException() {
return this.valueOf();
}
/**
* Add test cases here
*/
TryForIn( new TryObject( "hello", throwException, true ));
TryForIn( new TryObject( "hola", noException, false ));
/**
* Run the test.
*/
test();
/**
* This is the object that will be the "this" in a with block.
* The check function is either throwExeption() or noException().
* See above.
*
*/
function TryObject( value, fun, exception ) {
this.value = value;
this.exception = exception;
this.check = fun;
this.valueOf = function () { return this.value; }
}
/**
* This function has a for-in statement within a try block. Test cases
* are added after the try-catch-finally statement. Within the for-in
* block, call a function that can throw an exception. Verify that any
* exceptions are properly caught.
*/
function TryForIn( object ) {
try {
for ( p in object ) {
if ( typeof object[p] == "function" ) {
result = object[p]();
}
}
} catch ( e ) {
result = e;
}
testcases[tc++] = new TestCase(
SECTION,
"TryForIn( " + object+ " )",
(object.exception ? EXCEPTION_STRING +": " + object.value : object.value),
result );
}

Просмотреть файл

@ -0,0 +1,56 @@
/**
* File Name: try-008.js
* ECMA Section:
* Description: The try statement
*
* This test has a try block in a constructor.
*
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "try-008";
var VERSION = "ECMA_2";
var TITLE = "The try statement: try in a constructor";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
function Integer( value, exception ) {
try {
this.value = checkValue( value );
} catch ( e ) {
this.value = e.toString();
}
testcases[tc++] = new TestCase(
SECTION,
"Integer( " + value +" )",
(exception ? INVALID_INTEGER_VALUE +": " + value : this.value),
this.value );
}
var INVALID_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor";
function checkValue( value ) {
if ( Math.floor(value) != value || isNaN(value) ) {
throw ( INVALID_INTEGER_VALUE +": " + value );
} else {
return value;
}
}
// add test cases
new Integer( 3, false );
new Integer( NaN, true );
new Integer( 0, false );
new Integer( Infinity, false );
new Integer( -2.12, true );
new Integer( Math.LN2, true );
test();

Просмотреть файл

@ -0,0 +1,63 @@
/**
* File Name: try-009.js
* ECMA Section:
* Description: The try statement
*
* This test has a try block within a while block. Verify that an exception
* breaks out of the while. I don't really know why this is an interesting
* test case but Mike Shaver had two of these so what the hey.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "try-009";
var VERSION = "ECMA_2";
var TITLE = "The try statement: try in a while block";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
var EXCEPTION_STRING = "Exception thrown: ";
var NO_EXCEPTION_STRING = "No exception thrown: ";
TryInWhile( new TryObject( "hello", ThrowException, true ) );
TryInWhile( new TryObject( "aloha", NoException, false ));
test();
function TryObject( value, throwFunction, result ) {
this.value = value;
this.thrower = throwFunction;
this.result = result;
}
function ThrowException() {
throw EXCEPTION_STRING + this.value;
}
function NoException() {
return NO_EXCEPTION_STRING + this.value;
}
function TryInWhile( object ) {
result = null;
while ( true ) {
try {
object.thrower();
result = NO_EXCEPTION_STRING + object.value;
break;
} catch ( e ) {
result = e;
break;
}
}
testcases[tc++] = new TestCase(
SECTION,
"( "+ object +".thrower() )",
(object.result
? EXCEPTION_STRING + object.value :
NO_EXCEPTION_STRING + object.value),
result );
}

Просмотреть файл

@ -0,0 +1,70 @@
/**
* File Name: try-010.js
* ECMA Section:
* Description: The try statement
*
* This has a try block nested in the try block. Verify that the
* exception is caught by the right try block, and all finally blocks
* are executed.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "try-010";
var VERSION = "ECMA_2";
var TITLE = "The try statement: try in a tryblock";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
var EXCEPTION_STRING = "Exception thrown: ";
var NO_EXCEPTION_STRING = "No exception thrown: ";
NestedTry( new TryObject( "No Exceptions Thrown", NoException, NoException, 43 ) );
NestedTry( new TryObject( "Throw Exception in Outer Try", ThrowException, NoException, 48 ));
NestedTry( new TryObject( "Throw Exception in Inner Try", NoException, ThrowException, 45 ));
NestedTry( new TryObject( "Throw Exception in Both Trys", ThrowException, ThrowException, 48 ));
test();
function TryObject( description, tryOne, tryTwo, result ) {
this.description = description;
this.tryOne = tryOne;
this.tryTwo = tryTwo;
this.result = result;
}
function ThrowException() {
throw EXCEPTION_STRING + this.value;
}
function NoException() {
return NO_EXCEPTION_STRING + this.value;
}
function NestedTry( object ) {
result = 0;
try {
object.tryOne();
result += 1;
try {
object.tryTwo();
result += 2;
} catch ( e ) {
result +=4;
} finally {
result += 8;
}
} catch ( e ) {
result += 16;
} finally {
result += 32;
}
testcases[tc++] = new TestCase(
SECTION,
object.description,
object.result,
result );
}

Просмотреть файл

@ -0,0 +1,92 @@
/**
* File Name: try-012.js
* ECMA Section:
* Description: The try statement
*
* This test has a try with no catch, and a finally. This is like try-003,
* but throws from a finally block, not the try block.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "try-012";
var VERSION = "ECMA_2";
var TITLE = "The try statement";
var BUGNUMBER="336872";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
// Tests start here.
TrySomething( "x = \"hi\"", true );
TrySomething( "throw \"boo\"", true );
TrySomething( "throw 3", true );
test();
/**
* This function contains a try block with no catch block,
* but it does have a finally block. Try to evaluate expressions
* that do and do not throw exceptions.
*
* The productioni TryStatement Block Finally is evaluated as follows:
* 1. Evaluate Block
* 2. Evaluate Finally
* 3. If Result(2).type is normal return result 1 (in the test case, result 1 has
* the completion type throw)
* 4. return result 2 (does not get hit in this case)
*
*/
function TrySomething( expression, throwing ) {
innerFinally = "FAIL: DID NOT HIT INNER FINALLY BLOCK";
if (throwing) {
outerCatch = "FAILED: NO EXCEPTION CAUGHT";
} else {
outerCatch = "PASS";
}
outerFinally = "FAIL: DID NOT HIT OUTER FINALLY BLOCK";
// If the inner finally does not throw an exception, the result
// of the try block should be returned. (Type of inner return
// value should be throw if finally executes correctly
try {
try {
throw 0;
} finally {
innerFinally = "PASS";
eval( expression );
}
} catch ( e ) {
if (throwing) {
outerCatch = "PASS";
} else {
outerCatch = "FAIL: HIT OUTER CATCH BLOCK";
}
} finally {
outerFinally = "PASS";
}
testcases[tc++] = new TestCase(
SECTION,
"eval( " + expression +" ): evaluated inner finally block",
"PASS",
innerFinally );
testcases[tc++] = new TestCase(
SECTION,
"eval( " + expression +" ): evaluated outer catch block ",
"PASS",
outerCatch );
testcases[tc++] = new TestCase(
SECTION,
"eval( " + expression +" ): evaluated outer finally block",
"PASS",
outerFinally );
}

Просмотреть файл

@ -0,0 +1,39 @@
/**
* File Name: while-001
* ECMA Section:
* Description: while statement
*
* Verify that the while statement is not executed if the while expression is
* false
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "while-001";
var VERSION = "ECMA_2";
var TITLE = "while statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
DoWhile();
test();
function DoWhile() {
result = "pass";
while (false) {
result = "fail";
break;
}
testcases[tc++] = new TestCase(
SECTION,
"while statement: don't evaluate statement is expression is false",
"pass",
result );
}

Просмотреть файл

@ -0,0 +1,83 @@
/**
* File Name: while-002
* ECMA Section:
* Description: while statement
*
* Verify that the while statement is not executed if the while expression is
* false
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "while-002";
var VERSION = "ECMA_2";
var TITLE = "while statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
DoWhile( new DoWhileObject(
"while expression is null",
null,
"result = \"fail: should not have evaluated statements in while block;break"
) );
DoWhile( new DoWhileObject(
"while expression is undefined",
void 0,
"result = \"fail: should not have evaluated statements in while block; break"
));
DoWhile( new DoWhileObject(
"while expression is 0",
0,
"result = \"fail: should not have evaluated statements in while block; break;"
));
DoWhile( new DoWhileObject(
"while expression is eval(\"\")",
eval(""),
"result = \"fail: should not have evaluated statements in while block; break"
));
DoWhile( new DoWhileObject(
"while expression is NaN",
NaN,
"result = \"fail: should not have evaluated statements in while block; break"
));
test();
function DoWhileObject( d, e, s ) {
this.description = d;
this.whileExpression = e;
this.statements = s;
}
function DoWhile( object ) {
result = "pass";
while ( expression = object.whileExpression ) {
eval( object.statements );
}
// verify that the while expression was evaluated
testcases[tc++] = new TestCase(
SECTION,
"verify that while expression was evaluated (should be "+
object.whileExpression +")",
"pass",
(object.whileExpression == expression ||
( isNaN(object.whileExpression) && isNaN(expression) )
) ? "pass" : "fail" );
testcases[tc++] = new TestCase(
SECTION,
object.description,
"pass",
result );
}

Просмотреть файл

@ -0,0 +1,84 @@
/**
* File Name: while-003
* ECMA Section:
* Description: while statement
*
* The while expression evaluates to true, Statement returns abrupt completion.
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "while-003";
var VERSION = "ECMA_2";
var TITLE = "while statement";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
DoWhile( new DoWhileObject(
"while expression is true",
true,
"result = \"pass\";" ));
DoWhile( new DoWhileObject(
"while expression is 1",
1,
"result = \"pass\";" ));
DoWhile( new DoWhileObject(
"while expression is new Boolean(false)",
new Boolean(false),
"result = \"pass\";" ));
DoWhile( new DoWhileObject(
"while expression is new Object()",
new Object(),
"result = \"pass\";" ));
DoWhile( new DoWhileObject(
"while expression is \"hi\"",
"hi",
"result = \"pass\";" ));
/*
DoWhile( new DoWhileObject(
"while expression has a continue in it",
"true",
"if ( i == void 0 ) i = 0; result=\"pass\"; if ( ++i == 1 ) {continue;} else {break;} result=\"fail\";"
));
*/
test();
function DoWhileObject( d, e, s ) {
this.description = d;
this.whileExpression = e;
this.statements = s;
}
function DoWhile( object ) {
result = "fail: statements in while block were not evaluated";
while ( expression = object.whileExpression ) {
eval( object.statements );
break;
}
// verify that the while expression was evaluated
testcases[tc++] = new TestCase(
SECTION,
"verify that while expression was evaluated (should be "+
object.whileExpression +")",
"pass",
(object.whileExpression == expression ||
( isNaN(object.whileExpression) && isNaN(expression) )
) ? "pass" : "fail" );
testcases[tc++] = new TestCase(
SECTION,
object.description,
"pass",
result );
}

Просмотреть файл

@ -0,0 +1,214 @@
/**
* File Name: while-004
* ECMA Section:
* Description: while statement
*
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "while-004";
var VERSION = "ECMA_2";
var TITLE = "while statement";
var BUGNUMBER="316725";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var tc = 0;
var testcases = new Array();
DoWhile_1();
DoWhile_2();
DoWhile_3();
DoWhile_4();
DoWhile_5();
test();
/**
* Break out of a while by calling return.
*
* Tests: 12.6.2 step 6.
*/
function DoWhile_1() {
description = "return statement in a while block";
result = dowhile();
function dowhile() {
result = "pass";
while (true) {
return result;
result = "fail: hit code after return statement";
break;
}
}
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_1" + description,
"pass",
result );
}
/**
* While with a labeled continue statement. Verify that statements
* after the continue statement are not evaluated.
*
* Tests: 12.6.2 step 8.
*
*/
function DoWhile_2() {
var description = "while with a labeled continue statement";
var result1 = "pass";
var result2 = "fail: did not execute code after loop, but inside label";
var i = 0;
var j = 0;
theloop:
while( i++ < 10 ) {
j++;
continue theloop;
result1 = "failed: hit code after continue statement";
}
result2 = "pass";
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_2: " +description + " - code inside the loop, before the continue should be executed ("+j+")",
true,
j == 10 );
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_2: " +description +" - code after labeled continue should not be executed",
"pass",
result1 );
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_2: " +description +" - code after loop but inside label should be executed",
"pass",
result2 );
}
/**
* While with a labeled break.
*
*/
function DoWhile_3() {
var description = "while with a labeled break statement";
var result1 = "pass";
var result2 = "pass";
var result3 = "fail: did not get to code after label";
woohoo: {
while( true ) {
break woohoo;
result1 = "fail: got to code after a break";
}
result2 = "fail: got to code outside of loop but inside label";
}
result3 = "pass";
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_3: " +description +" - verify break out of loop",
"pass",
result1 );
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_3: " +description +" - verify break out of label",
"pass",
result2 );
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_3: " +description + " - verify correct exit from label",
"pass",
result3 );
}
/**
* Labled while with an unlabeled break
*
*/
function DoWhile_4() {
var description = "labeled while with an unlabeled break";
var result1 = "pass";
var result2 = "pass";
var result3 = "fail: did not evaluate statement after label";
woohooboy: {
while( true ) {
break woohooboy;
result1 = "fail: got to code after the break";
}
result2 = "fail: broke out of while, but not out of label";
}
result3 = "pass";
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_4: " +description +" - verify break out of while loop",
"pass",
result1 );
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_4: " +description + " - verify break out of label",
"pass",
result2 );
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_4: " +description +" - verify that statements after label are evaluated",
"pass",
result3 );
}
/**
* in this case, should behave the same way as
*
*
*/
function DoWhile_5() {
var description = "while with a labeled continue statement";
var result1 = "pass";
var result2 = "fail: did not execute code after loop, but inside label";
var i = 0;
var j = 0;
theloop: {
j++;
while( i++ < 10 ) {
continue;
result1 = "failed: hit code after continue statement";
}
result2 = "pass";
}
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_5: " +description + " - continue should not execute statements above the loop",
true,
( j == 1 ) );
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_5: " +description +" - code after labeled continue should not be executed",
"pass",
result1 );
testcases[tc++] = new TestCase(
SECTION,
"DoWhile_5: " +description +" - code after loop but inside label should be executed",
"pass",
result2 );
}

Просмотреть файл

@ -0,0 +1,100 @@
/**
* File Name: String/match-001.js
* ECMA Section: 15.6.4.9
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
/*
* String.match( regexp )
*
* If regexp is not an object of type RegExp, it is replaced with result
* of the expression new RegExp(regexp). Let string denote the result of
* converting the this value to a string. If regexp.global is false,
* return the result obtained by invoking RegExp.prototype.exec (see
* section 15.7.5.3) on regexp with string as parameter.
*
* Otherwise, set the regexp.lastIndex property to 0 and invoke
* RegExp.prototype.exec repeatedly until there is no match. If there is a
* match with an empty string (in other words, if the value of
* regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1.
* The value returned is an array with the properties 0 through n-1
* corresponding to the first element of the result of each matching
* invocation of RegExp.prototype.exec.
*
* Note that the match function is intentionally generic; it does not
* require that its this value be a string object. Therefore, it can be
* transferred to other kinds of objects for use as a method.
*/
var SECTION = "String/match-001.js";
var VERSION = "ECMA_2";
var TITLE = "String.prototype.match( regexp )";
startTest();
// the regexp argument is not a RegExp object
// this is not a string object
// cases in which the regexp global property is false
AddRegExpCases( 3, "3", "1234567890", 1, 2, ["3"] );
// cases in which the regexp object global property is true
AddGlobalRegExpCases( /34/g, "/34/g", "343443444", 3, ["34", "34", "34"] );
AddGlobalRegExpCases( /\d{1}/g, "/d{1}/g", "123456abcde7890", 10,
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] );
AddGlobalRegExpCases( /\d{2}/g, "/d{2}/g", "123456abcde7890", 5,
["12", "34", "56", "78", "90"] );
AddGlobalRegExpCases( /\D{2}/g, "/d{2}/g", "123456abcde7890", 2,
["ab", "cd"] );
test();
function AddRegExpCases(
regexp, str_regexp, string, length, index, matches_array ) {
AddTestCase(
"( " + string + " ).match(" + str_regexp +").length",
length,
string.match(regexp).length );
AddTestCase(
"( " + string + " ).match(" + str_regexp +").index",
index,
string.match(regexp).index );
AddTestCase(
"( " + string + " ).match(" + str_regexp +").input",
string,
string.match(regexp).input );
for ( var matches = 0; matches < matches_array.length; matches++ ) {
AddTestCase(
"( " + string + " ).match(" + str_regexp +")[" + matches +"]",
matches_array[matches],
string.match(regexp)[matches] );
}
}
function AddGlobalRegExpCases(
regexp, str_regexp, string, length, matches_array ) {
AddTestCase(
"( " + string + " ).match(" + str_regexp +").length",
length,
string.match(regexp).length );
for ( var matches = 0; matches < matches_array.length; matches++ ) {
AddTestCase(
"( " + string + " ).match(" + str_regexp +")[" + matches +"]",
matches_array[matches],
string.match(regexp)[matches] );
}
}

Просмотреть файл

@ -0,0 +1,168 @@
/**
* File Name: String/match-002.js
* ECMA Section: 15.6.4.9
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
/*
* String.match( regexp )
*
* If regexp is not an object of type RegExp, it is replaced with result
* of the expression new RegExp(regexp). Let string denote the result of
* converting the this value to a string. If regexp.global is false,
* return the result obtained by invoking RegExp.prototype.exec (see
* section 15.7.5.3) on regexp with string as parameter.
*
* Otherwise, set the regexp.lastIndex property to 0 and invoke
* RegExp.prototype.exec repeatedly until there is no match. If there is a
* match with an empty string (in other words, if the value of
* regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1.
* The value returned is an array with the properties 0 through n-1
* corresponding to the first element of the result of each matching
* invocation of RegExp.prototype.exec.
*
* Note that the match function is intentionally generic; it does not
* require that its this value be a string object. Therefore, it can be
* transferred to other kinds of objects for use as a method.
*
* This file tests cases in which regexp.global is false. Therefore,
* results should behave as regexp.exec with string passed as a parameter.
*
*/
var SECTION = "String/match-002.js";
var VERSION = "ECMA_2";
var TITLE = "String.prototype.match( regexp )";
startTest();
// the regexp argument is not a RegExp object
// this is not a string object
AddRegExpCases( /([\d]{5})([-\ ]?[\d]{4})?$/,
"/([\d]{5})([-\ ]?[\d]{4})?$/",
"Boston, Mass. 02134",
14,
["02134", "02134"]);
AddGlobalRegExpCases( /([\d]{5})([-\ ]?[\d]{4})?$/g,
"/([\d]{5})([-\ ]?[\d]{4})?$/g",
"Boston, Mass. 02134",
["02134", ]);
// set the value of lastIndex
re = /([\d]{5})([-\ ]?[\d]{4})?$/;
re.lastIndex = 0;
s = "Boston, MA 02134";
AddRegExpCases( re,
"re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex =0",
s,
s.lastIndexOf("0"),
["02134", ]);
re.lastIndex = s.length;
AddRegExpCases( re,
"re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
s.length,
s,
s.lastIndexOf("0"),
null );
re.lastIndex = s.lastIndexOf("0");
AddRegExpCases( re,
"re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
s.lastIndexOf("0"),
s,
s.lastIndexOf("0"),
["02134"]);
re.lastIndex = s.lastIndexOf("0") + 1;
AddRegExpCases( re,
"re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
s.lastIndexOf("0") +1,
s,
0,
null);
test();
function AddRegExpCases(
regexp, str_regexp, string, index, matches_array ) {
// prevent a runtime error
if ( regexp.exec(string) == null || matches_array == null ) {
AddTestCase(
string + ".match(" + regexp +")",
matches_array,
string.match(regexp) );
return;
}
AddTestCase(
"( " + string + " ).match(" + str_regexp +").length",
matches_array.length,
string.match(regexp).length );
AddTestCase(
"( " + string + " ).match(" + str_regexp +").index",
index,
string.match(regexp).index );
AddTestCase(
"( " + string + " ).match(" + str_regexp +").input",
string,
string.match(regexp).input );
var limit = matches_array.length > string.match(regexp).length ?
matches_array.length :
string.match(regexp).length;
for ( var matches = 0; matches < limit; matches++ ) {
AddTestCase(
"( " + string + " ).match(" + str_regexp +")[" + matches +"]",
matches_array[matches],
string.match(regexp)[matches] );
}
}
function AddGlobalRegExpCases(
regexp, str_regexp, string, matches_array ) {
// prevent a runtime error
if ( regexp.exec(string) == null || matches_array == null ) {
AddTestCase(
regexp + ".exec(" + string +")",
matches_array,
regexp.exec(string) );
return;
}
AddTestCase(
"( " + string + " ).match(" + str_regexp +").length",
matches_array.length,
string.match(regexp).length );
var limit = matches_array.length > string.match(regexp).length ?
matches_array.length :
string.match(regexp).length;
for ( var matches = 0; matches < limit; matches++ ) {
AddTestCase(
"( " + string + " ).match(" + str_regexp +")[" + matches +"]",
matches_array[matches],
string.match(regexp)[matches] );
}
}

Просмотреть файл

@ -0,0 +1,126 @@
/**
* File Name: String/match-003.js
* ECMA Section: 15.6.4.9
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
/*
* String.match( regexp )
*
* If regexp is not an object of type RegExp, it is replaced with result
* of the expression new RegExp(regexp). Let string denote the result of
* converting the this value to a string. If regexp.global is false,
* return the result obtained by invoking RegExp.prototype.exec (see
* section 15.7.5.3) on regexp with string as parameter.
*
* Otherwise, set the regexp.lastIndex property to 0 and invoke
* RegExp.prototype.exec repeatedly until there is no match. If there is a
* match with an empty string (in other words, if the value of
* regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1.
* The value returned is an array with the properties 0 through n-1
* corresponding to the first element of the result of each matching
* invocation of RegExp.prototype.exec.
*
* Note that the match function is intentionally generic; it does not
* require that its this value be a string object. Therefore, it can be
* transferred to other kinds of objects for use as a method.
*/
var SECTION = "String/match-003.js";
var VERSION = "ECMA_2";
var TITLE = "String.prototype.match( regexp )";
startTest();
// the regexp argument is not a RegExp object
// this is not a string object
// [if regexp.global is true] set the regexp.lastIndex property to 0 and
// invoke RegExp.prototype.exec repeatedly until there is no match. If
// there is a match with an empty string (in other words, if the value of
// regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1.
// The value returned is an array with the properties 0 through n-1
// corresponding to the first element of the result of each matching invocation
// of RegExp.prototype.exec.
// set the value of lastIndex
re = /([\d]{5})([-\ ]?[\d]{4})?$/g;
s = "Boston, MA 02134";
AddGlobalRegExpCases( re,
"re = " + re,
s,
["02134" ]);
re.lastIndex = 0;
AddGlobalRegExpCases(
re,
"re = " + re + "; re.lastIndex = 0 ",
s,
["02134"]);
re.lastIndex = s.length;
AddGlobalRegExpCases(
re,
"re = " + re + "; re.lastIndex = " + s.length,
s,
["02134"] );
re.lastIndex = s.lastIndexOf("0");
AddGlobalRegExpCases(
re,
"re = "+ re +"; re.lastIndex = " + s.lastIndexOf("0"),
s,
["02134"]);
re.lastIndex = s.lastIndexOf("0") + 1;
AddGlobalRegExpCases(
re,
"re = " +re+ "; re.lastIndex = " + (s.lastIndexOf("0") +1),
s,
["02134"]);
test();
function AddGlobalRegExpCases(
regexp, str_regexp, string, matches_array ) {
// prevent a runtime error
if ( string.match(regexp) == null || matches_array == null ) {
AddTestCase(
string + ".match(" + str_regexp +")",
matches_array,
string.match(regexp) );
return;
}
AddTestCase(
"( " + string + " ).match(" + str_regexp +").length",
matches_array.length,
string.match(regexp).length );
var limit = matches_array.length > string.match(regexp).length ?
matches_array.length :
string.match(regexp).length;
for ( var matches = 0; matches < limit; matches++ ) {
AddTestCase(
"( " + string + " ).match(" + str_regexp +")[" + matches +"]",
matches_array[matches],
string.match(regexp)[matches] );
}
}

Просмотреть файл

@ -0,0 +1,167 @@
/**
* File Name: String/match-004.js
* ECMA Section: 15.6.4.9
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
/*
* String.match( regexp )
*
* If regexp is not an object of type RegExp, it is replaced with result
* of the expression new RegExp(regexp). Let string denote the result of
* converting the this value to a string. If regexp.global is false,
* return the result obtained by invoking RegExp.prototype.exec (see
* section 15.7.5.3) on regexp with string as parameter.
*
* Otherwise, set the regexp.lastIndex property to 0 and invoke
* RegExp.prototype.exec repeatedly until there is no match. If there is a
* match with an empty string (in other words, if the value of
* regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1.
* The value returned is an array with the properties 0 through n-1
* corresponding to the first element of the result of each matching
* invocation of RegExp.prototype.exec.
*
* Note that the match function is intentionally generic; it does not
* require that its this value be a string object. Therefore, it can be
* transferred to other kinds of objects for use as a method.
*
*
* The match function should be intentionally generic, and not require
* this to be a string.
*
*/
var SECTION = "String/match-004.js";
var VERSION = "ECMA_2";
var TITLE = "String.prototype.match( regexp )";
var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=345818";
startTest();
// set the value of lastIndex
re = /0./;
s = 10203040506070809000;
Number.prototype.match = String.prototype.match;
AddRegExpCases( re,
"re = " + re ,
s,
String(s),
1,
["02"]);
re.lastIndex = 0;
AddRegExpCases( re,
"re = " + re +" [lastIndex is " + re.lastIndex+"]",
s,
String(s),
1,
["02"]);
/*
re.lastIndex = s.length;
AddRegExpCases( re,
"re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
s.length,
s,
s.lastIndexOf("0"),
null );
re.lastIndex = s.lastIndexOf("0");
AddRegExpCases( re,
"re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
s.lastIndexOf("0"),
s,
s.lastIndexOf("0"),
["02134"]);
re.lastIndex = s.lastIndexOf("0") + 1;
AddRegExpCases( re,
"re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
s.lastIndexOf("0") +1,
s,
0,
null);
*/
test();
function AddRegExpCases(
regexp, str_regexp, string, str_string, index, matches_array ) {
// prevent a runtime error
if ( regexp.exec(string) == null || matches_array == null ) {
AddTestCase(
string + ".match(" + regexp +")",
matches_array,
string.match(regexp) );
return;
}
AddTestCase(
"( " + string + " ).match(" + str_regexp +").length",
matches_array.length,
string.match(regexp).length );
AddTestCase(
"( " + string + " ).match(" + str_regexp +").index",
index,
string.match(regexp).index );
AddTestCase(
"( " + string + " ).match(" + str_regexp +").input",
string,
string.match(regexp).input );
var limit = matches_array.length > string.match(regexp).length ?
matches_array.length :
string.match(regexp).length;
for ( var matches = 0; matches < limit; matches++ ) {
AddTestCase(
"( " + string + " ).match(" + str_regexp +")[" + matches +"]",
matches_array[matches],
string.match(regexp)[matches] );
}
}
function AddGlobalRegExpCases(
regexp, str_regexp, string, matches_array ) {
// prevent a runtime error
if ( regexp.exec(string) == null || matches_array == null ) {
AddTestCase(
regexp + ".exec(" + string +")",
matches_array,
regexp.exec(string) );
return;
}
AddTestCase(
"( " + string + " ).match(" + str_regexp +").length",
matches_array.length,
string.match(regexp).length );
var limit = matches_array.length > string.match(regexp).length ?
matches_array.length :
string.match(regexp).length;
for ( var matches = 0; matches < limit; matches++ ) {
AddTestCase(
"( " + string + " ).match(" + str_regexp +")[" + matches +"]",
matches_array[matches],
string.match(regexp)[matches] );
}
}

Просмотреть файл

@ -0,0 +1,55 @@
/**
* File Name: String/replace-001.js
* ECMA Section: 15.6.4.10
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
var SECTION = "String/replace-001.js";
var VERSION = "ECMA_2";
var TITLE = "String.prototype.replace( regexp, replaceValue )";
startTest();
/*
* If regexp is not an object of type RegExp, it is replaced with the
* result of the expression new RegExp(regexp). Let string denote the
* result of converting the this value to a string. String is searched
* for the first occurrence of the regular expression pattern regexp if
* regexp.global is false, or all occurrences if regexp.global is true.
*
* The match is performed as in String.prototype.match, including the
* update of regexp.lastIndex. Let m be the number of matched
* parenthesized subexpressions as specified in section 15.7.5.3.
*
* If replaceValue is a function, then for each matched substring, call
* the function with the following m + 3 arguments. Argument 1 is the
* substring that matched. The next m arguments are all of the matched
* subexpressions. Argument m + 2 is the length of the left context, and
* argument m + 3 is string.
*
* The result is a string value derived from the original input by
* replacing each matched substring with the corresponding return value
* of the function call, converted to a string if need be.
*
* Otherwise, let newstring denote the result of converting replaceValue
* to a string. The result is a string value derived from the original
* input string by replacing each matched substring with a string derived
* from newstring by replacing characters in newstring by replacement text
* as specified in the following table:
*
* $& The matched substring.
* $ The portion of string that precedes the matched substring.
* $ The portion of string that follows the matched substring.
* $+ The substring matched by the last parenthesized subexpressions in
* the regular expression.
* $n The corresponding matched parenthesized subexpression n, where n
* is a single digit 0-9. If there are fewer than n subexpressions, $n
* is left unchanged.
*
* Note that the replace function is intentionally generic; it does not
* require that its this value be a string object. Therefore, it can be
* transferred to other kinds of objects for use as a method.
*/

Просмотреть файл

@ -0,0 +1,106 @@
/**
* File Name: String/split-001.js
* ECMA Section: 15.6.4.9
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
/*
* Since regular expressions have been part of JavaScript since 1.2, there
* are already tests for regular expressions in the js1_2/regexp folder.
*
* These new tests try to supplement the existing tests, and verify that
* our implementation of RegExp conforms to the ECMA specification, but
* does not try to be as exhaustive as in previous tests.
*
* The [,limit] argument to String.split is new, and not covered in any
* existing tests.
*
* String.split cases are covered in ecma/String/15.5.4.8-*.js.
* String.split where separator is a RegExp are in
* js1_2/regexp/string_split.js
*
*/
var SECTION = "ecma_2/String/split-001.js";
var VERSION = "ECMA_2";
var TITLE = "String.prototype.split( regexp, [,limit] )";
startTest();
// the separator is not supplied
// separator is undefined
// separator is an empty string
AddSplitCases( "splitme", "", "''", ["s", "p", "l", "i", "t", "m", "e"] );
AddSplitCases( "splitme", new RegExp(), "new RegExp()", ["s", "p", "l", "i", "t", "m", "e"] );
// separartor is a regexp
// separator regexp value global setting is set
// string is an empty string
// if separator is an empty string, split each by character
// this is not a String object
// limit is not a number
// limit is undefined
// limit is larger than 2^32-1
// limit is a negative number
test();
function AddSplitCases( string, separator, str_sep, split_array ) {
// verify that the result of split is an object of type Array
AddTestCase(
"( " + string + " ).split(" + str_sep +").constructor == Array",
true,
string.split(separator).constructor == Array );
// check the number of items in the array
AddTestCase(
"( " + string + " ).split(" + str_sep +").length",
split_array.length,
string.split(separator).length );
// check the value of each array item
var limit = (split_array.length > string.split(separator).length )
? split_array.length : string.split(separator).length;
for ( var matches = 0; matches < split_array.length; matches++ ) {
AddTestCase(
"( " + string + " ).split(" + str_sep +")[" + matches +"]",
split_array[matches],
string.split( separator )[matches] );
}
}
function AddLimitedSplitCases(
string, separator, str_sep, limit, str_limit, split_array ) {
// verify that the result of split is an object of type Array
AddTestCase(
"( " + string + " ).split(" + str_sep +", " + str_limit +
" ).constructor == Array",
true,
string.split(separator, limit).constructor == Array );
// check the length of the array
AddTestCase(
"( " + string + " ).split(" + str_sep +", " + str_limit + " ).length",
length,
string.split(separator).length );
// check the value of each array item
for ( var matches = 0; matches < split_array.length; matches++ ) {
AddTestCase(
"( " + string + " ).split(" + str_sep +", " + str_limit + " )[" + matches +"]",
split_array[matches],
string.split( separator )[matches] );
}
}

Просмотреть файл

@ -0,0 +1,257 @@
/**
* File Name: String/split-002.js
* ECMA Section: 15.6.4.9
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
/*
* Since regular expressions have been part of JavaScript since 1.2, there
* are already tests for regular expressions in the js1_2/regexp folder.
*
* These new tests try to supplement the existing tests, and verify that
* our implementation of RegExp conforms to the ECMA specification, but
* does not try to be as exhaustive as in previous tests.
*
* The [,limit] argument to String.split is new, and not covered in any
* existing tests.
*
* String.split cases are covered in ecma/String/15.5.4.8-*.js.
* String.split where separator is a RegExp are in
* js1_2/regexp/string_split.js
*
*/
var SECTION = "ecma_2/String/split-002.js";
var VERSION = "ECMA_2";
var TITLE = "String.prototype.split( regexp, [,limit] )";
startTest();
// the separator is not supplied
// separator is undefined
// separator is an empty string
// AddSplitCases( "splitme", "", "''", ["s", "p", "l", "i", "t", "m", "e"] );
// AddSplitCases( "splitme", new RegExp(), "new RegExp()", ["s", "p", "l", "i", "t", "m", "e"] );
// separator is an empty regexp
// separator is not supplied
CompareSplit( "hello", "ll" );
CompareSplit( "hello", "l" );
CompareSplit( "hello", "x" );
CompareSplit( "hello", "h" );
CompareSplit( "hello", "o" );
CompareSplit( "hello", "hello" );
CompareSplit( "hello", undefined );
CompareSplit( "hello", "");
CompareSplit( "hello", "hellothere" );
CompareSplit( new String("hello" ) );
Number.prototype.split = String.prototype.split;
CompareSplit( new Number(100111122133144155), 1 );
CompareSplitWithLimit(new Number(100111122133144155), 1, 1 );
CompareSplitWithLimit(new Number(100111122133144155), 1, 2 );
CompareSplitWithLimit(new Number(100111122133144155), 1, 0 );
CompareSplitWithLimit(new Number(100111122133144155), 1, 100 );
CompareSplitWithLimit(new Number(100111122133144155), 1, void 0 );
CompareSplitWithLimit(new Number(100111122133144155), 1, Math.pow(2,32)-1 );
CompareSplitWithLimit(new Number(100111122133144155), 1, "boo" );
CompareSplitWithLimit(new Number(100111122133144155), 1, -(Math.pow(2,32)-1) );
CompareSplitWithLimit( "hello", "l", NaN );
CompareSplitWithLimit( "hello", "l", 0 );
CompareSplitWithLimit( "hello", "l", 1 );
CompareSplitWithLimit( "hello", "l", 2 );
CompareSplitWithLimit( "hello", "l", 3 );
CompareSplitWithLimit( "hello", "l", 4 );
/*
CompareSplitWithLimit( "hello", "ll", 0 );
CompareSplitWithLimit( "hello", "ll", 1 );
CompareSplitWithLimit( "hello", "ll", 2 );
CompareSplit( "", " " );
CompareSplit( "" );
*/
// separartor is a regexp
// separator regexp value global setting is set
// string is an empty string
// if separator is an empty string, split each by character
// this is not a String object
// limit is not a number
// limit is undefined
// limit is larger than 2^32-1
// limit is a negative number
test();
function CompareSplit( string, separator ) {
split_1 = string.split( separator );
split_2 = string_split( string, separator );
AddTestCase(
"( " + string +".split(" + separator + ") ).length" ,
split_2.length,
split_1.length );
var limit = split_1.length > split_2.length ?
split_1.length : split_2.length;
for ( var split_item = 0; split_item < limit; split_item++ ) {
AddTestCase(
string + ".split(" + separator + ")["+split_item+"]",
split_2[split_item],
split_1[split_item] );
}
}
function CompareSplitWithLimit( string, separator, splitlimit ) {
split_1 = string.split( separator, splitlimit );
split_2 = string_split( string, separator, splitlimit );
AddTestCase(
"( " + string +".split(" + separator + ", " + splitlimit+") ).length" ,
split_2.length,
split_1.length );
var limit = split_1.length > split_2.length ?
split_1.length : split_2.length;
for ( var split_item = 0; split_item < limit; split_item++ ) {
AddTestCase(
string + ".split(" + separator + ", " + splitlimit+")["+split_item+"]",
split_2[split_item],
split_1[split_item] );
}
}
function string_split ( __this, separator, limit ) {
var result_1 = String(__this ); // 1
var A = new Array(); // 2
if ( separator == undefined ) { // 3
A[0] = result_1;
return A;
}
if ( limit == undefined ) { // 4
result_4 = Math.pow(2, 31 ) -1;
} else {
result_4 = ToUint32( limit );
}
var result_5 = result_1.length; // 5
var p = 0; // 6
if ( separator.constructor == RegExp ) { // 7
return goto_step_16( p, result_1, A, separator );
}
var result_8 = String(separator); // 8
var result_9 = result_8.length; // 9
while ( true ) { // 10, 11, 15
if ( A.length == result_4 ) {
return A;
}
var found_separator = false;
for ( k = p;
;
k++ )
{
if ( k + result_9 <= p && k + result_9 <= result_5 ) {
found_separator = true; // pattern is the empty string
continue;
}
if ( k + result_9 > result_5 ) {
found_separator = false;
break;
}
for ( j = 0; j < result_9; j++ ) {
if ( result_1.charAt( k + j ) != result_8.charAt( j ) ) {
found_separator = false;
break;
} else {
found_separator = true;
}
}
if ( found_separator ) {
break;
}
}
if ( !found_separator ) {
return goto_step_22( p, result_1, A );
} else {
result_12 = result_1.substring( p, k ); // 12
A[A.length] = result_12; // 13
}
p = k + result_9; // 14
}
function goto_step_10(p, result_1, A, regexp ) {
}
function goto_step_16(p, result_1, A, regexp ) {
while ( true ) {
if ( A.length == result_4 ) { // 16
return A;
}
// 17
for ( k = p; k < result_1.length; k++ ) {
match_result =
result_1.substring(k, result_1.length).match(regexp);
if ( match_result == null ) {
return goto_step_22( p, result_1, A );
}
}
var m = result_17.length // 18
var result_19 = result_1.substring( p, k );
A[A.length] = result_19;
}
}
function goto_step_22( p, result_1, A ) {
result_22 = result_1.substring( p, result_1.length ); // 22
A[A.length] = result_22; // 23
return A; // 24
}
}
function ToUint32( n ) {
n = Number( n );
var sign = ( n < 0 ) ? -1 : 1;
if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
return 0;
}
n = sign * Math.floor( Math.abs(n) )
n = n % Math.pow(2,32);
if ( n < 0 ){
n += Math.pow(2,32);
}
return ( n );
}

Просмотреть файл

@ -0,0 +1,120 @@
/**
* File Name: String/split-003.js
* ECMA Section: 15.6.4.9
* Description: Based on ECMA 2 Draft 7 February 1999
*
* Author: christine@netscape.com
* Date: 19 February 1999
*/
/*
* Since regular expressions have been part of JavaScript since 1.2, there
* are already tests for regular expressions in the js1_2/regexp folder.
*
* These new tests try to supplement the existing tests, and verify that
* our implementation of RegExp conforms to the ECMA specification, but
* does not try to be as exhaustive as in previous tests.
*
* The [,limit] argument to String.split is new, and not covered in any
* existing tests.
*
* String.split cases are covered in ecma/String/15.5.4.8-*.js.
* String.split where separator is a RegExp are in
* js1_2/regexp/string_split.js
*
*/
var SECTION = "ecma_2/String/split-003.js";
var VERSION = "ECMA_2";
var TITLE = "String.prototype.split( regexp, [,limit] )";
startTest();
// separartor is a regexp
// separator regexp value global setting is set
// string is an empty string
// if separator is an empty string, split each by character
// the expected results here are based on the behavior of perl5,
// except where exceptions are noted.
AddSplitCases( "hello", new RegExp, "new RegExp", ["h","e","l","l","o"] );
AddSplitCases( "hello", /l/, "/l/", ["he","","o"] );
AddLimitedSplitCases( "hello", /l/, "/l/", 0, ["he","","o"] );
AddLimitedSplitCases( "hello", /l/, "/l/", 1, ["he"] );
AddLimitedSplitCases( "hello", /l/, "/l/", 2, ["he","lo"] );
AddLimitedSplitCases( "hello", /l/, "/l/", 3, ["he","","o"] );
AddLimitedSplitCases( "hello", /l/, "/l/", 4, ["he","","o"] );
AddLimitedSplitCases( "hello", /l/, "/l/", void 0, ["he","","o"] );
AddLimitedSplitCases( "hello", /l/, "/l/", "hi", ["he","","o"] );
AddLimitedSplitCases( "hello", /l/, "/l/", undefined, ["he","","o"] );
AddSplitCases( "hello", new RegExp, "new RegExp", ["he","","o"] );
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 0, ["h","e","l","l","o"] );
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 1, ["hello"] );
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 2, ["h","ello"] );
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 3, ["h","e","llo"] );
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 4, ["h","e","l","lo"] );
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", void 0, ["h","e","l","l","o"] );
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", "hi", ["h","e","l","l","o"] );
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", undefined, ["h","e","l","l","o"] );
test();
function AddSplitCases( string, separator, str_sep, split_array ) {
// verify that the result of split is an object of type Array
AddTestCase(
"( " + string + " ).split(" + str_sep +").constructor == Array",
true,
string.split(separator).constructor == Array );
// check the number of items in the array
AddTestCase(
"( " + string + " ).split(" + str_sep +").length",
split_array.length,
string.split(separator).length );
// check the value of each array item
var limit = (split_array.length > string.split(separator).length )
? split_array.length : string.split(separator).length;
for ( var matches = 0; matches < split_array.length; matches++ ) {
AddTestCase(
"( " + string + " ).split(" + str_sep +")[" + matches +"]",
split_array[matches],
string.split( separator )[matches] );
}
}
function AddLimitedSplitCases(
string, separator, str_sep, limit, split_array ) {
// verify that the result of split is an object of type Array
AddTestCase(
"( " + string + " ).split(" + str_sep +", " + limit +
" ).constructor == Array",
true,
string.split(separator, limit).constructor == Array );
// check the length of the array
AddTestCase(
"( " + string + " ).split(" + str_sep +", " + limit + " ).length",
split_array.length,
string.split(separator).length );
// check the value of each array item
var slimit = (split_array.length > string.split(separator).length )
? split_array.length : string.split(separator).length;
for ( var matches = 0; matches < slimit; matches++ ) {
AddTestCase(
"( " + string + " ).split(" + str_sep +", " + limit + " )[" + matches +"]",
split_array[matches],
string.split( separator )[matches] );
}
}

Просмотреть файл

@ -0,0 +1,79 @@
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* JavaScript test library shared functions file for running the tests
* in the browser. Overrides the shell's print function with document.write
* and make everything HTML pretty.
*
* To run the tests in the browser, use the mkhtml.pl script to generate
* html pages that include the shell.js, browser.js (this file), and the
* test js file in script tags.
*
* The source of the page that is generated should look something like this:
* <script src="./../shell.js"></script>
* <script src="./../browser.js"></script>
* <script src="./mytest.js"></script>
*/
onerror = err;
var GLOBAL = "[object Window]";
function startTest() {
writeHeaderToLog( SECTION + " "+ TITLE);
if ( BUGNUMBER ) {
writeLineToLog ("BUGNUMBER: " + BUGNUMBER );
}
testcases = new Array();
tc = 0;
}
function writeLineToLog( string ) {
document.write( string + "<br>\n");
}
function writeHeaderToLog( string ) {
document.write( "<h2>" + string + "</h2>" );
}
function stopTest() {
var gc;
if ( gc != undefined ) {
gc();
}
document.write( "<hr>" );
}
function writeFormattedResult( expect, actual, string, passed ) {
var s = "<tt>"+ string ;
s += "<b>" ;
s += ( passed ) ? "<font color=#009900> &nbsp;" + PASSED
: "<font color=#aa0000>&nbsp;" + FAILED + expect + "</tt>";
writeLineToLog( s + "</font></b></tt>" );
return passed;
}
function err( msg, page, line ) {
writeLineToLog( "Test failed on line " + line + " with the message: " + msg );
testcases[tc].actual = "error";
testcases[tc].reason = msg;
writeTestCaseResult( testcases[tc].expect,
testcases[tc].actual,
testcases[tc].description +" = "+ testcases[tc].actual +
": " + testcases[tc].reason );
stopTest();
return true;
}

Просмотреть файл

Просмотреть файл

594
js/tests/ecma_2/jsref.js Normal file
Просмотреть файл

@ -0,0 +1,594 @@
var completed = false;
var testcases;
var tc = 0;
SECTION = "";
VERSION = "";
BUGNUMBER = "";
EXCLUDE = "";
BUGNUMBER = "";
TZ_DIFF = -8;
var TT = "";
var TT_ = "";
var BR = "";
var NBSP = " ";
var CR = "\n";
var FONT = "";
var FONT_ = "";
var FONT_RED = "";
var FONT_GREEN = "";
var B = "";
var B_ = ""
var H2 = "";
var H2_ = "";
var HR = "";
var DEBUG = false;
var PASSED = " PASSED!"
var FAILED = " FAILED! expected: ";
function test() {
for ( tc=0; tc < testcases.length; tc++ ) {
testcases[tc].passed = writeTestCaseResult(
testcases[tc].expect,
testcases[tc].actual,
testcases[tc].description +" = "+
testcases[tc].actual );
testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
}
stopTest();
return ( testcases );
}
function TestCase( n, d, e, a ) {
this.name = n;
this.description = d;
this.expect = e;
this.actual = a;
this.passed = true;
this.reason = "";
this.bugnumber = BUGNUMBER;
this.passed = getTestCaseResult( this.expect, this.actual );
if ( DEBUG ) {
writeLineToLog( "added " + this.description );
}
}
function startTest() {
// JavaScript 1.3 is supposed to be compliant ecma version 1.0
if ( VERSION == "ECMA_1" ) {
version ( "130" );
}
if ( VERSION == "JS_13" ) {
version ( "130" );
}
if ( VERSION == "JS_12" ) {
version ( "120" );
}
if ( VERSION == "JS_11" ) {
version ( "110" );
}
// for ecma version 2.0, we will leave the javascript version to
// the default ( for now ).
writeHeaderToLog( SECTION + " "+ TITLE);
testcases = new Array();
tc = 0;
}
function getTestCaseResult( expect, actual ) {
// because ( NaN == NaN ) always returns false, need to do
// a special compare to see if we got the right result.
if ( actual != actual ) {
if ( typeof actual == "object" ) {
actual = "NaN object";
} else {
actual = "NaN number";
}
}
if ( expect != expect ) {
if ( typeof expect == "object" ) {
expect = "NaN object";
} else {
expect = "NaN number";
}
}
var passed = ( expect == actual ) ? true : false;
// if both objects are numbers
// need to replace w/ IEEE standard for rounding
if ( !passed
&& typeof(actual) == "number"
&& typeof(expect) == "number"
) {
if ( Math.abs(actual-expect) < 0.0000001 ) {
passed = true;
}
}
// verify type is the same
if ( typeof(expect) != typeof(actual) ) {
passed = false;
}
return passed;
}
function writeTestCaseResult( expect, actual, string ) {
var passed = getTestCaseResult( expect, actual );
writeFormattedResult( expect, actual, string, passed );
return passed;
}
function writeFormattedResult( expect, actual, string, passed ) {
var s = TT + string ;
for ( k = 0;
k < (60 - string.length >= 0 ? 60 - string.length : 5) ;
k++ ) {
}
s += B ;
s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ;
writeLineToLog( s + FONT_ + B_ + TT_ );
return passed;
}
function writeLineToLog( string ) {
print( string + BR + CR );
}
function writeHeaderToLog( string ) {
print( H2 + string + H2_ );
}
function stopTest()
{
var sizeTag = "<#TEST CASES SIZE>";
var doneTag = "<#TEST CASES DONE>";
var beginTag = "<#TEST CASE ";
var endTag = ">";
print(sizeTag);
print(testcases.length);
for (tc = 0; tc < testcases.length; tc++)
{
print(beginTag + 'PASSED' + endTag);
print(testcases[tc].passed);
print(beginTag + 'NAME' + endTag);
print(testcases[tc].name);
print(beginTag + 'EXPECTED' + endTag);
print(testcases[tc].expect);
print(beginTag + 'ACTUAL' + endTag);
print(testcases[tc].actual);
print(beginTag + 'DESCRIPTION' + endTag);
print(testcases[tc].description);
print(beginTag + 'REASON' + endTag);
print(( testcases[tc].passed ) ? "" : "wrong value ");
print(beginTag + 'BUGNUMBER' + endTag);
print( BUGNUMBER );
}
print(doneTag);
print( HR );
gc();
}
function getFailedCases() {
for ( var i = 0; i < testcases.length; i++ ) {
if ( ! testcases[i].passed ) {
print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
}
}
}
function err( msg, page, line ) {
testcases[tc].actual = "error";
testcases[tc].reason = msg;
writeTestCaseResult( testcases[tc].expect,
testcases[tc].actual,
testcases[tc].description +" = "+ testcases[tc].actual +
": " + testcases[tc].reason );
stopTest();
return true;
}
/**
* Type Conversion functions used by Type Conversion
*
*/
/*
* Date functions used by tests in Date suite
*
*/
var msPerDay = 86400000;
var HoursPerDay = 24;
var MinutesPerHour = 60;
var SecondsPerMinute = 60;
var msPerSecond = 1000;
var msPerMinute = 60000; // msPerSecond * SecondsPerMinute
var msPerHour = 3600000; // msPerMinute * MinutesPerHour
var TIME_1970 = 0;
var TIME_2000 = 946684800000;
var TIME_1900 = -2208988800000;
function Day( t ) {
return ( Math.floor(t/msPerDay ) );
}
function DaysInYear( y ) {
if ( y % 4 != 0 ) {
return 365;
}
if ( (y % 4 == 0) && (y % 100 != 0) ) {
return 366;
}
if ( (y % 100 == 0) && (y % 400 != 0) ) {
return 365;
}
if ( (y % 400 == 0) ){
return 366;
} else {
return "ERROR: DaysInYear(" + y + ") case not covered";
}
}
function TimeInYear( y ) {
return ( DaysInYear(y) * msPerDay );
}
function DayNumber( t ) {
return ( Math.floor( t / msPerDay ) );
}
function TimeWithinDay( t ) {
if ( t < 0 ) {
return ( (t % msPerDay) + msPerDay );
} else {
return ( t % msPerDay );
}
}
function YearNumber( t ) {
}
function TimeFromYear( y ) {
return ( msPerDay * DayFromYear(y) );
}
function DayFromYear( y ) {
return ( 365*(y-1970) +
Math.floor((y-1969)/4) -
Math.floor((y-1901)/100) +
Math.floor((y-1601)/400) );
}
function InLeapYear( t ) {
if ( DaysInYear(YearFromTime(t)) == 365 ) {
return 0;
}
if ( DaysInYear(YearFromTime(t)) == 366 ) {
return 1;
} else {
return "ERROR: DayFromYear("+y+") case not covered";
}
}
function YearFromTime( t ) {
t = Number( t );
var sign = ( t < 0 ) ? -1 : 1;
var year = ( sign < 0 ) ? 1969 : 1970;
for ( var timeToTimeZero = t; ; ) {
// subtract the current year's time from the time that's left.
timeToTimeZero -= sign * TimeInYear(year)
// if there's less than the current year's worth of time left, then break.
if ( sign < 0 ) {
if ( sign * timeToTimeZero <= 0 ) {
break;
} else {
year += sign;
}
} else {
if ( sign * timeToTimeZero < 0 ) {
break;
} else {
year += sign;
}
}
}
return ( year );
}
function MonthFromTime( t ) {
// i know i could use switch but i'd rather not until it's part of ECMA
var day = DayWithinYear( t );
var leap = InLeapYear(t);
if ( (0 <= day) && (day < 31) ) {
return 0;
}
if ( (31 <= day) && (day < (59+leap)) ) {
return 1;
}
if ( ((59+leap) <= day) && (day < (90+leap)) ) {
return 2;
}
if ( ((90+leap) <= day) && (day < (120+leap)) ) {
return 3;
}
if ( ((120+leap) <= day) && (day < (151+leap)) ) {
return 4;
}
if ( ((151+leap) <= day) && (day < (181+leap)) ) {
return 5;
}
if ( ((181+leap) <= day) && (day < (212+leap)) ) {
return 6;
}
if ( ((212+leap) <= day) && (day < (243+leap)) ) {
return 7;
}
if ( ((243+leap) <= day) && (day < (273+leap)) ) {
return 8;
}
if ( ((273+leap) <= day) && (day < (304+leap)) ) {
return 9;
}
if ( ((304+leap) <= day) && (day < (334+leap)) ) {
return 10;
}
if ( ((334+leap) <= day) && (day < (365+leap)) ) {
return 11;
} else {
return "ERROR: MonthFromTime("+t+") not known";
}
}
function DayWithinYear( t ) {
return( Day(t) - DayFromYear(YearFromTime(t)));
}
function DateFromTime( t ) {
var day = DayWithinYear(t);
var month = MonthFromTime(t);
if ( month == 0 ) {
return ( day + 1 );
}
if ( month == 1 ) {
return ( day - 30 );
}
if ( month == 2 ) {
return ( day - 58 - InLeapYear(t) );
}
if ( month == 3 ) {
return ( day - 89 - InLeapYear(t));
}
if ( month == 4 ) {
return ( day - 119 - InLeapYear(t));
}
if ( month == 5 ) {
return ( day - 150- InLeapYear(t));
}
if ( month == 6 ) {
return ( day - 180- InLeapYear(t));
}
if ( month == 7 ) {
return ( day - 211- InLeapYear(t));
}
if ( month == 8 ) {
return ( day - 242- InLeapYear(t));
}
if ( month == 9 ) {
return ( day - 272- InLeapYear(t));
}
if ( month == 10 ) {
return ( day - 303- InLeapYear(t));
}
if ( month == 11 ) {
return ( day - 333- InLeapYear(t));
}
return ("ERROR: DateFromTime("+t+") not known" );
}
function WeekDay( t ) {
var weekday = (Day(t)+4) % 7;
return( weekday < 0 ? 7 + weekday : weekday );
}
// missing daylight savins time adjustment
function HourFromTime( t ) {
var h = Math.floor( t / msPerHour ) % HoursPerDay;
return ( (h<0) ? HoursPerDay + h : h );
}
function MinFromTime( t ) {
var min = Math.floor( t / msPerMinute ) % MinutesPerHour;
return( ( min < 0 ) ? MinutesPerHour + min : min );
}
function SecFromTime( t ) {
var sec = Math.floor( t / msPerSecond ) % SecondsPerMinute;
return ( (sec < 0 ) ? SecondsPerMinute + sec : sec );
}
function msFromTime( t ) {
var ms = t % msPerSecond;
return ( (ms < 0 ) ? msPerSecond + ms : ms );
}
function LocalTZA() {
return ( TZ_DIFF * msPerHour );
}
function UTC( t ) {
return ( t - LocalTZA() - DaylightSavingTA(t - LocalTZA()) );
}
function DaylightSavingTA( t ) {
t = t - LocalTZA();
var dst_start = GetFirstSundayInApril(t) + 2*msPerHour;
var dst_end = GetLastSundayInOctober(t)+ 2*msPerHour;
if ( t >= dst_start && t < dst_end ) {
return msPerHour;
} else {
return 0;
}
// Daylight Savings Time starts on the first Sunday in April at 2:00AM in
// PST. Other time zones will need to override this function.
print( new Date( UTC(dst_start + LocalTZA())) );
return UTC(dst_start + LocalTZA());
}
function GetFirstSundayInApril( t ) {
var year = YearFromTime(t);
var leap = InLeapYear(t);
var april = TimeFromYear(year) + TimeInMonth(0, leap) + TimeInMonth(1,leap) +
TimeInMonth(2,leap);
for ( var first_sunday = april; WeekDay(first_sunday) > 0;
first_sunday += msPerDay )
{
;
}
return first_sunday;
}
function GetLastSundayInOctober( t ) {
var year = YearFromTime(t);
var leap = InLeapYear(t);
for ( var oct = TimeFromYear(year), m = 0; m < 9; m++ ) {
oct += TimeInMonth(m, leap);
}
for ( var last_sunday = oct + 30*msPerDay; WeekDay(last_sunday) > 0;
last_sunday -= msPerDay )
{
;
}
return last_sunday;
}
function LocalTime( t ) {
return ( t + LocalTZA() + DaylightSavingTA(t) );
}
function MakeTime( hour, min, sec, ms ) {
if ( isNaN( hour ) || isNaN( min ) || isNaN( sec ) || isNaN( ms ) ) {
return Number.NaN;
}
hour = ToInteger(hour);
min = ToInteger( min);
sec = ToInteger( sec);
ms = ToInteger( ms );
return( (hour*msPerHour) + (min*msPerMinute) +
(sec*msPerSecond) + ms );
}
function MakeDay( year, month, date ) {
if ( isNaN(year) || isNaN(month) || isNaN(date) ) {
return Number.NaN;
}
year = ToInteger(year);
month = ToInteger(month);
date = ToInteger(date );
var sign = ( year < 1970 ) ? -1 : 1;
var t = ( year < 1970 ) ? 1 : 0;
var y = ( year < 1970 ) ? 1969 : 1970;
var result5 = year + Math.floor( month/12 );
var result6 = month % 12;
if ( year < 1970 ) {
for ( y = 1969; y >= year; y += sign ) {
t += sign * TimeInYear(y);
}
} else {
for ( y = 1970 ; y < year; y += sign ) {
t += sign * TimeInYear(y);
}
}
var leap = InLeapYear( t );
for ( var m = 0; m < month; m++ ) {
t += TimeInMonth( m, leap );
}
if ( YearFromTime(t) != result5 ) {
return Number.NaN;
}
if ( MonthFromTime(t) != result6 ) {
return Number.NaN;
}
if ( DateFromTime(t) != 1 ) {
return Number.NaN;
}
return ( (Day(t)) + date - 1 );
}
function TimeInMonth( month, leap ) {
// september april june november
// jan 0 feb 1 mar 2 apr 3 may 4 june 5 jul 6
// aug 7 sep 8 oct 9 nov 10 dec 11
if ( month == 3 || month == 5 || month == 8 || month == 10 ) {
return ( 30*msPerDay );
}
// all the rest
if ( month == 0 || month == 2 || month == 4 || month == 6 ||
month == 7 || month == 9 || month == 11 ) {
return ( 31*msPerDay );
}
// save february
return ( (leap == 0) ? 28*msPerDay : 29*msPerDay );
}
function MakeDate( day, time ) {
if ( day == Number.POSITIVE_INFINITY ||
day == Number.NEGATIVE_INFINITY ||
day == Number.NaN ) {
return Number.NaN;
}
if ( time == Number.POSITIVE_INFINITY ||
time == Number.POSITIVE_INFINITY ||
day == Number.NaN) {
return Number.NaN;
}
return ( day * msPerDay ) + time;
}
function TimeClip( t ) {
if ( isNaN( t ) ) {
return ( Number.NaN );
}
if ( Math.abs( t ) > 8.64e15 ) {
return ( Number.NaN );
}
return ( ToInteger( t ) );
}
function ToInteger( t ) {
t = Number( t );
if ( isNaN( t ) ){
return ( Number.NaN );
}
if ( t == 0 || t == -0 ||
t == Number.POSITIVE_INFINITY || t == Number.NEGATIVE_INFINITY ) {
return 0;
}
var sign = ( t < 0 ) ? -1 : 1;
return ( sign * Math.floor( Math.abs( t ) ) );
}
function Enumerate ( o ) {
var properties = new Array();
for ( p in o ) {
properties[ properties.length ] = new Array( p, o[p] );
}
return properties;
}
function AddTestCase( description, expect, actual ) {
testcases[tc++] = new TestCase( SECTION, description, expect, actual );
}
function getFailedCases() {
for ( var i = 0; i < testcases.length; i++ ) {
if ( ! testcases[i].passed ) {
print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
}
}
}

199
js/tests/ecma_2/shell.js Normal file
Просмотреть файл

@ -0,0 +1,199 @@
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* JavaScript shared functions file for running the tests in either
* stand-alone JavaScript engine. To run a test, first load this file,
* then load the test script.
*/
var completed = false;
var testcases;
var tc = 0;
SECTION = "";
VERSION = "";
BUGNUMBER="";
TZ_DIFF = -8;
var DEBUG = false;
var GLOBAL = "[object global]";
var PASSED = " PASSED!"
var FAILED = " FAILED! expected: ";
function test() {
for ( tc=0; tc < testcases.length; tc++ ) {
testcases[tc].passed = writeTestCaseResult(
testcases[tc].expect,
testcases[tc].actual,
testcases[tc].description +" = "+
testcases[tc].actual );
testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
}
stopTest();
return ( testcases );
}
function TestCase( n, d, e, a ) {
this.name = n;
this.description = d;
this.expect = e;
this.actual = a;
this.passed = true;
this.reason = "";
this.bugnumber = BUGNUMBER;
this.passed = getTestCaseResult( this.expect, this.actual );
if ( DEBUG ) {
writeLineToLog( "added " + this.description );
}
}
function startTest() {
if ( version ) {
// JavaScript 1.3 is supposed to be compliant ecma version 1.0
if ( VERSION == "ECMA_1" ) {
version ( "130" );
}
if ( VERSION == "JS_13" ) {
version ( "130" );
}
if ( VERSION == "JS_12" ) {
version ( "120" );
}
if ( VERSION == "JS_11" ) {
version ( "110" );
}
}
// for ecma version 2.0, we will leave the javascript version to
// the default ( for now ).
writeHeaderToLog( SECTION + " "+ TITLE);
if ( BUGNUMBER ) {
writeLineToLog ("BUGNUMBER: " + BUGNUMBER );
}
testcases = new Array();
tc = 0;
}
function getTestCaseResult( expect, actual ) {
// because ( NaN == NaN ) always returns false, need to do
// a special compare to see if we got the right result.
if ( actual != actual ) {
if ( typeof actual == "object" ) {
actual = "NaN object";
} else {
actual = "NaN number";
}
}
if ( expect != expect ) {
if ( typeof expect == "object" ) {
expect = "NaN object";
} else {
expect = "NaN number";
}
}
var passed = ( expect == actual ) ? true : false;
// if both objects are numbers
// need to replace w/ IEEE standard for rounding
if ( !passed
&& typeof(actual) == "number"
&& typeof(expect) == "number"
) {
if ( Math.abs(actual-expect) < 0.0000001 ) {
passed = true;
}
}
// verify type is the same
if ( typeof(expect) != typeof(actual) ) {
passed = false;
}
return passed;
}
function writeTestCaseResult( expect, actual, string ) {
var passed = getTestCaseResult( expect, actual );
writeFormattedResult( expect, actual, string, passed );
return passed;
}
function writeFormattedResult( expect, actual, string, passed ) {
var s = string ;
s += ( passed ) ? PASSED : FAILED + expect;
writeLineToLog( s);
return passed;
}
function writeLineToLog( string ) {
print( string );
}
function writeHeaderToLog( string ) {
print( string );
}
function stopTest() {
var gc;
if ( gc != undefined ) {
gc();
}
}
function getFailedCases() {
for ( var i = 0; i < testcases.length; i++ ) {
if ( ! testcases[i].passed ) {
print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
}
}
}
function err( msg, page, line ) {
writeLineToLog( page + " failed with error: " + msg + " on line " + line );
testcases[tc].actual = "error";
testcases[tc].reason = msg;
writeTestCaseResult( testcases[tc].expect,
testcases[tc].actual,
testcases[tc].description +" = "+ testcases[tc].actual +
": " + testcases[tc].reason );
stopTest();
return true;
}
function Enumerate ( o ) {
var properties = new Array();
for ( p in o ) {
properties[ properties.length ] = new Array( p, o[p] );
}
return properties;
}
function getFailedCases() {
for ( var i = 0; i < testcases.length; i++ ) {
if ( ! testcases[i].passed ) {
writeLineToLog( testcases[i].description +" = " +testcases[i].actual +
" expected: "+ testcases[i].expect );
}
}
}
function AddTestCase( description, expect, actual ) {
testcases[tc++] = new TestCase( SECTION, description, expect, actual );
}

Просмотреть файл

@ -0,0 +1,35 @@
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/**
* File Name: template.js
* Reference: ** replace with bugzilla URL or document reference **
* Description: ** replace with description of test **
* Author: ** replace with your e-mail address **
*/
var SECTION = ""; // if ECMA test, provide section number
var VERSION = "ECMA_2"; // Version of JavaScript or ECMA
var TITLE = ""; // Provide ECMA section title or description
var BUGNUMBER = ""; // Provide URL to bugsplat or bugzilla report
startTest(); // leave this alone
/* Calls to AddTestCase here */
test(); // leave this alone