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 ***** */
39 gTestfile = '15.5.4.8-1.js';
42 File Name: 15.5.4.8-1.js
43 ECMA Section: 15.5.4.8 String.prototype.split( separator )
46 Returns an Array object into which substrings of the result of converting
47 this object to a string have been stored. The substrings are determined by
48 searching from left to right for occurrences of the given separator; these
49 occurrences are not part of any substring in the returned array, but serve
50 to divide up this string value. The separator may be a string of any length.
52 As a special case, if the separator is the empty string, the string is split
53 up into individual characters; the length of the result array equals the
54 length of the string, and each substring contains one character.
56 If the separator is not supplied, then the result array contains just one
57 string, which is the string.
59 Author: christine@netscape.com, pschwartau@netscape.com
60 Date: 12 November 1997
61 Modified: 14 July 2002
62 Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155289
63 ECMA-262 Ed.3 Section 15.5.4.14
64 The length property of the split method is 2
68 var SECTION = "15.5.4.8-1";
69 var VERSION = "ECMA_1";
71 var TITLE = "String.prototype.split";
73 writeHeaderToLog( SECTION + " "+ TITLE);
75 new TestCase( SECTION, "String.prototype.split.length", 2, String.prototype.split.length );
76 new TestCase( SECTION, "delete String.prototype.split.length", false, delete String.prototype.split.length );
77 new TestCase( SECTION, "delete String.prototype.split.length; String.prototype.split.length", 2, eval("delete String.prototype.split.length; String.prototype.split.length") );
79 // test cases for when split is called with no arguments.
81 // this is a string object
83 new TestCase( SECTION,
84 "var s = new String('this is a string object'); typeof s.split()",
86 eval("var s = new String('this is a string object'); typeof s.split()") );
88 new TestCase( SECTION,
89 "var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()",
91 eval("var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()") );
93 new TestCase( SECTION,
94 "var s = new String('this is a string object'); s.split().length",
96 eval("var s = new String('this is a string object'); s.split().length") );
98 new TestCase( SECTION,
99 "var s = new String('this is a string object'); s.split()[0]",
100 "this is a string object",
101 eval("var s = new String('this is a string object'); s.split()[0]") );
103 // this is an object object
104 new TestCase( SECTION,
105 "var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()",
107 eval("var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()") );
109 new TestCase( SECTION,
110 "var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
112 eval("var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
114 new TestCase( SECTION,
115 "var obj = new Object(); obj.split = String.prototype.split; obj.split().length",
117 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split().length") );
119 new TestCase( SECTION,
120 "var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]",
122 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]") );
124 // this is a function object
125 new TestCase( SECTION,
126 "var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()",
128 eval("var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()") );
130 new TestCase( SECTION,
131 "var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
133 eval("var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
135 new TestCase( SECTION,
136 "var obj = new Function(); obj.split = String.prototype.split; obj.split().length",
138 eval("var obj = new Function(); obj.split = String.prototype.split; obj.split().length") );
140 new TestCase( SECTION,
141 "var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]",
143 eval("var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]") );
145 // this is a number object
146 new TestCase( SECTION,
147 "var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()",
149 eval("var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()") );
151 new TestCase( SECTION,
152 "var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
154 eval("var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
156 new TestCase( SECTION,
157 "var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length",
159 eval("var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length") );
161 new TestCase( SECTION,
162 "var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]",
164 eval("var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]") );
167 // this is the Math object
168 new TestCase( SECTION,
169 "var obj = Math; obj.split = String.prototype.split; typeof obj.split()",
171 eval("var obj = Math; obj.split = String.prototype.split; typeof obj.split()") );
173 new TestCase( SECTION,
174 "var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
176 eval("var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
178 new TestCase( SECTION,
179 "var obj = Math; obj.split = String.prototype.split; obj.split().length",
181 eval("var obj = Math; obj.split = String.prototype.split; obj.split().length") );
183 new TestCase( SECTION,
184 "var obj = Math; obj.split = String.prototype.split; obj.split()[0]",
186 eval("var obj = Math; obj.split = String.prototype.split; obj.split()[0]") );
188 // this is an array object
189 new TestCase( SECTION,
190 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()",
192 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()") );
194 new TestCase( SECTION,
195 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
197 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
199 new TestCase( SECTION,
200 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length",
202 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length") );
204 new TestCase( SECTION,
205 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]",
207 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]") );
209 // this is a Boolean object
211 new TestCase( SECTION,
212 "var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()",
214 eval("var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()") );
216 new TestCase( SECTION,
217 "var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
219 eval("var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
221 new TestCase( SECTION,
222 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length",
224 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length") );
226 new TestCase( SECTION,
227 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]",
229 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]") );