adding more javascript language tests to the repository.

This commit is contained in:
cbegle%netscape.com 1999-05-26 21:48:43 +00:00
Родитель 6899fcbce8
Коммит dab403813f
145 изменённых файлов: 15541 добавлений и 0 удалений

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

@ -0,0 +1,69 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: array_split_1.js
ECMA Section: Array.split()
Description:
These are tests from free perl suite.
Author: christine@netscape.com
Date: 12 november 1997
*/
var SECTION = "Free Perl";
var VERSION = "JS1_2";
var TITLE = "Array.split()";
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
testcases[tc++] = new TestCase( SECTION,
"('a,b,c'.split(',')).length",
3,
('a,b,c'.split(',')).length );
testcases[tc++] = new TestCase( SECTION,
"('a,b'.split(',')).length",
2,
('a,b'.split(',')).length );
testcases[tc++] = new TestCase( SECTION,
"('a'.split(',')).length",
1,
('a'.split(',')).length );
/*
* Deviate from ECMA by never splitting an empty string by any separator
* string into a non-empty array (an array of length 1 that contains the
* empty string).
*/
testcases[tc++] = new TestCase( SECTION,
"(''.split(',')).length",
0,
(''.split(',')).length );
test();

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

@ -0,0 +1,59 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: general1.js
Description: 'This tests out some of the functionality on methods on the Array objects'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String:push,unshift,shift';
writeHeaderToLog('Executing script: general1.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var array1 = [];
array1.push(123); //array1 = [123]
array1.push("dog"); //array1 = [123,dog]
array1.push(-99); //array1 = [123,dog,-99]
array1.push("cat"); //array1 = [123,dog,-99,cat]
testcases[count++] = new TestCase( SECTION, "array1.pop()", array1.pop(),'cat');
//array1 = [123,dog,-99]
array1.push("mouse"); //array1 = [123,dog,-99,mouse]
testcases[count++] = new TestCase( SECTION, "array1.shift()", array1.shift(),123);
//array1 = [dog,-99,mouse]
array1.unshift(96); //array1 = [96,dog,-99,mouse]
testcases[count++] = new TestCase( SECTION, "state of array", String([96,"dog",-99,"mouse"]), String(array1));
testcases[count++] = new TestCase( SECTION, "array1.length", array1.length,4);
array1.shift(); //array1 = [dog,-99,mouse]
array1.shift(); //array1 = [-99,mouse]
array1.shift(); //array1 = [mouse]
testcases[count++] = new TestCase( SECTION, "array1.shift()", array1.shift(),"mouse");
testcases[count++] = new TestCase( SECTION, "array1.shift()", "undefined", String(array1.shift()));
test();

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

@ -0,0 +1,75 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: general2.js
Description: 'This tests out some of the functionality on methods on the Array objects'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String:push,splice,concat,unshift,sort';
writeHeaderToLog('Executing script: general2.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
array1 = new Array();
array2 = [];
size = 10;
// this for loop populates array1 and array2 as follows:
// array1 = [0,1,2,3,4,....,size - 2,size - 1]
// array2 = [size - 1, size - 2,...,4,3,2,1,0]
for (var i = 0; i < size; i++)
{
array1.push(i);
array2.push(size - 1 - i);
}
// the following for loop reverses the order of array1 so
// that it should be similarly ordered to array2
for (i = array1.length; i > 0; i--)
{
array3 = array1.slice(1,i);
array1.splice(1,i-1);
array1 = array3.concat(array1);
}
// the following for loop reverses the order of array1
// and array2
for (i = 0; i < size; i++)
{
array1.push(array1.shift());
array2.unshift(array2.pop());
}
testcases[count++] = new TestCase( SECTION, "Array.push,pop,shift,unshift,slice,splice", true,String(array1) == String(array2));
array1.sort();
array2.sort();
testcases[count++] = new TestCase( SECTION, "Array.sort", true,String(array1) == String(array2));
test();

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

@ -0,0 +1,120 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: slice.js
Description: 'This tests out some of the functionality on methods on the Array objects'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String:slice';
writeHeaderToLog('Executing script: slice.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
function mySlice(a, from, to)
{
var from2 = from;
var to2 = to;
var returnArray = [];
var i;
if (from2 < 0) from2 = a.length + from;
if (to2 < 0) to2 = a.length + to;
if ((to2 > from2)&&(to2 > 0)&&(from2 < a.length))
{
if (from2 < 0) from2 = 0;
if (to2 > a.length) to2 = a.length;
for (i = from2; i < to2; ++i) returnArray.push(a[i]);
}
return returnArray;
}
// This function tests the slice command on an Array
// passed in. The arguments passed into slice range in
// value from -5 to the length of the array + 4. Every
// combination of the two arguments is tested. The expected
// result of the slice(...) method is calculated and
// compared to the actual result from the slice(...) method.
// If the Arrays are not similar false is returned.
function exhaustiveSliceTest(testname, a)
{
var x = 0;
var y = 0;
var errorMessage;
var reason = "";
var passed = true;
for (x = -(2 + a.length); x <= (2 + a.length); x++)
for (y = (2 + a.length); y >= -(2 + a.length); y--)
{
var b = a.slice(x,y);
var c = mySlice(a,x,y);
if (String(b) != String(c))
{
errorMessage =
"ERROR: 'TEST FAILED' ERROR: 'TEST FAILED' ERROR: 'TEST FAILED'\n" +
" test: " + "a.slice(" + x + "," + y + ")\n" +
" a: " + String(a) + "\n" +
" actual result: " + String(b) + "\n" +
" expected result: " + String(c) + "\n";
writeHeaderToLog(errorMessage);
reason = reason + errorMessage;
passed = false;
}
}
var testCase = new TestCase(SECTION, testname, true, passed);
if (passed == false)
testCase.reason = reason;
return testCase;
}
var a = ['a','test string',456,9.34,new String("string object"),[],['h','i','j','k']];
var b = [1,2,3,4,5,6,7,8,9,0];
testcases[count++] = exhaustiveSliceTest("exhaustive slice test 1", a);
testcases[count++] = exhaustiveSliceTest("exhaustive slice test 2", b);
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 );
}
test();

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

@ -0,0 +1,149 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: splice1.js
Description: 'Tests Array.splice(x,y) w/no var args'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String:splice 1';
var BUGNUMBER="123795";
writeHeaderToLog('Executing script: splice1.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
function mySplice(testArray, splicedArray, first, len, elements)
{
var removedArray = [];
var adjustedFirst = first;
var adjustedLen = len;
if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
if (adjustedFirst < 0) adjustedFirst = 0;
if (adjustedLen < 0) adjustedLen = 0;
for (i = 0; (i < adjustedFirst)&&(i < testArray.length); ++i)
splicedArray.push(testArray[i]);
if (adjustedFirst < testArray.length)
for (i = adjustedFirst; (i < adjustedFirst + adjustedLen) &&
(i < testArray.length); ++i)
{
removedArray.push(testArray[i]);
}
for (i = 0; i < elements.length; i++) splicedArray.push(elements[i]);
for (i = adjustedFirst + adjustedLen; i < testArray.length; i++)
splicedArray.push(testArray[i]);
return removedArray;
}
function exhaustiveSpliceTest(testname, testArray)
{
var errorMessage;
var passed = true;
var reason = "";
for (var first = -(testArray.length+2); first <= 2 + testArray.length; first++)
{
var actualSpliced = [];
var expectedSpliced = [];
var actualRemoved = [];
var expectedRemoved = [];
for (var len = 0; len < testArray.length + 2; len++)
{
actualSpliced = [];
expectedSpliced = [];
for (var i = 0; i < testArray.length; ++i)
actualSpliced.push(testArray[i]);
actualRemoved = actualSpliced.splice(first,len);
expectedRemoved = mySplice(testArray,expectedSpliced,first,len,[]);
var adjustedFirst = first;
if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
if (adjustedFirst < 0) adjustedFirst = 0;
if ( (String(actualSpliced) != String(expectedSpliced))
||(String(actualRemoved) != String(expectedRemoved)))
{
if ( (String(actualSpliced) == String(expectedSpliced))
&&(String(actualRemoved) != String(expectedRemoved)) )
{
if ( (expectedRemoved.length == 1)
&&(String(actualRemoved) == String(expectedRemoved[0]))) continue;
if ( expectedRemoved.length == 0 && actualRemoved == void 0) continue;
}
errorMessage =
"ERROR: 'TEST FAILED'\n" +
" test: " + "a.splice(" + first + "," + len + ",-97,new String('test arg'),[],9.8)\n" +
" a: " + String(testArray) + "\n" +
" actual spliced: " + String(actualSpliced) + "\n" +
" expected spliced: " + String(expectedSpliced) + "\n" +
" actual removed: " + String(actualRemoved) + "\n" +
" expected removed: " + String(expectedRemoved) + "\n";
writeHeaderToLog(errorMessage);
reason = reason + errorMessage;
passed = false;
}
}
}
var testcase = new TestCase( SECTION, testname, true, passed);
if (!passed)
testcase.reason = reason;
return testcase;
}
var a = ['a','test string',456,9.34,new String("string object"),[],['h','i','j','k']];
var b = [1,2,3,4,5,6,7,8,9,0];
testcases[count++] = exhaustiveSpliceTest("exhaustive splice w/no optional args 1",a);
testcases[count++] = exhaustiveSpliceTest("exhaustive splice w/no optional args 1",b);
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 );
}
test();

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

@ -0,0 +1,147 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: splice2.js
Description: 'Tests Array.splice(x,y) w/4 var args'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String:splice 2';
var BUGNUMBER="123795";
writeHeaderToLog('Executing script: splice2.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
function mySplice(testArray, splicedArray, first, len, elements)
{
var removedArray = [];
var adjustedFirst = first;
var adjustedLen = len;
if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
if (adjustedFirst < 0) adjustedFirst = 0;
if (adjustedLen < 0) adjustedLen = 0;
for (i = 0; (i < adjustedFirst)&&(i < testArray.length); ++i)
splicedArray.push(testArray[i]);
if (adjustedFirst < testArray.length)
for (i = adjustedFirst; (i < adjustedFirst + adjustedLen) && (i < testArray.length); ++i)
removedArray.push(testArray[i]);
for (i = 0; i < elements.length; i++) splicedArray.push(elements[i]);
for (i = adjustedFirst + adjustedLen; i < testArray.length; i++)
splicedArray.push(testArray[i]);
return removedArray;
}
function exhaustiveSpliceTestWithArgs(testname, testArray)
{
var passed = true;
var errorMessage;
var reason = "";
for (var first = -(testArray.length+2); first <= 2 + testArray.length; first++)
{
var actualSpliced = [];
var expectedSpliced = [];
var actualRemoved = [];
var expectedRemoved = [];
for (var len = 0; len < testArray.length + 2; len++)
{
actualSpliced = [];
expectedSpliced = [];
for (var i = 0; i < testArray.length; ++i)
actualSpliced.push(testArray[i]);
actualRemoved = actualSpliced.splice(first,len,-97,new String("test arg"),[],9.8);
expectedRemoved = mySplice(testArray,expectedSpliced,first,len,[-97,new String("test arg"),[],9.8]);
var adjustedFirst = first;
if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
if (adjustedFirst < 0) adjustedFirst = 0;
if ( (String(actualSpliced) != String(expectedSpliced))
||(String(actualRemoved) != String(expectedRemoved)))
{
if ( (String(actualSpliced) == String(expectedSpliced))
&&(String(actualRemoved) != String(expectedRemoved)) )
{
if ( (expectedRemoved.length == 1)
&&(String(actualRemoved) == String(expectedRemoved[0]))) continue;
if ( expectedRemoved.length == 0 && actualRemoved == void 0 ) continue;
}
errorMessage =
"ERROR: 'TEST FAILED' ERROR: 'TEST FAILED' ERROR: 'TEST FAILED'\n" +
" test: " + "a.splice(" + first + "," + len + ",-97,new String('test arg'),[],9.8)\n" +
" a: " + String(testArray) + "\n" +
" actual spliced: " + String(actualSpliced) + "\n" +
" expected spliced: " + String(expectedSpliced) + "\n" +
" actual removed: " + String(actualRemoved) + "\n" +
" expected removed: " + String(expectedRemoved);
reason = reason + errorMessage;
writeHeaderToLog(errorMessage);
passed = false;
}
}
}
var testcase = new TestCase(SECTION, testname, true, passed);
if (!passed) testcase.reason = reason;
return testcase;
}
var a = ['a','test string',456,9.34,new String("string object"),[],['h','i','j','k']];
var b = [1,2,3,4,5,6,7,8,9,0];
testcases[count++] = exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 1",a);
testcases[count++] = exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 2",b);
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 );
}
test();

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

@ -0,0 +1,117 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: tostring_1.js
ECMA Section: Array.toString()
Description:
This checks the ToString value of Array objects under JavaScript 1.2.
Author: christine@netscape.com
Date: 12 november 1997
*/
var SECTION = "JS1_2";
var VERSION = "JS1_2";
startTest();
var TITLE = "Array.toString()";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
var a = new Array();
var version;
if ( !version ) {
function version() { return 0; };
}
testcases[tc++] = new TestCase ( SECTION,
"var a = new Array(); a.toString()",
( version() == 120 ? "[]" : "" ),
a.toString() );
a[0] = void 0;
testcases[tc++] = new TestCase ( SECTION,
"a[0] = void 0; a.toString()",
( version() == 120 ? "[, ]" : "" ),
a.toString() );
testcases[tc++] = new TestCase( SECTION,
"a.length",
1,
a.length );
a[1] = void 0;
testcases[tc++] = new TestCase( SECTION,
"a[1] = void 0; a.toString()",
( version() == 120 ? "[, , ]" : "," ),
a.toString() );
a[1] = "hi";
testcases[tc++] = new TestCase( SECTION,
"a[1] = \"hi\"; a.toString()",
( version() == 120 ? "[, \"hi\"]" : ",hi" ),
a.toString() );
a[2] = void 0;
testcases[tc++] = new TestCase( SECTION,
"a[2] = void 0; a.toString()",
( version() == 120 ?"[, \"hi\", , ]":",hi,"),
a.toString() );
var b = new Array(1000);
var bstring = "";
for ( blen=0; blen<999; blen++) {
bstring += ",";
}
testcases[tc++] = new TestCase ( SECTION,
"var b = new Array(1000); b.toString()",
( version() == 120 ? "[1000]" : bstring ),
b.toString() );
testcases[tc++] = new TestCase( SECTION,
"b.length",
( version() == 120 ? 1 : 1000 ),
b.length );
test();
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,74 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: tostring_2.js
Reference: http://scopus.mcom.com/bugsplat/show_bug.cgi?id=114564
Description: toString in version 120
Author: christine@netscape.com
Date: 15 June 1998
*/
var SECTION = "Array/tostring_2.js";
var VERSION = "JS_12";
startTest();
var TITLE = "Array.toString";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
var a = [];
var version;
if ( !version ) {
function version() { return 0; };
}
testcases[tc++] = new TestCase ( SECTION,
"a.toString()",
( version() == 120 ? "[]" : "" ),
a.toString() );
testcases[tc++] = new TestCase ( SECTION,
"String( a )",
( version() == 120 ? "[]" : "" ),
String( a ) );
testcases[tc++] = new TestCase ( SECTION,
"a +''",
( version() == 120 ? "[]" : "" ),
a+"" );
test();
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,114 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: toString_1.js
ECMA Section: Object.toString()
Description:
This checks the ToString value of Object objects under JavaScript 1.2.
In JavaScript 1.2, Object.toString()
Author: christine@netscape.com
Date: 12 november 1997
*/
var SECTION = "JS1_2";
var VERSION = "JS1_2";
startTest();
var TITLE = "Object.toString()";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
var o = new Object();
testcases[testcases.length] = new TestCase( SECTION,
"var o = new Object(); o.toString()",
"{}",
o.toString() );
o = {};
testcases[testcases.length] = new TestCase( SECTION,
"o = {}; o.toString()",
"{}",
o.toString() );
o = { name:"object", length:0, value:"hello" }
testcases[testcases.length] = new TestCase( SECTION,
"o = { name:\"object\", length:0, value:\"hello\" }; o.toString()",
true,
checkObjectToString(o.toString(), ['name:"object"', 'length:0',
'value:"hello"']));
o = { name:"object", length:0, value:"hello",
toString:new Function( "return this.value+''" ) }
testcases[testcases.length] = new TestCase( SECTION,
"o = { name:\"object\", length:0, value:\"hello\", "+
"toString:new Function( \"return this.value+''\" ) }; o.toString()",
"hello",
o.toString() );
test();
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 );
}
/**
* checkObjectToString
*
* In JS1.2, Object.prototype.toString returns a representation of the
* object's properties as a string. However, the order of the properties
* in the resulting string is not specified. This function compares the
* resulting string with an array of strings to make sure that the
* resulting string is some permutation of the strings in the array.
*/
function checkObjectToString(s, a) {
var m = /^{(.*)\}$/(s);
if (!m)
return false; // should begin and end with curly brackets
var a2 = m[1].split(", ");
if (a.length != a2.length)
return false; // should be same length
a.sort();
a2.sort();
for (var i=0; i < a.length; i++) {
if (a[i] != a2[i])
return false; // should have identical elements
}
return true;
}

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

@ -0,0 +1,68 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: charCodeAt.js
Description: 'This tests new String object method: charCodeAt'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String:charCodeAt';
writeHeaderToLog('Executing script: charCodeAt.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var aString = new String("tEs5");
testcases[count++] = new TestCase( SECTION, "aString.charCodeAt(-2)", NaN, aString.charCodeAt(-2));
testcases[count++] = new TestCase( SECTION, "aString.charCodeAt(-1)", NaN, aString.charCodeAt(-1));
testcases[count++] = new TestCase( SECTION, "aString.charCodeAt( 0)", 116, aString.charCodeAt( 0));
testcases[count++] = new TestCase( SECTION, "aString.charCodeAt( 1)", 69, aString.charCodeAt( 1));
testcases[count++] = new TestCase( SECTION, "aString.charCodeAt( 2)", 115, aString.charCodeAt( 2));
testcases[count++] = new TestCase( SECTION, "aString.charCodeAt( 3)", 53, aString.charCodeAt( 3));
testcases[count++] = new TestCase( SECTION, "aString.charCodeAt( 4)", NaN, aString.charCodeAt( 4));
testcases[count++] = new TestCase( SECTION, "aString.charCodeAt( 5)", NaN, aString.charCodeAt( 5));
testcases[count++] = new TestCase( SECTION, "aString.charCodeAt( Infinity)", NaN, aString.charCodeAt( Infinity));
testcases[count++] = new TestCase( SECTION, "aString.charCodeAt(-Infinity)", NaN, aString.charCodeAt(-Infinity));
//testcases[count++] = new TestCase( SECTION, "aString.charCodeAt( )", 116, aString.charCodeAt( ));
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 );
}
test();

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

@ -0,0 +1,79 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: concat.js
Description: 'This tests the new String object method: concat'
Author: NickLerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String:concat';
writeHeaderToLog('Executing script: concat.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var aString = new String("test string");
var bString = new String(" another ");
testcases[count++] = new TestCase( SECTION, "aString.concat(' more')", "test string more", aString.concat(' more').toString());
testcases[count++] = new TestCase( SECTION, "aString.concat(bString)", "test string another ", aString.concat(bString).toString());
testcases[count++] = new TestCase( SECTION, "aString ", "test string", aString.toString());
testcases[count++] = new TestCase( SECTION, "bString ", " another ", bString.toString());
testcases[count++] = new TestCase( SECTION, "aString.concat(345) ", "test string345", aString.concat(345).toString());
testcases[count++] = new TestCase( SECTION, "aString.concat(true) ", "test stringtrue", aString.concat(true).toString());
testcases[count++] = new TestCase( SECTION, "aString.concat(null) ", "test stringnull", aString.concat(null).toString());
testcases[count++] = new TestCase( SECTION, "aString.concat([]) ", "test string[]", aString.concat([]).toString());
testcases[count++] = new TestCase( SECTION, "aString.concat([1,2,3])", "test string[1, 2, 3]", aString.concat([1,2,3]).toString());
testcases[count++] = new TestCase( SECTION, "'abcde'.concat(' more')", "abcde more", 'abcde'.concat(' more').toString());
testcases[count++] = new TestCase( SECTION, "'abcde'.concat(bString)", "abcde another ", 'abcde'.concat(bString).toString());
testcases[count++] = new TestCase( SECTION, "'abcde' ", "abcde", 'abcde');
testcases[count++] = new TestCase( SECTION, "'abcde'.concat(345) ", "abcde345", 'abcde'.concat(345).toString());
testcases[count++] = new TestCase( SECTION, "'abcde'.concat(true) ", "abcdetrue", 'abcde'.concat(true).toString());
testcases[count++] = new TestCase( SECTION, "'abcde'.concat(null) ", "abcdenull", 'abcde'.concat(null).toString());
testcases[count++] = new TestCase( SECTION, "'abcde'.concat([]) ", "abcde[]", 'abcde'.concat([]).toString());
testcases[count++] = new TestCase( SECTION, "'abcde'.concat([1,2,3])", "abcde[1, 2, 3]", 'abcde'.concat([1,2,3]).toString());
//what should this do:
testcases[count++] = new TestCase( SECTION, "'abcde'.concat() ", "abcde", 'abcde'.concat().toString());
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 );
}
test();

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

@ -0,0 +1,59 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: match.js
Description: 'This tests the new String object method: match'
Author: NickLerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String:match';
writeHeaderToLog('Executing script: match.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var aString = new String("this is a test string");
testcases[count++] = new TestCase( SECTION, "aString.match(/is.*test/) ", String(["is is a test"]), String(aString.match(/is.*test/)));
testcases[count++] = new TestCase( SECTION, "aString.match(/s.*s/) ", String(["s is a test s"]), String(aString.match(/s.*s/)));
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 );
}
test();

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

@ -0,0 +1,120 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: slice.js
Description: 'This tests the String object method: slice'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String.slice';
writeHeaderToLog('Executing script: slice.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
function myStringSlice(a, from, to)
{
var from2 = from;
var to2 = to;
var returnString = new String("");
var i;
if (from2 < 0) from2 = a.length + from;
if (to2 < 0) to2 = a.length + to;
if ((to2 > from2)&&(to2 > 0)&&(from2 < a.length))
{
if (from2 < 0) from2 = 0;
if (to2 > a.length) to2 = a.length;
for (i = from2; i < to2; ++i) returnString += a.charAt(i);
}
return returnString;
}
// This function tests the slice command on a String
// passed in. The arguments passed into slice range in
// value from -5 to the length of the array + 4. Every
// combination of the two arguments is tested. The expected
// result of the slice(...) method is calculated and
// compared to the actual result from the slice(...) method.
// If the Strings are not similar false is returned.
function exhaustiveStringSliceTest(testname, a)
{
var x = 0;
var y = 0;
var errorMessage;
var reason = "";
var passed = true;
for (x = -(2 + a.length); x <= (2 + a.length); x++)
for (y = (2 + a.length); y >= -(2 + a.length); y--)
{
var b = a.slice(x,y);
var c = myStringSlice(a,x,y);
if (String(b) != String(c))
{
errorMessage =
"ERROR: 'TEST FAILED' ERROR: 'TEST FAILED' ERROR: 'TEST FAILED'\n" +
" test: " + "a.slice(" + x + "," + y + ")\n" +
" a: " + String(a) + "\n" +
" actual result: " + String(b) + "\n" +
" expected result: " + String(c) + "\n";
writeHeaderToLog(errorMessage);
reason = reason + errorMessage;
passed = false;
}
}
var testCase = new TestCase(SECTION, testname, true, passed);
if (passed == false)
testCase.reason = reason;
return testCase;
}
var a = new String("abcdefghijklmnopqrstuvwxyz1234567890");
var b = new String("this is a test string");
testcases[count++] = exhaustiveStringSliceTest("exhaustive String.slice test 1", a);
testcases[count++] = exhaustiveStringSliceTest("exhaustive String.slice test 2", b);
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 );
}
test();

80
js/tests/js1_2/browser.js Normal file
Просмотреть файл

@ -0,0 +1,80 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code 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 " + page + " 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;
}

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

@ -0,0 +1,82 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: Function_object.js
Description: 'Testing Function objects'
Author: Nick Lerissa
Date: April 17, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'functions: Function_object';
writeHeaderToLog('Executing script: Function_object.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
function a_test_function(a,b,c)
{
return a + b + c;
}
f = a_test_function;
testcases[count++] = new TestCase( SECTION, "f.name",
'a_test_function', f.name);
testcases[count++] = new TestCase( SECTION, "f.length",
3, f.length);
testcases[count++] = new TestCase( SECTION, "f.arity",
3, f.arity);
testcases[count++] = new TestCase( SECTION, "f(2,3,4)",
9, f(2,3,4));
var fnName = version() == 120 ? '' : 'anonymous';
testcases[count++] = new TestCase( SECTION, "(new Function()).name",
fnName, (new Function()).name);
testcases[count++] = new TestCase( SECTION, "(new Function()).toString()",
'\nfunction ' + fnName + '() {\n}\n', (new Function()).toString());
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 );
}
test();

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

