Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / String / 15.5.4.8-1.js
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
4  *
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/
9  *
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
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
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.
22  *
23  * Contributor(s):
24  *
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.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 /**
41    File Name:          15.5.4.8-1.js
42    ECMA Section:       15.5.4.8 String.prototype.split( separator )
43    Description:
44
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.
50
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.
54
55    If the separator is not supplied, then the result array contains just one
56    string, which is the string.
57
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
64    *
65    */
66
67 var SECTION = "15.5.4.8-1";
68 var VERSION = "ECMA_1";
69 startTest();
70 var TITLE   = "String.prototype.split";
71
72 writeHeaderToLog( SECTION + " "+ TITLE);
73
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") );
77
78 // test cases for when split is called with no arguments.
79
80 // this is a string object
81
82 new TestCase(   SECTION,
83                 "var s = new String('this is a string object'); typeof s.split()",
84                 "object",
85                 eval("var s = new String('this is a string object'); typeof s.split()") );
86
87 new TestCase(   SECTION,
88                 "var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()",
89                 "[object Array]",
90                 eval("var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()") );
91
92 new TestCase(   SECTION,
93                 "var s = new String('this is a string object'); s.split().length",
94                 1,
95                 eval("var s = new String('this is a string object'); s.split().length") );
96
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]") );
101
102 // this is an object object
103 new TestCase(   SECTION,
104                 "var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()",
105                 "object",
106                 eval("var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()") );
107
108 new TestCase(   SECTION,
109                 "var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
110                 "[object Array]",
111                 eval("var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
112
113 new TestCase(   SECTION,
114                 "var obj = new Object(); obj.split = String.prototype.split; obj.split().length",
115                 1,
116                 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split().length") );
117
118 new TestCase(   SECTION,
119                 "var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]",
120                 "[object Object]",
121                 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]") );
122
123 // this is a function object
124 new TestCase(   SECTION,
125                 "var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()",
126                 "object",
127                 eval("var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()") );
128
129 new TestCase(   SECTION,
130                 "var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
131                 "[object Array]",
132                 eval("var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
133
134 new TestCase(   SECTION,
135                 "var obj = new Function(); obj.split = String.prototype.split; obj.split().length",
136                 1,
137                 eval("var obj = new Function(); obj.split = String.prototype.split; obj.split().length") );
138
139 new TestCase(   SECTION,
140                 "var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]",
141                 "[object Function]",
142                 eval("var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]") );
143
144 // this is a number object
145 new TestCase(   SECTION,
146                 "var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()",
147                 "object",
148                 eval("var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()") );
149
150 new TestCase(   SECTION,
151                 "var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
152                 "[object Array]",
153                 eval("var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
154
155 new TestCase(   SECTION,
156                 "var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length",
157                 1,
158                 eval("var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length") );
159
160 new TestCase(   SECTION,
161                 "var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]",
162                 "-1e+21",
163                 eval("var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]") );
164
165
166 // this is the Math object
167 new TestCase(   SECTION,
168                 "var obj = Math; obj.split = String.prototype.split; typeof obj.split()",
169                 "object",
170                 eval("var obj = Math; obj.split = String.prototype.split; typeof obj.split()") );
171
172 new TestCase(   SECTION,
173                 "var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
174                 "[object Array]",
175                 eval("var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
176
177 new TestCase(   SECTION,
178                 "var obj = Math; obj.split = String.prototype.split; obj.split().length",
179                 1,
180                 eval("var obj = Math; obj.split = String.prototype.split; obj.split().length") );
181
182 new TestCase(   SECTION,
183                 "var obj = Math; obj.split = String.prototype.split; obj.split()[0]",
184                 "[object Math]",
185                 eval("var obj = Math; obj.split = String.prototype.split; obj.split()[0]") );
186
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()",
190                 "object",
191                 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()") );
192
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()",
195                 "[object Array]",
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()") );
197
198 new TestCase(   SECTION,
199                 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length",
200                 1,
201                 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length") );
202
203 new TestCase(   SECTION,
204                 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]",
205                 "1,2,3,4,5",
206                 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]") );
207
208 // this is a Boolean object
209
210 new TestCase(   SECTION,
211                 "var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()",
212                 "object",
213                 eval("var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()") );
214
215 new TestCase(   SECTION,
216                 "var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
217                 "[object Array]",
218                 eval("var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
219
220 new TestCase(   SECTION,
221                 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length",
222                 1,
223                 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length") );
224
225 new TestCase(   SECTION,
226                 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]",
227                 "false",
228                 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]") );
229
230
231 test();