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.5.4.8-1.js
24 ECMA Section: 15.5.4.8 String.prototype.split( separator )
27 Returns an Array object into which substrings of the result of converting
28 this object to a string have been stored. The substrings are determined by
29 searching from left to right for occurrences of the given separator; these
30 occurrences are not part of any substring in the returned array, but serve
31 to divide up this string value. The separator may be a string of any length.
33 As a special case, if the separator is the empty string, the string is split
34 up into individual characters; the length of the result array equals the
35 length of the string, and each substring contains one character.
37 If the separator is not supplied, then the result array contains just one
38 string, which is the string.
40 Author: christine@netscape.com, pschwartau@netscape.com
41 Date: 12 November 1997
42 Modified: 14 July 2002
43 Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155289
44 ECMA-262 Ed.3 Section 15.5.4.14
45 The length property of the split method is 2
49 var SECTION
= "15.5.4.8-1";
50 var VERSION
= "ECMA_1";
52 var TITLE
= "String.prototype.split";
54 writeHeaderToLog( SECTION
+ " "+ TITLE
);
56 var testcases
= getTestCases();
59 function getTestCases() {
60 var array
= new Array();
63 array
[item
++] = new TestCase( SECTION
, "String.prototype.split.length", 2, String
.prototype.split
.length
);
64 array
[item
++] = new TestCase( SECTION
, "delete String.prototype.split.length", false, delete String
.prototype.split
.length
);
65 array
[item
++] = new TestCase( SECTION
, "delete String.prototype.split.length; String.prototype.split.length", 2, eval("delete String.prototype.split.length; String.prototype.split.length") );
67 // test cases for when split is called with no arguments.
69 // this is a string object
71 array
[item
++] = new TestCase( SECTION
,
72 "var s = new String('this is a string object'); typeof s.split()",
74 eval("var s = new String('this is a string object'); typeof s.split()") );
76 array
[item
++] = new TestCase( SECTION
,
77 "var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()",
79 eval("var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()") );
81 array
[item
++] = new TestCase( SECTION
,
82 "var s = new String('this is a string object'); s.split().length",
84 eval("var s = new String('this is a string object'); s.split().length") );
86 array
[item
++] = new TestCase( SECTION
,
87 "var s = new String('this is a string object'); s.split()[0]",
88 "this is a string object",
89 eval("var s = new String('this is a string object'); s.split()[0]") );
91 // this is an object object
92 array
[item
++] = new TestCase( SECTION
,
93 "var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()",
95 eval("var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()") );
97 array
[item
++] = new TestCase( SECTION
,
98 "var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
100 eval("var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
102 array
[item
++] = new TestCase( SECTION
,
103 "var obj = new Object(); obj.split = String.prototype.split; obj.split().length",
105 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split().length") );
107 array
[item
++] = new TestCase( SECTION
,
108 "var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]",
110 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]") );
112 // this is a function object
113 array
[item
++] = new TestCase( SECTION
,
114 "var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()",
116 eval("var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()") );
118 array
[item
++] = new TestCase( SECTION
,
119 "var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
121 eval("var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
123 array
[item
++] = new TestCase( SECTION
,
124 "var obj = new Function(); obj.split = String.prototype.split; obj.split().length",
126 eval("var obj = new Function(); obj.split = String.prototype.split; obj.split().length") );
128 array
[item
++] = new TestCase( SECTION
,
129 "var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]",
131 eval("var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]") );
133 // this is a number object
134 array
[item
++] = new TestCase( SECTION
,
135 "var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()",
137 eval("var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()") );
139 array
[item
++] = new TestCase( SECTION
,
140 "var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
142 eval("var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
144 array
[item
++] = new TestCase( SECTION
,
145 "var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length",
147 eval("var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length") );
149 array
[item
++] = new TestCase( SECTION
,
150 "var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]",
152 eval("var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]") );
155 // this is the Math object
156 array
[item
++] = new TestCase( SECTION
,
157 "var obj = Math; obj.split = String.prototype.split; typeof obj.split()",
159 eval("var obj = Math; obj.split = String.prototype.split; typeof obj.split()") );
161 array
[item
++] = new TestCase( SECTION
,
162 "var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
164 eval("var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
166 array
[item
++] = new TestCase( SECTION
,
167 "var obj = Math; obj.split = String.prototype.split; obj.split().length",
169 eval("var obj = Math; obj.split = String.prototype.split; obj.split().length") );
171 array
[item
++] = new TestCase( SECTION
,
172 "var obj = Math; obj.split = String.prototype.split; obj.split()[0]",
174 eval("var obj = Math; obj.split = String.prototype.split; obj.split()[0]") );
176 // this is an array object
177 array
[item
++] = new TestCase( SECTION
,
178 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()",
180 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()") );
182 array
[item
++] = new TestCase( SECTION
,
183 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
185 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
187 array
[item
++] = new TestCase( SECTION
,
188 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length",
190 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length") );
192 array
[item
++] = new TestCase( SECTION
,
193 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]",
195 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]") );
197 // this is a Boolean object
199 array
[item
++] = new TestCase( SECTION
,
200 "var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()",
202 eval("var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()") );
204 array
[item
++] = new TestCase( SECTION
,
205 "var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
207 eval("var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
209 array
[item
++] = new TestCase( SECTION
,
210 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length",
212 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length") );
214 array
[item
++] = new TestCase( SECTION
,
215 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]",
217 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]") );
223 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
224 testcases
[tc
].passed
= writeTestCaseResult(
225 testcases
[tc
].expect
,
226 testcases
[tc
].actual
,
227 testcases
[tc
].description
+" = "+
228 testcases
[tc
].actual
);
230 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
233 return ( testcases
);