@ -0,0 +1,80 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: Number.js
Description: 'This tests the function Number(Object)'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'functions: Number';
var BUGNUMBER="123435";
writeHeaderToLog('Executing script: Number.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
date = new Date(2200);
testcases[count++] = new TestCase( SECTION, "Number(new Date(2200)) ",
2200, (Number(date)));
testcases[count++] = new TestCase( SECTION, "Number(true) ",
1, (Number(true)));
testcases[count++] = new TestCase( SECTION, "Number(false) ",
0, (Number(false)));
testcases[count++] = new TestCase( SECTION, "Number('124') ",
124, (Number('124')));
testcases[count++] = new TestCase( SECTION, "Number('1.23') ",
1.23, (Number('1.23')));
testcases[count++] = new TestCase( SECTION, "Number({p:1}) ",
NaN, (Number({p:1})));
testcases[count++] = new TestCase( SECTION, "Number(null) ",
0, (Number(null)));
testcases[count++] = new TestCase( SECTION, "Number(-45) ",
-45, (Number(-45)));
// http://scopus.mcom.com/bugsplat/show_bug.cgi?id=123435
// under js1.2, Number([1,2,3]) should return 3.
testcases[count++] = new TestCase( SECTION, "Number([1,2,3]) ",
3, (Number([1,2,3])));
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 );
}
test();

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

@ -0,0 +1,70 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: String.js
Description: 'This tests the function String(Object)'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'functions: String';
writeHeaderToLog('Executing script: String.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
testcases[count++] = new TestCase( SECTION, "String(true) ",
'true', (String(true)));
testcases[count++] = new TestCase( SECTION, "String(false) ",
'false', (String(false)));
testcases[count++] = new TestCase( SECTION, "String(-124) ",
'-124', (String(-124)));
testcases[count++] = new TestCase( SECTION, "String(1.23) ",
'1.23', (String(1.23)));
testcases[count++] = new TestCase( SECTION, "String({p:1}) ",
'{p:1}', (String({p:1})));
testcases[count++] = new TestCase( SECTION, "String(null) ",
'null', (String(null)));
testcases[count++] = new TestCase( SECTION, "String([1,2,3]) ",
'[1, 2, 3]', (String([1,2,3])));
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 );
}
test();

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

@ -0,0 +1,70 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: definition-1.js
Reference: http://scopus.mcom.com/bugsplat/show_bug.cgi?id=111284
Description: Regression test for declaring functions.
Author: christine@netscape.com
Date: 15 June 1998
*/
var SECTION = "function/definition-1.js";
var VERSION = "JS_12";
startTest();
var TITLE = "Regression test for 111284";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
f1 = function() { return "passed!" }
function f2() { f3 = function() { return "passed!" }; return f3(); }
testcases[tc++] = new TestCase( SECTION,
'f1 = function() { return "passed!" }; f1()',
"passed!",
f1() );
testcases[tc++] = new TestCase( SECTION,
'function f2() { f3 = function { return "passed!" }; return f3() }; f2()',
"passed!",
f2() );
testcases[tc++] = new TestCase( SECTION,
'f3()',
"passed!",
f3() );
test();
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,71 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
* File Name: boolean-001.js
* Description:
*
* http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99232
*
* eval("function f(){}function g(){}") at top level is an error for JS1.2
* and above (missing ; between named function expressions), but declares f
* and g as functions below 1.2.
*
* Fails to produce error regardless of version:
* js> version(100)
* 120
* js> eval("function f(){}function g(){}")
* js> version(120);
* 100
* js> eval("function f(){}function g(){}")
* js>
* Author: christine@netscape.com
* Date: 11 August 1998
*/
var SECTION = "function-001.js";
var VERSION = "JS1_1";
startTest();
var TITLE = "functions not separated by semicolons are errors in version 120 and higher";
var BUGNUMBER="99232";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
testcases[tc++] = new TestCase(
SECTION,
"eval(\"function f(){}function g(){}\")",
"error",
eval("function f(){}function g(){}") );
test();
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,90 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: 15.3.5.1.js
ECMA Section: Function.length
Description:
The value of the length property is usually an integer that indicates the
"typical" number of arguments expected by the function. However, the
language permits the function to be invoked with some other number of
arguments. The behavior of a function when invoked on a number of arguments
other than the number specified by its length property depends on the function.
This checks the pre-ecma behavior Function.length.
http://scopus.mcom.com/bugsplat/show_bug.cgi?id=104204
Author: christine@netscape.com
Date: 12 november 1997
*/
var SECTION = "function/length.js";
var VERSION = "ECMA_1";
startTest();
var TITLE = "Function.length";
var BUGNUMBER="104204";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
var f = new Function( "a","b", "c", "return f.length");
if ( version() <= 120 ) {
testcases[tc++] = new TestCase( SECTION,
'var f = new Function( "a","b", "c", "return f.length"); f()',
0,
f() );
testcases[tc++] = new TestCase( SECTION,
'var f = new Function( "a","b", "c", "return f.length"); f(1,2,3,4,5)',
5,
f(1,2,3,4,5) );
} else {
testcases[tc++] = new TestCase( SECTION,
'var f = new Function( "a","b", "c", "return f.length"); f()',
3,
f() );
testcases[tc++] = new TestCase( SECTION,
'var f = new Function( "a","b", "c", "return f.length"); f(1,2,3,4,5)',
3,
f(1,2,3,4,5) );
}
test();
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,58 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: nesting-1.js
Reference: http://scopus.mcom.com/bugsplat/show_bug.cgi?id=122040
Description: Regression test for a nested function
Author: christine@netscape.com
Date: 15 June 1998
*/
var SECTION = "function/nesting-1.js";
var VERSION = "JS_12";
startTest();
var TITLE = "Regression test for 122040";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
function f(a) {function g(b) {return a+b;}; return g;}; f(7)
testcases[tc++] = new TestCase( SECTION,
'function f(a) {function g(b) {return a+b;}; return g;}; typeof f(7)',
"function",
typeof f(7) );
test();
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,80 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: nesting.js
Description: 'This tests the nesting of functions'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'functions: nesting';
writeHeaderToLog('Executing script: nesting.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
function outer_func(x)
{
var y = "outer";
testcases[count++] = new TestCase( SECTION, "outer:x ",
1111, x);
testcases[count++] = new TestCase( SECTION, "outer:y ",
'outer', y);
function inner_func(x)
{
var y = "inner";
testcases[count++] = new TestCase( SECTION, "inner:x ",
2222, x);
testcases[count++] = new TestCase( SECTION, "inner:y ",
'inner', y);
};
inner_func(2222);
testcases[count++] = new TestCase( SECTION, "outer:x ",
1111, x);
testcases[count++] = new TestCase( SECTION, "outer:y ",
'outer', y);
}
outer_func(1111);
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 );
}
test();

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

@ -0,0 +1,95 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: regexparg-1.js
Description:
Regression test for
http://scopus/bugsplat/show_bug.cgi?id=122787
Passing a regular expression as the first constructor argument fails
Author: christine@netscape.com
Date: 15 June 1998
*/
var SECTION = "JS_1.2";
var VERSION = "JS_1.2";
startTest();
var TITLE = "The variable statment";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
function f(x) {return x;}
x = f(/abc/);
testcases[tc++] = new TestCase( SECTION,
"function f(x) {return x;}; f()",
void 0,
f() );
testcases[tc++] = new TestCase( SECTION,
"f(\"hi\")",
"hi",
f("hi") );
testcases[tc++] = new TestCase( SECTION,
"new f(/abc/) +''",
"/abc/",
new f(/abc/) +"" );
testcases[tc++] = new TestCase( SECTION,
"f(/abc/)+'')",
"/abc/",
f(/abc/) +'');
testcases[tc++] = new TestCase( SECTION,
"typeof f(/abc/)",
"function",
typeof f(/abc/) );
testcases[tc++] = new TestCase( SECTION,
"typeof new f(/abc/)",
"function",
typeof new f(/abc/) );
testcases[tc++] = new TestCase( SECTION,
"x = new f(/abc/); x(\"hi\")",
null,
x("hi") );
// js> x()
test();
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,63 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: regexparg-1.js
Description:
Regression test for
http://scopus/bugsplat/show_bug.cgi?id=122787
Passing a regular expression as the first constructor argument fails
Author: christine@netscape.com
Date: 15 June 1998
*/
var SECTION = "JS_1.2";
var VERSION = "JS_1.2";
startTest();
var TITLE = "The variable statment";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
function f(x) {return x;}
x = f(/abc/);
testcases[tc++] = new TestCase( SECTION,
"function f(x) {return x;}; x = f(/abc/); x()",
"error",
x() );
test();
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,140 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: tostring-1.js
Section: Function.toString
Description:
Since the behavior of Function.toString() is implementation-dependent,
toString tests for function are not in the ECMA suite.
Currently, an attempt to parse the toString output for some functions
and verify that the result is something reasonable.
Author: christine@netscape.com
Date: 12 november 1997
*/
var SECTION = "tostring-1";
var VERSION = "JS1_2";
startTest();
var TITLE = "Function.toString()";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
var tab = " ";
t1 = new TestFunction( "stub", "value", tab + "return value;" );
t2 = new TestFunction( "ToString", "object", tab+"return object + \"\";" );
t3 = new TestFunction( "Add", "a, b, c, d, e", tab +"var s = a + b + c + d + e;\n" +
tab + "return s;" );
t4 = new TestFunction( "noop", "value" );
t5 = new TestFunction( "anonymous", "", tab+"return \"hello!\";" );
var f = new Function( "return \"hello!\"");
testcases[tc++] = new TestCase( SECTION,
"stub.toString()",
t1.valueOf(),
stub.toString() );
testcases[tc++] = new TestCase( SECTION,
"ToString.toString()",
t2.valueOf(),
ToString.toString() );
testcases[tc++] = new TestCase( SECTION,
"Add.toString()",
t3.valueOf(),
Add.toString() );
testcases[tc++] = new TestCase( SECTION,
"noop.toString()",
t4.toString(),
noop.toString() );
testcases[tc++] = new TestCase( SECTION,
"f.toString()",
t5.toString(),
f.toString() );
test();
function noop( value ) {
}
function Add( a, b, c, d, e ) {
var s = a + b + c + d + e;
return s;
}
function stub( value ) {
return value;
}
function ToString( object ) {
return object + "";
}
function ToBoolean( value ) {
if ( value == 0 || value == NaN || value == false ) {
return false;
} else {
return true;
}
}
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 TestFunction( name, args, body ) {
if ( name == "anonymous" && version() == 120 ) {
name = "";
}
this.name = name;
this.arguments = args.toString();
this.body = body;
/* the format of Function.toString() in JavaScript 1.2 is:
/n
function name ( arguments ) {
body
}
*/
this.value = "\nfunction " + (name ? name : "" )+
"("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}\n";
this.toString = new Function( "return this.value" );
this.valueOf = new Function( "return this.value" );
return this;
}

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

@ -0,0 +1,182 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: tostring-1.js
Section: Function.toString
Description:
Since the behavior of Function.toString() is implementation-dependent,
toString tests for function are not in the ECMA suite.
Currently, an attempt to parse the toString output for some functions
and verify that the result is something reasonable.
This verifies
http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99212
Author: christine@netscape.com
Date: 12 november 1997
*/
var SECTION = "tostring-2";
var VERSION = "JS1_2";
startTest();
var TITLE = "Function.toString()";
var BUGNUMBER="123444";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = new Array();
var tab = " ";
var equals = new TestFunction( "Equals", "a, b", tab+ "return a == b;" );
function Equals (a, b) {
return a == b;
}
var reallyequals = new TestFunction( "ReallyEquals", "a, b",
( version() <= 120 ) ? tab +"return a == b;" : tab +"return a === b;" );
function ReallyEquals( a, b ) {
return a === b;
}
var doesntequal = new TestFunction( "DoesntEqual", "a, b", tab + "return a != b;" );
function DoesntEqual( a, b ) {
return a != b;
}
var reallydoesntequal = new TestFunction( "ReallyDoesntEqual", "a, b",
( version() <= 120 ) ? tab +"return a != b;" : tab +"return a !== b;" );
function ReallyDoesntEqual( a, b ) {
return a !== b;
}
var testor = new TestFunction( "TestOr", "a", tab+"if (a == null || a == void 0) {\n"+
tab +tab+"return 0;\n"+tab+"} else {\n"+tab+tab+"return a;\n"+tab+"}" );
function TestOr( a ) {
if ( a == null || a == void 0 )
return 0;
else
return a;
}
var testand = new TestFunction( "TestAnd", "a", tab+"if (a != null && a != void 0) {\n"+
tab+tab+"return a;\n" + tab+ "} else {\n"+tab+tab+"return 0;\n"+tab+"}" );
function TestAnd( a ) {
if ( a != null && a != void 0 )
return a;
else
return 0;
}
var or = new TestFunction( "Or", "a, b", tab + "return a | b;" );
function Or( a, b ) {
return a | b;
}
var and = new TestFunction( "And", "a, b", tab + "return a & b;" );
function And( a, b ) {
return a & b;
}
var xor = new TestFunction( "XOr", "a, b", tab + "return a ^ b;" );
function XOr( a, b ) {
return a ^ b;
}
testcases[testcases.length] = new TestCase( SECTION,
"Equals.toString()",
equals.valueOf(),
Equals.toString() );
testcases[testcases.length] = new TestCase( SECTION,
"ReallyEquals.toString()",
reallyequals.valueOf(),
ReallyEquals.toString() );
testcases[testcases.length] = new TestCase( SECTION,
"DoesntEqual.toString()",
doesntequal.valueOf(),
DoesntEqual.toString() );
testcases[testcases.length] = new TestCase( SECTION,
"ReallyDoesntEqual.toString()",
reallydoesntequal.valueOf(),
ReallyDoesntEqual.toString() );
testcases[testcases.length] = new TestCase( SECTION,
"TestOr.toString()",
testor.valueOf(),
TestOr.toString() );
testcases[testcases.length] = new TestCase( SECTION,
"TestAnd.toString()",
testand.valueOf(),
TestAnd.toString() );
testcases[testcases.length] = new TestCase( SECTION,
"Or.toString()",
or.valueOf(),
Or.toString() );
testcases[testcases.length] = new TestCase( SECTION,
"And.toString()",
and.valueOf(),
And.toString() );
testcases[testcases.length] = new TestCase( SECTION,
"XOr.toString()",
xor.valueOf(),
XOr.toString() );
test();
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 TestFunction( name, args, body ) {
this.name = name;
this.arguments = args.toString();
this.body = body;
/* the format of Function.toString() in JavaScript 1.2 is:
/n
function name ( arguments ) {
body
}
*/
this.value = "\nfunction " + (name ? name : "anonymous" )+
"("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}\n";
this.toString = new Function( "return this.value" );
this.valueOf = new Function( "return this.value" );
return this;
}

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

@ -0,0 +1,223 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
var completed = false;
var testcases;
var tc = 0;
SECTION = "";
VERSION = "";
BUGNUMBER = "";
EXCLUDE = "";
/*
* constant strings
*/
var GLOBAL = "[object global]";
var PASSED = " PASSED!"
var FAILED = " FAILED! expected: ";
var DEBUG = false;
version("120");
/*
* change this for date tests if you're not in PST
*/
TZ_DIFF = -8;
/* wrapper for test cas constructor that doesn't require the SECTION
* argument.
*/
function AddTestCase( description, expect, actual ) {
testcases[tc++] = new TestCase( SECTION, description, expect, actual );
}
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 );
}
function startTest() {
// JavaScript 1.3 is supposed to be compliant ecma version 1.0
if ( VERSION == "ECMA_1" ) {
version ( "130" );
}
if ( VERSION == "JS_1.3" ) {
version ( "130" );
}
if ( VERSION == "JS_1.2" ) {
version ( "120" );
}
if ( VERSION == "JS_1.1" ) {
version ( "110" );
}
// for ecma version 2.0, we will leave the javascript version to
// the default ( for now ).
// print out bugnumber
if ( BUGNUMBER ) {
writeLineToLog ("BUGNUMBER: " + BUGNUMBER );
}
testcases = new Array();
tc = 0;
}
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 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, give a little leeway 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;
}
/*
* Begin printing functions. These functions use the shell's
* print function. When running tests in the browser, these
* functions, override these functions with functions that use
* document.write.
*/
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 );
}
/* end of print functions */
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);
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;
}
function Enumerate ( o ) {
var p;
for ( p in o ) {
print( p +": " + o[p] );
}
}
function GetContext() {
return Packages.com.netscape.javascript.Context.getCurrentContext();
}
function OptLevel( i ) {
i = Number(i);
var cx = GetContext();
cx.setOptimizationLevel(i);
}

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

@ -0,0 +1,69 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: equality.js
Description: 'This tests the operator =='
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'operator "=="';
writeHeaderToLog('Executing script: equality.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// the following two tests are incorrect
//testcases[count++] = new TestCase( SECTION, "(new String('') == new String('')) ",
// true, (new String('') == new String('')));
//testcases[count++] = new TestCase( SECTION, "(new Boolean(true) == new Boolean(true)) ",
// true, (new Boolean(true) == new Boolean(true)));
testcases[count++] = new TestCase( SECTION, "(new String('x') == 'x') ",
false, (new String('x') == 'x'));
testcases[count++] = new TestCase( SECTION, "('x' == new String('x')) ",
false, ('x' == new String('x')));
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 );
}
test();

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

@ -0,0 +1,89 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: strictEquality.js
Description: 'This tests the operator ==='
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'operator "==="';
writeHeaderToLog('Executing script: strictEquality.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
testcases[count++] = new TestCase( SECTION, "('8' === 8) ",
false, ('8' === 8));
testcases[count++] = new TestCase( SECTION, "(8 === 8) ",
true, (8 === 8));
testcases[count++] = new TestCase( SECTION, "(8 === true) ",
false, (8 === true));
testcases[count++] = new TestCase( SECTION, "(new String('') === new String('')) ",
false, (new String('') === new String('')));
testcases[count++] = new TestCase( SECTION, "(new Boolean(true) === new Boolean(true))",
false, (new Boolean(true) === new Boolean(true)));
var anObject = { one:1 , two:2 };
testcases[count++] = new TestCase( SECTION, "(anObject === anObject) ",
true, (anObject === anObject));
testcases[count++] = new TestCase( SECTION, "(anObject === { one:1 , two:2 }) ",
false, (anObject === { one:1 , two:2 }));
testcases[count++] = new TestCase( SECTION, "({ one:1 , two:2 } === anObject) ",
false, ({ one:1 , two:2 } === anObject));
testcases[count++] = new TestCase( SECTION, "(null === null) ",
true, (null === null));
testcases[count++] = new TestCase( SECTION, "(null === 0) ",
false, (null === 0));
testcases[count++] = new TestCase( SECTION, "(true === !false) ",
true, (true === !false));
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 );
}
test();

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

@ -0,0 +1,105 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_dollar_number.js
Description: 'Tests RegExps $1, ..., $9 properties'
Author: Nick Lerissa
Date: March 12, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: $1, ..., $9';
var BUGNUMBER="123802";
writeHeaderToLog('Executing script: RegExp_dollar_number.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$1
'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/);
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$1",
'abcdefghi', RegExp.$1);
// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$2
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$2",
'bcdefgh', RegExp.$2);
// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$3
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$3",
'cdefg', RegExp.$3);
// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$4
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$4",
'def', RegExp.$4);
// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$5
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$5",
'e', RegExp.$5);
// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$6
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$6",
'', RegExp.$6);
var a_to_z = 'abcdefghijklmnopqrstuvwxyz';
var regexp1 = /(a)b(c)d(e)f(g)h(i)j(k)l(m)n(o)p(q)r(s)t(u)v(w)x(y)z/
// 'abcdefghijklmnopqrstuvwxyz'.match(/(a)b(c)d(e)f(g)h(i)j(k)l(m)n(o)p(q)r(s)t(u)v(w)x(y)z/); RegExp.$1
a_to_z.match(regexp1);
testcases[count++] = new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$1",
'a', RegExp.$1);
testcases[count++] = new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$2",
'c', RegExp.$2);
testcases[count++] = new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$3",
'e', RegExp.$3);
testcases[count++] = new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$4",
'g', RegExp.$4);
testcases[count++] = new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$5",
'i', RegExp.$5);
testcases[count++] = new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$6",
'k', RegExp.$6);
testcases[count++] = new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$7",
'm', RegExp.$7);
testcases[count++] = new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$8",
'o', RegExp.$8);
testcases[count++] = new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$9",
'q', RegExp.$9);
/*
testcases[count++] = new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$10",
's', RegExp.$10);
*/
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 );
}
test();

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

@ -0,0 +1,99 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_input.js
Description: 'Tests RegExps input property'
Author: Nick Lerissa
Date: March 13, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: input';
writeHeaderToLog('Executing script: RegExp_input.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
RegExp.input = "abcd12357efg";
// RegExp.input = "abcd12357efg"; RegExp.input
RegExp.input = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp.input = 'abcd12357efg'; RegExp.input",
"abcd12357efg", RegExp.input);
// RegExp.input = "abcd12357efg"; /\d+/.exec('2345')
RegExp.input = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp.input = 'abcd12357efg'; /\\d+/.exec('2345')",
String(["2345"]), String(/\d+/.exec('2345')));
// RegExp.input = "abcd12357efg"; /\d+/.exec()
RegExp.input = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp.input = 'abcd12357efg'; /\\d+/.exec()",
String(["12357"]), String(/\d+/.exec()));
// RegExp.input = "abcd12357efg"; /[h-z]+/.exec()
RegExp.input = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp.input = 'abcd12357efg'; /[h-z]+/.exec()",
null, /[h-z]+/.exec());
// RegExp.input = "abcd12357efg"; /\d+/.test('2345')
RegExp.input = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp.input = 'abcd12357efg'; /\\d+/.test('2345')",
true, /\d+/.test('2345'));
// RegExp.input = "abcd12357efg"; /\d+/.test()
RegExp.input = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp.input = 'abcd12357efg'; /\\d+/.test()",
true, /\d+/.test());
// RegExp.input = "abcd12357efg"; (new RegExp('d+')).test()
RegExp.input = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp.input = 'abcd12357efg'; (new RegExp('d+')).test()",
true, (new RegExp('d+')).test());
// RegExp.input = "abcd12357efg"; /[h-z]+/.test()
RegExp.input = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp.input = 'abcd12357efg'; /[h-z]+/.test()",
false, /[h-z]+/.test());
// RegExp.input = "abcd12357efg"; (new RegExp('[h-z]+')).test()
RegExp.input = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp.input = 'abcd12357efg'; (new RegExp('[h-z]+')).test()",
false, (new RegExp('[h-z]+')).test());
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 );
}
test();

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

@ -0,0 +1,99 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_input_as_array.js
Description: 'Tests RegExps $_ property (same tests as RegExp_input.js but using $_)'
Author: Nick Lerissa
Date: March 13, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: input';
writeHeaderToLog('Executing script: RegExp_input.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
RegExp['$_'] = "abcd12357efg";
// RegExp['$_'] = "abcd12357efg"; RegExp['$_']
RegExp['$_'] = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp['$_'] = 'abcd12357efg'; RegExp['$_']",
"abcd12357efg", RegExp['$_']);
// RegExp['$_'] = "abcd12357efg"; /\d+/.exec('2345')
RegExp['$_'] = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp['$_'] = 'abcd12357efg'; /\\d+/.exec('2345')",
String(["2345"]), String(/\d+/.exec('2345')));
// RegExp['$_'] = "abcd12357efg"; /\d+/.exec()
RegExp['$_'] = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp['$_'] = 'abcd12357efg'; /\\d+/.exec()",
String(["12357"]), String(/\d+/.exec()));
// RegExp['$_'] = "abcd12357efg"; /[h-z]+/.exec()
RegExp['$_'] = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp['$_'] = 'abcd12357efg'; /[h-z]+/.exec()",
null, /[h-z]+/.exec());
// RegExp['$_'] = "abcd12357efg"; /\d+/.test('2345')
RegExp['$_'] = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp['$_'] = 'abcd12357efg'; /\\d+/.test('2345')",
true, /\d+/.test('2345'));
// RegExp['$_'] = "abcd12357efg"; /\d+/.test()
RegExp['$_'] = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp['$_'] = 'abcd12357efg'; /\\d+/.test()",
true, /\d+/.test());
// RegExp['$_'] = "abcd12357efg"; /[h-z]+/.test()
RegExp['$_'] = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp['$_'] = 'abcd12357efg'; /[h-z]+/.test()",
false, /[h-z]+/.test());
// RegExp['$_'] = "abcd12357efg"; (new RegExp('\d+')).test()
RegExp['$_'] = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp['$_'] = 'abcd12357efg'; (new RegExp('\d+')).test()",
true, (new RegExp('\d+')).test());
// RegExp['$_'] = "abcd12357efg"; (new RegExp('[h-z]+')).test()
RegExp['$_'] = "abcd12357efg";
testcases[count++] = new TestCase ( SECTION, "RegExp['$_'] = 'abcd12357efg'; (new RegExp('[h-z]+')).test()",
false, (new RegExp('[h-z]+')).test());
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 );
}
test();

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

@ -0,0 +1,80 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_lastIndex.js
Description: 'Tests RegExps lastIndex property'
Author: Nick Lerissa
Date: March 17, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: lastIndex';
var BUGNUMBER="123802";
writeHeaderToLog('Executing script: RegExp_lastIndex.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// re=/x./g; re.lastIndex=4; re.exec('xyabcdxa');
re=/x./g;
re.lastIndex=4;
testcases[count++] = new TestCase ( SECTION, "re=/x./g; re.lastIndex=4; re.exec('xyabcdxa')",
'["xa"]', String(re.exec('xyabcdxa')));
// re.lastIndex
testcases[count++] = new TestCase ( SECTION, "re.lastIndex",
8, re.lastIndex);
// re.exec('xyabcdef');
testcases[count++] = new TestCase ( SECTION, "re.exec('xyabcdef')",
null, re.exec('xyabcdef'));
// re.lastIndex
testcases[count++] = new TestCase ( SECTION, "re.lastIndex",
0, re.lastIndex);
// re.exec('xyabcdef');
testcases[count++] = new TestCase ( SECTION, "re.exec('xyabcdef')",
'["xy"]', String(re.exec('xyabcdef')));
// re.lastIndex=30; re.exec('123xaxbxc456');
re.lastIndex=30;
testcases[count++] = new TestCase ( SECTION, "re.lastIndex=30; re.exec('123xaxbxc456')",
null, re.exec('123xaxbxc456'));
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 );
}
test();

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

