1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 File Name: 15.5.4.8-1.js
42 ECMA Section: 15.5.4.8 String.prototype.split( separator )
45 Returns an Array object into which substrings of the result of converting
46 this object to a string have been stored. The substrings are determined by
47 searching from left to right for occurrences of the given separator; these
48 occurrences are not part of any substring in the returned array, but serve
49 to divide up this string value. The separator may be a string of any length.
51 As a special case, if the separator is the empty string, the string is split
52 up into individual characters; the length of the result array equals the
53 length of the string, and each substring contains one character.
55 If the separator is not supplied, then the result array contains just one
56 string, which is the string.
58 Author: christine@netscape.com, pschwartau@netscape.com
59 Date: 12 November 1997
60 Modified: 14 July 2002
61 Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155289
62 ECMA-262 Ed.3 Section 15.5.4.14
63 The length property of the split method is 2
67 var SECTION = "15.5.4.8-1";
68 var VERSION = "ECMA_1";
70 var TITLE = "String.prototype.split";
72 writeHeaderToLog( SECTION + " "+ TITLE);
74 new TestCase( SECTION, "String.prototype.split.length", 2, String.prototype.split.length );
75 new TestCase( SECTION, "delete String.prototype.split.length", false, delete String.prototype.split.length );
76 new TestCase( SECTION, "delete String.prototype.split.length; String.prototype.split.length", 2, eval("delete String.prototype.split.length; String.prototype.split.length") );
78 // test cases for when split is called with no arguments.
80 // this is a string object
82 new TestCase( SECTION,
83 "var s = new String('this is a string object'); typeof s.split()",
85 eval("var s = new String('this is a string object'); typeof s.split()") );
87 new TestCase( SECTION,
88 "var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()",
90 eval("var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()") );
92 new TestCase( SECTION,
93 "var s = new String('this is a string object'); s.split().length",
95 eval("var s = new String('this is a string object'); s.split().length") );
97 new TestCase( SECTION,
98 "var s = new String('this is a string object'); s.split()[0]",
99 "this is a string object",
100 eval("var s = new String('this is a string object'); s.split()[0]") );
102 // this is an object object
103 new TestCase( SECTION,
104 "var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()",
106 eval("var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()") );
108 new TestCase( SECTION,
109 "var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
111 eval("var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
113 new TestCase( SECTION,
114 "var obj = new Object(); obj.split = String.prototype.split; obj.split().length",
116 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split().length") );
118 new TestCase( SECTION,
119 "var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]",
121 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]") );
123 // this is a function object
124 new TestCase( SECTION,
125 "var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()",
127 eval("var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()") );
129 new TestCase( SECTION,
130 "var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
132 eval("var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
134 new TestCase( SECTION,
135 "var obj = new Function(); obj.split = String.prototype.split; obj.split().length",
137 eval("var obj = new Function(); obj.split = String.prototype.split; obj.split().length") );
139 new TestCase( SECTION,
140 "var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]",
142 eval("var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]") );
144 // this is a number object
145 new TestCase( SECTION,
146 "var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()",
148 eval("var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()") );
150 new TestCase( SECTION,
151 "var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
153 eval("var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
155 new TestCase( SECTION,
156 "var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length",
158 eval("var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length") );
160 new TestCase( SECTION,
161 "var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]",
163 eval("var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]") );
166 // this is the Math object
167 new TestCase( SECTION,
168 "var obj = Math; obj.split = String.prototype.split; typeof obj.split()",
170 eval("var obj = Math; obj.split = String.prototype.split; typeof obj.split()") );
172 new TestCase( SECTION,
173 "var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
175 eval("var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
177 new TestCase( SECTION,
178 "var obj = Math; obj.split = String.prototype.split; obj.split().length",
180 eval("var obj = Math; obj.split = String.prototype.split; obj.split().length") );
182 new TestCase( SECTION,
183 "var obj = Math; obj.split = String.prototype.split; obj.split()[0]",
185 eval("var obj = Math; obj.split = String.prototype.split; obj.split()[0]") );
187 // this is an array object
188 new TestCase( SECTION,
189 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()",
191 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()") );
193 new TestCase( SECTION,
194 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
196 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
198 new TestCase( SECTION,
199 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length",
201 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length") );
203 new TestCase( SECTION,
204 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]",
206 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]") );
208 // this is a Boolean object
210 new TestCase( SECTION,
211 "var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()",
213 eval("var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()") );
215 new TestCase( SECTION,
216 "var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
218 eval("var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
220 new TestCase( SECTION,
221 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length",
223 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length") );
225 new TestCase( SECTION,
226 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]",
228 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]") );