]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Array/15.4.4.3-1.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
23 File Name: 15.4.4.3-1.js
24 ECMA Section: 15.4.4.3-1 Array.prototype.join()
25 Description: The elements of this object are converted to strings and
26 these strings are then concatenated, separated by comma
27 characters. The result is the same as if the built-in join
28 method were invoiked for this object with no argument.
29 Author: christine@netscape.com, pschwartau@netscape.com
31 Modified: 14 July 2002
32 Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155285
33 ECMA-262 Ed.3 Section 15.4.4.5 Array.prototype.join()
34 Step 3: If |separator| is |undefined|, let |separator|
35 be the single-character string ","
39 var SECTION
= "15.4.4.3-1";
40 var VERSION
= "ECMA_1";
43 writeHeaderToLog( SECTION
+ " Array.prototype.join()");
45 var testcases
= getTestCases();
48 function getTestCases() {
49 var array
= new Array();
52 var ARR_PROTOTYPE
= Array
.prototype;
54 array
[item
++] = new TestCase( SECTION
, "Array.prototype.join.length", 1, Array
.prototype.join
.length
);
55 array
[item
++] = new TestCase( SECTION
, "delete Array.prototype.join.length", false, delete Array
.prototype.join
.length
);
56 array
[item
++] = new TestCase( SECTION
, "delete Array.prototype.join.length; Array.prototype.join.length", 1, eval("delete Array.prototype.join.length; Array.prototype.join.length") );
58 // case where array length is 0
60 array
[item
++] = new TestCase( SECTION
,
61 "var TEST_ARRAY = new Array(); TEST_ARRAY.join()",
63 eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join()") );
65 // array length is 0, but spearator is specified
67 array
[item
++] = new TestCase( SECTION
,
68 "var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')",
70 eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')") );
72 // length is greater than 0, separator is supplied
73 array
[item
++] = new TestCase( SECTION
,
74 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')",
75 "&&true&false&123&[object Object]&true",
76 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')") );
78 // length is greater than 0, separator is empty string
79 array
[item
++] = new TestCase( SECTION
,
80 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')",
81 "truefalse123[object Object]true",
82 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')") );
83 // length is greater than 0, separator is undefined
84 array
[item
++] = new TestCase( SECTION
,
85 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)",
86 ",,true,false,123,[object Object],true",
87 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)") );
89 // length is greater than 0, separator is not supplied
90 array
[item
++] = new TestCase( SECTION
,
91 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()",
92 ",,true,false,123,[object Object],true",
93 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()") );
95 // separator is a control character
96 array
[item
++] = new TestCase( SECTION
,
97 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')",
98 unescape("%u000B%u000Btrue%u000Bfalse%u000B123%u000B[object Object]%u000Btrue"),
99 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')") );
101 // length of array is 1
102 array
[item
++] = new TestCase( SECTION
,
103 "var TEST_ARRAY = new Array(true) ); TEST_ARRAY.join('\v')",
105 eval("var TEST_ARRAY = new Array(true); TEST_ARRAY.join('\v')") );
114 for ( var index
= 0; index
< TEST_LENGTH
; index
++ ) {
116 ARGUMENTS
+= ( index
== TEST_LENGTH
-1 ) ? "" : ",";
118 TEST_RESULT
+= index
;
119 TEST_RESULT
+= ( index
== TEST_LENGTH
-1 ) ? "" : SEPARATOR
;
122 TEST_ARRAY
= eval( "new Array( "+ARGUMENTS
+")" );
124 array
[item
++] = new TestCase( SECTION
, "TEST_ARRAY.join("+SEPARATOR
+")", TEST_RESULT
, TEST_ARRAY
.join( SEPARATOR
) );
126 array
[item
++] = new TestCase( SECTION
, "(new Array( Boolean(true), Boolean(false), null, void 0, Number(1e+21), Number(1e-7))).join()",
127 "true,false,,,1e+21,1e-7",
128 (new Array( Boolean(true), Boolean(false), null, void 0, Number(1e+21), Number(1e-7))).join() );
130 // this is not an Array object
131 array
[item
++] = new TestCase( SECTION
,
132 "var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')",
133 "true:false:111:0.5:1230000:NaN::",
134 eval("var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')") );
141 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
142 testcases
[tc
].passed
= writeTestCaseResult(
143 testcases
[tc
].expect
,
144 testcases
[tc
].actual
,
145 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
);
146 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
149 return ( testcases
);
151 function Object_1( value
) {
152 this.array
= value
.split(",");
153 this.length
= this.array
.length
;
154 for ( var i
= 0; i
< this.length
; i
++ ) {
155 this[i
] = eval(this.array
[i
]);
157 this.join
= Array
.prototype.join
;
158 this.getClass
= Object
.prototype.toString
;