diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/tests/js1_2/Array | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/js1_2/Array')
-rw-r--r-- | js/src/tests/js1_2/Array/array_split_1.js | 53 | ||||
-rw-r--r-- | js/src/tests/js1_2/Array/browser.js | 0 | ||||
-rw-r--r-- | js/src/tests/js1_2/Array/general1.js | 44 | ||||
-rw-r--r-- | js/src/tests/js1_2/Array/general2.js | 59 | ||||
-rw-r--r-- | js/src/tests/js1_2/Array/shell.js | 0 | ||||
-rw-r--r-- | js/src/tests/js1_2/Array/slice.js | 89 | ||||
-rw-r--r-- | js/src/tests/js1_2/Array/splice1.js | 119 | ||||
-rw-r--r-- | js/src/tests/js1_2/Array/splice2.js | 116 | ||||
-rw-r--r-- | js/src/tests/js1_2/Array/tostring_1.js | 93 | ||||
-rw-r--r-- | js/src/tests/js1_2/Array/tostring_2.js | 49 |
10 files changed, 622 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(); |