diff options
Diffstat (limited to 'js/src/tests/js1_2')
103 files changed, 5614 insertions, 0 deletions
diff --git a/js/src/tests/js1_2/Array/array_split_1.js b/js/src/tests/js1_2/Array/array_split_1.js new file mode 100644 index 000000000..8461d1b8c --- /dev/null +++ b/js/src/tests/js1_2/Array/array_split_1.js @@ -0,0 +1,53 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +new TestCase( SECTION, + "('a,b,c'.split(',')).length", + 3, + ('a,b,c'.split(',')).length ); + +new TestCase( SECTION, + "('a,b'.split(',')).length", + 2, + ('a,b'.split(',')).length ); + +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). + */ +new TestCase( SECTION, + "(''.split(',')).length", + 0, + (''.split(',')).length ); + +test(); diff --git a/js/src/tests/js1_2/Array/browser.js b/js/src/tests/js1_2/Array/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/Array/browser.js diff --git a/js/src/tests/js1_2/Array/general1.js b/js/src/tests/js1_2/Array/general1.js new file mode 100644 index 000000000..2ebb39d7a --- /dev/null +++ b/js/src/tests/js1_2/Array/general1.js @@ -0,0 +1,44 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 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] +new TestCase( SECTION, "array1.pop()", array1.pop(),'cat'); +//array1 = [123,dog,-99] +array1.push("mouse"); //array1 = [123,dog,-99,mouse] +new TestCase( SECTION, "array1.shift()", array1.shift(),123); +//array1 = [dog,-99,mouse] +array1.unshift(96); //array1 = [96,dog,-99,mouse] +new TestCase( SECTION, "state of array", String([96,"dog",-99,"mouse"]), String(array1)); +new TestCase( SECTION, "array1.length", array1.length,4); +array1.shift(); //array1 = [dog,-99,mouse] +array1.shift(); //array1 = [-99,mouse] +array1.shift(); //array1 = [mouse] +new TestCase( SECTION, "array1.shift()", array1.shift(),"mouse"); +new TestCase( SECTION, "array1.shift()", "undefined", String(array1.shift())); + +test(); + diff --git a/js/src/tests/js1_2/Array/general2.js b/js/src/tests/js1_2/Array/general2.js new file mode 100644 index 000000000..07779b72d --- /dev/null +++ b/js/src/tests/js1_2/Array/general2.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +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()); +} + +new TestCase( SECTION, "Array.push,pop,shift,unshift,slice,splice", true,String(array1) == String(array2)); +array1.sort(); +array2.sort(); +new TestCase( SECTION, "Array.sort", true,String(array1) == String(array2)); + +test(); + diff --git a/js/src/tests/js1_2/Array/shell.js b/js/src/tests/js1_2/Array/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/Array/shell.js diff --git a/js/src/tests/js1_2/Array/slice.js b/js/src/tests/js1_2/Array/slice.js new file mode 100644 index 000000000..8f95aa188 --- /dev/null +++ b/js/src/tests/js1_2/Array/slice.js @@ -0,0 +1,89 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 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]; + +exhaustiveSliceTest("exhaustive slice test 1", a); +exhaustiveSliceTest("exhaustive slice test 2", b); + +test(); + +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; +} diff --git a/js/src/tests/js1_2/Array/splice1.js b/js/src/tests/js1_2/Array/splice1.js new file mode 100644 index 000000000..37f36e19c --- /dev/null +++ b/js/src/tests/js1_2/Array/splice1.js @@ -0,0 +1,119 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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'; +var TITLE = 'String:splice 1'; +var BUGNUMBER="123795"; + +startTest(); +writeHeaderToLog('Executing script: splice1.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +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]; + +exhaustiveSpliceTest("exhaustive splice w/no optional args 1",a); +exhaustiveSpliceTest("exhaustive splice w/no optional args 1",b); + +test(); + + +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; +} diff --git a/js/src/tests/js1_2/Array/splice2.js b/js/src/tests/js1_2/Array/splice2.js new file mode 100644 index 000000000..9295d5540 --- /dev/null +++ b/js/src/tests/js1_2/Array/splice2.js @@ -0,0 +1,116 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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'; +var TITLE = 'String:splice 2'; +var BUGNUMBER="123795"; + +startTest(); +writeHeaderToLog('Executing script: splice2.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +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]; + +exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 1",a); +exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 2",b); + +test(); + + +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; +} diff --git a/js/src/tests/js1_2/Array/tostring_1.js b/js/src/tests/js1_2/Array/tostring_1.js new file mode 100644 index 000000000..55c749563 --- /dev/null +++ b/js/src/tests/js1_2/Array/tostring_1.js @@ -0,0 +1,93 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 a = new Array(); + +var VERSION = 0; + +if ( version() == 120 ) { + VERSION = "120"; +} else { + VERSION = ""; +} + +new TestCase ( SECTION, + "var a = new Array(); a.toString()", + ( VERSION == "120" ? "[]" : "" ), + a.toString() ); + +a[0] = void 0; + +new TestCase ( SECTION, + "a[0] = void 0; a.toString()", + ( VERSION == "120" ? "[, ]" : "" ), + a.toString() ); + + +new TestCase( SECTION, + "a.length", + 1, + a.length ); + +a[1] = void 0; + +new TestCase( SECTION, + "a[1] = void 0; a.toString()", + ( VERSION == "120" ? "[, , ]" : "," ), + a.toString() ); + +a[1] = "hi"; + +new TestCase( SECTION, + "a[1] = \"hi\"; a.toString()", + ( VERSION == "120" ? "[, \"hi\"]" : ",hi" ), + a.toString() ); + +a[2] = void 0; + +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 += ","; +} + + +new TestCase ( SECTION, + "var b = new Array(1000); b.toString()", + ( VERSION == "120" ? "[1000]" : bstring ), + b.toString() ); + + +new TestCase( SECTION, + "b.length", + ( VERSION == "120" ? 1 : 1000 ), + b.length ); + +test(); diff --git a/js/src/tests/js1_2/Array/tostring_2.js b/js/src/tests/js1_2/Array/tostring_2.js new file mode 100644 index 000000000..db9639926 --- /dev/null +++ b/js/src/tests/js1_2/Array/tostring_2.js @@ -0,0 +1,49 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 a = []; + + +if ( version() == 120 ) { + VERSION = "120"; +} else { + VERSION = ""; +} + +new TestCase ( SECTION, + "a.toString()", + ( VERSION == "120" ? "[]" : "" ), + a.toString() ); + +new TestCase ( SECTION, + "String( a )", + ( VERSION == "120" ? "[]" : "" ), + String( a ) ); + +new TestCase ( SECTION, + "a +''", + ( VERSION == "120" ? "[]" : "" ), + a+"" ); + +test(); diff --git a/js/src/tests/js1_2/Objects/browser.js b/js/src/tests/js1_2/Objects/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/Objects/browser.js diff --git a/js/src/tests/js1_2/Objects/shell.js b/js/src/tests/js1_2/Objects/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/Objects/shell.js diff --git a/js/src/tests/js1_2/Objects/toString-001.js b/js/src/tests/js1_2/Objects/toString-001.js new file mode 100644 index 000000000..085cba0b1 --- /dev/null +++ b/js/src/tests/js1_2/Objects/toString-001.js @@ -0,0 +1,87 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 o = new Object(); + +new TestCase( SECTION, + "var o = new Object(); o.toString()", + "{}", + o.toString() ); + +o = {}; + +new TestCase( SECTION, + "o = {}; o.toString()", + "{}", + o.toString() ); + +o = { name:"object", length:0, value:"hello" } + + 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+''" ) } + + new TestCase( SECTION, + "o = { name:\"object\", length:0, value:\"hello\", "+ + "toString:new Function( \"return this.value+''\" ) }; o.toString()", + "hello", + o.toString() ); + + + +test(); + +/** + * 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; +} + diff --git a/js/src/tests/js1_2/README b/js/src/tests/js1_2/README new file mode 100644 index 000000000..550890ec4 --- /dev/null +++ b/js/src/tests/js1_2/README @@ -0,0 +1 @@ +JavaScript 1.2 diff --git a/js/src/tests/js1_2/String/browser.js b/js/src/tests/js1_2/String/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/String/browser.js diff --git a/js/src/tests/js1_2/String/charCodeAt.js b/js/src/tests/js1_2/String/charCodeAt.js new file mode 100644 index 000000000..b746a06fb --- /dev/null +++ b/js/src/tests/js1_2/String/charCodeAt.js @@ -0,0 +1,38 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 aString = new String("tEs5"); + +new TestCase( SECTION, "aString.charCodeAt(-2)", NaN, aString.charCodeAt(-2)); +new TestCase( SECTION, "aString.charCodeAt(-1)", NaN, aString.charCodeAt(-1)); +new TestCase( SECTION, "aString.charCodeAt( 0)", 116, aString.charCodeAt( 0)); +new TestCase( SECTION, "aString.charCodeAt( 1)", 69, aString.charCodeAt( 1)); +new TestCase( SECTION, "aString.charCodeAt( 2)", 115, aString.charCodeAt( 2)); +new TestCase( SECTION, "aString.charCodeAt( 3)", 53, aString.charCodeAt( 3)); +new TestCase( SECTION, "aString.charCodeAt( 4)", NaN, aString.charCodeAt( 4)); +new TestCase( SECTION, "aString.charCodeAt( 5)", NaN, aString.charCodeAt( 5)); +new TestCase( SECTION, "aString.charCodeAt( Infinity)", NaN, aString.charCodeAt( Infinity)); +new TestCase( SECTION, "aString.charCodeAt(-Infinity)", NaN, aString.charCodeAt(-Infinity)); +//new TestCase( SECTION, "aString.charCodeAt( )", 116, aString.charCodeAt( )); + +test(); + diff --git a/js/src/tests/js1_2/String/concat.js b/js/src/tests/js1_2/String/concat.js new file mode 100644 index 000000000..a0828cf1c --- /dev/null +++ b/js/src/tests/js1_2/String/concat.js @@ -0,0 +1,50 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 aString = new String("test string"); +var bString = new String(" another "); + +new TestCase( SECTION, "aString.concat(' more')", "test string more", aString.concat(' more').toString()); +new TestCase( SECTION, "aString.concat(bString)", "test string another ", aString.concat(bString).toString()); +new TestCase( SECTION, "aString ", "test string", aString.toString()); +new TestCase( SECTION, "bString ", " another ", bString.toString()); +new TestCase( SECTION, "aString.concat(345) ", "test string345", aString.concat(345).toString()); +new TestCase( SECTION, "aString.concat(true) ", "test stringtrue", aString.concat(true).toString()); +new TestCase( SECTION, "aString.concat(null) ", "test stringnull", aString.concat(null).toString()); +new TestCase( SECTION, "aString.concat([]) ", "test string[]", aString.concat([]).toString()); +new TestCase( SECTION, "aString.concat([1,2,3])", "test string[1, 2, 3]", aString.concat([1,2,3]).toString()); + +new TestCase( SECTION, "'abcde'.concat(' more')", "abcde more", 'abcde'.concat(' more').toString()); +new TestCase( SECTION, "'abcde'.concat(bString)", "abcde another ", 'abcde'.concat(bString).toString()); +new TestCase( SECTION, "'abcde' ", "abcde", 'abcde'); +new TestCase( SECTION, "'abcde'.concat(345) ", "abcde345", 'abcde'.concat(345).toString()); +new TestCase( SECTION, "'abcde'.concat(true) ", "abcdetrue", 'abcde'.concat(true).toString()); +new TestCase( SECTION, "'abcde'.concat(null) ", "abcdenull", 'abcde'.concat(null).toString()); +new TestCase( SECTION, "'abcde'.concat([]) ", "abcde[]", 'abcde'.concat([]).toString()); +new TestCase( SECTION, "'abcde'.concat([1,2,3])", "abcde[1, 2, 3]", 'abcde'.concat([1,2,3]).toString()); + +//what should this do: +new TestCase( SECTION, "'abcde'.concat() ", "abcde", 'abcde'.concat().toString()); + +test(); + diff --git a/js/src/tests/js1_2/String/match.js b/js/src/tests/js1_2/String/match.js new file mode 100644 index 000000000..ef4df16f9 --- /dev/null +++ b/js/src/tests/js1_2/String/match.js @@ -0,0 +1,29 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 aString = new String("this is a test string"); + +new TestCase( SECTION, "aString.match(/is.*test/) ", String(["is is a test"]), String(aString.match(/is.*test/))); +new TestCase( SECTION, "aString.match(/s.*s/) ", String(["s is a test s"]), String(aString.match(/s.*s/))); + +test(); + diff --git a/js/src/tests/js1_2/String/shell.js b/js/src/tests/js1_2/String/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/String/shell.js diff --git a/js/src/tests/js1_2/String/slice.js b/js/src/tests/js1_2/String/slice.js new file mode 100644 index 000000000..e939434ae --- /dev/null +++ b/js/src/tests/js1_2/String/slice.js @@ -0,0 +1,90 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 a = new String("abcdefghijklmnopqrstuvwxyz1234567890"); +var b = new String("this is a test string"); + +exhaustiveStringSliceTest("exhaustive String.slice test 1", a); +exhaustiveStringSliceTest("exhaustive String.slice test 2", b); + +test(); + + +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; +} diff --git a/js/src/tests/js1_2/browser.js b/js/src/tests/js1_2/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/browser.js diff --git a/js/src/tests/js1_2/function/Function_object.js b/js/src/tests/js1_2/function/Function_object.js new file mode 100644 index 000000000..a6af708e2 --- /dev/null +++ b/js/src/tests/js1_2/function/Function_object.js @@ -0,0 +1,54 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +function a_test_function(a,b,c) +{ + return a + b + c; +} + +f = a_test_function; + + +new TestCase( SECTION, "f.name", + 'a_test_function', f.name); + +new TestCase( SECTION, "f.length", + 3, f.length); + +new TestCase( SECTION, "f.arity", + 3, f.arity); + +new TestCase( SECTION, "f(2,3,4)", + 9, f(2,3,4)); + +var fnName = (version() == 120) ? '' : 'anonymous'; + +new TestCase( SECTION, "(new Function()).name", + fnName, (new Function()).name); + +new TestCase( SECTION, "(new Function()).toString()", + 'function ' + fnName + '() {\n}', (new Function()).toString()); + +test(); + diff --git a/js/src/tests/js1_2/function/Number.js b/js/src/tests/js1_2/function/Number.js new file mode 100644 index 000000000..fa5288acf --- /dev/null +++ b/js/src/tests/js1_2/function/Number.js @@ -0,0 +1,52 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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'; +var TITLE = 'functions: Number'; +var BUGNUMBER="123435"; + +startTest(); +writeHeaderToLog('Executing script: Number.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +date = new Date(2200); + +new TestCase( SECTION, "Number(new Date(2200)) ", + 2200, (Number(date))); +new TestCase( SECTION, "Number(true) ", + 1, (Number(true))); +new TestCase( SECTION, "Number(false) ", + 0, (Number(false))); +new TestCase( SECTION, "Number('124') ", + 124, (Number('124'))); +new TestCase( SECTION, "Number('1.23') ", + 1.23, (Number('1.23'))); +new TestCase( SECTION, "Number({p:1}) ", + NaN, (Number({p:1}))); +new TestCase( SECTION, "Number(null) ", + 0, (Number(null))); +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. + +new TestCase( SECTION, "Number([1,2,3]) ", + 3, (Number([1,2,3]))); + + +test(); + diff --git a/js/src/tests/js1_2/function/String.js b/js/src/tests/js1_2/function/String.js new file mode 100644 index 000000000..6f182d8f0 --- /dev/null +++ b/js/src/tests/js1_2/function/String.js @@ -0,0 +1,40 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +new TestCase( SECTION, "String(true) ", + 'true', (String(true))); +new TestCase( SECTION, "String(false) ", + 'false', (String(false))); +new TestCase( SECTION, "String(-124) ", + '-124', (String(-124))); +new TestCase( SECTION, "String(1.23) ", + '1.23', (String(1.23))); +new TestCase( SECTION, "String({p:1}) ", + '{p:1}', (String({p:1}))); +new TestCase( SECTION, "String(null) ", + 'null', (String(null))); +new TestCase( SECTION, "String([1,2,3]) ", + '[1, 2, 3]', (String([1,2,3]))); + +test(); + diff --git a/js/src/tests/js1_2/function/browser.js b/js/src/tests/js1_2/function/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/function/browser.js diff --git a/js/src/tests/js1_2/function/definition-1.js b/js/src/tests/js1_2/function/definition-1.js new file mode 100644 index 000000000..bffd7590a --- /dev/null +++ b/js/src/tests/js1_2/function/definition-1.js @@ -0,0 +1,43 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +f1 = function() { return "passed!" } + + function f2() { f3 = function() { return "passed!" }; return f3(); } + +new TestCase( SECTION, + 'f1 = function() { return "passed!" }; f1()', + "passed!", + f1() ); + +new TestCase( SECTION, + 'function f2() { f3 = function { return "passed!" }; return f3() }; f2()', + "passed!", + f2() ); + +new TestCase( SECTION, + 'f3()', + "passed!", + f3() ); + +test(); + diff --git a/js/src/tests/js1_2/function/function-001-n.js b/js/src/tests/js1_2/function/function-001-n.js new file mode 100644 index 000000000..fe547aa60 --- /dev/null +++ b/js/src/tests/js1_2/function/function-001-n.js @@ -0,0 +1,44 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * 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"; +var TITLE = "functions not separated by semicolons are errors in version 120 and higher"; +var BUGNUMBER="99232"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +new TestCase( + SECTION, + "eval(\"function f(){}function g(){}\")", + "error", + eval("function f(){}function g(){}") ); + +test(); + diff --git a/js/src/tests/js1_2/function/length.js b/js/src/tests/js1_2/function/length.js new file mode 100644 index 000000000..f679aa14e --- /dev/null +++ b/js/src/tests/js1_2/function/length.js @@ -0,0 +1,63 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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"; +var TITLE = "Function.length"; +var BUGNUMBER="104204"; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +var f = new Function( "a","b", "c", "return f.length"); + +if ( version() <= 120 ) { + + new TestCase( SECTION, + 'var f = new Function( "a","b", "c", "return f.length"); f()', + 0, + f() ); + + 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 { + + new TestCase( SECTION, + 'var f = new Function( "a","b", "c", "return f.length"); f()', + 3, + f() ); + + 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(); diff --git a/js/src/tests/js1_2/function/nesting-1.js b/js/src/tests/js1_2/function/nesting-1.js new file mode 100644 index 000000000..334f1521a --- /dev/null +++ b/js/src/tests/js1_2/function/nesting-1.js @@ -0,0 +1,31 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +function f(a) {function g(b) {return a+b;}; return g;}; f(7); + +new TestCase( SECTION, + 'function f(a) {function g(b) {return a+b;}; return g;}; typeof f(7)', + "function", + typeof f(7) ); + +test(); + diff --git a/js/src/tests/js1_2/function/nesting.js b/js/src/tests/js1_2/function/nesting.js new file mode 100644 index 000000000..1e1f18dc6 --- /dev/null +++ b/js/src/tests/js1_2/function/nesting.js @@ -0,0 +1,50 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +function outer_func(x) +{ + var y = "outer"; + + new TestCase( SECTION, "outer:x ", + 1111, x); + new TestCase( SECTION, "outer:y ", + 'outer', y); + function inner_func(x) + { + var y = "inner"; + new TestCase( SECTION, "inner:x ", + 2222, x); + new TestCase( SECTION, "inner:y ", + 'inner', y); + }; + + inner_func(2222); + new TestCase( SECTION, "outer:x ", + 1111, x); + new TestCase( SECTION, "outer:y ", + 'outer', y); +} + +outer_func(1111); + +test(); + diff --git a/js/src/tests/js1_2/function/regexparg-1.js b/js/src/tests/js1_2/function/regexparg-1.js new file mode 100644 index 000000000..16c25bf9d --- /dev/null +++ b/js/src/tests/js1_2/function/regexparg-1.js @@ -0,0 +1,71 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 statement"; + +writeHeaderToLog( SECTION + " "+ TITLE); + +print("Note: Bug 61911 changed the behavior of typeof regexp in Gecko 1.9."); +print("Prior to Gecko 1.9, typeof regexp returned 'function'."); +print("However in Gecko 1.9 and later, typeof regexp will return 'object'."); + +function f(x) {return x;} + +x = f(/abc/); + +new TestCase( SECTION, + "function f(x) {return x;}; f()", + void 0, + f() ); + +new TestCase( SECTION, + "f(\"hi\")", + "hi", + f("hi") ); + +new TestCase( SECTION, + "new f(/abc/) +''", + "/abc/", + new f(/abc/) +"" ); + +new TestCase( SECTION, + "f(/abc/)+'')", + "/abc/", + f(/abc/) +''); + +new TestCase( SECTION, + "typeof f(/abc/)", + "object", + typeof f(/abc/) ); + +new TestCase( SECTION, + "typeof new f(/abc/)", + "object", + typeof new f(/abc/) ); + +new TestCase( SECTION, + "x = new f(/abc/); x.exec(\"hi\")", + null, + x.exec("hi") ); + + +// js> x() +test(); diff --git a/js/src/tests/js1_2/function/regexparg-2-n.js b/js/src/tests/js1_2/function/regexparg-2-n.js new file mode 100644 index 000000000..f0f862dbc --- /dev/null +++ b/js/src/tests/js1_2/function/regexparg-2-n.js @@ -0,0 +1,40 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 statement"; + +writeHeaderToLog( SECTION + " "+ TITLE); + +function f(x) {return x;} + +x = f(/abc/); + +DESCRIPTION = "function f(x) {return x;}; x = f(/abc/); x()"; +EXPECTED = "error"; + +new TestCase( SECTION, + "function f(x) {return x;}; x = f(/abc/); x()", + "error", + x() ); + +test(); + diff --git a/js/src/tests/js1_2/function/shell.js b/js/src/tests/js1_2/function/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/function/shell.js diff --git a/js/src/tests/js1_2/function/tostring-1.js b/js/src/tests/js1_2/function/tostring-1.js new file mode 100644 index 000000000..2f883410e --- /dev/null +++ b/js/src/tests/js1_2/function/tostring-1.js @@ -0,0 +1,112 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 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!\""); + +new TestCase( SECTION, + "stub.toString()", + t1.valueOf(), + stub.toString() ); + +new TestCase( SECTION, + "ToString.toString()", + t2.valueOf(), + ToString.toString() ); + +new TestCase( SECTION, + "Add.toString()", + t3.valueOf(), + Add.toString() ); + +new TestCase( SECTION, + "noop.toString()", + t4.toString(), + noop.toString() ); + +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 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: + function name ( arguments ) { + body + } + */ + this.value = "function " + (name ? name : "" )+ + "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}"; + + this.toString = new Function( "return this.value" ); + this.valueOf = new Function( "return this.value" ); + return this; +} diff --git a/js/src/tests/js1_2/function/tostring-2.js b/js/src/tests/js1_2/function/tostring-2.js new file mode 100644 index 000000000..feb22d709 --- /dev/null +++ b/js/src/tests/js1_2/function/tostring-2.js @@ -0,0 +1,155 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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"; +var TITLE = "Function.toString()"; +var BUGNUMBER="123444"; +startTest(); + +writeHeaderToLog( SECTION + " "+ TITLE); + +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; +} + +new TestCase( SECTION, + "Equals.toString()", + equals.valueOf(), + Equals.toString() ); + +new TestCase( SECTION, + "ReallyEquals.toString()", + reallyequals.valueOf(), + ReallyEquals.toString() ); + +new TestCase( SECTION, + "DoesntEqual.toString()", + doesntequal.valueOf(), + DoesntEqual.toString() ); + +new TestCase( SECTION, + "ReallyDoesntEqual.toString()", + reallydoesntequal.valueOf(), + ReallyDoesntEqual.toString() ); + +new TestCase( SECTION, + "TestOr.toString()", + testor.valueOf(), + TestOr.toString() ); + +new TestCase( SECTION, + "TestAnd.toString()", + testand.valueOf(), + TestAnd.toString() ); + +new TestCase( SECTION, + "Or.toString()", + or.valueOf(), + Or.toString() ); + +new TestCase( SECTION, + "And.toString()", + and.valueOf(), + And.toString() ); + +new TestCase( SECTION, + "XOr.toString()", + xor.valueOf(), + XOr.toString() ); + +test(); + +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: + function name ( arguments ) { + body + } + */ + this.value = "function " + (name ? name : "anonymous" )+ + "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}"; + + this.toString = new Function( "return this.value" ); + this.valueOf = new Function( "return this.value" ); + return this; +} diff --git a/js/src/tests/js1_2/operator/browser.js b/js/src/tests/js1_2/operator/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/operator/browser.js diff --git a/js/src/tests/js1_2/operator/equality.js b/js/src/tests/js1_2/operator/equality.js new file mode 100644 index 000000000..facc0113b --- /dev/null +++ b/js/src/tests/js1_2/operator/equality.js @@ -0,0 +1,39 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// the following two tests are incorrect +//new TestCase( SECTION, "(new String('') == new String('')) ", +// true, (new String('') == new String(''))); + +//new TestCase( SECTION, "(new Boolean(true) == new Boolean(true)) ", +// true, (new Boolean(true) == new Boolean(true))); + +new TestCase( SECTION, "(new String('x') == 'x') ", + false, (new String('x') == 'x')); + +new TestCase( SECTION, "('x' == new String('x')) ", + false, ('x' == new String('x'))); + + +test(); + diff --git a/js/src/tests/js1_2/operator/shell.js b/js/src/tests/js1_2/operator/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/operator/shell.js diff --git a/js/src/tests/js1_2/operator/strictEquality.js b/js/src/tests/js1_2/operator/strictEquality.js new file mode 100644 index 000000000..1bbbe0465 --- /dev/null +++ b/js/src/tests/js1_2/operator/strictEquality.js @@ -0,0 +1,59 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +new TestCase( SECTION, "('8' === 8) ", + false, ('8' === 8)); + +new TestCase( SECTION, "(8 === 8) ", + true, (8 === 8)); + +new TestCase( SECTION, "(8 === true) ", + false, (8 === true)); + +new TestCase( SECTION, "(new String('') === new String('')) ", + false, (new String('') === new String(''))); + +new TestCase( SECTION, "(new Boolean(true) === new Boolean(true))", + false, (new Boolean(true) === new Boolean(true))); + +var anObject = { one:1 , two:2 }; + +new TestCase( SECTION, "(anObject === anObject) ", + true, (anObject === anObject)); + +new TestCase( SECTION, "(anObject === { one:1 , two:2 }) ", + false, (anObject === { one:1 , two:2 })); + +new TestCase( SECTION, "({ one:1 , two:2 } === anObject) ", + false, ({ one:1 , two:2 } === anObject)); + +new TestCase( SECTION, "(null === null) ", + true, (null === null)); + +new TestCase( SECTION, "(null === 0) ", + false, (null === 0)); + +new TestCase( SECTION, "(true === !false) ", + true, (true === !false)); + +test(); + diff --git a/js/src/tests/js1_2/regexp/RegExp_dollar_number.js b/js/src/tests/js1_2/regexp/RegExp_dollar_number.js new file mode 100644 index 000000000..5bc1c8e51 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_dollar_number.js @@ -0,0 +1,77 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 "What\'s new in JavaScript 1.2"'; +var VERSION = 'no version'; +var TITLE = 'RegExp: $1, ..., $9'; +var BUGNUMBER="123802"; + +startTest(); +writeHeaderToLog('Executing script: RegExp_dollar_number.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); RegExp.$1 +'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/); +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 +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 +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 +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 +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 +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); + +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$1", + 'a', RegExp.$1); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$2", + 'c', RegExp.$2); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$3", + 'e', RegExp.$3); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$4", + 'g', RegExp.$4); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$5", + 'i', RegExp.$5); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$6", + 'k', RegExp.$6); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$7", + 'm', RegExp.$7); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$8", + 'o', RegExp.$8); +new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$9", + 'q', RegExp.$9); +/* + new TestCase ( SECTION, "'" + a_to_z + "'.match((a)b(c)....(y)z); RegExp.$10", + 's', RegExp.$10); +*/ +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_lastIndex.js b/js/src/tests/js1_2/regexp/RegExp_lastIndex.js new file mode 100644 index 000000000..a8ace2542 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_lastIndex.js @@ -0,0 +1,52 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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'; +var TITLE = 'RegExp: lastIndex'; +var BUGNUMBER="123802"; + +startTest(); +writeHeaderToLog('Executing script: RegExp_lastIndex.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + +// re=/x./g; re.lastIndex=4; re.exec('xyabcdxa'); +re=/x./g; +re.lastIndex=4; +new TestCase ( SECTION, "re=/x./g; re.lastIndex=4; re.exec('xyabcdxa')", + '["xa"]', String(re.exec('xyabcdxa'))); + +// re.lastIndex +new TestCase ( SECTION, "re.lastIndex", + 8, re.lastIndex); + +// re.exec('xyabcdef'); +new TestCase ( SECTION, "re.exec('xyabcdef')", + null, re.exec('xyabcdef')); + +// re.lastIndex +new TestCase ( SECTION, "re.lastIndex", + 0, re.lastIndex); + +// re.exec('xyabcdef'); +new TestCase ( SECTION, "re.exec('xyabcdef')", + '["xy"]', String(re.exec('xyabcdef'))); + +// re.lastIndex=30; re.exec('123xaxbxc456'); +re.lastIndex=30; +new TestCase ( SECTION, "re.lastIndex=30; re.exec('123xaxbxc456')", + null, re.exec('123xaxbxc456')); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_lastMatch.js b/js/src/tests/js1_2/regexp/RegExp_lastMatch.js new file mode 100644 index 000000000..a525d1cbe --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_lastMatch.js @@ -0,0 +1,54 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'foo'.match(/foo/); RegExp.lastMatch +'foo'.match(/foo/); +new TestCase ( SECTION, "'foo'.match(/foo/); RegExp.lastMatch", + 'foo', RegExp.lastMatch); + +// 'foo'.match(new RegExp('foo')); RegExp.lastMatch +'foo'.match(new RegExp('foo')); +new TestCase ( SECTION, "'foo'.match(new RegExp('foo')); RegExp.lastMatch", + 'foo', RegExp.lastMatch); + +// 'xxx'.match(/bar/); RegExp.lastMatch +'xxx'.match(/bar/); +new TestCase ( SECTION, "'xxx'.match(/bar/); RegExp.lastMatch", + 'foo', RegExp.lastMatch); + +// 'xxx'.match(/$/); RegExp.lastMatch +'xxx'.match(/$/); +new TestCase ( SECTION, "'xxx'.match(/$/); RegExp.lastMatch", + '', RegExp.lastMatch); + +// 'abcdefg'.match(/^..(cd)[a-z]+/); RegExp.lastMatch +'abcdefg'.match(/^..(cd)[a-z]+/); +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/); +new TestCase ( SECTION, "'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\\1/); RegExp.lastMatch", + 'abcdefgabcdefg', RegExp.lastMatch); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_lastMatch_as_array.js b/js/src/tests/js1_2/regexp/RegExp_lastMatch_as_array.js new file mode 100644 index 000000000..48405ae6f --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_lastMatch_as_array.js @@ -0,0 +1,54 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'foo'.match(/foo/); RegExp['$&'] +'foo'.match(/foo/); +new TestCase ( SECTION, "'foo'.match(/foo/); RegExp['$&']", + 'foo', RegExp['$&']); + +// 'foo'.match(new RegExp('foo')); RegExp['$&'] +'foo'.match(new RegExp('foo')); +new TestCase ( SECTION, "'foo'.match(new RegExp('foo')); RegExp['$&']", + 'foo', RegExp['$&']); + +// 'xxx'.match(/bar/); RegExp['$&'] +'xxx'.match(/bar/); +new TestCase ( SECTION, "'xxx'.match(/bar/); RegExp['$&']", + 'foo', RegExp['$&']); + +// 'xxx'.match(/$/); RegExp['$&'] +'xxx'.match(/$/); +new TestCase ( SECTION, "'xxx'.match(/$/); RegExp['$&']", + '', RegExp['$&']); + +// 'abcdefg'.match(/^..(cd)[a-z]+/); RegExp['$&'] +'abcdefg'.match(/^..(cd)[a-z]+/); +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/); +new TestCase ( SECTION, "'abcdefgabcdefg'.match(/(a(b(c(d)e)f)g)\\1/); RegExp['$&']", + 'abcdefgabcdefg', RegExp['$&']); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_lastParen.js b/js/src/tests/js1_2/regexp/RegExp_lastParen.js new file mode 100644 index 000000000..81c106ab8 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_lastParen.js @@ -0,0 +1,68 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abcd'.match(/(abc)d/); RegExp.lastParen +'abcd'.match(/(abc)d/); +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')); +new TestCase ( SECTION, "'abcd'.match(new RegExp('(abc)d')); RegExp.lastParen", + 'abc', RegExp.lastParen); + +// 'abcd'.match(/(bcd)e/); RegExp.lastParen +'abcd'.match(/(bcd)e/); +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)/); +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)/); +new TestCase ( SECTION, "'abcdefg'.match(/(a(b)c)(d(e)f)/); RegExp.lastParen", + 'e', RegExp.lastParen); + +// 'abcdefg'.match(/(^)abc/); RegExp.lastParen +'abcdefg'.match(/(^)abc/); +new TestCase ( SECTION, "'abcdefg'.match(/(^)abc/); RegExp.lastParen", + '', RegExp.lastParen); + +// 'abcdefg'.match(/(^a)bc/); RegExp.lastParen +'abcdefg'.match(/(^a)bc/); +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')); +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(^a)bc')); RegExp.lastParen", + 'a', RegExp.lastParen); + +// 'abcdefg'.match(/bc/); RegExp.lastParen +'abcdefg'.match(/bc/); +new TestCase ( SECTION, "'abcdefg'.match(/bc/); RegExp.lastParen", + '', RegExp.lastParen); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_lastParen_as_array.js b/js/src/tests/js1_2/regexp/RegExp_lastParen_as_array.js new file mode 100644 index 000000000..68bf35029 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_lastParen_as_array.js @@ -0,0 +1,68 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abcd'.match(/(abc)d/); RegExp['$+'] +'abcd'.match(/(abc)d/); +new TestCase ( SECTION, "'abcd'.match(/(abc)d/); RegExp['$+']", + 'abc', RegExp['$+']); + +// 'abcd'.match(/(bcd)e/); RegExp['$+'] +'abcd'.match(/(bcd)e/); +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)/); +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)')); +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)/); +new TestCase ( SECTION, "'abcdefg'.match(/(a(b)c)(d(e)f)/); RegExp['$+']", + 'e', RegExp['$+']); + +// 'abcdefg'.match(/(^)abc/); RegExp['$+'] +'abcdefg'.match(/(^)abc/); +new TestCase ( SECTION, "'abcdefg'.match(/(^)abc/); RegExp['$+']", + '', RegExp['$+']); + +// 'abcdefg'.match(/(^a)bc/); RegExp['$+'] +'abcdefg'.match(/(^a)bc/); +new TestCase ( SECTION, "'abcdefg'.match(/(^a)bc/); RegExp['$+']", + 'a', RegExp['$+']); + +// 'abcdefg'.match(new RegExp('(^a)bc')); RegExp['$+'] +'abcdefg'.match(new RegExp('(^a)bc')); +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(^a)bc')); RegExp['$+']", + 'a', RegExp['$+']); + +// 'abcdefg'.match(/bc/); RegExp['$+'] +'abcdefg'.match(/bc/); +new TestCase ( SECTION, "'abcdefg'.match(/bc/); RegExp['$+']", + '', RegExp['$+']); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_leftContext.js b/js/src/tests/js1_2/regexp/RegExp_leftContext.js new file mode 100644 index 000000000..2fdb38975 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_leftContext.js @@ -0,0 +1,58 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abc123xyz'.match(/123/); RegExp.leftContext +'abc123xyz'.match(/123/); +new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp.leftContext", + 'abc', RegExp.leftContext); + +// 'abc123xyz'.match(/456/); RegExp.leftContext +'abc123xyz'.match(/456/); +new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp.leftContext", + 'abc', RegExp.leftContext); + +// 'abc123xyz'.match(/abc123xyz/); RegExp.leftContext +'abc123xyz'.match(/abc123xyz/); +new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp.leftContext", + '', RegExp.leftContext); + +// 'xxxx'.match(/$/); RegExp.leftContext +'xxxx'.match(/$/); +new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp.leftContext", + 'xxxx', RegExp.leftContext); + +// 'test'.match(/^/); RegExp.leftContext +'test'.match(/^/); +new TestCase ( SECTION, "'test'.match(/^/); RegExp.leftContext", + '', RegExp.leftContext); + +// 'xxxx'.match(new RegExp('$')); RegExp.leftContext +'xxxx'.match(new RegExp('$')); +new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp.leftContext", + 'xxxx', RegExp.leftContext); + +// 'test'.match(new RegExp('^')); RegExp.leftContext +'test'.match(new RegExp('^')); +new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp.leftContext", + '', RegExp.leftContext); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_leftContext_as_array.js b/js/src/tests/js1_2/regexp/RegExp_leftContext_as_array.js new file mode 100644 index 000000000..ffde0f7c3 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_leftContext_as_array.js @@ -0,0 +1,58 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abc123xyz'.match(/123/); RegExp['$`'] +'abc123xyz'.match(/123/); +new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp['$`']", + 'abc', RegExp['$`']); + +// 'abc123xyz'.match(/456/); RegExp['$`'] +'abc123xyz'.match(/456/); +new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp['$`']", + 'abc', RegExp['$`']); + +// 'abc123xyz'.match(/abc123xyz/); RegExp['$`'] +'abc123xyz'.match(/abc123xyz/); +new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp['$`']", + '', RegExp['$`']); + +// 'xxxx'.match(/$/); RegExp['$`'] +'xxxx'.match(/$/); +new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp['$`']", + 'xxxx', RegExp['$`']); + +// 'test'.match(/^/); RegExp['$`'] +'test'.match(/^/); +new TestCase ( SECTION, "'test'.match(/^/); RegExp['$`']", + '', RegExp['$`']); + +// 'xxxx'.match(new RegExp('$')); RegExp['$`'] +'xxxx'.match(new RegExp('$')); +new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp['$`']", + 'xxxx', RegExp['$`']); + +// 'test'.match(new RegExp('^')); RegExp['$`'] +'test'.match(new RegExp('^')); +new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp['$`']", + '', RegExp['$`']); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_object.js b/js/src/tests/js1_2/regexp/RegExp_object.js new file mode 100644 index 000000000..4c39474ea --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_object.js @@ -0,0 +1,56 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 SSN_pattern = new RegExp("\\d{3}-\\d{2}-\\d{4}"); + +// testing SSN pattern +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 +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 +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 +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 +new TestCase ( SECTION, "String(PHONE_pattern.toString())", + "/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/", String(PHONE_pattern.toString())); + +// testing conversion to String +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 +new TestCase ( SECTION, "SSN_pattern - 8", + NaN,SSN_pattern - 8); + +var testPattern = new RegExp("(\\d+)45(\\d+)90"); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_rightContext.js b/js/src/tests/js1_2/regexp/RegExp_rightContext.js new file mode 100644 index 000000000..f618cedf3 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_rightContext.js @@ -0,0 +1,58 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abc123xyz'.match(/123/); RegExp.rightContext +'abc123xyz'.match(/123/); +new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp.rightContext", + 'xyz', RegExp.rightContext); + +// 'abc123xyz'.match(/456/); RegExp.rightContext +'abc123xyz'.match(/456/); +new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp.rightContext", + 'xyz', RegExp.rightContext); + +// 'abc123xyz'.match(/abc123xyz/); RegExp.rightContext +'abc123xyz'.match(/abc123xyz/); +new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp.rightContext", + '', RegExp.rightContext); + +// 'xxxx'.match(/$/); RegExp.rightContext +'xxxx'.match(/$/); +new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp.rightContext", + '', RegExp.rightContext); + +// 'test'.match(/^/); RegExp.rightContext +'test'.match(/^/); +new TestCase ( SECTION, "'test'.match(/^/); RegExp.rightContext", + 'test', RegExp.rightContext); + +// 'xxxx'.match(new RegExp('$')); RegExp.rightContext +'xxxx'.match(new RegExp('$')); +new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp.rightContext", + '', RegExp.rightContext); + +// 'test'.match(new RegExp('^')); RegExp.rightContext +'test'.match(new RegExp('^')); +new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp.rightContext", + 'test', RegExp.rightContext); + +test(); diff --git a/js/src/tests/js1_2/regexp/RegExp_rightContext_as_array.js b/js/src/tests/js1_2/regexp/RegExp_rightContext_as_array.js new file mode 100644 index 000000000..24c4ae069 --- /dev/null +++ b/js/src/tests/js1_2/regexp/RegExp_rightContext_as_array.js @@ -0,0 +1,58 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abc123xyz'.match(/123/); RegExp['$\''] +'abc123xyz'.match(/123/); +new TestCase ( SECTION, "'abc123xyz'.match(/123/); RegExp['$\'']", + 'xyz', RegExp['$\'']); + +// 'abc123xyz'.match(/456/); RegExp['$\''] +'abc123xyz'.match(/456/); +new TestCase ( SECTION, "'abc123xyz'.match(/456/); RegExp['$\'']", + 'xyz', RegExp['$\'']); + +// 'abc123xyz'.match(/abc123xyz/); RegExp['$\''] +'abc123xyz'.match(/abc123xyz/); +new TestCase ( SECTION, "'abc123xyz'.match(/abc123xyz/); RegExp['$\'']", + '', RegExp['$\'']); + +// 'xxxx'.match(/$/); RegExp['$\''] +'xxxx'.match(/$/); +new TestCase ( SECTION, "'xxxx'.match(/$/); RegExp['$\'']", + '', RegExp['$\'']); + +// 'test'.match(/^/); RegExp['$\''] +'test'.match(/^/); +new TestCase ( SECTION, "'test'.match(/^/); RegExp['$\'']", + 'test', RegExp['$\'']); + +// 'xxxx'.match(new RegExp('$')); RegExp['$\''] +'xxxx'.match(new RegExp('$')); +new TestCase ( SECTION, "'xxxx'.match(new RegExp('$')); RegExp['$\'']", + '', RegExp['$\'']); + +// 'test'.match(new RegExp('^')); RegExp['$\''] +'test'.match(new RegExp('^')); +new TestCase ( SECTION, "'test'.match(new RegExp('^')); RegExp['$\'']", + 'test', RegExp['$\'']); + +test(); diff --git a/js/src/tests/js1_2/regexp/alphanumeric.js b/js/src/tests/js1_2/regexp/alphanumeric.js new file mode 100644 index 000000000..1dc3fb2e3 --- /dev/null +++ b/js/src/tests/js1_2/regexp/alphanumeric.js @@ -0,0 +1,97 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 non_alphanumeric = "~`!@#$%^&*()-+={[}]|\\:;'<,>./?\f\n\r\t\v " + '"'; +var alphanumeric = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + +// be sure all alphanumerics are matched by \w +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 +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 +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 +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 +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 +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) +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) +new TestCase ( SECTION, + "'" + s + "'.match(/\W+/)", + String([non_alphanumeric]), String(s.match(/\W+/))); + +s = 'abcd*&^%$$'; +// be sure the following test behaves consistently +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] + '%^'; + 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)); + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\W'))", + String([non_alphanumeric[i]]), String(s.match(new RegExp('\\W')))); +} + +test(); diff --git a/js/src/tests/js1_2/regexp/asterisk.js b/js/src/tests/js1_2/regexp/asterisk.js new file mode 100644 index 000000000..373c9554e --- /dev/null +++ b/js/src/tests/js1_2/regexp/asterisk.js @@ -0,0 +1,73 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abcddddefg'.match(new RegExp('d*')) +new TestCase ( SECTION, "'abcddddefg'.match(new RegExp('d*'))", + String([""]), String('abcddddefg'.match(new RegExp('d*')))); + +// 'abcddddefg'.match(new RegExp('cd*')) +new TestCase ( SECTION, "'abcddddefg'.match(new RegExp('cd*'))", + String(["cdddd"]), String('abcddddefg'.match(new RegExp('cd*')))); + +// 'abcdefg'.match(new RegExp('cx*d')) +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('cx*d'))", + String(["cd"]), String('abcdefg'.match(new RegExp('cx*d')))); + +// 'xxxxxxx'.match(new RegExp('(x*)(x+)')) +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+)')) +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+)')) +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*)')) +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+$')) +new TestCase ( SECTION, "'xxxxxxyyyyyy'.match(new RegExp('x*y+$'))", + String(["xxxxxxyyyyyy"]), String('xxxxxxyyyyyy'.match(new RegExp('x*y+$')))); + +// 'abcdef'.match(/[\d]*[\s]*bc./) +new TestCase ( SECTION, "'abcdef'.match(/[\\d]*[\\s]*bc./)", + String(["bcd"]), String('abcdef'.match(/[\d]*[\s]*bc./))); + +// 'abcdef'.match(/bc..[\d]*[\s]*/) +new TestCase ( SECTION, "'abcdef'.match(/bc..[\\d]*[\\s]*/)", + String(["bcde"]), String('abcdef'.match(/bc..[\d]*[\s]*/))); + +// 'a1b2c3'.match(/.*/) +new TestCase ( SECTION, "'a1b2c3'.match(/.*/)", + String(["a1b2c3"]), String('a1b2c3'.match(/.*/))); + +// 'a0.b2.c3'.match(/[xyz]*1/) +new TestCase ( SECTION, "'a0.b2.c3'.match(/[xyz]*1/)", + null, 'a0.b2.c3'.match(/[xyz]*1/)); + +test(); diff --git a/js/src/tests/js1_2/regexp/backslash.js b/js/src/tests/js1_2/regexp/backslash.js new file mode 100644 index 000000000..6ad35809e --- /dev/null +++ b/js/src/tests/js1_2/regexp/backslash.js @@ -0,0 +1,47 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abcde'.match(new RegExp('\e')) +new TestCase ( SECTION, "'abcde'.match(new RegExp('\e'))", + String(["e"]), String('abcde'.match(new RegExp('\e')))); + +// 'ab\\cde'.match(new RegExp('\\\\')) +new TestCase ( SECTION, "'ab\\cde'.match(new RegExp('\\\\'))", + String(["\\"]), String('ab\\cde'.match(new RegExp('\\\\')))); + +// 'ab\\cde'.match(/\\/) (using literal) +new TestCase ( SECTION, "'ab\\cde'.match(/\\\\/)", + String(["\\"]), String('ab\\cde'.match(/\\/))); + +// 'before ^$*+?.()|{}[] after'.match(new RegExp('\^\$\*\+\?\.\(\)\|\{\}\[\]')) +new TestCase ( SECTION, + "'before ^$*+?.()|{}[] after'.match(new RegExp('\\^\\$\\*\\+\\?\\.\\(\\)\\|\\{\\}\\[\\]'))", + String(["^$*+?.()|{}[]"]), + String('before ^$*+?.()|{}[] after'.match(new RegExp('\\^\\$\\*\\+\\?\\.\\(\\)\\|\\{\\}\\[\\]')))); + +// 'before ^$*+?.()|{}[] after'.match(/\^\$\*\+\?\.\(\)\|\{\}\[\]/) (using literal) +new TestCase ( SECTION, + "'before ^$*+?.()|{}[] after'.match(/\\^\\$\\*\\+\\?\\.\\(\\)\\|\\{\\}\\[\\]/)", + String(["^$*+?.()|{}[]"]), + String('before ^$*+?.()|{}[] after'.match(/\^\$\*\+\?\.\(\)\|\{\}\[\]/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/backspace.js b/js/src/tests/js1_2/regexp/backspace.js new file mode 100644 index 000000000..3e7a0003a --- /dev/null +++ b/js/src/tests/js1_2/regexp/backspace.js @@ -0,0 +1,47 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abc\bdef'.match(new RegExp('.[\b].')) +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].')) +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')) +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\\]]+')) +new TestCase ( SECTION, "'abc\bdef'.match(new RegExp('[^\\[\\b\\]]+'))", + String(["abc"]), String('abc\bdef'.match(new RegExp('[^\\[\\b\\]]+')))); + +// 'abcdef'.match(new RegExp('[^\\[\b\\]]+')) +new TestCase ( SECTION, "'abcdef'.match(new RegExp('[^\\[\\b\\]]+'))", + String(["abcdef"]), String('abcdef'.match(new RegExp('[^\\[\\b\\]]+')))); + +// 'abcdef'.match(/[^\[\b\]]+/) +new TestCase ( SECTION, "'abcdef'.match(/[^\\[\\b\\]]+/)", + String(["abcdef"]), String('abcdef'.match(/[^\[\b\]]+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/beginLine.js b/js/src/tests/js1_2/regexp/beginLine.js new file mode 100644 index 000000000..464f12e8b --- /dev/null +++ b/js/src/tests/js1_2/regexp/beginLine.js @@ -0,0 +1,44 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'abcde'.match(new RegExp('^ab')) +new TestCase ( SECTION, "'abcde'.match(new RegExp('^ab'))", + String(["ab"]), String('abcde'.match(new RegExp('^ab')))); + +// 'ab\ncde'.match(new RegExp('^..^e')) +new TestCase ( SECTION, "'ab\ncde'.match(new RegExp('^..^e'))", + null, 'ab\ncde'.match(new RegExp('^..^e'))); + +// 'yyyyy'.match(new RegExp('^xxx')) +new TestCase ( SECTION, "'yyyyy'.match(new RegExp('^xxx'))", + null, 'yyyyy'.match(new RegExp('^xxx'))); + +// '^^^x'.match(new RegExp('^\\^+')) +new TestCase ( SECTION, "'^^^x'.match(new RegExp('^\\^+'))", + String(['^^^']), String('^^^x'.match(new RegExp('^\\^+')))); + +// '^^^x'.match(/^\^+/) +new TestCase ( SECTION, "'^^^x'.match(/^\\^+/)", + String(['^^^']), String('^^^x'.match(/^\^+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/browser.js b/js/src/tests/js1_2/regexp/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/regexp/browser.js diff --git a/js/src/tests/js1_2/regexp/character_class.js b/js/src/tests/js1_2/regexp/character_class.js new file mode 100644 index 000000000..800de9a09 --- /dev/null +++ b/js/src/tests/js1_2/regexp/character_class.js @@ -0,0 +1,76 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'abcde'.match(new RegExp('ab[ercst]de')) +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')) +new TestCase ( SECTION, "'abcde'.match(new RegExp('ab[erst]de'))", + null, 'abcde'.match(new RegExp('ab[erst]de'))); + +// 'abcdefghijkl'.match(new RegExp('[d-h]+')) +new TestCase ( SECTION, "'abcdefghijkl'.match(new RegExp('[d-h]+'))", + String(["defgh"]), String('abcdefghijkl'.match(new RegExp('[d-h]+')))); + +// 'abc6defghijkl'.match(new RegExp('[1234567].{2}')) +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]+')) +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')) +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')) +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]')) +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}')) +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')) +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')) +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}')) +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}/) +new TestCase ( SECTION, "'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)", + String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/compile.js b/js/src/tests/js1_2/regexp/compile.js new file mode 100644 index 000000000..c1d4acc81 --- /dev/null +++ b/js/src/tests/js1_2/regexp/compile.js @@ -0,0 +1,62 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 regularExpression = new RegExp(); + +regularExpression.compile("[0-9]{3}x[0-9]{4}","i"); + +new TestCase ( SECTION, + "(compile '[0-9]{3}x[0-9]{4}','i')", + String(["456X7890"]), String('234X456X7890'.match(regularExpression))); + +new TestCase ( SECTION, + "source of (compile '[0-9]{3}x[0-9]{4}','i')", + "[0-9]{3}x[0-9]{4}", regularExpression.source); + +new TestCase ( SECTION, + "global of (compile '[0-9]{3}x[0-9]{4}','i')", + false, regularExpression.global); + +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"); + +new TestCase ( SECTION, + "(compile '[0-9]{3}X[0-9]{3}','g')", + String(["234X456"]), String('234X456X7890'.match(regularExpression))); + +new TestCase ( SECTION, + "source of (compile '[0-9]{3}X[0-9]{3}','g')", + "[0-9]{3}X[0-9]{3}", regularExpression.source); + +new TestCase ( SECTION, + "global of (compile '[0-9]{3}X[0-9]{3}','g')", + true, regularExpression.global); + +new TestCase ( SECTION, + "ignoreCase of (compile '[0-9]{3}X[0-9]{3}','g')", + false, regularExpression.ignoreCase); + + +test(); diff --git a/js/src/tests/js1_2/regexp/control_characters.js b/js/src/tests/js1_2/regexp/control_characters.js new file mode 100644 index 000000000..82857e6f7 --- /dev/null +++ b/js/src/tests/js1_2/regexp/control_characters.js @@ -0,0 +1,40 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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'; +var TITLE = 'RegExp: .'; +var BUGNUMBER="123802"; + +startTest(); +writeHeaderToLog('Executing script: control_characters.js'); +writeHeaderToLog( SECTION + " "+ TITLE); + + +// 'àOÐ ê:i¢Ø'.match(new RegExp('.+')) +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¢Ø'; +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); +new TestCase ( SECTION, "string1 = " + string1 + " string1.match(string1)", + String([string1]), String(string1.match(string1))); + +test(); diff --git a/js/src/tests/js1_2/regexp/digit.js b/js/src/tests/js1_2/regexp/digit.js new file mode 100644 index 000000000..ce3c6554d --- /dev/null +++ b/js/src/tests/js1_2/regexp/digit.js @@ -0,0 +1,86 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 non_digits = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"'; + +var digits = "1234567890"; + +// be sure all digits are matched by \d +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 +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 +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 +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 +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 +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'; + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\d'))", + String([digits[i]]), String(s.match(new RegExp('\\d')))); + 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'; + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\D'))", + String([non_digits[i]]), String(s.match(new RegExp('\\D')))); + new TestCase ( SECTION, + "'" + s + "'.match(/\\D/)", + String([non_digits[i]]), String(s.match(/\D/))); +} + +test(); diff --git a/js/src/tests/js1_2/regexp/dot.js b/js/src/tests/js1_2/regexp/dot.js new file mode 100644 index 000000000..9bcb9dfc4 --- /dev/null +++ b/js/src/tests/js1_2/regexp/dot.js @@ -0,0 +1,64 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'abcde'.match(new RegExp('ab.de')) +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('.+')) +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.*')) +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('.+')) +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('.+')) +new TestCase ( SECTION, "'....'.match(new RegExp('.+'))", + String(["...."]), String('....'.match(new RegExp('.+')))); + +// 'abcdefghijklmnopqrstuvwxyz'.match(new RegExp('.+')) +new TestCase ( SECTION, "'abcdefghijklmnopqrstuvwxyz'.match(new RegExp('.+'))", + String(["abcdefghijklmnopqrstuvwxyz"]), String('abcdefghijklmnopqrstuvwxyz'.match(new RegExp('.+')))); + +// 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.match(new RegExp('.+')) +new TestCase ( SECTION, "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.match(new RegExp('.+'))", + String(["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]), String('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.match(new RegExp('.+')))); + +// '`1234567890-=~!@#$%^&*()_+'.match(new RegExp('.+')) +new TestCase ( SECTION, "'`1234567890-=~!@#$%^&*()_+'.match(new RegExp('.+'))", + String(["`1234567890-=~!@#$%^&*()_+"]), String('`1234567890-=~!@#$%^&*()_+'.match(new RegExp('.+')))); + +// '|\\[{]};:"\',<>.?/'.match(new RegExp('.+')) +new TestCase ( SECTION, "'|\\[{]};:\"\',<>.?/'.match(new RegExp('.+'))", + String(["|\\[{]};:\"\',<>.?/"]), String('|\\[{]};:\"\',<>.?/'.match(new RegExp('.+')))); + +// '|\\[{]};:"\',<>.?/'.match(/.+/) +new TestCase ( SECTION, "'|\\[{]};:\"\',<>.?/'.match(/.+/)", + String(["|\\[{]};:\"\',<>.?/"]), String('|\\[{]};:\"\',<>.?/'.match(/.+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/endLine.js b/js/src/tests/js1_2/regexp/endLine.js new file mode 100644 index 000000000..2edbccccb --- /dev/null +++ b/js/src/tests/js1_2/regexp/endLine.js @@ -0,0 +1,44 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'abcde'.match(new RegExp('de$')) +new TestCase ( SECTION, "'abcde'.match(new RegExp('de$'))", + String(["de"]), String('abcde'.match(new RegExp('de$')))); + +// 'ab\ncde'.match(new RegExp('..$e$')) +new TestCase ( SECTION, "'ab\ncde'.match(new RegExp('..$e$'))", + null, 'ab\ncde'.match(new RegExp('..$e$'))); + +// 'yyyyy'.match(new RegExp('xxx$')) +new TestCase ( SECTION, "'yyyyy'.match(new RegExp('xxx$'))", + null, 'yyyyy'.match(new RegExp('xxx$'))); + +// 'a$$$'.match(new RegExp('\\$+$')) +new TestCase ( SECTION, "'a$$$'.match(new RegExp('\\$+$'))", + String(['$$$']), String('a$$$'.match(new RegExp('\\$+$')))); + +// 'a$$$'.match(/\$+$/) +new TestCase ( SECTION, "'a$$$'.match(/\\$+$/)", + String(['$$$']), String('a$$$'.match(/\$+$/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/everything.js b/js/src/tests/js1_2/regexp/everything.js new file mode 100644 index 000000000..c1947a390 --- /dev/null +++ b/js/src/tests/js1_2/regexp/everything.js @@ -0,0 +1,49 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'Sally and Fred are sure to come.'.match(/^[a-z\s]*/i) +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)$')) +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+)/) +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) +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) +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*)+/) +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*)+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/exec.js b/js/src/tests/js1_2/regexp/exec.js new file mode 100644 index 000000000..783260145 --- /dev/null +++ b/js/src/tests/js1_2/regexp/exec.js @@ -0,0 +1,45 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +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'))); + +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'); +new TestCase ( SECTION, + "re.exec('23 2 34 678 9 09')", + String(["34 678"]), String(re.exec('23 2 34 678 9 09'))); + +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'); +new TestCase ( SECTION, + "(re.exec('23 2 34 678 9 09').length", + 1, (re.exec('23 2 34 678 9 09')).length); + +test(); diff --git a/js/src/tests/js1_2/regexp/flags.js b/js/src/tests/js1_2/regexp/flags.js new file mode 100644 index 000000000..e2529a844 --- /dev/null +++ b/js/src/tests/js1_2/regexp/flags.js @@ -0,0 +1,53 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// testing optional flag 'i' +new TestCase ( SECTION, "'aBCdEfGHijKLmno'.match(/fghijk/i)", + String(["fGHijK"]), String('aBCdEfGHijKLmno'.match(/fghijk/i))); + +new TestCase ( SECTION, "'aBCdEfGHijKLmno'.match(new RegExp('fghijk','i'))", + String(["fGHijK"]), String('aBCdEfGHijKLmno'.match(new RegExp("fghijk","i")))); + +// testing optional flag 'g' +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))); + +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' +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))); + +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')))); + +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))); + +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')))); + + +test(); + diff --git a/js/src/tests/js1_2/regexp/global.js b/js/src/tests/js1_2/regexp/global.js new file mode 100644 index 000000000..442374cd9 --- /dev/null +++ b/js/src/tests/js1_2/regexp/global.js @@ -0,0 +1,63 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// /xyz/g.global +new TestCase ( SECTION, "/xyz/g.global", + true, /xyz/g.global); + +// /xyz/.global +new TestCase ( SECTION, "/xyz/.global", + false, /xyz/.global); + +// '123 456 789'.match(/\d+/g) +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) +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+/) +new TestCase ( SECTION, "'123 456 789'.match(/\\d+/)", + String(["123"]), String('123 456 789'.match(/\d+/))); + +// (new RegExp('[a-z]','g')).global +new TestCase ( SECTION, "(new RegExp('[a-z]','g')).global", + true, (new RegExp('[a-z]','g')).global); + +// (new RegExp('[a-z]','i')).global +new TestCase ( SECTION, "(new RegExp('[a-z]','i')).global", + false, (new RegExp('[a-z]','i')).global); + +// '123 456 789'.match(new RegExp('\\d+','g')) +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')) +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')) +new TestCase ( SECTION, "'123 456 789'.match(new RegExp('\\\\d+','i'))", + String(["123"]), String('123 456 789'.match(new RegExp('\\d+','i')))); + +test(); diff --git a/js/src/tests/js1_2/regexp/hexadecimal.js b/js/src/tests/js1_2/regexp/hexadecimal.js new file mode 100644 index 000000000..09ecea77b --- /dev/null +++ b/js/src/tests/js1_2/regexp/hexadecimal.js @@ -0,0 +1,75 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 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"; + +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"; + +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"; + +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"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["456789:;<=>?@"]), String(testString.match(new RegExp(testPattern)))); + +testPattern = '\\x7B\\x7C\\x7D\\x7E'; + +testString = "1234{|}~ABC"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["{|}~"]), String(testString.match(new RegExp(testPattern)))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(new RegExp('[A-\\x5A]+'))", + String(["FOUND"]), String('canthisbeFOUND'.match(new RegExp('[A-\\x5A]+')))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(new RegExp('[\\x61-\\x7A]+'))", + String(["canthisbe"]), String('canthisbeFOUND'.match(new RegExp('[\\x61-\\x7A]+')))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(/[\\x61-\\x7A]+/)", + String(["canthisbe"]), String('canthisbeFOUND'.match(/[\x61-\x7A]+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/ignoreCase.js b/js/src/tests/js1_2/regexp/ignoreCase.js new file mode 100644 index 000000000..f02ba91b0 --- /dev/null +++ b/js/src/tests/js1_2/regexp/ignoreCase.js @@ -0,0 +1,80 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// /xyz/i.ignoreCase +new TestCase ( SECTION, "/xyz/i.ignoreCase", + true, /xyz/i.ignoreCase); + +// /xyz/.ignoreCase +new TestCase ( SECTION, "/xyz/.ignoreCase", + false, /xyz/.ignoreCase); + +// 'ABC def ghi'.match(/[a-z]+/ig) +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) +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) +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) +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]+/) +new TestCase ( SECTION, "'ABC def ghi'.match(/[a-z]+/)", + String(["def"]), String('ABC def ghi'.match(/[a-z]+/))); + +// (new RegExp('xyz','i')).ignoreCase +new TestCase ( SECTION, "(new RegExp('xyz','i')).ignoreCase", + true, (new RegExp('xyz','i')).ignoreCase); + +// (new RegExp('xyz')).ignoreCase +new TestCase ( SECTION, "(new RegExp('xyz')).ignoreCase", + false, (new RegExp('xyz')).ignoreCase); + +// 'ABC def ghi'.match(new RegExp('[a-z]+','ig')) +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')) +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')) +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')) +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]+')) +new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('[a-z]+'))", + String(["def"]), String('ABC def ghi'.match(new RegExp('[a-z]+')))); + +test(); diff --git a/js/src/tests/js1_2/regexp/interval.js b/js/src/tests/js1_2/regexp/interval.js new file mode 100644 index 000000000..1cd681817 --- /dev/null +++ b/js/src/tests/js1_2/regexp/interval.js @@ -0,0 +1,83 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2}c')) +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}')) +new TestCase ( SECTION, "'aaabbbbcccddeeeefffff'.match(new RegExp('b{8}'))", + null, 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8}'))); + +// 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,}c')) +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')) +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')) +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')) +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')) +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')) +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}')) +new TestCase ( SECTION, "'weirwerdf'.match(new RegExp('.{0,93}'))", + String(["weirwerdf"]), String('weirwerdf'.match(new RegExp('.{0,93}')))); + +// 'wqe456646dsff'.match(new RegExp('\d{1,}')) +new TestCase ( SECTION, "'wqe456646dsff'.match(new RegExp('\\d{1,}'))", + String(["456646"]), String('wqe456646dsff'.match(new RegExp('\\d{1,}')))); + +// '123123'.match(new RegExp('(123){1,}')) +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')) +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/) +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,}')) +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,}/) +new TestCase ( SECTION, "'xxxxxxx'.match(/x{1,2}x{1,}/)", + String(["xxxxxxx"]), String('xxxxxxx'.match(/x{1,2}x{1,}/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/octal.js b/js/src/tests/js1_2/regexp/octal.js new file mode 100644 index 000000000..79228428b --- /dev/null +++ b/js/src/tests/js1_2/regexp/octal.js @@ -0,0 +1,75 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 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"; + +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"; + +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"; + +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"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["456789:;<=>?@"]), String(testString.match(new RegExp(testPattern)))); + +testPattern = '\\173\\174\\175\\176'; + +testString = "1234{|}~ABC"; + +new TestCase ( SECTION, + "'" + testString + "'.match(new RegExp('" + testPattern + "'))", + String(["{|}~"]), String(testString.match(new RegExp(testPattern)))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(new RegExp('[A-\\132]+'))", + String(["FOUND"]), String('canthisbeFOUND'.match(new RegExp('[A-\\132]+')))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(new RegExp('[\\141-\\172]+'))", + String(["canthisbe"]), String('canthisbeFOUND'.match(new RegExp('[\\141-\\172]+')))); + +new TestCase ( SECTION, + "'canthisbeFOUND'.match(/[\\141-\\172]+/)", + String(["canthisbe"]), String('canthisbeFOUND'.match(/[\141-\172]+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/parentheses.js b/js/src/tests/js1_2/regexp/parentheses.js new file mode 100644 index 000000000..90209cf0b --- /dev/null +++ b/js/src/tests/js1_2/regexp/parentheses.js @@ -0,0 +1,75 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abc'.match(new RegExp('(abc)')) +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')) +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})')) +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')) +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')) +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')) +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')) +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(..(..)..)')) +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(..(..)..)'))", + String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(new RegExp('a(..(..)..)')))); + +// 'abcdefg'.match(/a(..(..)..)/) +new TestCase ( SECTION, "'abcdefg'.match(/a(..(..)..)/)", + String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(/a(..(..)..)/))); + +// 'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))')) +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')) +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')) +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/) +new TestCase ( SECTION, "'abcd'.match(/a(.?)b\\1c\\1d\\1/)", + String(["abcd",""]), String('abcd'.match(/a(.?)b\1c\1d\1/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/plus.js b/js/src/tests/js1_2/regexp/plus.js new file mode 100644 index 000000000..0d5c40f33 --- /dev/null +++ b/js/src/tests/js1_2/regexp/plus.js @@ -0,0 +1,55 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abcdddddefg'.match(new RegExp('d+')) +new TestCase ( SECTION, "'abcdddddefg'.match(new RegExp('d+'))", + String(["ddddd"]), String('abcdddddefg'.match(new RegExp('d+')))); + +// 'abcdefg'.match(new RegExp('o+')) +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('o+'))", + null, 'abcdefg'.match(new RegExp('o+'))); + +// 'abcdefg'.match(new RegExp('d+')) +new TestCase ( SECTION, "'abcdefg'.match(new RegExp('d+'))", + String(['d']), String('abcdefg'.match(new RegExp('d+')))); + +// 'abbbbbbbc'.match(new RegExp('(b+)(b+)(b+)')) +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*)')) +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+')) +new TestCase ( SECTION, "'abbbbbbbc'.match(new RegExp('b*b+'))", + String(['bbbbbbb']), String('abbbbbbbc'.match(new RegExp('b*b+')))); + +// 'abbbbbbbc'.match(/(b+)(b*)/) +new TestCase ( SECTION, "'abbbbbbbc'.match(/(b+)(b*)/)", + String(["bbbbbbb","bbbbbbb",""]), String('abbbbbbbc'.match(/(b+)(b*)/))); + +// 'abbbbbbbc'.match(new RegExp('b*b+')) +new TestCase ( SECTION, "'abbbbbbbc'.match(/b*b+/)", + String(['bbbbbbb']), String('abbbbbbbc'.match(/b*b+/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/question_mark.js b/js/src/tests/js1_2/regexp/question_mark.js new file mode 100644 index 000000000..e159be8bb --- /dev/null +++ b/js/src/tests/js1_2/regexp/question_mark.js @@ -0,0 +1,67 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abcdef'.match(new RegExp('cd?e')) +new TestCase ( SECTION, "'abcdef'.match(new RegExp('cd?e'))", + String(["cde"]), String('abcdef'.match(new RegExp('cd?e')))); + +// 'abcdef'.match(new RegExp('cdx?e')) +new TestCase ( SECTION, "'abcdef'.match(new RegExp('cdx?e'))", + String(["cde"]), String('abcdef'.match(new RegExp('cdx?e')))); + +// 'pqrstuvw'.match(new RegExp('o?pqrst')) +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?')) +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')) +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/) +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')) +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')) +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/) +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('\\??\\??\\??\\??\\??')) +new TestCase ( SECTION, "'?????'.match(new RegExp('\\??\\??\\??\\??\\??'))", + String(["?????"]), String('?????'.match(new RegExp('\\??\\??\\??\\??\\??')))); + +// 'test'.match(new RegExp('.?.?.?.?.?.?.?')) +new TestCase ( SECTION, "'test'.match(new RegExp('.?.?.?.?.?.?.?'))", + String(["test"]), String('test'.match(new RegExp('.?.?.?.?.?.?.?')))); + +test(); diff --git a/js/src/tests/js1_2/regexp/regress-6359.js b/js/src/tests/js1_2/regexp/regress-6359.js new file mode 100644 index 000000000..5a63f0ac2 --- /dev/null +++ b/js/src/tests/js1_2/regexp/regress-6359.js @@ -0,0 +1,53 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: regress-6359.js + * Reference: ** replace with bugzilla URL or document reference ** + * Description: ** replace with description of test ** + * Author: ** replace with your e-mail address ** + */ + +var SECTION = "js1_2"; // provide a document reference (ie, ECMA section) +var VERSION = "ECMA_2"; // Version of JavaScript or ECMA +var TITLE = "Regression test for bugzilla # 6359"; // Provide ECMA section title or a description +var BUGNUMBER = "http://bugzilla.mozilla.org/show_bug.cgi?id=6359"; // Provide URL to bugsplat or bugzilla report + +startTest(); // leave this alone + +/* + * Calls to AddTestCase here. AddTestCase is a function that is defined + * in shell.js and takes three arguments: + * - a string representation of what is being tested + * - the expected result + * - the actual result + * + * For example, a test might look like this: + * + * var zip = /[\d]{5}$/; + * + * AddTestCase( + * "zip = /[\d]{5}$/; \"PO Box 12345 Boston, MA 02134\".match(zip)", // description of the test + * "02134", // expected result + * "PO Box 12345 Boston, MA 02134".match(zip) ); // actual result + * + */ + +AddTestCase( '/(a*)b\1+/.exec("baaac").length', + 2, + /(a*)b\1+/.exec("baaac").length ); + +AddTestCase( '/(a*)b\1+/.exec("baaac")[0]', + "b", + /(a*)b\1+/.exec("baaac")[0]); + +AddTestCase( '/(a*)b\1+/.exec("baaac")[1]', + "", + /(a*)b\1+/.exec("baaac")[1]); + + +test(); // leave this alone. this executes the test cases and +// displays results. diff --git a/js/src/tests/js1_2/regexp/regress-9141.js b/js/src/tests/js1_2/regexp/regress-9141.js new file mode 100644 index 000000000..987995feb --- /dev/null +++ b/js/src/tests/js1_2/regexp/regress-9141.js @@ -0,0 +1,72 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + + +/** + * File Name: regress-9141.js + * Reference: "http://bugzilla.mozilla.org/show_bug.cgi?id=9141"; + * Description: + * From waldemar@netscape.com: + * + * The following page crashes the system: + * + * <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" + * "http://www.w3.org/TR/REC-html40/loose.dtd"> + * <HTML> + * <HEAD> + * </HEAD> + * <BODY> + * <SCRIPT type="text/javascript"> + * var s = "x"; + * for (var i = 0; i != 13; i++) s += s; + * var a = /(?:xx|x)*[slash](s); + * var b = /(xx|x)*[slash](s); + * document.write("Results = " + a.length + "," + b.length); + * </SCRIPT> + * </BODY> + */ + +var SECTION = "js1_2"; // provide a document reference (ie, ECMA section) +var VERSION = "ECMA_2"; // Version of JavaScript or ECMA +var TITLE = "Regression test for bugzilla # 9141"; // Provide ECMA section title or a description +var BUGNUMBER = "http://bugzilla.mozilla.org/show_bug.cgi?id=9141"; // Provide URL to bugsplat or bugzilla report + +startTest(); // leave this alone + +/* + * Calls to AddTestCase here. AddTestCase is a function that is defined + * in shell.js and takes three arguments: + * - a string representation of what is being tested + * - the expected result + * - the actual result + * + * For example, a test might look like this: + * + * var zip = /[\d]{5}$/; + * + * AddTestCase( + * "zip = /[\d]{5}$/; \"PO Box 12345 Boston, MA 02134\".match(zip)", // description of the test + * "02134", // expected result + * "PO Box 12345 Boston, MA 02134".match(zip) ); // actual result + * + */ + +var s = "x"; +for (var i = 0; i != 13; i++) s += s; +var a = /(?:xx|x)*/.exec(s); +var b = /(xx|x)*/.exec(s); + +AddTestCase( "var s = 'x'; for (var i = 0; i != 13; i++) s += s; " + + "a = /(?:xx|x)*/.exec(s); a.length", + 1, + a.length ); + +AddTestCase( "var b = /(xx|x)*/.exec(s); b.length", + 2, + b.length ); + +test(); // leave this alone. this executes the test cases and +// displays results. diff --git a/js/src/tests/js1_2/regexp/shell.js b/js/src/tests/js1_2/regexp/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/regexp/shell.js diff --git a/js/src/tests/js1_2/regexp/simple_form.js b/js/src/tests/js1_2/regexp/simple_form.js new file mode 100644 index 000000000..3c3e98dad --- /dev/null +++ b/js/src/tests/js1_2/regexp/simple_form.js @@ -0,0 +1,58 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + Filename: simple_form.js + Description: 'Tests regular expressions using simple form: re.exec(...)' + + 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); + +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'))); + +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'))); + +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); + +var re = /[0-9]{3}/; +new TestCase ( SECTION, + "re.exec('23 2 34 678 9 09')", + String(["678"]), String(re.exec('23 2 34 678 9 09'))); + +re = /3.{4}8/; +new TestCase ( SECTION, + "re.exec('23 2 34 678 9 09')", + String(["34 678"]), String(re.exec('23 2 34 678 9 09'))); + +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'))); + +re =/3.{4}8/; +new TestCase ( SECTION, + "(re.exec('23 2 34 678 9 09').length", + 1, (re.exec('23 2 34 678 9 09')).length); + +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); + +test(); diff --git a/js/src/tests/js1_2/regexp/source.js b/js/src/tests/js1_2/regexp/source.js new file mode 100644 index 000000000..84b226a43 --- /dev/null +++ b/js/src/tests/js1_2/regexp/source.js @@ -0,0 +1,56 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// /xyz/g.source +new TestCase ( SECTION, "/xyz/g.source", + "xyz", /xyz/g.source); + +// /xyz/.source +new TestCase ( SECTION, "/xyz/.source", + "xyz", /xyz/.source); + +// /abc\\def/.source +new TestCase ( SECTION, "/abc\\\\def/.source", + "abc\\\\def", /abc\\def/.source); + +// /abc[\b]def/.source +new TestCase ( SECTION, "/abc[\\b]def/.source", + "abc[\\b]def", /abc[\b]def/.source); + +// (new RegExp('xyz')).source +new TestCase ( SECTION, "(new RegExp('xyz')).source", + "xyz", (new RegExp('xyz')).source); + +// (new RegExp('xyz','g')).source +new TestCase ( SECTION, "(new RegExp('xyz','g')).source", + "xyz", (new RegExp('xyz','g')).source); + +// (new RegExp('abc\\\\def')).source +new TestCase ( SECTION, "(new RegExp('abc\\\\\\\\def')).source", + "abc\\\\def", (new RegExp('abc\\\\def')).source); + +// (new RegExp('abc[\\b]def')).source +new TestCase ( SECTION, "(new RegExp('abc[\\\\b]def')).source", + "abc[\\b]def", (new RegExp('abc[\\b]def')).source); + +test(); diff --git a/js/src/tests/js1_2/regexp/special_characters.js b/js/src/tests/js1_2/regexp/special_characters.js new file mode 100644 index 000000000..1e40eb69d --- /dev/null +++ b/js/src/tests/js1_2/regexp/special_characters.js @@ -0,0 +1,126 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// testing backslash '\' +new TestCase ( SECTION, "'^abcdefghi'.match(/\^abc/)", String(["^abc"]), String('^abcdefghi'.match(/\^abc/))); + +// testing beginning of line '^' +new TestCase ( SECTION, "'abcdefghi'.match(/^abc/)", String(["abc"]), String('abcdefghi'.match(/^abc/))); + +// testing end of line '$' +new TestCase ( SECTION, "'abcdefghi'.match(/fghi$/)", String(["ghi"]), String('abcdefghi'.match(/ghi$/))); + +// testing repeat '*' +new TestCase ( SECTION, "'eeeefghi'.match(/e*/)", String(["eeee"]), String('eeeefghi'.match(/e*/))); + +// testing repeat 1 or more times '+' +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e+/)", String(["eeee"]), String('abcdeeeefghi'.match(/e+/))); + +// testing repeat 0 or 1 time '?' +new TestCase ( SECTION, "'abcdefghi'.match(/abc?de/)", String(["abcde"]), String('abcdefghi'.match(/abc?de/))); + +// testing any character '.' +new TestCase ( SECTION, "'abcdefghi'.match(/c.e/)", String(["cde"]), String('abcdefghi'.match(/c.e/))); + +// testing remembering () +new TestCase ( SECTION, "'abcewirjskjdabciewjsdf'.match(/(abc).+\\1'/)", + String(["abcewirjskjdabc","abc"]), String('abcewirjskjdabciewjsdf'.match(/(abc).+\1/))); + +// testing or match '|' +new TestCase ( SECTION, "'abcdefghi'.match(/xyz|def/)", String(["def"]), String('abcdefghi'.match(/xyz|def/))); + +// testing repeat n {n} +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3}/)", String(["eee"]), String('abcdeeeefghi'.match(/e{3}/))); + +// testing min repeat n {n,} +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3,}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{3,}/))); + +// testing min/max repeat {min, max} +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{2,8}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{2,8}/))); + +// testing any in set [abc...] +new TestCase ( SECTION, "'abcdefghi'.match(/cd[xey]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[xey]fgh/))); + +// testing any in set [a-z] +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...] +new TestCase ( SECTION, "'abcdefghi'.match(/cd[^xy]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[^xy]fgh/))); + +// testing any not in set [^a-z] +new TestCase ( SECTION, "'netscape inc'.match(/t[^a-c]ca/)", String(["tsca"]), String('netscape inc'.match(/t[^a-c]ca/))); + +// testing backspace [\b] +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 +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 +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 +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' +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' +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' +new TestCase ( SECTION, "'a b a\rb'.match(/a\rb/)", String(["a\rb"]), String('a b a\rb'.match(/a\rb/))); + +// testing whitespace '\s' +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' +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' +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' +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' +new TestCase ( SECTION, "'%AZaz09_$'.match(/\w+/)", String(["AZaz09_"]), String('%AZaz09_$'.match(/\w+/))); + +// testing non alphnumeric characters '\W' +new TestCase ( SECTION, "'azx$%#@*4534'.match(/\W+/)", String(["$%#@*"]), String('azx$%#@*4534'.match(/\W+/))); + +// testing back references '\<number>' +new TestCase ( SECTION, "'test'.match(/(t)es\\1/)", String(["test","t"]), String('test'.match(/(t)es\1/))); + +// testing hex excaping with '\' +new TestCase ( SECTION, "'abcdef'.match(/\x63\x64/)", String(["cd"]), String('abcdef'.match(/\x63\x64/))); + +// testing oct excaping with '\' +new TestCase ( SECTION, "'abcdef'.match(/\\143\\144/)", String(["cd"]), String('abcdef'.match(/\143\144/))); + +test(); + diff --git a/js/src/tests/js1_2/regexp/string_replace.js b/js/src/tests/js1_2/regexp/string_replace.js new file mode 100644 index 000000000..1b3c832fd --- /dev/null +++ b/js/src/tests/js1_2/regexp/string_replace.js @@ -0,0 +1,92 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'adddb'.replace(/ddd/,"XX") +new TestCase ( SECTION, "'adddb'.replace(/ddd/,'XX')", + "aXXb", 'adddb'.replace(/ddd/,'XX')); + +// 'adddb'.replace(/eee/,"XX") +new TestCase ( SECTION, "'adddb'.replace(/eee/,'XX')", + 'adddb', 'adddb'.replace(/eee/,'XX')); + +// '34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**') +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') +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') +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+(..)$'),'****') +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+(..)$'),'****')); + + +/* + * Test replacement over ropes. The char to rope node ratio must be sufficiently + * high for the special-case code to be tested. + */ +var stringA = "abcdef"; +var stringB = "ghijk"; +var stringC = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"; +stringC += stringC; +stringC += stringC; +stringC[0]; /* flatten stringC */ +var stringD = "lmn"; + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('aa', '')", + stringA + stringB + stringC, (stringA + stringB + stringC).replace('aa', '')); + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('abc', 'AA')", + "AAdefghijk" + stringC, (stringA + stringB + stringC).replace('abc', 'AA')); + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('def', 'AA')", + "abcAAghijk" + stringC, (stringA + stringB + stringC).replace('def', 'AA')); + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('efg', 'AA')", + "abcdAAhijk" + stringC, (stringA + stringB + stringC).replace('efg', 'AA')); + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('fgh', 'AA')", + "abcdeAAijk" + stringC, (stringA + stringB + stringC).replace('fgh', 'AA')); + +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('ghi', 'AA')", + "abcdefAAjk" + stringC, (stringA + stringB + stringC).replace('ghi', 'AA')); + +new TestCase ( SECTION, "(stringC + stringD).replace('lmn', 'AA')", + stringC + "AA", (stringC + stringD).replace('lmn', 'AA')); + +new TestCase ( SECTION, "(stringC + stringD).replace('lmno', 'AA')", + stringC + stringD, (stringC + stringD).replace('lmno', 'AA')); + +new TestCase ( SECTION, "(stringC + stringD).replace('mn', 'AA')", + stringC + "lAA", (stringC + stringD).replace('mn', 'AA')); + +new TestCase ( SECTION, "(stringC + stringD).replace('n', 'AA')", + stringC + "lmAA", (stringC + stringD).replace('n', 'AA')); + + +test(); diff --git a/js/src/tests/js1_2/regexp/string_search.js b/js/src/tests/js1_2/regexp/string_search.js new file mode 100644 index 000000000..93c786fbe --- /dev/null +++ b/js/src/tests/js1_2/regexp/string_search.js @@ -0,0 +1,55 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +// 'abcdefg'.search(/d/) +new TestCase ( SECTION, "'abcdefg'.search(/d/)", + 3, 'abcdefg'.search(/d/)); + +// 'abcdefg'.search(/x/) +new TestCase ( SECTION, "'abcdefg'.search(/x/)", + -1, 'abcdefg'.search(/x/)); + +// 'abcdefg123456hijklmn'.search(/\d+/) +new TestCase ( SECTION, "'abcdefg123456hijklmn'.search(/\d+/)", + 7, 'abcdefg123456hijklmn'.search(/\d+/)); + +// 'abcdefg123456hijklmn'.search(new RegExp()) +new TestCase ( SECTION, "'abcdefg123456hijklmn'.search(new RegExp())", + 0, 'abcdefg123456hijklmn'.search(new RegExp())); + +// 'abc'.search(new RegExp('$')) +new TestCase ( SECTION, "'abc'.search(new RegExp('$'))", + 3, 'abc'.search(new RegExp('$'))); + +// 'abc'.search(new RegExp('^')) +new TestCase ( SECTION, "'abc'.search(new RegExp('^'))", + 0, 'abc'.search(new RegExp('^'))); + +// 'abc1'.search(/.\d/) +new TestCase ( SECTION, "'abc1'.search(/.\d/)", + 2, 'abc1'.search(/.\d/)); + +// 'abc1'.search(/\d{2}/) +new TestCase ( SECTION, "'abc1'.search(/\d{2}/)", + -1, 'abc1'.search(/\d{2}/)); + +test(); diff --git a/js/src/tests/js1_2/regexp/string_split.js b/js/src/tests/js1_2/regexp/string_split.js new file mode 100644 index 000000000..c810bff95 --- /dev/null +++ b/js/src/tests/js1_2/regexp/string_split.js @@ -0,0 +1,61 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'a b c de f'.split(/\s/) +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) +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/) +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+/) +new TestCase ( SECTION, "'dfe23iu 34 =+65--'.split(/\d+/)", + String(["dfe","iu "," =+","--"]), String('dfe23iu 34 =+65--'.split(/\d+/))); + +// 'dfe23iu 34 =+65--'.split(new RegExp('\d+')) +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]/) +new TestCase ( SECTION, "'abc'.split(/[a-z]/)", + String(["","",""]), String('abc'.split(/[a-z]/))); + +// 'abc'.split(/[a-z]/) +new TestCase ( SECTION, "'abc'.split(/[a-z]/)", + String(["","",""]), String('abc'.split(/[a-z]/))); + +// 'abc'.split(new RegExp('[a-z]')) +new TestCase ( SECTION, "'abc'.split(new RegExp('[a-z]'))", + String(["","",""]), String('abc'.split(new RegExp('[a-z]')))); + +// 'abc'.split(new RegExp('[a-z]')) +new TestCase ( SECTION, "'abc'.split(new RegExp('[a-z]'))", + String(["","",""]), String('abc'.split(new RegExp('[a-z]')))); + +test(); diff --git a/js/src/tests/js1_2/regexp/test.js b/js/src/tests/js1_2/regexp/test.js new file mode 100644 index 000000000..588520eb4 --- /dev/null +++ b/js/src/tests/js1_2/regexp/test.js @@ -0,0 +1,55 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + +new TestCase ( SECTION, + "/[0-9]{3}/.test('23 2 34 678 9 09')", + true, /[0-9]{3}/.test('23 2 34 678 9 09')); + +new TestCase ( SECTION, + "/[0-9]{3}/.test('23 2 34 78 9 09')", + false, /[0-9]{3}/.test('23 2 34 78 9 09')); + +new TestCase ( SECTION, + "/\w+ \w+ \w+/.test('do a test')", + true, /\w+ \w+ \w+/.test("do a test")); + +new TestCase ( SECTION, + "/\w+ \w+ \w+/.test('a test')", + false, /\w+ \w+ \w+/.test("a test")); + +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')); + +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')); + +new TestCase ( SECTION, + "(new RegExp('\\\\w+ \\\\w+ \\\\w+')).test('do a test')", + true, (new RegExp('\\w+ \\w+ \\w+')).test("do a test")); + +new TestCase ( SECTION, + "(new RegExp('\\\\w+ \\\\w+ \\\\w+')).test('a test')", + false, (new RegExp('\\w+ \\w+ \\w+')).test("a test")); + +test(); diff --git a/js/src/tests/js1_2/regexp/toString.js b/js/src/tests/js1_2/regexp/toString.js new file mode 100644 index 000000000..e6b6cc883 --- /dev/null +++ b/js/src/tests/js1_2/regexp/toString.js @@ -0,0 +1,47 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 re = new RegExp(); re.toString() For what to expect, + * see http://bugzilla.mozilla.org/show_bug.cgi?id=225343#c7 + */ +var re = new RegExp(); +new TestCase ( SECTION, "var re = new RegExp(); re.toString()", + '/(?:)/', re.toString()); + +// re = /.+/; re.toString(); +re = /.+/; +new TestCase ( SECTION, "re = /.+/; re.toString()", + '/.+/', re.toString()); + +// re = /test/gi; re.toString() +re = /test/gi; +new TestCase ( SECTION, "re = /test/gi; re.toString()", + '/test/gi', re.toString()); + +// re = /test2/ig; re.toString() +re = /test2/ig; +new TestCase ( SECTION, "re = /test2/ig; re.toString()", + '/test2/gi', re.toString()); + +test(); diff --git a/js/src/tests/js1_2/regexp/vertical_bar.js b/js/src/tests/js1_2/regexp/vertical_bar.js new file mode 100644 index 000000000..636f1c9cf --- /dev/null +++ b/js/src/tests/js1_2/regexp/vertical_bar.js @@ -0,0 +1,64 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'abc'.match(new RegExp('xyz|abc')) +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')) +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|...')) +new TestCase ( SECTION, "'abc'.match(new RegExp('xyz|...'))", + String(["abc"]), String('abc'.match(new RegExp('xyz|...')))); + +// 'abc'.match(new RegExp('(.)..|abc')) +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')) +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')) +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)')) +new TestCase ( SECTION, "'Hi Bob'.match(new RegExp('(Rob)|(Bob)|(Robert)|(Bobby)'))", + String(["Bob",undefined,"Bob", undefined, undefined]), String('Hi Bob'.match(new RegExp('(Rob)|(Bob)|(Robert)|(Bobby)')))); + +// 'abcdef'.match(new RegExp('abc|bcd|cde|def')) +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)/) +new TestCase ( SECTION, "'Hi Bob'.match(/(Rob)|(Bob)|(Robert)|(Bobby)/)", + String(["Bob",undefined,"Bob", undefined, undefined]), String('Hi Bob'.match(/(Rob)|(Bob)|(Robert)|(Bobby)/))); + +// 'abcdef'.match(/abc|bcd|cde|def/) +new TestCase ( SECTION, "'abcdef'.match(/abc|bcd|cde|def/)", + String(["abc"]), String('abcdef'.match(/abc|bcd|cde|def/))); + +test(); diff --git a/js/src/tests/js1_2/regexp/whitespace.js b/js/src/tests/js1_2/regexp/whitespace.js new file mode 100644 index 000000000..ab99b59d5 --- /dev/null +++ b/js/src/tests/js1_2/regexp/whitespace.js @@ -0,0 +1,91 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 non_whitespace = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()-+={[}]|\\:;'<,>./?1234567890" + '"'; +var whitespace = "\f\n\r\t\v "; + +// be sure all whitespace is matched by \s +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 +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 +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 +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 +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 +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]+')) +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'; + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\\\s'))", + String([whitespace[i]]), String(s.match(new RegExp('\\s')))); + 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] + ' '; + new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\\\S'))", + String([non_whitespace[i]]), String(s.match(new RegExp('\\S')))); + new TestCase ( SECTION, + "'" + s + "'.match(/\S/)", + String([non_whitespace[i]]), String(s.match(/\S/))); +} + + +test(); diff --git a/js/src/tests/js1_2/regexp/word_boundary.js b/js/src/tests/js1_2/regexp/word_boundary.js new file mode 100644 index 000000000..ca96081f8 --- /dev/null +++ b/js/src/tests/js1_2/regexp/word_boundary.js @@ -0,0 +1,87 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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); + + +// 'cowboy boyish boy'.match(new RegExp('\bboy\b')) +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); + + 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); + + 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"; + +new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\Ba\\d+b\\B'))", + String(["a1111b"]), String(s.match(new RegExp('\\Ba\\d+b\\B')))); + +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)"; + +new TestCase ( SECTION, + "'" + s + "'.match(new RegExp('\\ba\\d+b\\b'))", + String(["a1111b"]), String(s.match(new RegExp('\\ba\\d+b\\b')))); + +new TestCase ( SECTION, + "'" + s + "'.match(/\\ba\\d+b\\b/)", + String(["a1111b"]), String(s.match(/\ba\d+b\b/))); + +test(); diff --git a/js/src/tests/js1_2/regress/browser.js b/js/src/tests/js1_2/regress/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/regress/browser.js diff --git a/js/src/tests/js1_2/regress/regress-144834.js b/js/src/tests/js1_2/regress/regress-144834.js new file mode 100644 index 000000000..1db9babaf --- /dev/null +++ b/js/src/tests/js1_2/regress/regress-144834.js @@ -0,0 +1,50 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * + * Date: 05 July 2002 + * SUMMARY: Testing local var having same name as switch label inside function + * + * The code below crashed while compiling in JS1.1 or JS1.2 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=144834 + * + */ +//----------------------------------------------------------------------------- +var BUGNUMBER = 144834; +var summary = 'Local var having same name as switch label inside function'; + +print(BUGNUMBER); +print(summary); + + +function RedrawSched() +{ + var MinBound; + + switch (i) + { + case MinBound : + } +} + + +/* + * Also try eval scope - + */ +var s = ''; +s += 'function RedrawSched()'; +s += '{'; +s += ' var MinBound;'; +s += ''; +s += ' switch (i)'; +s += ' {'; +s += ' case MinBound :'; +s += ' }'; +s += '}'; +eval(s); + +AddTestCase('Do not crash', 'No Crash', 'No Crash'); +test(); diff --git a/js/src/tests/js1_2/regress/regress-7703.js b/js/src/tests/js1_2/regress/regress-7703.js new file mode 100644 index 000000000..1ea5a34d5 --- /dev/null +++ b/js/src/tests/js1_2/regress/regress-7703.js @@ -0,0 +1,69 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + + +/** + * File Name: regress-7703.js + * Reference: "http://bugzilla.mozilla.org/show_bug.cgi?id=7703"; + * Description: See the text of the bugnumber above + */ + +var SECTION = "js1_2"; // provide a document reference (ie, ECMA section) +var VERSION = "JS1_2"; // Version of JavaScript or ECMA +var TITLE = "Regression test for bugzilla # 7703"; // Provide ECMA section title or a description +var BUGNUMBER = "http://bugzilla.mozilla.org/show_bug.cgi?id=7703"; // Provide URL to bugsplat or bugzilla report + +startTest(); // leave this alone + +/* + * Calls to AddTestCase here. AddTestCase is a function that is defined + * in shell.js and takes three arguments: + * - a string representation of what is being tested + * - the expected result + * - the actual result + * + * For example, a test might look like this: + * + * var zip = /[\d]{5}$/; + * + * AddTestCase( + * "zip = /[\d]{5}$/; \"PO Box 12345 Boston, MA 02134\".match(zip)", // description of the test + * "02134", // expected result + * "PO Box 12345 Boston, MA 02134".match(zip) ); // actual result + * + */ + +types = []; +function inspect(object) { + for (prop in object) { + var x = object[prop]; + types[types.length] = (typeof x); + } +} + +var o = {a: 1, b: 2}; +inspect(o); + +AddTestCase( "inspect(o),length", 2, types.length ); +AddTestCase( "inspect(o)[0]", "number", types[0] ); +AddTestCase( "inspect(o)[1]", "number", types[1] ); + +types_2 = []; + +function inspect_again(object) { + for (prop in object) { + types_2[types_2.length] = (typeof object[prop]); + } +} + +inspect_again(o); +AddTestCase( "inspect_again(o),length", 2, types.length ); +AddTestCase( "inspect_again(o)[0]", "number", types[0] ); +AddTestCase( "inspect_again(o)[1]", "number", types[1] ); + + +test(); // leave this alone. this executes the test cases and +// displays results. diff --git a/js/src/tests/js1_2/regress/shell.js b/js/src/tests/js1_2/regress/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/regress/shell.js diff --git a/js/src/tests/js1_2/shell.js b/js/src/tests/js1_2/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/shell.js diff --git a/js/src/tests/js1_2/statements/break.js b/js/src/tests/js1_2/statements/break.js new file mode 100644 index 000000000..77c4983d0 --- /dev/null +++ b/js/src/tests/js1_2/statements/break.js @@ -0,0 +1,130 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 i,j; + +for (i = 0; i < 1000; i++) +{ + if (i == 100) break; +} + +// 'breaking out of "for" loop' +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"' +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' +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"' +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' +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"' +new TestCase ( SECTION, 'breaking out of a "do" loop with a "label"', + 500, j); + +test(); diff --git a/js/src/tests/js1_2/statements/browser.js b/js/src/tests/js1_2/statements/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/statements/browser.js diff --git a/js/src/tests/js1_2/statements/continue.js b/js/src/tests/js1_2/statements/continue.js new file mode 100644 index 000000000..0017ba88d --- /dev/null +++ b/js/src/tests/js1_2/statements/continue.js @@ -0,0 +1,143 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 i,j; + +j = 0; +for (i = 0; i < 200; i++) +{ + if (i == 100) + continue; + j++; +} + +// '"continue" in a "for" loop' +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"' +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' +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"' +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' +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"' +new TestCase ( SECTION, '"continue" in a "do" loop with a "label"', + 999, j); + +test(); diff --git a/js/src/tests/js1_2/statements/do_while.js b/js/src/tests/js1_2/statements/do_while.js new file mode 100644 index 000000000..90ad5117e --- /dev/null +++ b/js/src/tests/js1_2/statements/do_while.js @@ -0,0 +1,35 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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 done = false; +var x = 0; +do +{ + if (x++ == 3) done = true; +} while (!done); + +new TestCase( SECTION, "do_while ", + 4, x); + +//load('d:/javascript/tests/output/statements/do_while.js') +test(); + diff --git a/js/src/tests/js1_2/statements/shell.js b/js/src/tests/js1_2/statements/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/statements/shell.js diff --git a/js/src/tests/js1_2/statements/switch.js b/js/src/tests/js1_2/statements/switch.js new file mode 100644 index 000000000..c7d3548de --- /dev/null +++ b/js/src/tests/js1_2/statements/switch.js @@ -0,0 +1,96 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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'; +var TITLE = 'statements: switch'; +var BUGNUMBER="323696"; + +startTest(); +writeHeaderToLog("Executing script: switch.js"); +writeHeaderToLog( SECTION + " "+ TITLE); + + +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; +} + +new TestCase ( SECTION, 'switch statement', + true, match1); + +new TestCase ( SECTION, 'switch statement', + true, match2); + +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; +} +new TestCase ( SECTION, 'switch statement', + false, match1); + +new TestCase ( SECTION, 'switch statement', + false, match2); + +new TestCase ( SECTION, 'switch statement', + false, match3); + +new TestCase ( SECTION, 'switch statement', + false, match4); + +new TestCase ( SECTION, 'switch statement', + true, match5); + +test(); diff --git a/js/src/tests/js1_2/statements/switch2.js b/js/src/tests/js1_2/statements/switch2.js new file mode 100644 index 000000000..86b2251fa --- /dev/null +++ b/js/src/tests/js1_2/statements/switch2.js @@ -0,0 +1,158 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + 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'; +var TITLE = 'statements: switch'; +var BUGNUMBER="323626"; + +startTest(); +writeHeaderToLog("Executing script: switch2.js"); +writeHeaderToLog( SECTION + " "+ TITLE); + +// 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 ""; +} +new TestCase(SECTION, 'switch statement', + f0("a"), "ab*"); + +new TestCase(SECTION, 'switch statement', + f0("b"), "ab*"); + +new TestCase(SECTION, 'switch statement', + f0("*"), "ab*"); + +new TestCase(SECTION, 'switch statement', + f0("c"), "c"); + +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 ""; +} + +new TestCase(SECTION, 'switch statement', + f1("a"), "ab*"); + +new TestCase(SECTION, 'switch statement', + f1("b"), "ab*"); + +new TestCase(SECTION, 'switch statement', + f1("*"), "ab*"); + +new TestCase(SECTION, 'switch statement', + f1("c"), "c"); + +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; +} + +new TestCase(SECTION, 'switch statement', + f2(0), 1); + +new TestCase(SECTION, 'switch statement', + f2(1), 1); + +new TestCase(SECTION, 'switch statement', + f2(2), 2); + +new TestCase(SECTION, 'switch statement', + f2(3), 3); + +// empty switch: make sure expression is evaluated +var se = 0; +switch (se = 1) { +} +new TestCase(SECTION, 'switch statement', + se, 1); + +// only default +se = 0; +switch (se) { +default: + se = 1; +} +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; +} +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; +} +new TestCase(SECTION, 'switch statement', + se, 2); +print("hi"); + +test(); + +// Needed: tests for evaluation time of case expressions. +// This issue was under debate at ECMA, so postponing for now. + diff --git a/js/src/tests/js1_2/version120/boolean-001.js b/js/src/tests/js1_2/version120/boolean-001.js new file mode 100644 index 000000000..180d2c7d1 --- /dev/null +++ b/js/src/tests/js1_2/version120/boolean-001.js @@ -0,0 +1,44 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * File Name: boolean-001.js + * Description: + * + * In JavaScript 1.2, new Boolean(false) evaluates to false. + * + * Author: christine@netscape.com + * Date: 11 August 1998 + */ +var SECTION = "boolean-001.js"; +var VERSION = "JS1_2"; +startTest(); +var TITLE = "new Boolean(false) should evaluate to false"; + +writeHeaderToLog( SECTION + " "+ TITLE); + +BooleanTest( "new Boolean(true)", new Boolean(true), true ); +BooleanTest( "new Boolean(false)", new Boolean(false), false ); +BooleanTest( "true", true, true ); +BooleanTest( "false", false, false ); + +test(); + +function BooleanTest( string, object, expect ) { + if ( object ) { + result = true; + } else { + result = false; + } + + new TestCase( + SECTION, + string, + expect, + result ); +} + diff --git a/js/src/tests/js1_2/version120/browser.js b/js/src/tests/js1_2/version120/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_2/version120/browser.js diff --git a/js/src/tests/js1_2/version120/regress-99663.js b/js/src/tests/js1_2/version120/regress-99663.js new file mode 100644 index 000000000..7da6f6cd3 --- /dev/null +++ b/js/src/tests/js1_2/version120/regress-99663.js @@ -0,0 +1,132 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +//----------------------------------------------------------------------------- +var UBound = 0; +var BUGNUMBER = 99663; +var summary = 'Regression test for Bugzilla bug 99663'; +/* + * This testcase expects error messages containing + * the phrase 'read-only' or something similar - + */ +var READONLY = /read\s*-?\s*only/; +var READONLY_TRUE = 'a "read-only" error'; +var READONLY_FALSE = 'Error: '; +var FAILURE = 'NO ERROR WAS GENERATED!'; +var status = ''; +var actual = ''; +var expect= ''; +var statusitems = []; +var expectedvalues = []; +var actualvalues = []; + + +/* + * These MUST be compiled in JS1.2 or less for the test to work - see above + */ +function f1() +{ + with (it) + { + for (rdonly in this); + } +} + + +function f2() +{ + for (it.rdonly in this); +} + + +function f3(s) +{ + for (it[s] in this); +} + + + +/* + * Begin testing by capturing actual vs. expected values. + * Initialize to FAILURE; this will get reset if all goes well - + */ +actual = FAILURE; +try +{ + f1(); +} +catch(e) +{ + actual = readOnly(e.message); +} +expect= READONLY_TRUE; +status = 'Section 1 of test - got ' + actual; +addThis(); + + +actual = FAILURE; +try +{ + f2(); +} +catch(e) +{ + actual = readOnly(e.message); +} +expect= READONLY_TRUE; +status = 'Section 2 of test - got ' + actual; +addThis(); + + +actual = FAILURE; +try +{ + f3('rdonly'); +} +catch(e) +{ + actual = readOnly(e.message); +} +expect= READONLY_TRUE; +status = 'Section 3 of test - got ' + actual; +addThis(); + + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + + + +function readOnly(msg) +{ + if (msg.match(READONLY)) + return READONLY_TRUE; + return READONLY_FALSE + msg; +} + + +function addThis() +{ + statusitems[UBound] = status; + actualvalues[UBound] = actual; + expectedvalues[UBound] = expect; + UBound++; +} + + +function test() +{ + print ('Bug Number ' + bug); + print ('STATUS: ' + summary); + + for (var i=0; i<UBound; i++) + { + writeTestCaseResult(expectedvalues[i], actualvalues[i], statusitems[i]); + } +} diff --git a/js/src/tests/js1_2/version120/shell.js b/js/src/tests/js1_2/version120/shell.js new file mode 100644 index 000000000..d16c2aa02 --- /dev/null +++ b/js/src/tests/js1_2/version120/shell.js @@ -0,0 +1,9 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* all files in this dir need version(120) called before they are *loaded* */ + + +version(120); |