@ -0,0 +1,82 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_lastMatch.js
Description: 'Tests RegExps lastMatch property'
Author: Nick Lerissa
Date: March 12, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: lastMatch';
writeHeaderToLog('Executing script: RegExp_lastMatch.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'foo'.match(/foo/); RegExp.lastMatch
'foo'.match(/foo/);
testcases[count++] = new TestCase ( SECTION, "'foo'.match(/foo/); RegExp.lastMatch",
'foo', RegExp.lastMatch);
// 'foo'.match(new RegExp('foo')); RegExp.lastMatch
'foo'.match(new RegExp('foo'));
testcases[count++] = new TestCase ( SECTION, "'foo'.match(new RegExp('foo')); RegExp.lastMatch",
'foo', RegExp.lastMatch);
// 'xxx'.match(/bar/); RegExp.lastMatch
'xxx'.match(/bar/);
testcases[count++] = new TestCase ( SECTION, "'xxx'.match(/bar/); RegExp.lastMatch",
'foo', RegExp.lastMatch);
// 'xxx'.match(/$/); RegExp.lastMatch
'xxx'.match(/$/);
testcases[count++] = new TestCase ( SECTION, "'xxx'.match(/$/); RegExp.lastMatch",
'', RegExp.lastMatch);
// 'abcdefg'.match(/^..(cd)[a-z]+/); RegExp.lastMatch
'abcdefg'.match(/^..(cd)[a-z]+/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/^..(cd)[a-z]+/); RegExp.lastMatch",
'abcdefg', RegExp.lastMatch);
// 'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\1/); RegExp.lastMatch
'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\1/);
testcases[count++] = new TestCase ( SECTION, "'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\\1/); RegExp.lastMatch",
'abcdefgabcdefg', RegExp.lastMatch);
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 );
}
test();

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

@ -0,0 +1,82 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_lastMatch_as_array.js
Description: 'Tests RegExps $& property (same tests as RegExp_lastMatch.js but using $&)'
Author: Nick Lerissa
Date: March 13, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: $&';
writeHeaderToLog('Executing script: RegExp_lastMatch_as_array.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'foo'.match(/foo/); RegExp['$&']
'foo'.match(/foo/);
testcases[count++] = new TestCase ( SECTION, "'foo'.match(/foo/); RegExp['$&']",
'foo', RegExp['$&']);
// 'foo'.match(new RegExp('foo')); RegExp['$&']
'foo'.match(new RegExp('foo'));
testcases[count++] = new TestCase ( SECTION, "'foo'.match(new RegExp('foo')); RegExp['$&']",
'foo', RegExp['$&']);
// 'xxx'.match(/bar/); RegExp['$&']
'xxx'.match(/bar/);
testcases[count++] = new TestCase ( SECTION, "'xxx'.match(/bar/); RegExp['$&']",
'foo', RegExp['$&']);
// 'xxx'.match(/$/); RegExp['$&']
'xxx'.match(/$/);
testcases[count++] = new TestCase ( SECTION, "'xxx'.match(/$/); RegExp['$&']",
'', RegExp['$&']);
// 'abcdefg'.match(/^..(cd)[a-z]+/); RegExp['$&']
'abcdefg'.match(/^..(cd)[a-z]+/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/^..(cd)[a-z]+/); RegExp['$&']",
'abcdefg', RegExp['$&']);
// 'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\1/); RegExp['$&']
'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\1/);
testcases[count++] = new TestCase ( SECTION, "'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\\1/); RegExp['$&']",
'abcdefgabcdefg', RegExp['$&']);
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 );
}
test();

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

@ -0,0 +1,97 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_lastParen.js
Description: 'Tests RegExps lastParen property'
Author: Nick Lerissa
Date: March 12, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: lastParen';
writeHeaderToLog('Executing script: RegExp_lastParen.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcd'.match(/(abc)d/); RegExp.lastParen
'abcd'.match(/(abc)d/);
testcases[count++] = new TestCase ( SECTION, "'abcd'.match(/(abc)d/); RegExp.lastParen",
'abc', RegExp.lastParen);
// 'abcd'.match(new RegExp('(abc)d')); RegExp.lastParen
'abcd'.match(new RegExp('(abc)d'));
testcases[count++] = new TestCase ( SECTION, "'abcd'.match(new RegExp('(abc)d')); RegExp.lastParen",
'abc', RegExp.lastParen);
// 'abcd'.match(/(bcd)e/); RegExp.lastParen
'abcd'.match(/(bcd)e/);
testcases[count++] = new TestCase ( SECTION, "'abcd'.match(/(bcd)e/); RegExp.lastParen",
'abc', RegExp.lastParen);
// 'abcdefg'.match(/(a(b(c(d)e)f)g)/); RegExp.lastParen
'abcdefg'.match(/(a(b(c(d)e)f)g)/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/(a(b(c(d)e)f)g)/); RegExp.lastParen",
'd', RegExp.lastParen);
// 'abcdefg'.match(/(a(b)c)(d(e)f)/); RegExp.lastParen
'abcdefg'.match(/(a(b)c)(d(e)f)/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/(a(b)c)(d(e)f)/); RegExp.lastParen",
'e', RegExp.lastParen);
// 'abcdefg'.match(/(^)abc/); RegExp.lastParen
'abcdefg'.match(/(^)abc/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/(^)abc/); RegExp.lastParen",
'', RegExp.lastParen);
// 'abcdefg'.match(/(^a)bc/); RegExp.lastParen
'abcdefg'.match(/(^a)bc/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/(^a)bc/); RegExp.lastParen",
'a', RegExp.lastParen);
// 'abcdefg'.match(new RegExp('(^a)bc')); RegExp.lastParen
'abcdefg'.match(new RegExp('(^a)bc'));
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(^a)bc')); RegExp.lastParen",
'a', RegExp.lastParen);
// 'abcdefg'.match(/bc/); RegExp.lastParen
'abcdefg'.match(/bc/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/bc/); RegExp.lastParen",
'', RegExp.lastParen);
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 );
}
test();

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

@ -0,0 +1,97 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_lastParen_as_array.js
Description: 'Tests RegExps $+ property (same tests as RegExp_lastParen.js but using $+)'
Author: Nick Lerissa
Date: March 13, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: $+';
writeHeaderToLog('Executing script: RegExp_lastParen_as_array.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcd'.match(/(abc)d/); RegExp['$+']
'abcd'.match(/(abc)d/);
testcases[count++] = new TestCase ( SECTION, "'abcd'.match(/(abc)d/); RegExp['$+']",
'abc', RegExp['$+']);
// 'abcd'.match(/(bcd)e/); RegExp['$+']
'abcd'.match(/(bcd)e/);
testcases[count++] = new TestCase ( SECTION, "'abcd'.match(/(bcd)e/); RegExp['$+']",
'abc', RegExp['$+']);
// 'abcdefg'.match(/(a(b(c(d)e)f)g)/); RegExp['$+']
'abcdefg'.match(/(a(b(c(d)e)f)g)/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/(a(b(c(d)e)f)g)/); RegExp['$+']",
'd', RegExp['$+']);
// 'abcdefg'.match(new RegExp('(a(b(c(d)e)f)g)')); RegExp['$+']
'abcdefg'.match(new RegExp('(a(b(c(d)e)f)g)'));
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(a(b(c(d)e)f)g)')); RegExp['$+']",
'd', RegExp['$+']);
// 'abcdefg'.match(/(a(b)c)(d(e)f)/); RegExp['$+']
'abcdefg'.match(/(a(b)c)(d(e)f)/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/(a(b)c)(d(e)f)/); RegExp['$+']",
'e', RegExp['$+']);
// 'abcdefg'.match(/(^)abc/); RegExp['$+']
'abcdefg'.match(/(^)abc/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/(^)abc/); RegExp['$+']",
'', RegExp['$+']);
// 'abcdefg'.match(/(^a)bc/); RegExp['$+']
'abcdefg'.match(/(^a)bc/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/(^a)bc/); RegExp['$+']",
'a', RegExp['$+']);
// 'abcdefg'.match(new RegExp('(^a)bc')); RegExp['$+']
'abcdefg'.match(new RegExp('(^a)bc'));
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(^a)bc')); RegExp['$+']",
'a', RegExp['$+']);
// 'abcdefg'.match(/bc/); RegExp['$+']
'abcdefg'.match(/bc/);
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/bc/); RegExp['$+']",
'', RegExp['$+']);
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 );
}
test();

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

@ -0,0 +1,87 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_leftContext.js
Description: 'Tests RegExps leftContext property'
Author: Nick Lerissa
Date: March 12, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: leftContext';
writeHeaderToLog('Executing script: RegExp_leftContext.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abc123xyz'.match(/123/); RegExp.leftContext
'abc123xyz'.match(/123/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp.leftContext",
'abc', RegExp.leftContext);
// 'abc123xyz'.match(/456/); RegExp.leftContext
'abc123xyz'.match(/456/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp.leftContext",
'abc', RegExp.leftContext);
// 'abc123xyz'.match(/abc123xyz/); RegExp.leftContext
'abc123xyz'.match(/abc123xyz/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp.leftContext",
'', RegExp.leftContext);
// 'xxxx'.match(/$/); RegExp.leftContext
'xxxx'.match(/$/);
testcases[count++] = new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp.leftContext",
'xxxx', RegExp.leftContext);
// 'test'.match(/^/); RegExp.leftContext
'test'.match(/^/);
testcases[count++] = new TestCase ( SECTION, "'test'.match(/^/); RegExp.leftContext",
'', RegExp.leftContext);
// 'xxxx'.match(new RegExp('$')); RegExp.leftContext
'xxxx'.match(new RegExp('$'));
testcases[count++] = new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp.leftContext",
'xxxx', RegExp.leftContext);
// 'test'.match(new RegExp('^')); RegExp.leftContext
'test'.match(new RegExp('^'));
testcases[count++] = new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp.leftContext",
'', RegExp.leftContext);
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 );
}
test();

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

@ -0,0 +1,87 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_leftContext_as_array.js
Description: 'Tests RegExps leftContext property (same tests as RegExp_leftContext.js but using $`)'
Author: Nick Lerissa
Date: March 12, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: $`';
writeHeaderToLog('Executing script: RegExp_leftContext_as_array.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abc123xyz'.match(/123/); RegExp['$`']
'abc123xyz'.match(/123/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp['$`']",
'abc', RegExp['$`']);
// 'abc123xyz'.match(/456/); RegExp['$`']
'abc123xyz'.match(/456/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp['$`']",
'abc', RegExp['$`']);
// 'abc123xyz'.match(/abc123xyz/); RegExp['$`']
'abc123xyz'.match(/abc123xyz/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp['$`']",
'', RegExp['$`']);
// 'xxxx'.match(/$/); RegExp['$`']
'xxxx'.match(/$/);
testcases[count++] = new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp['$`']",
'xxxx', RegExp['$`']);
// 'test'.match(/^/); RegExp['$`']
'test'.match(/^/);
testcases[count++] = new TestCase ( SECTION, "'test'.match(/^/); RegExp['$`']",
'', RegExp['$`']);
// 'xxxx'.match(new RegExp('$')); RegExp['$`']
'xxxx'.match(new RegExp('$'));
testcases[count++] = new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp['$`']",
'xxxx', RegExp['$`']);
// 'test'.match(new RegExp('^')); RegExp['$`']
'test'.match(new RegExp('^'));
testcases[count++] = new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp['$`']",
'', RegExp['$`']);
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 );
}
test();

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

@ -0,0 +1,126 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_multiline.js
Description: 'Tests RegExps multiline property'
Author: Nick Lerissa
Date: March 12, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: multiline';
writeHeaderToLog('Executing script: RegExp_multiline.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// First we do a series of tests with RegExp.multiline set to false (default value)
// Following this we do the same tests with RegExp.multiline set true(**).
// RegExp.multiline
testcases[count++] = new TestCase ( SECTION, "RegExp.multiline",
false, RegExp.multiline);
// (multiline == false) '123\n456'.match(/^4../)
testcases[count++] = new TestCase ( SECTION, "(multiline == false) '123\\n456'.match(/^4../)",
null, '123\n456'.match(/^4../));
// (multiline == false) 'a11\na22\na23\na24'.match(/^a../g)
testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'a11\\na22\\na23\\na24'.match(/^a../g)",
String(['a11']), String('a11\na22\na23\na24'.match(/^a../g)));
// (multiline == false) 'a11\na22'.match(/^.+^./)
testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'a11\na22'.match(/^.+^./)",
null, 'a11\na22'.match(/^.+^./));
// (multiline == false) '123\n456'.match(/.3$/)
testcases[count++] = new TestCase ( SECTION, "(multiline == false) '123\\n456'.match(/.3$/)",
null, '123\n456'.match(/.3$/));
// (multiline == false) 'a11\na22\na23\na24'.match(/a..$/g)
testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'a11\\na22\\na23\\na24'.match(/a..$/g)",
String(['a24']), String('a11\na22\na23\na24'.match(/a..$/g)));
// (multiline == false) 'abc\ndef'.match(/c$...$/)
testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'abc\ndef'.match(/c$...$/)",
null, 'abc\ndef'.match(/c$...$/));
// (multiline == false) 'a11\na22\na23\na24'.match(new RegExp('a..$','g'))
testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'a11\\na22\\na23\\na24'.match(new RegExp('a..$','g'))",
String(['a24']), String('a11\na22\na23\na24'.match(new RegExp('a..$','g'))));
// (multiline == false) 'abc\ndef'.match(new RegExp('c$...$'))
testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'abc\ndef'.match(new RegExp('c$...$'))",
null, 'abc\ndef'.match(new RegExp('c$...$')));
// **Now we do the tests with RegExp.multiline set to true
// RegExp.multiline = true; RegExp.multiline
RegExp.multiline = true;
testcases[count++] = new TestCase ( SECTION, "RegExp.multiline = true; RegExp.multiline",
true, RegExp.multiline);
// (multiline == true) '123\n456'.match(/^4../)
testcases[count++] = new TestCase ( SECTION, "(multiline == true) '123\\n456'.match(/^4../)",
String(['456']), String('123\n456'.match(/^4../)));
// (multiline == true) 'a11\na22\na23\na24'.match(/^a../g)
testcases[count++] = new TestCase ( SECTION, "(multiline == true) 'a11\\na22\\na23\\na24'.match(/^a../g)",
String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(/^a../g)));
// (multiline == true) 'a11\na22'.match(/^.+^./)
//testcases[count++] = new TestCase ( SECTION, "(multiline == true) 'a11\na22'.match(/^.+^./)",
// String(['a11\na']), String('a11\na22'.match(/^.+^./)));
// (multiline == true) '123\n456'.match(/.3$/)
testcases[count++] = new TestCase ( SECTION, "(multiline == true) '123\\n456'.match(/.3$/)",
String(['23']), String('123\n456'.match(/.3$/)));
// (multiline == true) 'a11\na22\na23\na24'.match(/a..$/g)
testcases[count++] = new TestCase ( SECTION, "(multiline == true) 'a11\\na22\\na23\\na24'.match(/a..$/g)",
String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(/a..$/g)));
// (multiline == true) 'a11\na22\na23\na24'.match(new RegExp('a..$','g'))
testcases[count++] = new TestCase ( SECTION, "(multiline == true) 'a11\\na22\\na23\\na24'.match(new RegExp('a..$','g'))",
String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(new RegExp('a..$','g'))));
// (multiline == true) 'abc\ndef'.match(/c$....$/)
//testcases[count++] = new TestCase ( SECTION, "(multiline == true) 'abc\ndef'.match(/c$.+$/)",
// 'c\ndef', String('abc\ndef'.match(/c$.+$/)));
RegExp.multiline = false;
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 );
}
test();

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

@ -0,0 +1,126 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_multiline_as_array.js
Description: 'Tests RegExps $* property (same tests as RegExp_multiline.js but using $*)'
Author: Nick Lerissa
Date: March 13, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: $*';
writeHeaderToLog('Executing script: RegExp_multiline_as_array.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// First we do a series of tests with RegExp['$*'] set to false (default value)
// Following this we do the same tests with RegExp['$*'] set true(**).
// RegExp['$*']
testcases[count++] = new TestCase ( SECTION, "RegExp['$*']",
false, RegExp['$*']);
// (['$*'] == false) '123\n456'.match(/^4../)
testcases[count++] = new TestCase ( SECTION, "(['$*'] == false) '123\\n456'.match(/^4../)",
null, '123\n456'.match(/^4../));
// (['$*'] == false) 'a11\na22\na23\na24'.match(/^a../g)
testcases[count++] = new TestCase ( SECTION, "(['$*'] == false) 'a11\\na22\\na23\\na24'.match(/^a../g)",
String(['a11']), String('a11\na22\na23\na24'.match(/^a../g)));
// (['$*'] == false) 'a11\na22'.match(/^.+^./)
testcases[count++] = new TestCase ( SECTION, "(['$*'] == false) 'a11\na22'.match(/^.+^./)",
null, 'a11\na22'.match(/^.+^./));
// (['$*'] == false) '123\n456'.match(/.3$/)
testcases[count++] = new TestCase ( SECTION, "(['$*'] == false) '123\\n456'.match(/.3$/)",
null, '123\n456'.match(/.3$/));
// (['$*'] == false) 'a11\na22\na23\na24'.match(/a..$/g)
testcases[count++] = new TestCase ( SECTION, "(['$*'] == false) 'a11\\na22\\na23\\na24'.match(/a..$/g)",
String(['a24']), String('a11\na22\na23\na24'.match(/a..$/g)));
// (['$*'] == false) 'abc\ndef'.match(/c$...$/)
testcases[count++] = new TestCase ( SECTION, "(['$*'] == false) 'abc\ndef'.match(/c$...$/)",
null, 'abc\ndef'.match(/c$...$/));
// (['$*'] == false) 'a11\na22\na23\na24'.match(new RegExp('a..$','g'))
testcases[count++] = new TestCase ( SECTION, "(['$*'] == false) 'a11\\na22\\na23\\na24'.match(new RegExp('a..$','g'))",
String(['a24']), String('a11\na22\na23\na24'.match(new RegExp('a..$','g'))));
// (['$*'] == false) 'abc\ndef'.match(new RegExp('c$...$'))
testcases[count++] = new TestCase ( SECTION, "(['$*'] == false) 'abc\ndef'.match(new RegExp('c$...$'))",
null, 'abc\ndef'.match(new RegExp('c$...$')));
// **Now we do the tests with RegExp['$*'] set to true
// RegExp['$*'] = true; RegExp['$*']
RegExp['$*'] = true;
testcases[count++] = new TestCase ( SECTION, "RegExp['$*'] = true; RegExp['$*']",
true, RegExp['$*']);
// (['$*'] == true) '123\n456'.match(/^4../)
testcases[count++] = new TestCase ( SECTION, "(['$*'] == true) '123\\n456'.match(/^4../)",
String(['456']), String('123\n456'.match(/^4../)));
// (['$*'] == true) 'a11\na22\na23\na24'.match(/^a../g)
testcases[count++] = new TestCase ( SECTION, "(['$*'] == true) 'a11\\na22\\na23\\na24'.match(/^a../g)",
String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(/^a../g)));
// (['$*'] == true) 'a11\na22'.match(/^.+^./)
//testcases[count++] = new TestCase ( SECTION, "(['$*'] == true) 'a11\na22'.match(/^.+^./)",
// String(['a11\na']), String('a11\na22'.match(/^.+^./)));
// (['$*'] == true) '123\n456'.match(/.3$/)
testcases[count++] = new TestCase ( SECTION, "(['$*'] == true) '123\\n456'.match(/.3$/)",
String(['23']), String('123\n456'.match(/.3$/)));
// (['$*'] == true) 'a11\na22\na23\na24'.match(/a..$/g)
testcases[count++] = new TestCase ( SECTION, "(['$*'] == true) 'a11\\na22\\na23\\na24'.match(/a..$/g)",
String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(/a..$/g)));
// (['$*'] == true) 'a11\na22\na23\na24'.match(new RegExp('a..$','g'))
testcases[count++] = new TestCase ( SECTION, "(['$*'] == true) 'a11\\na22\\na23\\na24'.match(new RegExp('a..$','g'))",
String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(new RegExp('a..$','g'))));
// (['$*'] == true) 'abc\ndef'.match(/c$....$/)
//testcases[count++] = new TestCase ( SECTION, "(['$*'] == true) 'abc\ndef'.match(/c$.+$/)",
// 'c\ndef', String('abc\ndef'.match(/c$.+$/)));
RegExp['$*'] = false;
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 );
}
test();

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

@ -0,0 +1,85 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_object.js
Description: 'Tests regular expressions creating RexExp Objects'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: object';
writeHeaderToLog('Executing script: RegExp_object.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var SSN_pattern = new RegExp("\\d{3}-\\d{2}-\\d{4}");
// testing SSN pattern
testcases[count++] = new TestCase ( SECTION, "'Test SSN is 123-34-4567'.match(SSN_pattern))",
String(["123-34-4567"]), String('Test SSN is 123-34-4567'.match(SSN_pattern)));
// testing SSN pattern
testcases[count++] = new TestCase ( SECTION, "'Test SSN is 123-34-4567'.match(SSN_pattern))",
String(["123-34-4567"]), String('Test SSN is 123-34-4567'.match(SSN_pattern)));
var PHONE_pattern = new RegExp("\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})");
// testing PHONE pattern
testcases[count++] = new TestCase ( SECTION, "'Our phone number is (408)345-2345.'.match(PHONE_pattern))",
String(["(408)345-2345","408","345","2345"]), String('Our phone number is (408)345-2345.'.match(PHONE_pattern)));
// testing PHONE pattern
testcases[count++] = new TestCase ( SECTION, "'The phone number is 408-345-2345!'.match(PHONE_pattern))",
String(["408-345-2345","408","345","2345"]), String('The phone number is 408-345-2345!'.match(PHONE_pattern)));
// testing PHONE pattern
testcases[count++] = new TestCase ( SECTION, "String(PHONE_pattern.toString())",
"/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/", String(PHONE_pattern.toString()));
// testing conversion to String
testcases[count++] = new TestCase ( SECTION, "PHONE_pattern + ' is the string'",
"/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/ is the string",PHONE_pattern + ' is the string');
// testing conversion to int
testcases[count++] = new TestCase ( SECTION, "SSN_pattern - 8",
NaN,SSN_pattern - 8);
var testPattern = new RegExp("(\\d+)45(\\d+)90");
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 );
}
test();

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

@ -0,0 +1,87 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_rightContext.js
Description: 'Tests RegExps rightContext property'
Author: Nick Lerissa
Date: March 12, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: rightContext';
writeHeaderToLog('Executing script: RegExp_rightContext.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abc123xyz'.match(/123/); RegExp.rightContext
'abc123xyz'.match(/123/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp.rightContext",
'xyz', RegExp.rightContext);
// 'abc123xyz'.match(/456/); RegExp.rightContext
'abc123xyz'.match(/456/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp.rightContext",
'xyz', RegExp.rightContext);
// 'abc123xyz'.match(/abc123xyz/); RegExp.rightContext
'abc123xyz'.match(/abc123xyz/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp.rightContext",
'', RegExp.rightContext);
// 'xxxx'.match(/$/); RegExp.rightContext
'xxxx'.match(/$/);
testcases[count++] = new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp.rightContext",
'', RegExp.rightContext);
// 'test'.match(/^/); RegExp.rightContext
'test'.match(/^/);
testcases[count++] = new TestCase ( SECTION, "'test'.match(/^/); RegExp.rightContext",
'test', RegExp.rightContext);
// 'xxxx'.match(new RegExp('$')); RegExp.rightContext
'xxxx'.match(new RegExp('$'));
testcases[count++] = new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp.rightContext",
'', RegExp.rightContext);
// 'test'.match(new RegExp('^')); RegExp.rightContext
'test'.match(new RegExp('^'));
testcases[count++] = new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp.rightContext",
'test', RegExp.rightContext);
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 );
}
test();

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

@ -0,0 +1,87 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: RegExp_rightContext_as_array.js
Description: 'Tests RegExps $\' property (same tests as RegExp_rightContext.js but using $\)'
Author: Nick Lerissa
Date: March 12, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: $\'';
writeHeaderToLog('Executing script: RegExp_rightContext.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abc123xyz'.match(/123/); RegExp['$\'']
'abc123xyz'.match(/123/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp['$\'']",
'xyz', RegExp['$\'']);
// 'abc123xyz'.match(/456/); RegExp['$\'']
'abc123xyz'.match(/456/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp['$\'']",
'xyz', RegExp['$\'']);
// 'abc123xyz'.match(/abc123xyz/); RegExp['$\'']
'abc123xyz'.match(/abc123xyz/);
testcases[count++] = new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp['$\'']",
'', RegExp['$\'']);
// 'xxxx'.match(/$/); RegExp['$\'']
'xxxx'.match(/$/);
testcases[count++] = new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp['$\'']",
'', RegExp['$\'']);
// 'test'.match(/^/); RegExp['$\'']
'test'.match(/^/);
testcases[count++] = new TestCase ( SECTION, "'test'.match(/^/); RegExp['$\'']",
'test', RegExp['$\'']);
// 'xxxx'.match(new RegExp('$')); RegExp['$\'']
'xxxx'.match(new RegExp('$'));
testcases[count++] = new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp['$\'']",
'', RegExp['$\'']);
// 'test'.match(new RegExp('^')); RegExp['$\'']
'test'.match(new RegExp('^'));
testcases[count++] = new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp['$\'']",
'test', RegExp['$\'']);
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 );
}
test();

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

