michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 15.4.4.3-1.js michael@0: ECMA Section: 15.4.4.3-1 Array.prototype.join() michael@0: Description: The elements of this object are converted to strings and michael@0: these strings are then concatenated, separated by comma michael@0: characters. The result is the same as if the built-in join michael@0: method were invoiked for this object with no argument. michael@0: Author: christine@netscape.com, pschwartau@netscape.com michael@0: Date: 07 October 1997 michael@0: Modified: 14 July 2002 michael@0: Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155285 michael@0: ECMA-262 Ed.3 Section 15.4.4.5 Array.prototype.join() michael@0: Step 3: If |separator| is |undefined|, let |separator| michael@0: be the single-character string "," michael@0: * michael@0: */ michael@0: michael@0: var SECTION = "15.4.4.3-1"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " Array.prototype.join()"); michael@0: michael@0: var ARR_PROTOTYPE = Array.prototype; michael@0: michael@0: new TestCase( SECTION, "Array.prototype.join.length", 1, Array.prototype.join.length ); michael@0: new TestCase( SECTION, "delete Array.prototype.join.length", false, delete Array.prototype.join.length ); michael@0: new TestCase( SECTION, "delete Array.prototype.join.length; Array.prototype.join.length", 1, eval("delete Array.prototype.join.length; Array.prototype.join.length") ); michael@0: michael@0: // case where array length is 0 michael@0: michael@0: new TestCase( SECTION, michael@0: "var TEST_ARRAY = new Array(); TEST_ARRAY.join()", michael@0: "", michael@0: eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join()") ); michael@0: michael@0: // array length is 0, but spearator is specified michael@0: michael@0: new TestCase( SECTION, michael@0: "var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')", michael@0: "", michael@0: eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')") ); michael@0: michael@0: // length is greater than 0, separator is supplied michael@0: new TestCase( SECTION, michael@0: "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')", michael@0: "&&true&false&123&[object Object]&true", michael@0: eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')") ); michael@0: michael@0: // length is greater than 0, separator is empty string michael@0: new TestCase( SECTION, michael@0: "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')", michael@0: "truefalse123[object Object]true", michael@0: eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')") ); michael@0: michael@0: // length is greater than 0, separator is undefined michael@0: new TestCase( SECTION, michael@0: "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)", michael@0: ",,true,false,123,[object Object],true", michael@0: eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)") ); michael@0: michael@0: // length is greater than 0, separator is not supplied michael@0: new TestCase( SECTION, michael@0: "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()", michael@0: ",,true,false,123,[object Object],true", michael@0: eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()") ); michael@0: michael@0: // separator is a control character michael@0: new TestCase( SECTION, michael@0: "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')", michael@0: decodeURIComponent("%0B%0Btrue%0Bfalse%0B123%0B[object Object]%0Btrue"), michael@0: eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')") ); michael@0: michael@0: // length of array is 1 michael@0: new TestCase( SECTION, michael@0: "var TEST_ARRAY = new Array(true) ); TEST_ARRAY.join('\v')", michael@0: "true", michael@0: eval("var TEST_ARRAY = new Array(true); TEST_ARRAY.join('\v')") ); michael@0: michael@0: michael@0: SEPARATOR = "\t" michael@0: TEST_LENGTH = 100; michael@0: TEST_STRING = ""; michael@0: ARGUMENTS = ""; michael@0: TEST_RESULT = ""; michael@0: michael@0: for ( var index = 0; index < TEST_LENGTH; index++ ) { michael@0: ARGUMENTS += index; michael@0: ARGUMENTS += ( index == TEST_LENGTH -1 ) ? "" : ","; michael@0: michael@0: TEST_RESULT += index; michael@0: TEST_RESULT += ( index == TEST_LENGTH -1 ) ? "" : SEPARATOR; michael@0: } michael@0: michael@0: TEST_ARRAY = eval( "new Array( "+ARGUMENTS +")" ); michael@0: michael@0: new TestCase( SECTION, michael@0: "TEST_ARRAY.join("+SEPARATOR+")", michael@0: TEST_RESULT, michael@0: TEST_ARRAY.join( SEPARATOR ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(new Array( Boolean(true), Boolean(false), null, void 0, Number(1e+21), Number(1e-7))).join()", michael@0: "true,false,,,1e+21,1e-7", michael@0: (new Array( Boolean(true), Boolean(false), null, void 0, Number(1e+21), Number(1e-7))).join() ); michael@0: michael@0: // this is not an Array object michael@0: new TestCase( SECTION, michael@0: "var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')", michael@0: "true:false:111:0.5:1230000:NaN::", michael@0: eval("var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')") ); michael@0: michael@0: test(); michael@0: michael@0: function Object_1( value ) { michael@0: this.array = value.split(","); michael@0: this.length = this.array.length; michael@0: for ( var i = 0; i < this.length; i++ ) { michael@0: this[i] = eval(this.array[i]); michael@0: } michael@0: this.join = Array.prototype.join; michael@0: this.getClass = Object.prototype.toString; michael@0: }