@ -0,0 +1,126 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: alphanumeric.js
Description: 'Tests regular expressions with \w and \W special characters'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: \\w and \\W';
writeHeaderToLog('Executing script: alphanumeric.js');
writeHeaderToLog( SECTION + " " + TITLE);
var count = 0;
var testcases = new Array();
var non_alphanumeric = "~`!@#$%^&*()-+={[}]|\\:;'<,>./?\f\n\r\t\v " + '"';
var alphanumeric = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
// be sure all alphanumerics are matched by \w
testcases[count++] = new TestCase ( SECTION,
"'" + alphanumeric + "'.match(new RegExp('\\w+'))",
String([alphanumeric]), String(alphanumeric.match(new RegExp('\\w+'))));
// be sure all non-alphanumerics are matched by \W
testcases[count++] = new TestCase ( SECTION,
"'" + non_alphanumeric + "'.match(new RegExp('\\W+'))",
String([non_alphanumeric]), String(non_alphanumeric.match(new RegExp('\\W+'))));
// be sure all non-alphanumerics are not matched by \w
testcases[count++] = new TestCase ( SECTION,
"'" + non_alphanumeric + "'.match(new RegExp('\\w'))",
null, non_alphanumeric.match(new RegExp('\\w')));
// be sure all alphanumerics are not matched by \W
testcases[count++] = new TestCase ( SECTION,
"'" + alphanumeric + "'.match(new RegExp('\\W'))",
null, alphanumeric.match(new RegExp('\\W')));
var s = non_alphanumeric + alphanumeric;
// be sure all alphanumerics are matched by \w
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\w+'))",
String([alphanumeric]), String(s.match(new RegExp('\\w+'))));
s = alphanumeric + non_alphanumeric;
// be sure all non-alphanumerics are matched by \W
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\W+'))",
String([non_alphanumeric]), String(s.match(new RegExp('\\W+'))));
// be sure all alphanumerics are matched by \w (using literals)
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(/\w+/)",
String([alphanumeric]), String(s.match(/\w+/)));
s = alphanumeric + non_alphanumeric;
// be sure all non-alphanumerics are matched by \W (using literals)
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(/\W+/)",
String([non_alphanumeric]), String(s.match(/\W+/)));
s = 'abcd*&^%$$';
// be sure the following test behaves consistently
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(/(\w+)...(\W+)/)",
String([s , 'abcd' , '%$$']), String(s.match(/(\w+)...(\W+)/)));
var i;
// be sure all alphanumeric characters match individually
for (i = 0; i < alphanumeric.length; ++i)
{
s = '#$' + alphanumeric[i] + '%^';
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\w'))",
String([alphanumeric[i]]), String(s.match(new RegExp('\\w'))));
}
// be sure all non_alphanumeric characters match individually
for (i = 0; i < non_alphanumeric.length; ++i)
{
s = 'sd' + non_alphanumeric[i] + String((i+10) * (i+10) - 2 * (i+10));
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\W'))",
String([non_alphanumeric[i]]), String(s.match(new RegExp('\\W'))));
}
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 );
}
test();

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

@ -0,0 +1,102 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: asterisk.js
Description: 'Tests regular expressions containing *'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: *';
writeHeaderToLog('Executing script: aterisk.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcddddefg'.match(new RegExp('d*'))
testcases[count++] = new TestCase ( SECTION, "'abcddddefg'.match(new RegExp('d*'))",
String([""]), String('abcddddefg'.match(new RegExp('d*'))));
// 'abcddddefg'.match(new RegExp('cd*'))
testcases[count++] = new TestCase ( SECTION, "'abcddddefg'.match(new RegExp('cd*'))",
String(["cdddd"]), String('abcddddefg'.match(new RegExp('cd*'))));
// 'abcdefg'.match(new RegExp('cx*d'))
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('cx*d'))",
String(["cd"]), String('abcdefg'.match(new RegExp('cx*d'))));
// 'xxxxxxx'.match(new RegExp('(x*)(x+)'))
testcases[count++] = new TestCase ( SECTION, "'xxxxxxx'.match(new RegExp('(x*)(x+)'))",
String(["xxxxxxx","xxxxxx","x"]), String('xxxxxxx'.match(new RegExp('(x*)(x+)'))));
// '1234567890'.match(new RegExp('(\\d*)(\\d+)'))
testcases[count++] = new TestCase ( SECTION, "'1234567890'.match(new RegExp('(\\d*)(\\d+)'))",
String(["1234567890","123456789","0"]),
String('1234567890'.match(new RegExp('(\\d*)(\\d+)'))));
// '1234567890'.match(new RegExp('(\\d*)\\d(\\d+)'))
testcases[count++] = new TestCase ( SECTION, "'1234567890'.match(new RegExp('(\\d*)\\d(\\d+)'))",
String(["1234567890","12345678","0"]),
String('1234567890'.match(new RegExp('(\\d*)\\d(\\d+)'))));
// 'xxxxxxx'.match(new RegExp('(x+)(x*)'))
testcases[count++] = new TestCase ( SECTION, "'xxxxxxx'.match(new RegExp('(x+)(x*)'))",
String(["xxxxxxx","xxxxxxx",""]), String('xxxxxxx'.match(new RegExp('(x+)(x*)'))));
// 'xxxxxxyyyyyy'.match(new RegExp('x*y+$'))
testcases[count++] = new TestCase ( SECTION, "'xxxxxxyyyyyy'.match(new RegExp('x*y+$'))",
String(["xxxxxxyyyyyy"]), String('xxxxxxyyyyyy'.match(new RegExp('x*y+$'))));
// 'abcdef'.match(/[\d]*[\s]*bc./)
testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(/[\\d]*[\\s]*bc./)",
String(["bcd"]), String('abcdef'.match(/[\d]*[\s]*bc./)));
// 'abcdef'.match(/bc..[\d]*[\s]*/)
testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(/bc..[\\d]*[\\s]*/)",
String(["bcde"]), String('abcdef'.match(/bc..[\d]*[\s]*/)));
// 'a1b2c3'.match(/.*/)
testcases[count++] = new TestCase ( SECTION, "'a1b2c3'.match(/.*/)",
String(["a1b2c3"]), String('a1b2c3'.match(/.*/)));
// 'a0.b2.c3'.match(/[xyz]*1/)
testcases[count++] = new TestCase ( SECTION, "'a0.b2.c3'.match(/[xyz]*1/)",
null, 'a0.b2.c3'.match(/[xyz]*1/));
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 );
}
test();

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

@ -0,0 +1,76 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: backslash.js
Description: 'Tests regular expressions containing \'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: \\';
writeHeaderToLog('Executing script: backslash.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcde'.match(new RegExp('\e'))
testcases[count++] = new TestCase ( SECTION, "'abcde'.match(new RegExp('\e'))",
String(["e"]), String('abcde'.match(new RegExp('\e'))));
// 'ab\\cde'.match(new RegExp('\\\\'))
testcases[count++] = new TestCase ( SECTION, "'ab\\cde'.match(new RegExp('\\\\'))",
String(["\\"]), String('ab\\cde'.match(new RegExp('\\\\'))));
// 'ab\\cde'.match(/\\/) (using literal)
testcases[count++] = new TestCase ( SECTION, "'ab\\cde'.match(/\\\\/)",
String(["\\"]), String('ab\\cde'.match(/\\/)));
// 'before ^$*+?.()|{}[] after'.match(new RegExp('\^\$\*\+\?\.\(\)\|\{\}\[\]'))
testcases[count++] = new TestCase ( SECTION,
"'before ^$*+?.()|{}[] after'.match(new RegExp('\\^\\$\\*\\+\\?\\.\\(\\)\\|\\{\\}\\[\\]'))",
String(["^$*+?.()|{}[]"]),
String('before ^$*+?.()|{}[] after'.match(new RegExp('\\^\\$\\*\\+\\?\\.\\(\\)\\|\\{\\}\\[\\]'))));
// 'before ^$*+?.()|{}[] after'.match(/\^\$\*\+\?\.\(\)\|\{\}\[\]/) (using literal)
testcases[count++] = new TestCase ( SECTION,
"'before ^$*+?.()|{}[] after'.match(/\\^\\$\\*\\+\\?\\.\\(\\)\\|\\{\\}\\[\\]/)",
String(["^$*+?.()|{}[]"]),
String('before ^$*+?.()|{}[] after'.match(/\^\$\*\+\?\.\(\)\|\{\}\[\]/)));
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 );
}
test();

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

@ -0,0 +1,76 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: backspace.js
Description: 'Tests regular expressions containing [\b]'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: [\b]';
writeHeaderToLog('Executing script: backspace.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abc\bdef'.match(new RegExp('.[\b].'))
testcases[count++] = new TestCase ( SECTION, "'abc\bdef'.match(new RegExp('.[\\b].'))",
String(["c\bd"]), String('abc\bdef'.match(new RegExp('.[\\b].'))));
// 'abc\\bdef'.match(new RegExp('.[\b].'))
testcases[count++] = new TestCase ( SECTION, "'abc\\bdef'.match(new RegExp('.[\\b].'))",
null, 'abc\\bdef'.match(new RegExp('.[\\b].')));
// 'abc\b\b\bdef'.match(new RegExp('c[\b]{3}d'))
testcases[count++] = new TestCase ( SECTION, "'abc\b\b\bdef'.match(new RegExp('c[\\b]{3}d'))",
String(["c\b\b\bd"]), String('abc\b\b\bdef'.match(new RegExp('c[\\b]{3}d'))));
// 'abc\bdef'.match(new RegExp('[^\\[\b\\]]+'))
testcases[count++] = new TestCase ( SECTION, "'abc\bdef'.match(new RegExp('[^\\[\\b\\]]+'))",
String(["abc"]), String('abc\bdef'.match(new RegExp('[^\\[\\b\\]]+'))));
// 'abcdef'.match(new RegExp('[^\\[\b\\]]+'))
testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(new RegExp('[^\\[\\b\\]]+'))",
String(["abcdef"]), String('abcdef'.match(new RegExp('[^\\[\\b\\]]+'))));
// 'abcdef'.match(/[^\[\b\]]+/)
testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(/[^\\[\\b\\]]+/)",
String(["abcdef"]), String('abcdef'.match(/[^\[\b\]]+/)));
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 );
}
test();

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

@ -0,0 +1,77 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: beginLine.js
Description: 'Tests regular expressions containing ^'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: ^';
writeHeaderToLog('Executing script: beginLine.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcde'.match(new RegExp('^ab'))
testcases[count++] = new TestCase ( SECTION, "'abcde'.match(new RegExp('^ab'))",
String(["ab"]), String('abcde'.match(new RegExp('^ab'))));
// 'ab\ncde'.match(new RegExp('^..^e'))
testcases[count++] = new TestCase ( SECTION, "'ab\ncde'.match(new RegExp('^..^e'))",
null, 'ab\ncde'.match(new RegExp('^..^e')));
// 'yyyyy'.match(new RegExp('^xxx'))
testcases[count++] = new TestCase ( SECTION, "'yyyyy'.match(new RegExp('^xxx'))",
null, 'yyyyy'.match(new RegExp('^xxx')));
// '^^^x'.match(new RegExp('^\\^+'))
testcases[count++] = new TestCase ( SECTION, "'^^^x'.match(new RegExp('^\\^+'))",
String(['^^^']), String('^^^x'.match(new RegExp('^\\^+'))));
// '^^^x'.match(/^\^+/)
testcases[count++] = new TestCase ( SECTION, "'^^^x'.match(/^\\^+/)",
String(['^^^']), String('^^^x'.match(/^\^+/)));
RegExp.multiline = true;
// 'abc\n123xyz'.match(new RegExp('^\d+')) <multiline==true>
testcases[count++] = new TestCase ( SECTION, "'abc\n123xyz'.match(new RegExp('^\\d+'))",
String(['123']), String('abc\n123xyz'.match(new RegExp('^\\d+'))));
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 );
}
test();

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

@ -0,0 +1,104 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: character_class.js
Description: 'Tests regular expressions containing []'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: []';
writeHeaderToLog('Executing script: character_class.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcde'.match(new RegExp('ab[ercst]de'))
testcases[count++] = new TestCase ( SECTION, "'abcde'.match(new RegExp('ab[ercst]de'))",
String(["abcde"]), String('abcde'.match(new RegExp('ab[ercst]de'))));
// 'abcde'.match(new RegExp('ab[erst]de'))
testcases[count++] = new TestCase ( SECTION, "'abcde'.match(new RegExp('ab[erst]de'))",
null, 'abcde'.match(new RegExp('ab[erst]de')));
// 'abcdefghijkl'.match(new RegExp('[d-h]+'))
testcases[count++] = new TestCase ( SECTION, "'abcdefghijkl'.match(new RegExp('[d-h]+'))",
String(["defgh"]), String('abcdefghijkl'.match(new RegExp('[d-h]+'))));
// 'abc6defghijkl'.match(new RegExp('[1234567].{2}'))
testcases[count++] = new TestCase ( SECTION, "'abc6defghijkl'.match(new RegExp('[1234567].{2}'))",
String(["6de"]), String('abc6defghijkl'.match(new RegExp('[1234567].{2}'))));
// '\n\n\abc324234\n'.match(new RegExp('[a-c\d]+'))
testcases[count++] = new TestCase ( SECTION, "'\n\n\abc324234\n'.match(new RegExp('[a-c\\d]+'))",
String(["abc324234"]), String('\n\n\abc324234\n'.match(new RegExp('[a-c\\d]+'))));
// 'abc'.match(new RegExp('ab[.]?c'))
testcases[count++] = new TestCase ( SECTION, "'abc'.match(new RegExp('ab[.]?c'))",
String(["abc"]), String('abc'.match(new RegExp('ab[.]?c'))));
// 'abc'.match(new RegExp('a[b]c'))
testcases[count++] = new TestCase ( SECTION, "'abc'.match(new RegExp('a[b]c'))",
String(["abc"]), String('abc'.match(new RegExp('a[b]c'))));
// 'a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))
testcases[count++] = new TestCase ( SECTION, "'a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))",
String(["def"]), String('a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))));
// '123*&$abc'.match(new RegExp('[*&$]{3}'))
testcases[count++] = new TestCase ( SECTION, "'123*&$abc'.match(new RegExp('[*&$]{3}'))",
String(["*&$"]), String('123*&$abc'.match(new RegExp('[*&$]{3}'))));
// 'abc'.match(new RegExp('a[^1-9]c'))
testcases[count++] = new TestCase ( SECTION, "'abc'.match(new RegExp('a[^1-9]c'))",
String(["abc"]), String('abc'.match(new RegExp('a[^1-9]c'))));
// 'abc'.match(new RegExp('a[^b]c'))
testcases[count++] = new TestCase ( SECTION, "'abc'.match(new RegExp('a[^b]c'))",
null, 'abc'.match(new RegExp('a[^b]c')));
// 'abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))
testcases[count++] = new TestCase ( SECTION, "'abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))",
String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))));
// 'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)
testcases[count++] = new TestCase ( SECTION, "'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)",
String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)));
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 );
}
test();

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

@ -0,0 +1,91 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: compile.js
Description: 'Tests regular expressions method compile'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: compile';
writeHeaderToLog('Executing script: compile.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var regularExpression = new RegExp();
regularExpression.compile("[0-9]{3}x[0-9]{4}","i");
testcases[count++] = new TestCase ( SECTION,
"(compile '[0-9]{3}x[0-9]{4}','i')",
String(["456X7890"]), String('234X456X7890'.match(regularExpression)));
testcases[count++] = new TestCase ( SECTION,
"source of (compile '[0-9]{3}x[0-9]{4}','i')",
"[0-9]{3}x[0-9]{4}", regularExpression.source);
testcases[count++] = new TestCase ( SECTION,
"global of (compile '[0-9]{3}x[0-9]{4}','i')",
false, regularExpression.global);
testcases[count++] = new TestCase ( SECTION,
"ignoreCase of (compile '[0-9]{3}x[0-9]{4}','i')",
true, regularExpression.ignoreCase);
regularExpression.compile("[0-9]{3}X[0-9]{3}","g");
testcases[count++] = new TestCase ( SECTION,
"(compile '[0-9]{3}X[0-9]{3}','g')",
String(["234X456"]), String('234X456X7890'.match(regularExpression)));
testcases[count++] = new TestCase ( SECTION,
"source of (compile '[0-9]{3}X[0-9]{3}','g')",
"[0-9]{3}X[0-9]{3}", regularExpression.source);
testcases[count++] = new TestCase ( SECTION,
"global of (compile '[0-9]{3}X[0-9]{3}','g')",
true, regularExpression.global);
testcases[count++] = new TestCase ( SECTION,
"ignoreCase of (compile '[0-9]{3}X[0-9]{3}','g')",
false, regularExpression.ignoreCase);
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 );
}
test();

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

@ -0,0 +1,68 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: control_characters.js
Description: 'Tests regular expressions containing .'
Author: Nick Lerissa
Date: April 8, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: .';
var BUGNUMBER="123802";
writeHeaderToLog('Executing script: control_characters.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'àOÐ ê:i¢Ø'.match(new RegExp('.+'))
testcases[count++] = new TestCase ( SECTION, "'àOÐ ê:i¢Ø'.match(new RegExp('.+'))",
String(['àOÐ ê:i¢Ø']), String('àOÐ ê:i¢Ø'.match(new RegExp('.+'))));
// string1.match(new RegExp(string1))
var string1 = 'àOÐ ê:i¢Ø';
testcases[count++] = new TestCase ( SECTION, "string1 = " + string1 + " string1.match(string1)",
String([string1]), String(string1.match(string1)));
string1 = "";
for (var i = 0; i < 32; i++)
string1 += String.fromCharCode(i);
testcases[count++] = new TestCase ( SECTION, "string1 = " + string1 + " string1.match(string1)",
String([string1]), String(string1.match(string1)));
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 );
}
test();

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

@ -0,0 +1,116 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: digit.js
Description: 'Tests regular expressions containing \d'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: \\d';
writeHeaderToLog('Executing script: digit.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var non_digits = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"';
var digits = "1234567890";
// be sure all digits are matched by \d
testcases[count++] = new TestCase ( SECTION,
"'" + digits + "'.match(new RegExp('\\d+'))",
String([digits]), String(digits.match(new RegExp('\\d+'))));
// be sure all non-digits are matched by \D
testcases[count++] = new TestCase ( SECTION,
"'" + non_digits + "'.match(new RegExp('\\D+'))",
String([non_digits]), String(non_digits.match(new RegExp('\\D+'))));
// be sure all non-digits are not matched by \d
testcases[count++] = new TestCase ( SECTION,
"'" + non_digits + "'.match(new RegExp('\\d'))",
null, non_digits.match(new RegExp('\\d')));
// be sure all digits are not matched by \D
testcases[count++] = new TestCase ( SECTION,
"'" + digits + "'.match(new RegExp('\\D'))",
null, digits.match(new RegExp('\\D')));
var s = non_digits + digits;
// be sure all digits are matched by \d
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\d+'))",
String([digits]), String(s.match(new RegExp('\\d+'))));
var s = digits + non_digits;
// be sure all non-digits are matched by \D
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\D+'))",
String([non_digits]), String(s.match(new RegExp('\\D+'))));
var i;
// be sure all digits match individually
for (i = 0; i < digits.length; ++i)
{
s = 'ab' + digits[i] + 'cd';
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\d'))",
String([digits[i]]), String(s.match(new RegExp('\\d'))));
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(/\\d/)",
String([digits[i]]), String(s.match(/\d/)));
}
// be sure all non_digits match individually
for (i = 0; i < non_digits.length; ++i)
{
s = '12' + non_digits[i] + '34';
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\D'))",
String([non_digits[i]]), String(s.match(new RegExp('\\D'))));
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(/\\D/)",
String([non_digits[i]]), String(s.match(/\D/)));
}
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 );
}
test();

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

@ -0,0 +1,92 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: dot.js
Description: 'Tests regular expressions containing .'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: .';
writeHeaderToLog('Executing script: dot.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcde'.match(new RegExp('ab.de'))
testcases[count++] = new TestCase ( SECTION, "'abcde'.match(new RegExp('ab.de'))",
String(["abcde"]), String('abcde'.match(new RegExp('ab.de'))));
// 'line 1\nline 2'.match(new RegExp('.+'))
testcases[count++] = new TestCase ( SECTION, "'line 1\nline 2'.match(new RegExp('.+'))",
String(["line 1"]), String('line 1\nline 2'.match(new RegExp('.+'))));
// 'this is a test'.match(new RegExp('.*a.*'))
testcases[count++] = new TestCase ( SECTION, "'this is a test'.match(new RegExp('.*a.*'))",
String(["this is a test"]), String('this is a test'.match(new RegExp('.*a.*'))));
// 'this is a *&^%$# test'.match(new RegExp('.+'))
testcases[count++] = new TestCase ( SECTION, "'this is a *&^%$# test'.match(new RegExp('.+'))",
String(["this is a *&^%$# test"]), String('this is a *&^%$# test'.match(new RegExp('.+'))));
// '....'.match(new RegExp('.+'))
testcases[count++] = new TestCase ( SECTION, "'....'.match(new RegExp('.+'))",
String(["...."]), String('....'.match(new RegExp('.+'))));
// 'abcdefghijklmnopqrstuvwxyz'.match(new RegExp('.+'))
testcases[count++] = new TestCase ( SECTION, "'abcdefghijklmnopqrstuvwxyz'.match(new RegExp('.+'))",
String(["abcdefghijklmnopqrstuvwxyz"]), String('abcdefghijklmnopqrstuvwxyz'.match(new RegExp('.+'))));
// 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.match(new RegExp('.+'))
testcases[count++] = new TestCase ( SECTION, "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.match(new RegExp('.+'))",
String(["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]), String('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.match(new RegExp('.+'))));
// '`1234567890-=~!@#$%^&*()_+'.match(new RegExp('.+'))
testcases[count++] = new TestCase ( SECTION, "'`1234567890-=~!@#$%^&*()_+'.match(new RegExp('.+'))",
String(["`1234567890-=~!@#$%^&*()_+"]), String('`1234567890-=~!@#$%^&*()_+'.match(new RegExp('.+'))));
// '|\\[{]};:"\',<>.?/'.match(new RegExp('.+'))
testcases[count++] = new TestCase ( SECTION, "'|\\[{]};:\"\',<>.?/'.match(new RegExp('.+'))",
String(["|\\[{]};:\"\',<>.?/"]), String('|\\[{]};:\"\',<>.?/'.match(new RegExp('.+'))));
// '|\\[{]};:"\',<>.?/'.match(/.+/)
testcases[count++] = new TestCase ( SECTION, "'|\\[{]};:\"\',<>.?/'.match(/.+/)",
String(["|\\[{]};:\"\',<>.?/"]), String('|\\[{]};:\"\',<>.?/'.match(/.+/)));
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 );
}
test();

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

@ -0,0 +1,77 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: endLine.js
Description: 'Tests regular expressions containing $'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: $';
writeHeaderToLog('Executing script: endLine.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcde'.match(new RegExp('de$'))
testcases[count++] = new TestCase ( SECTION, "'abcde'.match(new RegExp('de$'))",
String(["de"]), String('abcde'.match(new RegExp('de$'))));
// 'ab\ncde'.match(new RegExp('..$e$'))
testcases[count++] = new TestCase ( SECTION, "'ab\ncde'.match(new RegExp('..$e$'))",
null, 'ab\ncde'.match(new RegExp('..$e$')));
// 'yyyyy'.match(new RegExp('xxx$'))
testcases[count++] = new TestCase ( SECTION, "'yyyyy'.match(new RegExp('xxx$'))",
null, 'yyyyy'.match(new RegExp('xxx$')));
// 'a$$$'.match(new RegExp('\\$+$'))
testcases[count++] = new TestCase ( SECTION, "'a$$$'.match(new RegExp('\\$+$'))",
String(['$$$']), String('a$$$'.match(new RegExp('\\$+$'))));
// 'a$$$'.match(/\$+$/)
testcases[count++] = new TestCase ( SECTION, "'a$$$'.match(/\\$+$/)",
String(['$$$']), String('a$$$'.match(/\$+$/)));
RegExp.multiline = true;
// 'abc\n123xyz890\nxyz'.match(new RegExp('\d+$')) <multiline==true>
testcases[count++] = new TestCase ( SECTION, "'abc\n123xyz890\nxyz'.match(new RegExp('\\d+$'))",
String(['890']), String('abc\n123xyz890\nxyz'.match(new RegExp('\\d+$'))));
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 );
}
test();

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

@ -0,0 +1,77 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: everything.js
Description: 'Tests regular expressions'
Author: Nick Lerissa
Date: March 24, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp';
writeHeaderToLog('Executing script: everything.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'Sally and Fred are sure to come.'.match(/^[a-z\s]*/i)
testcases[count++] = new TestCase ( SECTION, "'Sally and Fred are sure to come'.match(/^[a-z\\s]*/i)",
String(["Sally and Fred are sure to come"]), String('Sally and Fred are sure to come'.match(/^[a-z\s]*/i)));
// 'test123W+xyz'.match(new RegExp('^[a-z]*[0-9]+[A-Z]?.(123|xyz)$'))
testcases[count++] = new TestCase ( SECTION, "'test123W+xyz'.match(new RegExp('^[a-z]*[0-9]+[A-Z]?.(123|xyz)$'))",
String(["test123W+xyz","xyz"]), String('test123W+xyz'.match(new RegExp('^[a-z]*[0-9]+[A-Z]?.(123|xyz)$'))));
// 'number one 12365 number two 9898'.match(/(\d+)\D+(\d+)/)
testcases[count++] = new TestCase ( SECTION, "'number one 12365 number two 9898'.match(/(\d+)\D+(\d+)/)",
String(["12365 number two 9898","12365","9898"]), String('number one 12365 number two 9898'.match(/(\d+)\D+(\d+)/)));
var simpleSentence = /(\s?[^\!\?\.]+[\!\?\.])+/;
// 'See Spot run.'.match(simpleSentence)
testcases[count++] = new TestCase ( SECTION, "'See Spot run.'.match(simpleSentence)",
String(["See Spot run.","See Spot run."]), String('See Spot run.'.match(simpleSentence)));
// 'I like it. What's up? I said NO!'.match(simpleSentence)
testcases[count++] = new TestCase ( SECTION, "'I like it. What's up? I said NO!'.match(simpleSentence)",
String(["I like it. What's up? I said NO!",' I said NO!']), String('I like it. What\'s up? I said NO!'.match(simpleSentence)));
// 'the quick brown fox jumped over the lazy dogs'.match(/((\w+)\s*)+/)
testcases[count++] = new TestCase ( SECTION, "'the quick brown fox jumped over the lazy dogs'.match(/((\\w+)\\s*)+/)",
String(['the quick brown fox jumped over the lazy dogs','dogs','dogs']),String('the quick brown fox jumped over the lazy dogs'.match(/((\w+)\s*)+/)));
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 );
}
test();

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

@ -0,0 +1,74 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: exec.js
Description: 'Tests regular expressions exec compile'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: exec';
writeHeaderToLog('Executing script: exec.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
testcases[count++] = new TestCase ( SECTION,
"/[0-9]{3}/.exec('23 2 34 678 9 09')",
String(["678"]), String(/[0-9]{3}/.exec('23 2 34 678 9 09')));
testcases[count++] = new TestCase ( SECTION,
"/3.{4}8/.exec('23 2 34 678 9 09')",
String(["34 678"]), String(/3.{4}8/.exec('23 2 34 678 9 09')));
var re = new RegExp('3.{4}8');
testcases[count++] = new TestCase ( SECTION,
"re.exec('23 2 34 678 9 09')",
String(["34 678"]), String(re.exec('23 2 34 678 9 09')));
testcases[count++] = new TestCase ( SECTION,
"(/3.{4}8/.exec('23 2 34 678 9 09').length",
1, (/3.{4}8/.exec('23 2 34 678 9 09')).length);
re = new RegExp('3.{4}8');
testcases[count++] = new TestCase ( SECTION,
"(re.exec('23 2 34 678 9 09').length",
1, (re.exec('23 2 34 678 9 09')).length);
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 );
}
test();

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

@ -0,0 +1,81 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: regexp.js
Description: 'Tests regular expressions using flags "i" and "g"'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'regular expression flags with flags "i" and "g"';
writeHeaderToLog('Executing script: flags.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// testing optional flag 'i'
testcases[count++] = new TestCase ( SECTION, "'aBCdEfGHijKLmno'.match(/fghijk/i)",
String(["fGHijK"]), String('aBCdEfGHijKLmno'.match(/fghijk/i)));
testcases[count++] = new TestCase ( SECTION, "'aBCdEfGHijKLmno'.match(new RegExp('fghijk','i'))",
String(["fGHijK"]), String('aBCdEfGHijKLmno'.match(new RegExp("fghijk","i"))));
// testing optional flag 'g'
testcases[count++] = new TestCase ( SECTION, "'xa xb xc xd xe xf'.match(/x./g)",
String(["xa","xb","xc","xd","xe","xf"]), String('xa xb xc xd xe xf'.match(/x./g)));
testcases[count++] = new TestCase ( SECTION, "'xa xb xc xd xe xf'.match(new RegExp('x.','g'))",
String(["xa","xb","xc","xd","xe","xf"]), String('xa xb xc xd xe xf'.match(new RegExp('x.','g'))));
// testing optional flags 'g' and 'i'
testcases[count++] = new TestCase ( SECTION, "'xa Xb xc xd Xe xf'.match(/x./gi)",
String(["xa","Xb","xc","xd","Xe","xf"]), String('xa Xb xc xd Xe xf'.match(/x./gi)));
testcases[count++] = new TestCase ( SECTION, "'xa Xb xc xd Xe xf'.match(new RegExp('x.','gi'))",
String(["xa","Xb","xc","xd","Xe","xf"]), String('xa Xb xc xd Xe xf'.match(new RegExp('x.','gi'))));
testcases[count++] = new TestCase ( SECTION, "'xa Xb xc xd Xe xf'.match(/x./ig)",
String(["xa","Xb","xc","xd","Xe","xf"]), String('xa Xb xc xd Xe xf'.match(/x./ig)));
testcases[count++] = new TestCase ( SECTION, "'xa Xb xc xd Xe xf'.match(new RegExp('x.','ig'))",
String(["xa","Xb","xc","xd","Xe","xf"]), String('xa Xb xc xd Xe xf'.match(new RegExp('x.','ig'))));
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 );
}
test();

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

@ -0,0 +1,92 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: global.js
Description: 'Tests RegExp attribute global'
Author: Nick Lerissa
Date: March 13, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: global';
writeHeaderToLog('Executing script: global.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// /xyz/g.global
testcases[count++] = new TestCase ( SECTION, "/xyz/g.global",
true, /xyz/g.global);
// /xyz/.global
testcases[count++] = new TestCase ( SECTION, "/xyz/.global",
false, /xyz/.global);
// '123 456 789'.match(/\d+/g)
testcases[count++] = new TestCase ( SECTION, "'123 456 789'.match(/\\d+/g)",
String(["123","456","789"]), String('123 456 789'.match(/\d+/g)));
// '123 456 789'.match(/(\d+)/g)
testcases[count++] = new TestCase ( SECTION, "'123 456 789'.match(/(\\d+)/g)",
String(["123","456","789"]), String('123 456 789'.match(/(\d+)/g)));
// '123 456 789'.match(/\d+/)
testcases[count++] = new TestCase ( SECTION, "'123 456 789'.match(/\\d+/)",
String(["123"]), String('123 456 789'.match(/\d+/)));
// (new RegExp('[a-z]','g')).global
testcases[count++] = new TestCase ( SECTION, "(new RegExp('[a-z]','g')).global",
true, (new RegExp('[a-z]','g')).global);
// (new RegExp('[a-z]','i')).global
testcases[count++] = new TestCase ( SECTION, "(new RegExp('[a-z]','i')).global",
false, (new RegExp('[a-z]','i')).global);
// '123 456 789'.match(new RegExp('\\d+','g'))
testcases[count++] = new TestCase ( SECTION, "'123 456 789'.match(new RegExp('\\\\d+','g'))",
String(["123","456","789"]), String('123 456 789'.match(new RegExp('\\d+','g'))));
// '123 456 789'.match(new RegExp('(\\d+)','g'))
testcases[count++] = new TestCase ( SECTION, "'123 456 789'.match(new RegExp('(\\\\d+)','g'))",
String(["123","456","789"]), String('123 456 789'.match(new RegExp('(\\d+)','g'))));
// '123 456 789'.match(new RegExp('\\d+','i'))
testcases[count++] = new TestCase ( SECTION, "'123 456 789'.match(new RegExp('\\\\d+','i'))",
String(["123"]), String('123 456 789'.match(new RegExp('\\d+','i'))));
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 );
}
test();

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

@ -0,0 +1,105 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: hexadecimal.js
Description: 'Tests regular expressions containing \<number> '
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: \x# (hex) ';
writeHeaderToLog('Executing script: hexadecimal.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var testPattern = '\\x41\\x42\\x43\\x44\\x45\\x46\\x47\\x48\\x49\\x4A\\x4B\\x4C\\x4D\\x4E\\x4F\\x50\\x51\\x52\\x53\\x54\\x55\\x56\\x57\\x58\\x59\\x5A';
var testString = "12345ABCDEFGHIJKLMNOPQRSTUVWXYZ67890";
testcases[count++] = new TestCase ( SECTION,
"'" + testString + "'.match(new RegExp('" + testPattern + "'))",
String(["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]), String(testString.match(new RegExp(testPattern))));
testPattern = '\\x61\\x62\\x63\\x64\\x65\\x66\\x67\\x68\\x69\\x6A\\x6B\\x6C\\x6D\\x6E\\x6F\\x70\\x71\\x72\\x73\\x74\\x75\\x76\\x77\\x78\\x79\\x7A';
testString = "12345AabcdefghijklmnopqrstuvwxyzZ67890";
testcases[count++] = new TestCase ( SECTION,
"'" + testString + "'.match(new RegExp('" + testPattern + "'))",
String(["abcdefghijklmnopqrstuvwxyz"]), String(testString.match(new RegExp(testPattern))));
testPattern = '\\x20\\x21\\x22\\x23\\x24\\x25\\x26\\x27\\x28\\x29\\x2A\\x2B\\x2C\\x2D\\x2E\\x2F\\x30\\x31\\x32\\x33';
testString = "abc !\"#$%&'()*+,-./0123ZBC";
testcases[count++] = new TestCase ( SECTION,
"'" + testString + "'.match(new RegExp('" + testPattern + "'))",
String([" !\"#$%&'()*+,-./0123"]), String(testString.match(new RegExp(testPattern))));
testPattern = '\\x34\\x35\\x36\\x37\\x38\\x39\\x3A\\x3B\\x3C\\x3D\\x3E\\x3F\\x40';
testString = "123456789:;<=>?@ABC";
testcases[count++] = new TestCase ( SECTION,
"'" + testString + "'.match(new RegExp('" + testPattern + "'))",
String(["456789:;<=>?@"]), String(testString.match(new RegExp(testPattern))));
testPattern = '\\x7B\\x7C\\x7D\\x7E';
testString = "1234{|}~ABC";
testcases[count++] = new TestCase ( SECTION,
"'" + testString + "'.match(new RegExp('" + testPattern + "'))",
String(["{|}~"]), String(testString.match(new RegExp(testPattern))));
testcases[count++] = new TestCase ( SECTION,
"'canthisbeFOUND'.match(new RegExp('[A-\\x5A]+'))",
String(["FOUND"]), String('canthisbeFOUND'.match(new RegExp('[A-\\x5A]+'))));
testcases[count++] = new TestCase ( SECTION,
"'canthisbeFOUND'.match(new RegExp('[\\x61-\\x7A]+'))",
String(["canthisbe"]), String('canthisbeFOUND'.match(new RegExp('[\\x61-\\x7A]+'))));
testcases[count++] = new TestCase ( SECTION,
"'canthisbeFOUND'.match(/[\\x61-\\x7A]+/)",
String(["canthisbe"]), String('canthisbeFOUND'.match(/[\x61-\x7A]+/)));
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 );
}
test();

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

@ -0,0 +1,108 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: ignoreCase.js
Description: 'Tests RegExp attribute ignoreCase'
Author: Nick Lerissa
Date: March 13, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: ignoreCase';
writeHeaderToLog('Executing script: ignoreCase.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// /xyz/i.ignoreCase
testcases[count++] = new TestCase ( SECTION, "/xyz/i.ignoreCase",
true, /xyz/i.ignoreCase);
// /xyz/.ignoreCase
testcases[count++] = new TestCase ( SECTION, "/xyz/.ignoreCase",
false, /xyz/.ignoreCase);
// 'ABC def ghi'.match(/[a-z]+/ig)
testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(/[a-z]+/ig)",
String(["ABC","def","ghi"]), String('ABC def ghi'.match(/[a-z]+/ig)));
// 'ABC def ghi'.match(/[a-z]+/i)
testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(/[a-z]+/i)",
String(["ABC"]), String('ABC def ghi'.match(/[a-z]+/i)));
// 'ABC def ghi'.match(/([a-z]+)/ig)
testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(/([a-z]+)/ig)",
String(["ABC","def","ghi"]), String('ABC def ghi'.match(/([a-z]+)/ig)));
// 'ABC def ghi'.match(/([a-z]+)/i)
testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(/([a-z]+)/i)",
String(["ABC","ABC"]), String('ABC def ghi'.match(/([a-z]+)/i)));
// 'ABC def ghi'.match(/[a-z]+/)
testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(/[a-z]+/)",
String(["def"]), String('ABC def ghi'.match(/[a-z]+/)));
// (new RegExp('xyz','i')).ignoreCase
testcases[count++] = new TestCase ( SECTION, "(new RegExp('xyz','i')).ignoreCase",
true, (new RegExp('xyz','i')).ignoreCase);
// (new RegExp('xyz')).ignoreCase
testcases[count++] = new TestCase ( SECTION, "(new RegExp('xyz')).ignoreCase",
false, (new RegExp('xyz')).ignoreCase);
// 'ABC def ghi'.match(new RegExp('[a-z]+','ig'))
testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('[a-z]+','ig'))",
String(["ABC","def","ghi"]), String('ABC def ghi'.match(new RegExp('[a-z]+','ig'))));
// 'ABC def ghi'.match(new RegExp('[a-z]+','i'))
testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('[a-z]+','i'))",
String(["ABC"]), String('ABC def ghi'.match(new RegExp('[a-z]+','i'))));
// 'ABC def ghi'.match(new RegExp('([a-z]+)','ig'))
testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('([a-z]+)','ig'))",
String(["ABC","def","ghi"]), String('ABC def ghi'.match(new RegExp('([a-z]+)','ig'))));
// 'ABC def ghi'.match(new RegExp('([a-z]+)','i'))
testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('([a-z]+)','i'))",
String(["ABC","ABC"]), String('ABC def ghi'.match(new RegExp('([a-z]+)','i'))));
// 'ABC def ghi'.match(new RegExp('[a-z]+'))
testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('[a-z]+'))",
String(["def"]), String('ABC def ghi'.match(new RegExp('[a-z]+'))));
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 );
}
test();

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

@ -0,0 +1,112 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: interval.js
Description: 'Tests regular expressions containing {}'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: {}';
writeHeaderToLog('Executing script: interval.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2}c'))
testcases[count++] = new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{2}c'))",
String(["bbc"]), String('aaabbbbcccddeeeefffff'.match(new RegExp('b{2}c'))));
// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8}'))
testcases[count++] = new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{8}'))",
null, 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8}')));
// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,}c'))
testcases[count++] = new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,}c'))",
String(["bbbbc"]), String('aaabbbbcccddeeeefffff'.match(new RegExp('b{2,}c'))));
// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8,}c'))
testcases[count++] = new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{8,}c'))",
null, 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8,}c')));
// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,3}c'))
testcases[count++] = new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,3}c'))",
String(["bbbc"]), String('aaabbbbcccddeeeefffff'.match(new RegExp('b{2,3}c'))));
// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{42,93}c'))
testcases[count++] = new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{42,93}c'))",
null, 'aaabbbbcccddeeeefffff'.match(new RegExp('b{42,93}c')));
// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{0,93}c'))
testcases[count++] = new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{0,93}c'))",
String(["bbbbc"]), String('aaabbbbcccddeeeefffff'.match(new RegExp('b{0,93}c'))));
// 'aaabbbbcccddeeeefffff'.match(new RegExp('bx{0,93}c'))
testcases[count++] = new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('bx{0,93}c'))",
String(["bc"]), String('aaabbbbcccddeeeefffff'.match(new RegExp('bx{0,93}c'))));
// 'weirwerdf'.match(new RegExp('.{0,93}'))
testcases[count++] = new TestCase ( SECTION, "'weirwerdf'.match(new RegExp('.{0,93}'))",
String(["weirwerdf"]), String('weirwerdf'.match(new RegExp('.{0,93}'))));
// 'wqe456646dsff'.match(new RegExp('\d{1,}'))
testcases[count++] = new TestCase ( SECTION, "'wqe456646dsff'.match(new RegExp('\\d{1,}'))",
String(["456646"]), String('wqe456646dsff'.match(new RegExp('\\d{1,}'))));
// '123123'.match(new RegExp('(123){1,}'))
testcases[count++] = new TestCase ( SECTION, "'123123'.match(new RegExp('(123){1,}'))",
String(["123123","123"]), String('123123'.match(new RegExp('(123){1,}'))));
// '123123x123'.match(new RegExp('(123){1,}x\1'))
testcases[count++] = new TestCase ( SECTION, "'123123x123'.match(new RegExp('(123){1,}x\\1'))",
String(["123123x123","123"]), String('123123x123'.match(new RegExp('(123){1,}x\\1'))));
// '123123x123'.match(/(123){1,}x\1/)
testcases[count++] = new TestCase ( SECTION, "'123123x123'.match(/(123){1,}x\\1/)",
String(["123123x123","123"]), String('123123x123'.match(/(123){1,}x\1/)));
// 'xxxxxxx'.match(new RegExp('x{1,2}x{1,}'))
testcases[count++] = new TestCase ( SECTION, "'xxxxxxx'.match(new RegExp('x{1,2}x{1,}'))",
String(["xxxxxxx"]), String('xxxxxxx'.match(new RegExp('x{1,2}x{1,}'))));
// 'xxxxxxx'.match(/x{1,2}x{1,}/)
testcases[count++] = new TestCase ( SECTION, "'xxxxxxx'.match(/x{1,2}x{1,}/)",
String(["xxxxxxx"]), String('xxxxxxx'.match(/x{1,2}x{1,}/)));
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 );
}
test();

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

@ -0,0 +1,105 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: octal.js
Description: 'Tests regular expressions containing \<number> '
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: \# (octal) ';
writeHeaderToLog('Executing script: octal.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var testPattern = '\\101\\102\\103\\104\\105\\106\\107\\110\\111\\112\\113\\114\\115\\116\\117\\120\\121\\122\\123\\124\\125\\126\\127\\130\\131\\132';
var testString = "12345ABCDEFGHIJKLMNOPQRSTUVWXYZ67890";
testcases[count++] = new TestCase ( SECTION,
"'" + testString + "'.match(new RegExp('" + testPattern + "'))",
String(["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]), String(testString.match(new RegExp(testPattern))));
testPattern = '\\141\\142\\143\\144\\145\\146\\147\\150\\151\\152\\153\\154\\155\\156\\157\\160\\161\\162\\163\\164\\165\\166\\167\\170\\171\\172';
testString = "12345AabcdefghijklmnopqrstuvwxyzZ67890";
testcases[count++] = new TestCase ( SECTION,
"'" + testString + "'.match(new RegExp('" + testPattern + "'))",
String(["abcdefghijklmnopqrstuvwxyz"]), String(testString.match(new RegExp(testPattern))));
testPattern = '\\40\\41\\42\\43\\44\\45\\46\\47\\50\\51\\52\\53\\54\\55\\56\\57\\60\\61\\62\\63';
testString = "abc !\"#$%&'()*+,-./0123ZBC";
testcases[count++] = new TestCase ( SECTION,
"'" + testString + "'.match(new RegExp('" + testPattern + "'))",
String([" !\"#$%&'()*+,-./0123"]), String(testString.match(new RegExp(testPattern))));
testPattern = '\\64\\65\\66\\67\\70\\71\\72\\73\\74\\75\\76\\77\\100';
testString = "123456789:;<=>?@ABC";
testcases[count++] = new TestCase ( SECTION,
"'" + testString + "'.match(new RegExp('" + testPattern + "'))",
String(["456789:;<=>?@"]), String(testString.match(new RegExp(testPattern))));
testPattern = '\\173\\174\\175\\176';
testString = "1234{|}~ABC";
testcases[count++] = new TestCase ( SECTION,
"'" + testString + "'.match(new RegExp('" + testPattern + "'))",
String(["{|}~"]), String(testString.match(new RegExp(testPattern))));
testcases[count++] = new TestCase ( SECTION,
"'canthisbeFOUND'.match(new RegExp('[A-\\132]+'))",
String(["FOUND"]), String('canthisbeFOUND'.match(new RegExp('[A-\\132]+'))));
testcases[count++] = new TestCase ( SECTION,
"'canthisbeFOUND'.match(new RegExp('[\\141-\\172]+'))",
String(["canthisbe"]), String('canthisbeFOUND'.match(new RegExp('[\\141-\\172]+'))));
testcases[count++] = new TestCase ( SECTION,
"'canthisbeFOUND'.match(/[\\141-\\172]+/)",
String(["canthisbe"]), String('canthisbeFOUND'.match(/[\141-\172]+/)));
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 );
}
test();

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

@ -0,0 +1,104 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: parentheses.js
Description: 'Tests regular expressions containing ()'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: ()';
writeHeaderToLog('Executing script: parentheses.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abc'.match(new RegExp('(abc)'))
testcases[count++] = new TestCase ( SECTION, "'abc'.match(new RegExp('(abc)'))",
String(["abc","abc"]), String('abc'.match(new RegExp('(abc)'))));
// 'abcdefg'.match(new RegExp('a(bc)d(ef)g'))
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(bc)d(ef)g'))",
String(["abcdefg","bc","ef"]), String('abcdefg'.match(new RegExp('a(bc)d(ef)g'))));
// 'abcdefg'.match(new RegExp('(.{3})(.{4})'))
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(.{3})(.{4})'))",
String(["abcdefg","abc","defg"]), String('abcdefg'.match(new RegExp('(.{3})(.{4})'))));
// 'aabcdaabcd'.match(new RegExp('(aa)bcd\1'))
testcases[count++] = new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa)bcd\\1'))",
String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa)bcd\\1'))));
// 'aabcdaabcd'.match(new RegExp('(aa).+\1'))
testcases[count++] = new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa).+\\1'))",
String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa).+\\1'))));
// 'aabcdaabcd'.match(new RegExp('(.{2}).+\1'))
testcases[count++] = new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(.{2}).+\\1'))",
String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(.{2}).+\\1'))));
// '123456123456'.match(new RegExp('(\d{3})(\d{3})\1\2'))
testcases[count++] = new TestCase ( SECTION, "'123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2'))",
String(["123456123456","123","456"]), String('123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2'))));
// 'abcdefg'.match(new RegExp('a(..(..)..)'))
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(..(..)..)'))",
String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(new RegExp('a(..(..)..)'))));
// 'abcdefg'.match(/a(..(..)..)/)
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/a(..(..)..)/)",
String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(/a(..(..)..)/)));
// 'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))
testcases[count++] = new TestCase ( SECTION, "'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))",
String(["abcdef","abc","bc","c","def","ef","f"]), String('xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))));
// 'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\2\5'))
testcases[count++] = new TestCase ( SECTION, "'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5'))",
String(["abcdefbcef","abc","bc","c","def","ef","f"]), String('xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5'))));
// 'abcd'.match(new RegExp('a(.?)b\1c\1d\1'))
testcases[count++] = new TestCase ( SECTION, "'abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1'))",
String(["abcd",""]), String('abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1'))));
// 'abcd'.match(/a(.?)b\1c\1d\1/)
testcases[count++] = new TestCase ( SECTION, "'abcd'.match(/a(.?)b\\1c\\1d\\1/)",
String(["abcd",""]), String('abcd'.match(/a(.?)b\1c\1d\1/)));
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 );
}
test();

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

@ -0,0 +1,84 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: plus.js
Description: 'Tests regular expressions containing +'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: +';
writeHeaderToLog('Executing script: plus.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcdddddefg'.match(new RegExp('d+'))
testcases[count++] = new TestCase ( SECTION, "'abcdddddefg'.match(new RegExp('d+'))",
String(["ddddd"]), String('abcdddddefg'.match(new RegExp('d+'))));
// 'abcdefg'.match(new RegExp('o+'))
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('o+'))",
null, 'abcdefg'.match(new RegExp('o+')));
// 'abcdefg'.match(new RegExp('d+'))
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('d+'))",
String(['d']), String('abcdefg'.match(new RegExp('d+'))));
// 'abbbbbbbc'.match(new RegExp('(b+)(b+)(b+)'))
testcases[count++] = new TestCase ( SECTION, "'abbbbbbbc'.match(new RegExp('(b+)(b+)(b+)'))",
String(["bbbbbbb","bbbbb","b","b"]), String('abbbbbbbc'.match(new RegExp('(b+)(b+)(b+)'))));
// 'abbbbbbbc'.match(new RegExp('(b+)(b*)'))
testcases[count++] = new TestCase ( SECTION, "'abbbbbbbc'.match(new RegExp('(b+)(b*)'))",
String(["bbbbbbb","bbbbbbb",""]), String('abbbbbbbc'.match(new RegExp('(b+)(b*)'))));
// 'abbbbbbbc'.match(new RegExp('b*b+'))
testcases[count++] = new TestCase ( SECTION, "'abbbbbbbc'.match(new RegExp('b*b+'))",
String(['bbbbbbb']), String('abbbbbbbc'.match(new RegExp('b*b+'))));
// 'abbbbbbbc'.match(/(b+)(b*)/)
testcases[count++] = new TestCase ( SECTION, "'abbbbbbbc'.match(/(b+)(b*)/)",
String(["bbbbbbb","bbbbbbb",""]), String('abbbbbbbc'.match(/(b+)(b*)/)));
// 'abbbbbbbc'.match(new RegExp('b*b+'))
testcases[count++] = new TestCase ( SECTION, "'abbbbbbbc'.match(/b*b+/)",
String(['bbbbbbb']), String('abbbbbbbc'.match(/b*b+/)));
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 );
}
test();

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

@ -0,0 +1,96 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: question_mark.js
Description: 'Tests regular expressions containing ?'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: ?';
writeHeaderToLog('Executing script: question_mark.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcdef'.match(new RegExp('cd?e'))
testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(new RegExp('cd?e'))",
String(["cde"]), String('abcdef'.match(new RegExp('cd?e'))));
// 'abcdef'.match(new RegExp('cdx?e'))
testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(new RegExp('cdx?e'))",
String(["cde"]), String('abcdef'.match(new RegExp('cdx?e'))));
// 'pqrstuvw'.match(new RegExp('o?pqrst'))
testcases[count++] = new TestCase ( SECTION, "'pqrstuvw'.match(new RegExp('o?pqrst'))",
String(["pqrst"]), String('pqrstuvw'.match(new RegExp('o?pqrst'))));
// 'abcd'.match(new RegExp('x?y?z?'))
testcases[count++] = new TestCase ( SECTION, "'abcd'.match(new RegExp('x?y?z?'))",
String([""]), String('abcd'.match(new RegExp('x?y?z?'))));
// 'abcd'.match(new RegExp('x?ay?bz?c'))
testcases[count++] = new TestCase ( SECTION, "'abcd'.match(new RegExp('x?ay?bz?c'))",
String(["abc"]), String('abcd'.match(new RegExp('x?ay?bz?c'))));
// 'abcd'.match(/x?ay?bz?c/)
testcases[count++] = new TestCase ( SECTION, "'abcd'.match(/x?ay?bz?c/)",
String(["abc"]), String('abcd'.match(/x?ay?bz?c/)));
// 'abbbbc'.match(new RegExp('b?b?b?b'))
testcases[count++] = new TestCase ( SECTION, "'abbbbc'.match(new RegExp('b?b?b?b'))",
String(["bbbb"]), String('abbbbc'.match(new RegExp('b?b?b?b'))));
// '123az789'.match(new RegExp('ab?c?d?x?y?z'))
testcases[count++] = new TestCase ( SECTION, "'123az789'.match(new RegExp('ab?c?d?x?y?z'))",
String(["az"]), String('123az789'.match(new RegExp('ab?c?d?x?y?z'))));
// '123az789'.match(/ab?c?d?x?y?z/)
testcases[count++] = new TestCase ( SECTION, "'123az789'.match(/ab?c?d?x?y?z/)",
String(["az"]), String('123az789'.match(/ab?c?d?x?y?z/)));
// '?????'.match(new RegExp('\\??\\??\\??\\??\\??'))
testcases[count++] = new TestCase ( SECTION, "'?????'.match(new RegExp('\\??\\??\\??\\??\\??'))",
String(["?????"]), String('?????'.match(new RegExp('\\??\\??\\??\\??\\??'))));
// 'test'.match(new RegExp('.?.?.?.?.?.?.?'))
testcases[count++] = new TestCase ( SECTION, "'test'.match(new RegExp('.?.?.?.?.?.?.?'))",
String(["test"]), String('test'.match(new RegExp('.?.?.?.?.?.?.?'))));
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 );
}
test();

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

@ -0,0 +1,87 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: simple_form.js
Description: 'Tests regular expressions using simple form: re(...)'
Author: Nick Lerissa
Date: March 19, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: simple form';
writeHeaderToLog('Executing script: simple_form.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
testcases[count++] = new TestCase ( SECTION,
"/[0-9]{3}/('23 2 34 678 9 09')",
String(["678"]), String(/[0-9]{3}/('23 2 34 678 9 09')));
testcases[count++] = new TestCase ( SECTION,
"/3.{4}8/('23 2 34 678 9 09')",
String(["34 678"]), String(/3.{4}8/('23 2 34 678 9 09')));
testcases[count++] = new TestCase ( SECTION,
"(/3.{4}8/('23 2 34 678 9 09').length",
1, (/3.{4}8/('23 2 34 678 9 09')).length);
var re = /[0-9]{3}/;
testcases[count++] = new TestCase ( SECTION,
"re('23 2 34 678 9 09')",
String(["678"]), String(re('23 2 34 678 9 09')));
re = /3.{4}8/;
testcases[count++] = new TestCase ( SECTION,
"re('23 2 34 678 9 09')",
String(["34 678"]), String(re('23 2 34 678 9 09')));
testcases[count++] = new TestCase ( SECTION,
"/3.{4}8/('23 2 34 678 9 09')",
String(["34 678"]), String(/3.{4}8/('23 2 34 678 9 09')));
re =/3.{4}8/;
testcases[count++] = new TestCase ( SECTION,
"(re('23 2 34 678 9 09').length",
1, (re('23 2 34 678 9 09')).length);
testcases[count++] = new TestCase ( SECTION,
"(/3.{4}8/('23 2 34 678 9 09').length",
1, (/3.{4}8/('23 2 34 678 9 09')).length);
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 );
}
test();

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

@ -0,0 +1,84 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: source.js
Description: 'Tests RegExp attribute source'
Author: Nick Lerissa
Date: March 13, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: source';
writeHeaderToLog('Executing script: source.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// /xyz/g.source
testcases[count++] = new TestCase ( SECTION, "/xyz/g.source",
"xyz", /xyz/g.source);
// /xyz/.source
testcases[count++] = new TestCase ( SECTION, "/xyz/.source",
"xyz", /xyz/.source);
// /abc\\def/.source
testcases[count++] = new TestCase ( SECTION, "/abc\\\\def/.source",
"abc\\\\def", /abc\\def/.source);
// /abc[\b]def/.source
testcases[count++] = new TestCase ( SECTION, "/abc[\\b]def/.source",
"abc[\\b]def", /abc[\b]def/.source);
// (new RegExp('xyz')).source
testcases[count++] = new TestCase ( SECTION, "(new RegExp('xyz')).source",
"xyz", (new RegExp('xyz')).source);
// (new RegExp('xyz','g')).source
testcases[count++] = new TestCase ( SECTION, "(new RegExp('xyz','g')).source",
"xyz", (new RegExp('xyz','g')).source);
// (new RegExp('abc\\\\def')).source
testcases[count++] = new TestCase ( SECTION, "(new RegExp('abc\\\\\\\\def')).source",
"abc\\\\def", (new RegExp('abc\\\\def')).source);
// (new RegExp('abc[\\b]def')).source
testcases[count++] = new TestCase ( SECTION, "(new RegExp('abc[\\\\b]def')).source",
"abc[\\b]def", (new RegExp('abc[\\b]def')).source);
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 );
}
test();

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

@ -0,0 +1,154 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: special_characters.js
Description: 'Tests regular expressions containing special characters'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: special_charaters';
writeHeaderToLog('Executing script: special_characters.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// testing backslash '\'
testcases[count++] = new TestCase ( SECTION, "'^abcdefghi'.match(/\^abc/)", String(["^abc"]), String('^abcdefghi'.match(/\^abc/)));
// testing beginning of line '^'
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/^abc/)", String(["abc"]), String('abcdefghi'.match(/^abc/)));
// testing end of line '$'
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/fghi$/)", String(["ghi"]), String('abcdefghi'.match(/ghi$/)));
// testing repeat '*'
testcases[count++] = new TestCase ( SECTION, "'eeeefghi'.match(/e*/)", String(["eeee"]), String('eeeefghi'.match(/e*/)));
// testing repeat 1 or more times '+'
testcases[count++] = new TestCase ( SECTION, "'abcdeeeefghi'.match(/e+/)", String(["eeee"]), String('abcdeeeefghi'.match(/e+/)));
// testing repeat 0 or 1 time '?'
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/abc?de/)", String(["abcde"]), String('abcdefghi'.match(/abc?de/)));
// testing any character '.'
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/c.e/)", String(["cde"]), String('abcdefghi'.match(/c.e/)));
// testing remembering ()
testcases[count++] = new TestCase ( SECTION, "'abcewirjskjdabciewjsdf'.match(/(abc).+\\1'/)",
String(["abcewirjskjdabc","abc"]), String('abcewirjskjdabciewjsdf'.match(/(abc).+\1/)));
// testing or match '|'
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/xyz|def/)", String(["def"]), String('abcdefghi'.match(/xyz|def/)));
// testing repeat n {n}
testcases[count++] = new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3}/)", String(["eee"]), String('abcdeeeefghi'.match(/e{3}/)));
// testing min repeat n {n,}
testcases[count++] = new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3,}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{3,}/)));
// testing min/max repeat {min, max}
testcases[count++] = new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{2,8}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{2,8}/)));
// testing any in set [abc...]
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/cd[xey]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[xey]fgh/)));
// testing any in set [a-z]
testcases[count++] = new TestCase ( SECTION, "'netscape inc'.match(/t[r-v]ca/)", String(["tsca"]), String('netscape inc'.match(/t[r-v]ca/)));
// testing any not in set [^abc...]
testcases[count++] = new TestCase ( SECTION, "'abcdefghi'.match(/cd[^xy]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[^xy]fgh/)));
// testing any not in set [^a-z]
testcases[count++] = new TestCase ( SECTION, "'netscape inc'.match(/t[^a-c]ca/)", String(["tsca"]), String('netscape inc'.match(/t[^a-c]ca/)));
// testing backspace [\b]
testcases[count++] = new TestCase ( SECTION, "'this is b\ba test'.match(/is b[\b]a test/)",
String(["is b\ba test"]), String('this is b\ba test'.match(/is b[\b]a test/)));
// testing word boundary \b
testcases[count++] = new TestCase ( SECTION, "'today is now - day is not now'.match(/\bday.*now/)",
String(["day is not now"]), String('today is now - day is not now'.match(/\bday.*now/)));
// control characters???
// testing any digit \d
testcases[count++] = new TestCase ( SECTION, "'a dog - 1 dog'.match(/\d dog/)", String(["1 dog"]), String('a dog - 1 dog'.match(/\d dog/)));
// testing any non digit \d
testcases[count++] = new TestCase ( SECTION, "'a dog - 1 dog'.match(/\D dog/)", String(["a dog"]), String('a dog - 1 dog'.match(/\D dog/)));
// testing form feed '\f'
testcases[count++] = new TestCase ( SECTION, "'a b a\fb'.match(/a\fb/)", String(["a\fb"]), String('a b a\fb'.match(/a\fb/)));
// testing line feed '\n'
testcases[count++] = new TestCase ( SECTION, "'a b a\nb'.match(/a\nb/)", String(["a\nb"]), String('a b a\nb'.match(/a\nb/)));
// testing carriage return '\r'
testcases[count++] = new TestCase ( SECTION, "'a b a\rb'.match(/a\rb/)", String(["a\rb"]), String('a b a\rb'.match(/a\rb/)));
// testing whitespace '\s'
testcases[count++] = new TestCase ( SECTION, "'xa\f\n\r\t\vbz'.match(/a\s+b/)", String(["a\f\n\r\t\vb"]), String('xa\f\n\r\t\vbz'.match(/a\s+b/)));
// testing non whitespace '\S'
testcases[count++] = new TestCase ( SECTION, "'a\tb a b a-b'.match(/a\Sb/)", String(["a-b"]), String('a\tb a b a-b'.match(/a\Sb/)));
// testing tab '\t'
testcases[count++] = new TestCase ( SECTION, "'a\t\tb a b'.match(/a\t{2}/)", String(["a\t\t"]), String('a\t\tb a b'.match(/a\t{2}/)));
// testing vertical tab '\v'
testcases[count++] = new TestCase ( SECTION, "'a\v\vb a b'.match(/a\v{2}/)", String(["a\v\v"]), String('a\v\vb a b'.match(/a\v{2}/)));
// testing alphnumeric characters '\w'
testcases[count++] = new TestCase ( SECTION, "'%AZaz09_$'.match(/\w+/)", String(["AZaz09_"]), String('%AZaz09_$'.match(/\w+/)));
// testing non alphnumeric characters '\W'
testcases[count++] = new TestCase ( SECTION, "'azx$%#@*4534'.match(/\W+/)", String(["$%#@*"]), String('azx$%#@*4534'.match(/\W+/)));
// testing back references '\<number>'
testcases[count++] = new TestCase ( SECTION, "'test'.match(/(t)es\\1/)", String(["test","t"]), String('test'.match(/(t)es\1/)));
// testing hex excaping with '\'
testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(/\x63\x64/)", String(["cd"]), String('abcdef'.match(/\x63\x64/)));
// testing oct excaping with '\'
testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(/\\143\\144/)", String(["cd"]), String('abcdef'.match(/\143\144/)));
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 );
}
test();

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

@ -0,0 +1,77 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: string_replace.js
Description: 'Tests the replace method on Strings using regular expressions'
Author: Nick Lerissa
Date: March 11, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String: replace';
writeHeaderToLog('Executing script: string_replace.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'adddb'.replace(/ddd/,"XX")
testcases[count++] = new TestCase ( SECTION, "'adddb'.replace(/ddd/,'XX')",
"aXXb", 'adddb'.replace(/ddd/,'XX'));
// 'adddb'.replace(/eee/,"XX")
testcases[count++] = new TestCase ( SECTION, "'adddb'.replace(/eee/,'XX')",
'adddb', 'adddb'.replace(/eee/,'XX'));
// '34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**')
testcases[count++] = new TestCase ( SECTION, "'34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**')",
"34 56 ** 12", '34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**'));
// '34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX')
testcases[count++] = new TestCase ( SECTION, "'34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX')",
"34 56 78b 12", '34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX'));
// 'original'.replace(new RegExp(),'XX')
testcases[count++] = new TestCase ( SECTION, "'original'.replace(new RegExp(),'XX')",
"XXoriginal", 'original'.replace(new RegExp(),'XX'));
// 'qwe ert x\t\n 345654AB'.replace(new RegExp('x\s*\d+(..)$'),'****')
testcases[count++] = new TestCase ( SECTION, "'qwe ert x\t\n 345654AB'.replace(new RegExp('x\\s*\\d+(..)$'),'****')",
"qwe ert ****", 'qwe ert x\t\n 345654AB'.replace(new RegExp('x\\s*\\d+(..)$'),'****'));
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 );
}
test();

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

@ -0,0 +1,84 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: string_search.js
Description: 'Tests the search method on Strings using regular expressions'
Author: Nick Lerissa
Date: March 12, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String: search';
writeHeaderToLog('Executing script: string_search.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abcdefg'.search(/d/)
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.search(/d/)",
3, 'abcdefg'.search(/d/));
// 'abcdefg'.search(/x/)
testcases[count++] = new TestCase ( SECTION, "'abcdefg'.search(/x/)",
-1, 'abcdefg'.search(/x/));
// 'abcdefg123456hijklmn'.search(/\d+/)
testcases[count++] = new TestCase ( SECTION, "'abcdefg123456hijklmn'.search(/\d+/)",
7, 'abcdefg123456hijklmn'.search(/\d+/));
// 'abcdefg123456hijklmn'.search(new RegExp())
testcases[count++] = new TestCase ( SECTION, "'abcdefg123456hijklmn'.search(new RegExp())",
0, 'abcdefg123456hijklmn'.search(new RegExp()));
// 'abc'.search(new RegExp('$'))
testcases[count++] = new TestCase ( SECTION, "'abc'.search(new RegExp('$'))",
3, 'abc'.search(new RegExp('$')));
// 'abc'.search(new RegExp('^'))
testcases[count++] = new TestCase ( SECTION, "'abc'.search(new RegExp('^'))",
0, 'abc'.search(new RegExp('^')));
// 'abc1'.search(/.\d/)
testcases[count++] = new TestCase ( SECTION, "'abc1'.search(/.\d/)",
2, 'abc1'.search(/.\d/));
// 'abc1'.search(/\d{2}/)
testcases[count++] = new TestCase ( SECTION, "'abc1'.search(/\d{2}/)",
-1, 'abc1'.search(/\d{2}/));
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 );
}
test();

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

@ -0,0 +1,88 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: string_split.js
Description: 'Tests the split method on Strings using regular expressions'
Author: Nick Lerissa
Date: March 11, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'String: split';
writeHeaderToLog('Executing script: string_split.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'a b c de f'.split(/\s/)
testcases[count++] = new TestCase ( SECTION, "'a b c de f'.split(/\s/)",
String(["a","b","c","de","f"]), String('a b c de f'.split(/\s/)));
// 'a b c de f'.split(/\s/,3)
testcases[count++] = new TestCase ( SECTION, "'a b c de f'.split(/\s/,3)",
String(["a","b","c"]), String('a b c de f'.split(/\s/,3)));
// 'a b c de f'.split(/X/)
testcases[count++] = new TestCase ( SECTION, "'a b c de f'.split(/X/)",
String(["a b c de f"]), String('a b c de f'.split(/X/)));
// 'dfe23iu 34 =+65--'.split(/\d+/)
testcases[count++] = new TestCase ( SECTION, "'dfe23iu 34 =+65--'.split(/\d+/)",
String(["dfe","iu "," =+","--"]), String('dfe23iu 34 =+65--'.split(/\d+/)));
// 'dfe23iu 34 =+65--'.split(new RegExp('\d+'))
testcases[count++] = new TestCase ( SECTION, "'dfe23iu 34 =+65--'.split(new RegExp('\\d+'))",
String(["dfe","iu "," =+","--"]), String('dfe23iu 34 =+65--'.split(new RegExp('\\d+'))));
// 'abc'.split(/[a-z]/)
testcases[count++] = new TestCase ( SECTION, "'abc'.split(/[a-z]/)",
String(["","",""]), String('abc'.split(/[a-z]/)));
// 'abc'.split(/[a-z]/)
testcases[count++] = new TestCase ( SECTION, "'abc'.split(/[a-z]/)",
String(["","",""]), String('abc'.split(/[a-z]/)));
// 'abc'.split(new RegExp('[a-z]'))
testcases[count++] = new TestCase ( SECTION, "'abc'.split(new RegExp('[a-z]'))",
String(["","",""]), String('abc'.split(new RegExp('[a-z]'))));
// 'abc'.split(new RegExp('[a-z]'))
testcases[count++] = new TestCase ( SECTION, "'abc'.split(new RegExp('[a-z]'))",
String(["","",""]), String('abc'.split(new RegExp('[a-z]'))));
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 );
}
test();

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

@ -0,0 +1,84 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: test.js
Description: 'Tests regular expressions method compile'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: test';
writeHeaderToLog('Executing script: test.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
testcases[count++] = new TestCase ( SECTION,
"/[0-9]{3}/.test('23 2 34 678 9 09')",
true, /[0-9]{3}/.test('23 2 34 678 9 09'));
testcases[count++] = new TestCase ( SECTION,
"/[0-9]{3}/.test('23 2 34 78 9 09')",
false, /[0-9]{3}/.test('23 2 34 78 9 09'));
testcases[count++] = new TestCase ( SECTION,
"/\w+ \w+ \w+/.test('do a test')",
true, /\w+ \w+ \w+/.test("do a test"));
testcases[count++] = new TestCase ( SECTION,
"/\w+ \w+ \w+/.test('a test')",
false, /\w+ \w+ \w+/.test("a test"));
testcases[count++] = new TestCase ( SECTION,
"(new RegExp('[0-9]{3}')).test('23 2 34 678 9 09')",
true, (new RegExp('[0-9]{3}')).test('23 2 34 678 9 09'));
testcases[count++] = new TestCase ( SECTION,
"(new RegExp('[0-9]{3}')).test('23 2 34 78 9 09')",
false, (new RegExp('[0-9]{3}')).test('23 2 34 78 9 09'));
testcases[count++] = new TestCase ( SECTION,
"(new RegExp('\\\\w+ \\\\w+ \\\\w+')).test('do a test')",
true, (new RegExp('\\w+ \\w+ \\w+')).test("do a test"));
testcases[count++] = new TestCase ( SECTION,
"(new RegExp('\\\\w+ \\\\w+ \\\\w+')).test('a test')",
false, (new RegExp('\\w+ \\w+ \\w+')).test("a test"));
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 );
}
test();

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

@ -0,0 +1,72 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: toString.js
Description: 'Tests RegExp method toString'
Author: Nick Lerissa
Date: March 13, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: toString';
writeHeaderToLog('Executing script: toString.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// var re = new RegExp(); re.toString()
var re = new RegExp();
testcases[count++] = new TestCase ( SECTION, "var re = new RegExp(); re.toString()",
'//', re.toString());
// re = /.+/; re.toString();
re = /.+/;
testcases[count++] = new TestCase ( SECTION, "re = /.+/; re.toString()",
'/.+/', re.toString());
// re = /test/gi; re.toString()
re = /test/gi;
testcases[count++] = new TestCase ( SECTION, "re = /test/gi; re.toString()",
'/test/gi', re.toString());
// re = /test2/ig; re.toString()
re = /test2/ig;
testcases[count++] = new TestCase ( SECTION, "re = /test2/ig; re.toString()",
'/test2/gi', re.toString());
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 );
}
test();

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

@ -0,0 +1,92 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: vertical_bar.js
Description: 'Tests regular expressions containing |'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: |';
writeHeaderToLog('Executing script: vertical_bar.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'abc'.match(new RegExp('xyz|abc'))
testcases[count++] = new TestCase ( SECTION, "'abc'.match(new RegExp('xyz|abc'))",
String(["abc"]), String('abc'.match(new RegExp('xyz|abc'))));
// 'this is a test'.match(new RegExp('quiz|exam|test|homework'))
testcases[count++] = new TestCase ( SECTION, "'this is a test'.match(new RegExp('quiz|exam|test|homework'))",
String(["test"]), String('this is a test'.match(new RegExp('quiz|exam|test|homework'))));
// 'abc'.match(new RegExp('xyz|...'))
testcases[count++] = new TestCase ( SECTION, "'abc'.match(new RegExp('xyz|...'))",
String(["abc"]), String('abc'.match(new RegExp('xyz|...'))));
// 'abc'.match(new RegExp('(.)..|abc'))
testcases[count++] = new TestCase ( SECTION, "'abc'.match(new RegExp('(.)..|abc'))",
String(["abc","a"]), String('abc'.match(new RegExp('(.)..|abc'))));
// 'color: grey'.match(new RegExp('.+: gr(a|e)y'))
testcases[count++] = new TestCase ( SECTION, "'color: grey'.match(new RegExp('.+: gr(a|e)y'))",
String(["color: grey","e"]), String('color: grey'.match(new RegExp('.+: gr(a|e)y'))));
// 'no match'.match(new RegExp('red|white|blue'))
testcases[count++] = new TestCase ( SECTION, "'no match'.match(new RegExp('red|white|blue'))",
null, 'no match'.match(new RegExp('red|white|blue')));
// 'Hi Bob'.match(new RegExp('(Rob)|(Bob)|(Robert)|(Bobby)'))
testcases[count++] = new TestCase ( SECTION, "'Hi Bob'.match(new RegExp('(Rob)|(Bob)|(Robert)|(Bobby)'))",
String(["Bob","","Bob"]), String('Hi Bob'.match(new RegExp('(Rob)|(Bob)|(Robert)|(Bobby)'))));
// 'abcdef'.match(new RegExp('abc|bcd|cde|def'))
testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(new RegExp('abc|bcd|cde|def'))",
String(["abc"]), String('abcdef'.match(new RegExp('abc|bcd|cde|def'))));
// 'Hi Bob'.match(/(Rob)|(Bob)|(Robert)|(Bobby)/)
testcases[count++] = new TestCase ( SECTION, "'Hi Bob'.match(/(Rob)|(Bob)|(Robert)|(Bobby)/)",
String(["Bob","","Bob"]), String('Hi Bob'.match(/(Rob)|(Bob)|(Robert)|(Bobby)/)));
// 'abcdef'.match(/abc|bcd|cde|def/)
testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(/abc|bcd|cde|def/)",
String(["abc"]), String('abcdef'.match(/abc|bcd|cde|def/)));
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 );
}
test();

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

@ -0,0 +1,119 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: whitespace.js
Description: 'Tests regular expressions containing \f\n\r\t\v\s\S\ '
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: \\f\\n\\r\\t\\v\\s\\S ';
writeHeaderToLog('Executing script: whitespace.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var non_whitespace = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()-+={[}]|\\:;'<,>./?1234567890" + '"';
var whitespace = "\f\n\r\t\v ";
// be sure all whitespace is matched by \s
testcases[count++] = new TestCase ( SECTION,
"'" + whitespace + "'.match(new RegExp('\\s+'))",
String([whitespace]), String(whitespace.match(new RegExp('\\s+'))));
// be sure all non-whitespace is matched by \S
testcases[count++] = new TestCase ( SECTION,
"'" + non_whitespace + "'.match(new RegExp('\\S+'))",
String([non_whitespace]), String(non_whitespace.match(new RegExp('\\S+'))));
// be sure all non-whitespace is not matched by \s
testcases[count++] = new TestCase ( SECTION,
"'" + non_whitespace + "'.match(new RegExp('\\s'))",
null, non_whitespace.match(new RegExp('\\s')));
// be sure all whitespace is not matched by \S
testcases[count++] = new TestCase ( SECTION,
"'" + whitespace + "'.match(new RegExp('\\S'))",
null, whitespace.match(new RegExp('\\S')));
var s = non_whitespace + whitespace;
// be sure all digits are matched by \s
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\s+'))",
String([whitespace]), String(s.match(new RegExp('\\s+'))));
s = whitespace + non_whitespace;
// be sure all non-whitespace are matched by \S
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\S+'))",
String([non_whitespace]), String(s.match(new RegExp('\\S+'))));
// '1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+'))
testcases[count++] = new TestCase ( SECTION, "'1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+'))",
String(["find me"]), String('1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+'))));
var i;
// be sure all whitespace characters match individually
for (i = 0; i < whitespace.length; ++i)
{
s = 'ab' + whitespace[i] + 'cd';
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\\\s'))",
String([whitespace[i]]), String(s.match(new RegExp('\\s'))));
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(/\s/)",
String([whitespace[i]]), String(s.match(/\s/)));
}
// be sure all non_whitespace characters match individually
for (i = 0; i < non_whitespace.length; ++i)
{
s = ' ' + non_whitespace[i] + ' ';
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\\\S'))",
String([non_whitespace[i]]), String(s.match(new RegExp('\\S'))));
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(/\S/)",
String([non_whitespace[i]]), String(s.match(/\S/)));
}
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 );
}
test();

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

@ -0,0 +1,116 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: word_boundary.js
Description: 'Tests regular expressions containing \b and \B'
Author: Nick Lerissa
Date: March 10, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'RegExp: \\b and \\B';
writeHeaderToLog('Executing script: word_boundary.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// 'cowboy boyish boy'.match(new RegExp('\bboy\b'))
testcases[count++] = new TestCase ( SECTION, "'cowboy boyish boy'.match(new RegExp('\\bboy\\b'))",
String(["boy"]), String('cowboy boyish boy'.match(new RegExp('\\bboy\\b'))));
var boundary_characters = "\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"';
var non_boundary_characters = '1234567890_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var s = '';
var i;
// testing whether all boundary characters are matched when they should be
for (i = 0; i < boundary_characters.length; ++i)
{
s = '123ab' + boundary_characters.charAt(i) + '123c' + boundary_characters.charAt(i);
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\b123[a-z]\\b'))",
String(["123c"]), String(s.match(new RegExp('\\b123[a-z]\\b'))));
}
// testing whether all non-boundary characters are matched when they should be
for (i = 0; i < non_boundary_characters.length; ++i)
{
s = '123ab' + non_boundary_characters.charAt(i) + '123c' + non_boundary_characters.charAt(i);
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\B123[a-z]\\B'))",
String(["123c"]), String(s.match(new RegExp('\\B123[a-z]\\B'))));
}
s = '';
// testing whether all boundary characters are not matched when they should not be
for (i = 0; i < boundary_characters.length; ++i)
{
s += boundary_characters[i] + "a" + i + "b";
}
s += "xa1111bx";
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\Ba\\d+b\\B'))",
String(["a1111b"]), String(s.match(new RegExp('\\Ba\\d+b\\B'))));
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(/\\Ba\\d+b\\B/)",
String(["a1111b"]), String(s.match(/\Ba\d+b\B/)));
s = '';
// testing whether all non-boundary characters are not matched when they should not be
for (i = 0; i < non_boundary_characters.length; ++i)
{
s += non_boundary_characters[i] + "a" + i + "b";
}
s += "(a1111b)";
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(new RegExp('\\ba\\d+b\\b'))",
String(["a1111b"]), String(s.match(new RegExp('\\ba\\d+b\\b'))));
testcases[count++] = new TestCase ( SECTION,
"'" + s + "'.match(/\\ba\\d+b\\b/)",
String(["a1111b"]), String(s.match(/\ba\d+b\b/)));
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 );
}
test();

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

@ -0,0 +1,162 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
var completed = false;
var testcases;
SECTION = "";
VERSION = "";
startTest();
BUGNUMBER = "";
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 );
}
/* wrapper for test cas constructor that doesn't require the SECTION
* argument.
*/
function AddTestCase( description, expect, actual ) {
testcases[tc++] = new TestCase( SECTION, description, expect, actual );
}
function TestCase( n, d, e, a ) {
this.name = n;
this.description = d;
this.expect = e;
this.actual = a;
this.passed = true;
this.reason = "";
this.passed = getTestCaseResult( this.expect, this.actual );
}
/*
// JavaScript 1.3 is supposed to be compliant ecma version 1.0
if ( VERSION == "ECMA_1" ) {
startTest();
version ( "130" );
}
if ( VERSION == "JS_1.3" ) {
startTest();
version ( "130" );
}
if ( VERSION == "JS_1.2" ) {
startTest();
version ( "120" );
}
if ( VERSION == "JS_1.1" ) {
startTest();
version ( "110" );
}
// for ecma version 2.0, we will leave the javascript version to
// the default ( for now ).
*/
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, give a little leeway 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;
}
/*
* Begin printing functions. These functions use the shell's
* print function. When running tests in the browser, these
* functions, override these functions with functions that use
* document.write.
*/
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 );
}
/* end of print functions */
function stopTest() {
var gc;
if ( gc != undefined ) {
gc();
}
}

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

@ -0,0 +1,159 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: break.js
Description: 'Tests the break statement'
Author: Nick Lerissa
Date: March 18, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'statements: break';
writeHeaderToLog("Executing script: break.js");
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var i,j;
for (i = 0; i < 1000; i++)
{
if (i == 100) break;
}
// 'breaking out of "for" loop'
testcases[count++] = new TestCase ( SECTION, 'breaking out of "for" loop',
100, i);
j = 2000;
out1:
for (i = 0; i < 1000; i++)
{
if (i == 100)
{
out2:
for (j = 0; j < 1000; j++)
{
if (j == 500) break out1;
}
j = 2001;
}
j = 2002;
}
// 'breaking out of a "for" loop with a "label"'
testcases[count++] = new TestCase ( SECTION, 'breaking out of a "for" loop with a "label"',
500, j);
i = 0;
while (i < 1000)
{
if (i == 100) break;
i++;
}
// 'breaking out of a "while" loop'
testcases[count++] = new TestCase ( SECTION, 'breaking out of a "while" loop',
100, i );
j = 2000;
i = 0;
out3:
while (i < 1000)
{
if (i == 100)
{
j = 0;
out4:
while (j < 1000)
{
if (j == 500) break out3;
j++;
}
j = 2001;
}
j = 2002;
i++;
}
// 'breaking out of a "while" loop with a "label"'
testcases[count++] = new TestCase ( SECTION, 'breaking out of a "while" loop with a "label"',
500, j);
i = 0;
do
{
if (i == 100) break;
i++;
} while (i < 1000);
// 'breaking out of a "do" loop'
testcases[count++] = new TestCase ( SECTION, 'breaking out of a "do" loop',
100, i );
j = 2000;
i = 0;
out5:
do
{
if (i == 100)
{
j = 0;
out6:
do
{
if (j == 500) break out5;
j++;
}while (j < 1000);
j = 2001;
}
j = 2002;
i++;
}while (i < 1000);
// 'breaking out of a "do" loop with a "label"'
testcases[count++] = new TestCase ( SECTION, 'breaking out of a "do" loop with a "label"',
500, j);
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 );
}
test();

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

@ -0,0 +1,172 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: continue.js
Description: 'Tests the continue statement'
Author: Nick Lerissa
Date: March 18, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'statements: continue';
writeHeaderToLog("Executing script: continue.js");
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var i,j;
j = 0;
for (i = 0; i < 200; i++)
{
if (i == 100)
continue;
j++;
}
// '"continue" in a "for" loop'
testcases[count++] = new TestCase ( SECTION, '"continue" in "for" loop',
199, j);
j = 0;
out1:
for (i = 0; i < 1000; i++)
{
if (i == 100)
{
out2:
for (var k = 0; k < 1000; k++)
{
if (k == 500) continue out1;
}
j = 3000;
}
j++;
}
// '"continue" in a "for" loop with a "label"'
testcases[count++] = new TestCase ( SECTION, '"continue" in "for" loop with a "label"',
999, j);
i = 0;
j = 1;
while (i != j)
{
i++;
if (i == 100) continue;
j++;
}
// '"continue" in a "while" loop'
testcases[count++] = new TestCase ( SECTION, '"continue" in a "while" loop',
100, j );
j = 0;
i = 0;
out3:
while (i < 1000)
{
if (i == 100)
{
var k = 0;
out4:
while (k < 1000)
{
if (k == 500)
{
i++;
continue out3;
}
k++;
}
j = 3000;
}
j++;
i++;
}
// '"continue" in a "while" loop with a "label"'
testcases[count++] = new TestCase ( SECTION, '"continue" in a "while" loop with a "label"',
999, j);
i = 0;
j = 1;
do
{
i++;
if (i == 100) continue;
j++;
} while (i != j);
// '"continue" in a "do" loop'
testcases[count++] = new TestCase ( SECTION, '"continue" in a "do" loop',
100, j );
j = 0;
i = 0;
out5:
do
{
if (i == 100)
{
var k = 0;
out6:
do
{
if (k == 500)
{
i++;
continue out5;
}
k++;
}while (k < 1000);
j = 3000;
}
j++;
i++;
}while (i < 1000);
// '"continue" in a "do" loop with a "label"'
testcases[count++] = new TestCase ( SECTION, '"continue" in a "do" loop with a "label"',
999, j);
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 );
}
test();

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

@ -0,0 +1,65 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: do_while.js
Description: 'This tests the new do_while loop'
Author: Nick Lerissa
Date: Fri Feb 13 09:58:28 PST 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'statements: do_while';
writeHeaderToLog('Executing script: do_while.js');
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var done = false;
var x = 0;
do
{
if (x++ == 3) done = true;
} while (!done);
testcases[count++] = new TestCase( SECTION, "do_while ",
4, x);
//load('d:/javascript/tests/output/statements/do_while.js')
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 );
}
test();

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

@ -0,0 +1,124 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: switch.js
Description: 'Tests the switch statement'
http://scopus.mcom.com/bugsplat/show_bug.cgi?id=323696
Author: Nick Lerissa
Date: March 19, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'statements: switch';
var BUGNUMBER="323696";
writeHeaderToLog("Executing script: switch.js");
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
var var1 = "match string";
var match1 = false;
var match2 = false;
var match3 = false;
switch (var1)
{
case "match string":
match1 = true;
case "bad string 1":
match2 = true;
break;
case "bad string 2":
match3 = true;
}
testcases[count++] = new TestCase ( SECTION, 'switch statement',
true, match1);
testcases[count++] = new TestCase ( SECTION, 'switch statement',
true, match2);
testcases[count++] = new TestCase ( SECTION, 'switch statement',
false, match3);
var var2 = 3;
var match1 = false;
var match2 = false;
var match3 = false;
var match4 = false;
var match5 = false;
switch (var2)
{
case 1:
/* switch (var1)
{
case "foo":
match1 = true;
break;
case 3:
match2 = true;
break;
}*/
match3 = true;
break;
case 2:
match4 = true;
break;
case 3:
match5 = true;
break;
}
testcases[count++] = new TestCase ( SECTION, 'switch statement',
false, match1);
testcases[count++] = new TestCase ( SECTION, 'switch statement',
false, match2);
testcases[count++] = new TestCase ( SECTION, 'switch statement',
false, match3);
testcases[count++] = new TestCase ( SECTION, 'switch statement',
false, match4);
testcases[count++] = new TestCase ( SECTION, 'switch statement',
true, match5);
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 );
}
test();

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

@ -0,0 +1,185 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Filename: switch2.js
Description: 'Tests the switch statement'
http://scopus.mcom.com/bugsplat/show_bug.cgi?id=323696
Author: Norris Boyd
Date: July 31, 1998
*/
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
var VERSION = 'no version';
startTest();
var TITLE = 'statements: switch';
var BUGNUMBER="323626";
writeHeaderToLog("Executing script: switch2.js");
writeHeaderToLog( SECTION + " "+ TITLE);
var count = 0;
var testcases = new Array();
// test defaults not at the end; regression test for a bug that
// nearly made it into 4.06
function f0(i) {
switch(i) {
default:
case "a":
case "b":
return "ab*"
case "c":
return "c";
case "d":
return "d";
}
return "";
}
testcases[count++] = new TestCase(SECTION, 'switch statement',
f0("a"), "ab*");
testcases[count++] = new TestCase(SECTION, 'switch statement',
f0("b"), "ab*");
testcases[count++] = new TestCase(SECTION, 'switch statement',
f0("*"), "ab*");
testcases[count++] = new TestCase(SECTION, 'switch statement',
f0("c"), "c");
testcases[count++] = new TestCase(SECTION, 'switch statement',
f0("d"), "d");
function f1(i) {
switch(i) {
case "a":
case "b":
default:
return "ab*"
case "c":
return "c";
case "d":
return "d";
}
return "";
}
testcases[count++] = new TestCase(SECTION, 'switch statement',
f1("a"), "ab*");
testcases[count++] = new TestCase(SECTION, 'switch statement',
f1("b"), "ab*");
testcases[count++] = new TestCase(SECTION, 'switch statement',
f1("*"), "ab*");
testcases[count++] = new TestCase(SECTION, 'switch statement',
f1("c"), "c");
testcases[count++] = new TestCase(SECTION, 'switch statement',
f1("d"), "d");
// Switch on integer; will use TABLESWITCH opcode in C engine
function f2(i) {
switch (i) {
case 0:
case 1:
return 1;
case 2:
return 2;
}
// with no default, control will fall through
return 3;
}
testcases[count++] = new TestCase(SECTION, 'switch statement',
f2(0), 1);
testcases[count++] = new TestCase(SECTION, 'switch statement',
f2(1), 1);
testcases[count++] = new TestCase(SECTION, 'switch statement',
f2(2), 2);
testcases[count++] = new TestCase(SECTION, 'switch statement',
f2(3), 3);
// empty switch: make sure expression is evaluated
var se = 0;
switch (se = 1) {
}
testcases[count++] = new TestCase(SECTION, 'switch statement',
se, 1);
// only default
se = 0;
switch (se) {
default:
se = 1;
}
testcases[count++] = new TestCase(SECTION, 'switch statement',
se, 1);
// in loop, break should only break out of switch
se = 0;
for (var i=0; i < 2; i++) {
switch (i) {
case 0:
case 1:
break;
}
se = 1;
}
testcases[count++] = new TestCase(SECTION, 'switch statement',
se, 1);
// test "fall through"
se = 0;
i = 0;
switch (i) {
case 0:
se++;
/* fall through */
case 1:
se++;
break;
}
testcases[count++] = new TestCase(SECTION, 'switch statement',
se, 2);
test();
// Needed: tests for evaluation time of case expressions.
// This issue was under debate at ECMA, so postponing for now.
function test() {
writeLineToLog("hi");
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,156 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: array-001.js
Description:
When accessing a Java field whose value is a java.lang.Array,
or if a java method returns a java.lang.Array, JavaScript should
read the value as the JavaScript JavaArray, an object whose class
is JavaArray.
To test this:
1. Call a java method that returns a java.lang.Array
2. Check the value of the returned object, which should be the value
of the array. Iterate through the array indices.
3. Check the type of the returned object, which should be "object"
4. Check the class of the object, using Object.prototype.toString,
which should be "[object JavaArray]"
5. Check the class of the JavaArray, using getClass, and compare
it to java.lang.Class.forName("java.lang.Array");
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "Java Array to JavaScript JavaArray object";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// In all test cases, the expected type is "object, and the expected
// class is "Number"
var E_TYPE = "object";
var E_CLASS = "[object JavaArray]";
var test_array = new Array();
// Create arrays of actual results (java_array) and expected results
// (test_array).
var java_array = new Array();
var i = 0;
// byte[]
var byte_array = ( new java.lang.String("hello") ).getBytes();
java_array[i] = new JavaValue( byte_array );
test_array[i] = new TestValue( "( new java.lang.String('hello') ).getBytes()",
["h".charCodeAt(0),
"e".charCodeAt(0),
"l".charCodeAt(0),
"l".charCodeAt(0),
"o".charCodeAt(0) ],
"[B"
);
i++;
// char[]
var char_array = ( new java.lang.String("rhino") ).toCharArray();
java_array[i] = new JavaValue( char_array );
test_array[i] = new TestValue( "( new java.lang.String('rhino') ).toCharArray()",
[ "r".charCodeAt(0),
"h".charCodeAt(0),
"i".charCodeAt(0),
"n".charCodeAt(0),
"o".charCodeAt(0)],
"[C");
i++;
for ( i = 0; i < java_array.length; i++ ) {
CompareValues( java_array[i], test_array[i] );
}
test();
function CompareValues( javaval, testval ) {
// Check value
for ( var i = 0; i < testval.value.length; i++ ) {
testcases[testcases.length] = new TestCase( SECTION,
"("+ testval.description +")["+i+"]",
testval.value[i],
javaval.value[i] );
}
// Check type
testcases[testcases.length] = new TestCase( SECTION,
"typeof (" + testval.description +")",
testval.type,
javaval.type );
// Check class
testcases[testcases.length ] = new TestCase( SECTION,
"The Java Class of ( "+ testval.description +" )",
testval.lcclass +"",
javaval.lcclass +"");
}
function JavaValue( value ) {
this.value = value;
this.type = typeof value;
this.classname = this.value.getClass();
jlo_class = java.lang.Class.forName("java.lang.Object")
jlo_getClass_method = jlo_class.getMethod("getClass", null)
this.lcclass = jlo_getClass_method.invoke(value, null );
return this;
}
function TestValue( description, value, lcclass ) {
this.lcclass = java.lang.Class.forName( lcclass );
this.description = description;
this.value = value;
this.type = E_TYPE;
this.classname = E_CLASS;
return this;
}
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,115 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: array-002.js
Description:
JavaArrays should have a length property that specifies the number of
elements in the array.
JavaArray elements can be referenced with the [] array index operator.
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "Java Array to JavaScript JavaArray object";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// In all test cases, the expected type is "object, and the expected
// class is "JavaArray"
var E_TYPE = "object";
var E_CLASS = "[object JavaArray]";
// Create arrays of actual results (java_array) and expected results
// (test_array).
var java_array = new Array();
var test_array = new Array();
var i = 0;
// byte[]
var byte_array = ( new java.lang.String("ABCDEFGHIJKLMNOPQRSTUVWXYZ") ).getBytes();
java_array[i] = new JavaValue( byte_array );
test_array[i] = new TestValue( "( new java.lang.String('ABCDEFGHIJKLMNOPQRSTUVWXYZ') ).getBytes()",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".length
);
i++;
// char[]
var char_array = ( new java.lang.String("rhino") ).toCharArray();
java_array[i] = new JavaValue( char_array );
test_array[i] = new TestValue( "( new java.lang.String('rhino') ).toCharArray()",
"rhino".length );
i++;
for ( i = 0; i < java_array.length; i++ ) {
CompareValues( java_array[i], test_array[i] );
}
test();
function CompareValues( javaval, testval ) {
// Check length
testcases[testcases.length] = new TestCase( SECTION,
"("+ testval.description +").length",
testval.value,
javaval.length );
}
function JavaValue( value ) {
this.value = value;
this.length = value.length;
this.type = typeof value;
this.classname = this.value.toString();
return this;
}
function TestValue( description, value ) {
this.description = description;
this.length = value
this.value = value;
this.type = E_TYPE;
this.classname = E_CLASS;
return this;
}
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,156 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: array-003.js
Description:
JavaArray elements should be enumerable using a for/in loop.
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "Java Array to JavaScript JavaArray object";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// In all test cases, the expected type is "object, and the expected
// class is "Number"
var E_TYPE = "object";
var E_CLASS = "[object JavaArray]";
// Create arrays of actual results (java_array) and expected results
// (test_array).
var java_array = new Array();
var test_array = new Array();
var i = 0;
// byte[]
var byte_array = ( new java.lang.String("hello") ).getBytes();
java_array[i] = new JavaValue( byte_array );
test_array[i] = new TestValue( "( new java.lang.String('hello') ).getBytes()",
["h".charCodeAt(0),
"e".charCodeAt(0),
"l".charCodeAt(0),
"l".charCodeAt(0),
"o".charCodeAt(0) ],
"[B"
);
i++;
// char[]
var char_array = ( new java.lang.String("rhino") ).toCharArray();
java_array[i] = new JavaValue( char_array );
test_array[i] = new TestValue( "( new java.lang.String('rhino') ).toCharArray()",
[ "r".charCodeAt(0),
"h".charCodeAt(0),
"i".charCodeAt(0),
"n".charCodeAt(0),
"o".charCodeAt(0) ],
"[C" );
i++;
for ( i = 0; i < java_array.length; i++ ) {
CompareValues( java_array[i], test_array[i] );
}
test();
function CompareValues( javaval, testval ) {
// Check value
var p;
var e = 0;
for ( p in javaval.value ) {
testcases[testcases.length] = new TestCase( SECTION,
"("+ testval.description +")["+p+"]",
testval.value[p],
javaval.value[p] );
e++;
}
/* Number of elements enumerated should be same as number of elements in
* the array
*/
testcases[testcases.length] = new TestCase( SECTION,
"number of elements enumerated:",
testval.length,
e );
// Check type
testcases[testcases.length] = new TestCase( SECTION,
"typeof (" + testval.description +")",
testval.type,
javaval.type );
// Check class.
testcases[testcases.length ] = new TestCase( SECTION,
"The Java Class of ( "+ testval.description +" )",
testval.lcclass,
javaval.lcclass );
}
function JavaValue( value ) {
this.value = value;
this.type = typeof value;
this.classname = this.value.toString();
jlo_class = java.lang.Class.forName("java.lang.Object")
jlo_getClass_method = jlo_class.getMethod("getClass", null)
this.lcclass = jlo_getClass_method.invoke(value, null );
return this;
}
function TestValue( description, value, lcclass ) {
this.lcclass = java.lang.Class.forName( lcclass );
this.description = description;
this.length = value.length;
this.value = value;
this.type = E_TYPE;
this.classname = E_CLASS;
return this;
}
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,127 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: array-004.js
Description:
Access array indices that are out of bounds.
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "Java Array to JavaScript JavaArray object";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// In all test cases, the expected type is "object, and the expected
// class is "JavaArray"
var E_TYPE = "object";
var E_CLASS = "[object JavaArray]";
// Create arrays of actual results (java_array) and expected results
// (test_array).
var java_array = new Array();
var test_array = new Array();
var i = 0;
// byte[]
var byte_array = ( new java.lang.String("ABCDEFGHIJKLMNOPQRSTUVWXYZ") ).getBytes();
java_array[i] = new JavaValue( byte_array );
test_array[i] = new TestValue( "( new java.lang.String('ABCDEFGHIJKLMNOPQRSTUVWXYZ') ).getBytes()",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".length
);
i++;
// char[]
var char_array = ( new java.lang.String("rhino") ).toCharArray();
java_array[i] = new JavaValue( char_array );
test_array[i] = new TestValue( "( new java.lang.String('rhino') ).toCharArray()",
"rhino".length );
i++;
for ( i = 0; i < java_array.length; i++ ) {
CompareValues( java_array[i], test_array[i] );
}
test();
function CompareValues( javaval, testval ) {
// Check length
testcases[testcases.length] = new TestCase( SECTION,
"("+ testval.description +").length",
testval.value,
javaval.length );
// access element [-1]
testcases[testcases.length] = new TestCase(
SECTION,
"("+testval.description+")[-1]",
void 0,
javaval[-1] );
// access element [length]
testcases[testcases.length] = new TestCase(
SECTION,
"("+testval.description+")["+testval.value+"]",
void 0,
javaval[testval.value] );
}
function JavaValue( value ) {
this.value = value;
this.length = value.length;
this.type = typeof value;
this.classname = this.value.toString();
return this;
}
function TestValue( description, value ) {
this.description = description;
this.length = value
this.value = value;
this.type = E_TYPE;
this.classname = E_CLASS;
return this;
}
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,119 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: array-005.js
Description:
Put and Get JavaArray Elements
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "Java Array to JavaScript JavaArray object";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// In all test cases, the expected type is "object, and the expected
// class is "JavaArray"
var E_TYPE = "object";
var E_CLASS = "[object JavaArray]";
var byte_array = ( new java.lang.String("hi") ).getBytes();
testcases[testcases.length] = new TestCase(
SECTION,
"byte_array = new java.lang.String(\"hi\")).getBytes(); delete byte_array.length",
false,
delete byte_array.length );
testcases[testcases.length] = new TestCase(
SECTION,
"byte_array[0]",
("hi").charCodeAt(0),
byte_array[0]);
testcases[testcases.length] = new TestCase(
SECTION,
"byte_array[1]",
("hi").charCodeAt(1),
byte_array[1]);
byte_array.length = 0;
testcases[testcases.length] = new TestCase(
SECTION,
"byte_array.length = 0; byte_array.length",
2,
byte_array.length );
var properties = "";
for ( var p in byte_array ) {
properties += ( p == "length" ) ? p : "";
}
testcases[testcases.length] = new TestCase(
SECTION,
"for ( var p in byte_array ) { properties += p ==\"length\" ? p : \"\" }; properties",
"",
properties );
testcases[testcases.length] = new TestCase(
SECTION,
"byte_array[\"length\"]",
2,
byte_array["length"] );
byte_array["0"] = 127;
testcases[testcases.length] = new TestCase(
SECTION,
"byte_array[\"0\"] = 127; byte_array[0]",
127,
byte_array[0] );
byte_array[1] = 99;
testcases[testcases.length] = new TestCase(
SECTION,
"byte_array[1] = 99; byte_array[\"1\"]",
99,
byte_array["1"] );
test();
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,65 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: array-005.js
Description:
Put and Get JavaArray Elements
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "Java Array to JavaScript JavaArray object";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// In all test cases, the expected type is "object, and the expected
// class is "JavaArray"
var E_TYPE = "object";
var E_CLASS = "[object JavaArray]";
var byte_array = ( new java.lang.String("hi") ).getBytes();
testcases[testcases.length] = new TestCase(
SECTION,
"byte_array[\"foo\"]",
void 0,
byte_array["foo"] );
test();
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,69 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: array-005.js
Description:
Put and Get JavaArray Elements
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "Java Array to JavaScript JavaArray object";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// In all test cases, the expected type is "object, and the expected
// class is "JavaArray"
var E_TYPE = "object";
var E_CLASS = "[object JavaArray]";
var byte_array = ( new java.lang.String("hi") ).getBytes();
byte_array.name = "name";
testcases[testcases.length] = new TestCase(
SECTION,
"byte_array.name = \"name\"; byte_array.name",
void 0,
byte_array.name );
byte_array["0"] = 127;
test();
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,66 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: array-008-n.js
Description:
JavaArrays should have a length property that specifies the number of
elements in the array.
JavaArray elements can be referenced with the [] array index operator.
This attempts to access an array index that is out of bounds. It should
fail with a JS runtime error.
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "Java Array to JavaScript JavaArray object";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
dt = new Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass;
var ba_length = dt.PUB_ARRAY_BYTE.length;
testcases[tc++] = new TestCase(
SECTION,
"dt.PUB_ARRAY_BYTE.length = "+ ba_length,
"error",
dt.PUB_ARRAY_BYTE[ba_length] );
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,151 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: class-001.js
Description:
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect Classes";
var VERSION = "1_3";
var TITLE = "JavaClass objects";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// All packages are of the type "function", since they implement [[Construct]]
// and [[Call]]
var E_TYPE = "function";
// The JavaScript [[Class]] property for all Classes is "[object JavaClass]"
var E_JSCLASS = "[object JavaClass]";
// Create arrays of actual results (java_array) and
// expected results (test_array).
var java_array = new Array();
var test_array = new Array();
var i = 0;
java_array[i] = new JavaValue( java.awt.Image );
test_array[i] = new TestValue( "java.awt.Image" );
i++;
java_array[i] = new JavaValue( java.beans.Beans );
test_array[i] = new TestValue( "java.beans.Beans" );
i++;
java_array[i] = new JavaValue( java.io.File );
test_array[i] = new TestValue( "java.io.File" );
i++;
java_array[i] = new JavaValue( java.lang.String );
test_array[i] = new TestValue( "java.lang.String" );
i++;
java_array[i] = new JavaValue( java.math.BigDecimal );
test_array[i] = new TestValue( "java.math.BigDecimal" );
i++;
java_array[i] = new JavaValue( java.net.URL );
test_array[i] = new TestValue( "java.net.URL" );
i++;
java_array[i] = new JavaValue( java.rmi.RMISecurityManager );
test_array[i] = new TestValue( "java.rmi.RMISecurityManager" );
i++;
java_array[i] = new JavaValue( java.text.DateFormat );
test_array[i] = new TestValue( "java.text.DateFormat" );
i++;
java_array[i] = new JavaValue( java.util.Vector );
test_array[i] = new TestValue( "java.util.Vector" );
i++;
/*
java_array[i] = new JavaValue( Packages.com.netscape.javascript.Context );
test_array[i] = new TestValue( "Packages.com.netscape.javascript.Context" );
i++;
*/
for ( i = 0; i < java_array.length; i++ ) {
CompareValues( java_array[i], test_array[i] );
}
test();
function CompareValues( javaval, testval ) {
// Check type, which should be E_TYPE
testcases[testcases.length] = new TestCase( SECTION,
"typeof (" + testval.description +")",
testval.type,
javaval.type );
/*
// Check JavaScript class, which should be E_JSCLASS
testcases[testcases.length] = new TestCase( SECTION,
"(" + testval.description +".)getJSClass()",
testval.jsclass,
javaval.jsclass );
*/
// Check the class's name, which should be the description, minus the "Package." part.
testcases[testcases.length] = new TestCase( SECTION,
"(" + testval.description +") +''",
testval.classname,
javaval.classname );
}
function JavaValue( value ) {
// Object.prototype.toString will show its JavaScript wrapper object.
// value.__proto__.getJSClass = Object.prototype.toString;
// this.jsclass = value.getJSClass();
this.classname = value +"";
this.type = typeof value;
return this;
}
function TestValue( description, value ) {
this.description = description;
this.type = E_TYPE;
this.jclass = E_JSCLASS;
this.lcclass = java.lang.Class.forName( description );
this.classname = "[JavaClass " +
( ( description.substring(0,9) == "Packages." )
? description.substring(9,description.length)
: description
) + "]"
return this;
}
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,152 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
File Name: class-001.js
Description:
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect Classes";
var VERSION = "1_3";
var TITLE = "JavaClass objects";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// All packages are of the type "function", since they implement [[Construct]]
// and [[Call]]
var E_TYPE = "function";
// The JavaScript [[Class]] property for all Classes is "[object JavaClass]"
var E_JSCLASS = "[object JavaClass]";
// Create arrays of actual results (java_array) and
// expected results (test_array).
var java_array = new Array();
var test_array = new Array();
var i = 0;
java_array[i] = new JavaValue( java.awt.Image );
test_array[i] = new TestValue( "java.awt.Image" );
i++;
java_array[i] = new JavaValue( java.beans.Beans );
test_array[i] = new TestValue( "java.beans.Beans" );
i++;
java_array[i] = new JavaValue( java.io.File );
test_array[i] = new TestValue( "java.io.File" );
i++;
java_array[i] = new JavaValue( java.lang.String );
test_array[i] = new TestValue( "java.lang.String" );
i++;
java_array[i] = new JavaValue( java.math.BigDecimal );
test_array[i] = new TestValue( "java.math.BigDecimal" );
i++;
java_array[i] = new JavaValue( java.net.URL );
test_array[i] = new TestValue( "java.net.URL" );
i++;
java_array[i] = new JavaValue( java.rmi.RMISecurityManager );
test_array[i] = new TestValue( "java.rmi.RMISecurityManager" );
i++;
java_array[i] = new JavaValue( java.text.DateFormat );
test_array[i] = new TestValue( "java.text.DateFormat" );
i++;
java_array[i] = new JavaValue( java.util.Vector );
test_array[i] = new TestValue( "java.util.Vector" );
i++;
/*
works for rhino only
java_array[i] = new JavaValue( Packages.com.netscape.javascript.Context );
test_array[i] = new TestValue( "Packages.com.netscape.javascript.Context" );
i++;
*/
for ( i = 0; i < java_array.length; i++ ) {
CompareValues( java_array[i], test_array[i] );
}
test();
function CompareValues( javaval, testval ) {
// Check type, which should be E_TYPE
testcases[testcases.length] = new TestCase( SECTION,
"typeof (" + testval.description +")",
testval.type,
javaval.type );
/*
// Check JavaScript class, which should be E_JSCLASS
testcases[testcases.length] = new TestCase( SECTION,
"(" + testval.description +").getJSClass()",
testval.jsclass,
javaval.jsclass );
*/
// Check the class's name, which should be the description, minus the "Package." part.
testcases[testcases.length] = new TestCase( SECTION,
"(" + testval.description +") +''",
testval.classname,
javaval.classname );
}
function JavaValue( value ) {
// this suceeds in LC1, but fails in LC2
// Object.prototype.toString will show its JavaScript wrapper object.
// value.__proto__.getJSClass = Object.prototype.toString;
// this.jsclass = value.getJSClass();
this.classname = value +"";
this.type = typeof value;
return this;
}
function TestValue( description, value ) {
this.description = description;
this.type = E_TYPE;
this.jsclass = E_JSCLASS;
this.classname = "[JavaClass " +
( ( description.substring(0,9) == "Packages." )
? description.substring(9,description.length)
: description
) + "]"
return this;
}
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,142 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Template for LiveConnect Tests
File Name: number-006.js
Description:
When setting the value of a Java field with a JavaScript number or
when passing a JavaScript number to a Java method as an argument,
LiveConnect should be able to convert the number to any one of the
following types:
byte
short
int
long
float
double
char
java.lang.Double
Note that the value of the Java field may not be as precise as the
JavaScript value's number, if for example, you pass a large number to
a short or byte, or a float to integer.
JavaScript numbers cannot be converted to instances of java.lang.Float
or java.lang.Integer.
This test does not cover the cases in which a Java method returns one
of the above primitive Java types.
Currently split up into numerous tests, since rhino live connect fails
to translate numbers into the correct types.
test for creating java.lang.Short objects.
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "LiveConnect JavaScript to Java Data Type Conversion";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// typeof all resulting objects is "object";
var E_TYPE = "object";
// JS class of all resulting objects is "JavaObject";
var E_JSCLASS = "[object JavaObject]";
var a = new Array();
var i = 0;
a[i++] = new TestObject( "new java.lang.Character(\"0.0\")",
new java.lang.Character("a"), "a".charCodeAt(0) );
a[i++] = new TestObject( "new java.lang.Character(\"0.\")",
new java.lang.Character("0"), "0".charCodeAt(0) );
a[i++] = new TestObject( "new java.lang.Character( 5 )",
new java.lang.Character(5), 5 );
a[i++] = new TestObject( "new java.lang.Character( 5.5 )",
new java.lang.Character(5.5), 5 );
a[i++] = new TestObject( "new java.lang.Character( Number(5) )",
new java.lang.Character(Number(5)), 5 );
a[i++] = new TestObject( "new java.lang.Character( Number(5.5) )",
new java.lang.Character(Number(5.5)), 5 );
for ( var i = 0; i < a.length; i++ ) {
// check typeof
testcases[testcases.length] = new TestCase(
SECTION,
"typeof (" + a[i].description +")",
a[i].type,
typeof a[i].javavalue );
/*
// check the js class
testcases[testcases.length] = new TestCase(
SECTION,
"("+ a[i].description +").getJSClass()",
E_JSCLASS,
a[i].jsclass );
*/
// check the number value of the object
testcases[testcases.length] = new TestCase(
SECTION,
"Number(" + a[i].description +")",
a[i].jsvalue,
Number( a[i].javavalue.charValue() ) );
}
test();
function TestObject( description, javavalue, jsvalue ) {
// LC2 does not support the proto property of liveconnect object
// this.javavalue.__proto__.getJSClass = Object.prototype.toString;
// this.jsclass = this.javavalue.getJSClass();
this.description = description;
this.javavalue = javavalue;
this.jsvalue = jsvalue;
this.type = E_TYPE;
return this;
}
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,142 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Template for LiveConnect Tests
File Name: number-002.js
Description:
When setting the value of a Java field with a JavaScript number or
when passing a JavaScript number to a Java method as an argument,
LiveConnect should be able to convert the number to any one of the
following types:
byte
short
int
long
float
double
char
java.lang.Double
Note that the value of the Java field may not be as precise as the
JavaScript value's number, if for example, you pass a large number to
a short or byte, or a float to integer.
JavaScript numbers cannot be converted to instances of java.lang.Float
or java.lang.Integer.
This test does not cover the cases in which a Java method returns one
of the above primitive Java types.
Currently split up into numerous tests, since rhino live connect fails
to translate numbers into the correct types.
test for creating java.lang.Double objects.
@author christine@netscape.com
@version 1.00
*/
var SECTION = "double-001";
var VERSION = "1_3";
var TITLE = "LiveConnect JavaScript to Java Data Type Conversion";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// typeof all resulting objects is "object";
var E_TYPE = "object";
// JS class of all resulting objects is "JavaObject";
var E_JSCLASS = "[object JavaObject]";
var a = new Array();
var i = 0;
a[i++] = new TestObject( "new java.lang.Double(\"0.0\")",
new java.lang.Double("0.0"), 0 );
a[i++] = new TestObject( "new java.lang.Double(\"0.0\")",
new java.lang.Double("0"), 0 );
a[i++] = new TestObject( "new java.lang.Double( 5 )",
new java.lang.Double(5), 5 );
a[i++] = new TestObject( "new java.lang.Double( 5.5 )",
new java.lang.Double(5.5), 5.5 );
a[i++] = new TestObject( "new java.lang.Double( Number(5) )",
new java.lang.Double(Number(5)), 5 );
a[i++] = new TestObject( "new java.lang.Double( Number(5.5) )",
new java.lang.Double(Number(5.5)), 5.5 );
for ( var i = 0; i < a.length; i++ ) {
// check typeof
testcases[testcases.length] = new TestCase(
SECTION,
"typeof (" + a[i].description +")",
a[i].type,
typeof a[i].javavalue );
/*
// check the js class
testcases[testcases.length] = new TestCase(
SECTION,
"("+ a[i].description +").getJSClass()",
E_JSCLASS,
a[i].jsclass );
*/
// check the number value of the object
testcases[testcases.length] = new TestCase(
SECTION,
"Number(" + a[i].description +")",
a[i].jsvalue,
Number( a[i].javavalue ) );
}
test();
function TestObject( description, javavalue, jsvalue ) {
this.description = description;
this.javavalue = javavalue;
this.jsvalue = jsvalue;
this.type = E_TYPE;
// LC2 does not support the proto property in Java objects
// this.javavalue.__proto__.getJSClass = Object.prototype.toString;
// this.jsclass = this.javavalue.getJSClass();
return this;
}
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,139 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Template for LiveConnect Tests
File Name: number-001.js
Description:
When setting the value of a Java field with a JavaScript number or
when passing a JavaScript number to a Java method as an argument,
LiveConnect should be able to convert the number to any one of the
following types:
byte
short
int
long
float
double
char
java.lang.Double
Note that the value of the Java field may not be as precise as the
JavaScript value's number, if for example, you pass a large number to
a short or byte, or a float to integer.
JavaScript numbers cannot be converted to instances of java.lang.Float
or java.lang.Integer.
This test does not cover the cases in which a Java method returns one
of the above primitive Java types.
Currently split up into numerous tests, since rhino live connect fails
to translate numbers into the correct types.
Test for passing JavasScript numbers to static java.lang.Integer methods.
@author christine@netscape.com
@version 1.00
*/
var SECTION = "double-001";
var VERSION = "1_3";
var TITLE = "LiveConnect JavaScript to Java Data Type Conversion";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// typeof all resulting objects is "object";
var E_TYPE = "object";
// JS class of all resulting objects is "JavaObject";
var E_JSCLASS = "[object JavaObject]";
var a = new Array();
var i = 0;
a[i++] = new TestObject( "java.lang.Double.toString(0)",
java.lang.Double.toString(0), "0.0" );
a[i++] = new TestObject( "java.lang.Double.toString(NaN)",
java.lang.Double.toString(NaN), "NaN" );
a[i++] = new TestObject( "java.lang.Double.toString(5)",
java.lang.Double.toString(5), "5.0" );
a[i++] = new TestObject( "java.lang.Double.toString(9.9)",
java.lang.Double.toString(9.9), "9.9" );
a[i++] = new TestObject( "java.lang.Double.toString(-9.9)",
java.lang.Double.toString(-9.9), "-9.9" );
for ( var i = 0; i < a.length; i++ ) {
// check typeof
testcases[testcases.length] = new TestCase(
SECTION,
"typeof (" + a[i].description +")",
a[i].type,
typeof a[i].javavalue );
/*
// check the js class
testcases[testcases.length] = new TestCase(
SECTION,
"("+ a[i].description +").getJSClass()",
E_JSCLASS,
a[i].jsclass );
*/
// check the number value of the object
testcases[testcases.length] = new TestCase(
SECTION,
"String(" + a[i].description +")",
a[i].jsvalue,
String( a[i].javavalue ) );
}
test();
function TestObject( description, javavalue, jsvalue ) {
this.description = description;
this.javavalue = javavalue;
this.jsvalue = jsvalue;
this.type = E_TYPE;
// LC2 does not support the proto property in Java objects
// this.javavalue.__proto__.getJSClass = Object.prototype.toString;
// this.jsclass = this.javavalue.getJSClass();
return this;
}
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,144 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Template for LiveConnect Tests
File Name: number-002.js
Description:
When setting the value of a Java field with a JavaScript number or
when passing a JavaScript number to a Java method as an argument,
LiveConnect should be able to convert the number to any one of the
following types:
byte
short
int
long
float
double
char
java.lang.Double
Note that the value of the Java field may not be as precise as the
JavaScript value's number, if for example, you pass a large number to
a short or byte, or a float to integer.
JavaScript numbers cannot be converted to instances of java.lang.Float
or java.lang.Integer.
This test does not cover the cases in which a Java method returns one
of the above primitive Java types.
Currently split up into numerous tests, since rhino live connect fails
to translate numbers into the correct types.
test for creating java.lang.Float objects.
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "LiveConnect JavaScript to Java Data Type Conversion";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// typeof all resulting objects is "object";
var E_TYPE = "object";
// JS class of all resulting objects is "JavaObject";
var E_JSCLASS = "[object JavaObject]";
var a = new Array();
var i = 0;
a[i++] = new TestObject( "new java.lang.Float(\"0.0\")",
new java.lang.Float("0.0"), 0 );
a[i++] = new TestObject( "new java.lang.Float(\"0.\")",
new java.lang.Float("0"), 0 );
a[i++] = new TestObject( "new java.lang.Float( 5 )",
new java.lang.Float(5), 5 );
a[i++] = new TestObject( "new java.lang.Float( 5.5 )",
new java.lang.Float(5.5), 5.5 );
a[i++] = new TestObject( "new java.lang.Float( Number(5) )",
new java.lang.Float(Number(5)), 5 );
a[i++] = new TestObject( "new java.lang.Float( Number(5.5) )",
new java.lang.Float(Number(5.5)), 5.5 );
for ( var i = 0; i < a.length; i++ ) {
// check typeof
testcases[testcases.length] = new TestCase(
SECTION,
"typeof (" + a[i].description +")",
a[i].type,
typeof a[i].javavalue );
/*
// check the js class
testcases[testcases.length] = new TestCase(
SECTION,
"("+ a[i].description +").getJSClass()",
E_JSCLASS,
a[i].jsclass );
*/
// check the number value of the object
testcases[testcases.length] = new TestCase(
SECTION,
"Number(" + a[i].description +")",
a[i].jsvalue,
Number( a[i].javavalue ) );
}
test();
function TestObject( description, javavalue, jsvalue ) {
this.description = description;
this.javavalue = javavalue;
this.jsvalue = jsvalue;
this.type = E_TYPE;
// LC2 does not support the proto property in Java objects
// this.javavalue.__proto__.getJSClass = Object.prototype.toString;
// this.jsclass = this.javavalue.getJSClass();
return this;
}
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,139 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Template for LiveConnect Tests
File Name: number-001.js
Description:
When setting the value of a Java field with a JavaScript number or
when passing a JavaScript number to a Java method as an argument,
LiveConnect should be able to convert the number to any one of the
following types:
byte
short
int
long
float
double
char
java.lang.Double
Note that the value of the Java field may not be as precise as the
JavaScript value's number, if for example, you pass a large number to
a short or byte, or a float to integer.
JavaScript numbers cannot be converted to instances of java.lang.Float
or java.lang.Integer.
This test does not cover the cases in which a Java method returns one
of the above primitive Java types.
Currently split up into numerous tests, since rhino live connect fails
to translate numbers into the correct types.
Test for passing JavasScript numbers to static java.lang.Integer methods.
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "LiveConnect JavaScript to Java Data Type Conversion";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// typeof all resulting objects is "object";
var E_TYPE = "object";
// JS class of all resulting objects is "JavaObject";
var E_JSCLASS = "[object JavaObject]";
var a = new Array();
var i = 0;
a[i++] = new TestObject( "java.lang.Float.toString(0)",
java.lang.Float.toString(0), "0.0" );
a[i++] = new TestObject( "java.lang.Float.toString(NaN)",
java.lang.Float.toString(NaN), "NaN" );
a[i++] = new TestObject( "java.lang.Float.toString(5)",
java.lang.Float.toString(5), "5.0" );
a[i++] = new TestObject( "java.lang.Float.toString(9.9)",
java.lang.Float.toString(9.9), "9.9" );
a[i++] = new TestObject( "java.lang.Float.toString(-9.9)",
java.lang.Float.toString(-9.9), "-9.9" );
for ( var i = 0; i < a.length; i++ ) {
// check typeof
testcases[testcases.length] = new TestCase(
SECTION,
"typeof (" + a[i].description +")",
a[i].type,
typeof a[i].javavalue );
/*
// check the js class
testcases[testcases.length] = new TestCase(
SECTION,
"("+ a[i].description +").getJSClass()",
E_JSCLASS,
a[i].jsclass );
*/
// check the number value of the object
testcases[testcases.length] = new TestCase(
SECTION,
"String(" + a[i].description +")",
a[i].jsvalue,
String( a[i].javavalue ) );
}
test();
function TestObject( description, javavalue, jsvalue ) {
this.description = description;
this.javavalue = javavalue;
this.jsvalue = jsvalue;
this.type = E_TYPE;
// LC2 does not support the proto property in Java objects
// this.javavalue.__proto__.getJSClass = Object.prototype.toString;
// this.jsclass = this.javavalue.getJSClass();
return this;
}
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,144 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Template for LiveConnect Tests
File Name: number-001.js
Description:
When setting the value of a Java field with a JavaScript number or
when passing a JavaScript number to a Java method as an argument,
LiveConnect should be able to convert the number to any one of the
following types:
byte
short
int
long
float
double
char
java.lang.Double
Note that the value of the Java field may not be as precise as the
JavaScript value's number, if for example, you pass a large number to
a short or byte, or a float to integer.
JavaScript numbers cannot be converted to instances of java.lang.Float
or java.lang.Integer.
This test does not cover the cases in which a Java method returns one
of the above primitive Java types.
Currently split up into numerous tests, since rhino live connect fails
to translate numbers into the correct types.
test for creating java.lang.Integer objects.
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "LiveConnect JavaScript to Java Data Type Conversion";
var BUGNUMBER="196276";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// typeof all resulting objects is "object";
var E_TYPE = "object";
// JS class of all resulting objects is "JavaObject";
var E_JSCLASS = "[object JavaObject]";
var a = new Array();
var i = 0;
a[i++] = new TestObject( "new java.lang.Integer(\"0.\")",
new java.lang.Integer("0"), 0 );
a[i++] = new TestObject( "new java.lang.Integer( 5 )",
new java.lang.Integer(5), 5 );
a[i++] = new TestObject( "new java.lang.Integer( 5.5 )",
new java.lang.Integer(5.5), 5 );
a[i++] = new TestObject( "new java.lang.Integer( Number(5) )",
new java.lang.Integer(Number(5)), 5 );
a[i++] = new TestObject( "new java.lang.Integer( Number(5.5) )",
new java.lang.Integer(Number(5.5)), 5 );
for ( var i = 0; i < a.length; i++ ) {
// check typeof
testcases[testcases.length] = new TestCase(
SECTION,
"typeof (" + a[i].description +")",
a[i].type,
typeof a[i].javavalue );
/*
// check the js class
testcases[testcases.length] = new TestCase(
SECTION,
"("+ a[i].description +").getJSClass()",
E_JSCLASS,
a[i].jsclass );
*/
// check the number value of the object
testcases[testcases.length] = new TestCase(
SECTION,
"Number(" + a[i].description +")",
a[i].jsvalue,
Number( a[i].javavalue ) );
}
test();
function TestObject( description, javavalue, jsvalue ) {
this.description = description;
this.javavalue = javavalue;
this.jsvalue = jsvalue;
this.type = E_TYPE;
// LC2 does not support the proto property in Java objects
// this.javavalue.__proto__.getJSClass = Object.prototype.toString;
// this.jsclass = this.javavalue.getJSClass();
return this;
}
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,138 @@
/* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*
*/
/**
Template for LiveConnect Tests
File Name: number-001.js
Description:
When setting the value of a Java field with a JavaScript number or
when passing a JavaScript number to a Java method as an argument,
LiveConnect should be able to convert the number to any one of the
following types:
byte
short
int
long
float
double
char
java.lang.Double
Note that the value of the Java field may not be as precise as the
JavaScript value's number, if for example, you pass a large number to
a short or byte, or a float to integer.
JavaScript numbers cannot be converted to instances of java.lang.Float
or java.lang.Integer.
This test does not cover the cases in which a Java method returns one
of the above primitive Java types.
Currently split up into numerous tests, since rhino live connect fails
to translate numbers into the correct types.
Test for passing JavasScript numbers to static java.lang.Integer methods.
@author christine@netscape.com
@version 1.00
*/
var SECTION = "LiveConnect";
var VERSION = "1_3";
var TITLE = "LiveConnect JavaScript to Java Data Type Conversion";
var testcases = new Array();
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
// typeof all resulting objects is "object";
var E_TYPE = "object";
// JS class of all resulting objects is "JavaObject";
var E_JSCLASS = "[object JavaObject]";
var a = new Array();
var i = 0;
a[i++] = new TestObject( "java.lang.Integer.toString(0)",
java.lang.Integer.toString(0), "0" );
// a[i++] = new TestObject( "java.lang.Integer.toString(NaN)",
// java.lang.Integer.toString(NaN), "NaN" );
a[i++] = new TestObject( "java.lang.Integer.toString(5)",
java.lang.Integer.toString(5), "5" );
a[i++] = new TestObject( "java.lang.Integer.toString(9.9)",
java.lang.Integer.toString(9.9), "9" );
a[i++] = new TestObject( "java.lang.Integer.toString(-9.9)",
java.lang.Integer.toString(-9.9), "-9" );
for ( var i = 0; i < a.length; i++ ) {
// check typeof
testcases[testcases.length] = new TestCase(
SECTION,
"typeof (" + a[i].description +")",
a[i].type,
typeof a[i].javavalue );
/*
// check the js class
testcases[testcases.length] = new TestCase(
SECTION,
"("+ a[i].description +").getJSClass()",
E_JSCLASS,
a[i].jsclass );
*/
// check the number value of the object
testcases[testcases.length] = new TestCase(
SECTION,
"String(" + a[i].description +")",
a[i].jsvalue,
String( a[i].javavalue ) );
}
test();
function TestObject( description, javavalue, jsvalue ) {
this.description = description;
this.javavalue = javavalue;
this.jsvalue = jsvalue;
this.type = E_TYPE;
// this.javavalue.__proto__.getJSClass = Object.prototype.toString;
// this.jsclass = this.javavalue.getJSClass();
return this;
}
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 );
}

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше