|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 File Name: 15.5.4.8-1.js |
|
9 ECMA Section: 15.5.4.8 String.prototype.split( separator ) |
|
10 Description: |
|
11 |
|
12 Returns an Array object into which substrings of the result of converting |
|
13 this object to a string have been stored. The substrings are determined by |
|
14 searching from left to right for occurrences of the given separator; these |
|
15 occurrences are not part of any substring in the returned array, but serve |
|
16 to divide up this string value. The separator may be a string of any length. |
|
17 |
|
18 As a special case, if the separator is the empty string, the string is split |
|
19 up into individual characters; the length of the result array equals the |
|
20 length of the string, and each substring contains one character. |
|
21 |
|
22 If the separator is not supplied, then the result array contains just one |
|
23 string, which is the string. |
|
24 |
|
25 Author: christine@netscape.com, pschwartau@netscape.com |
|
26 Date: 12 November 1997 |
|
27 Modified: 14 July 2002 |
|
28 Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155289 |
|
29 ECMA-262 Ed.3 Section 15.5.4.14 |
|
30 The length property of the split method is 2 |
|
31 * |
|
32 */ |
|
33 |
|
34 var SECTION = "15.5.4.8-1"; |
|
35 var VERSION = "ECMA_1"; |
|
36 startTest(); |
|
37 var TITLE = "String.prototype.split"; |
|
38 |
|
39 writeHeaderToLog( SECTION + " "+ TITLE); |
|
40 |
|
41 new TestCase( SECTION, "String.prototype.split.length", 2, String.prototype.split.length ); |
|
42 new TestCase( SECTION, "delete String.prototype.split.length", false, delete String.prototype.split.length ); |
|
43 new TestCase( SECTION, "delete String.prototype.split.length; String.prototype.split.length", 2, eval("delete String.prototype.split.length; String.prototype.split.length") ); |
|
44 |
|
45 // test cases for when split is called with no arguments. |
|
46 |
|
47 // this is a string object |
|
48 |
|
49 new TestCase( SECTION, |
|
50 "var s = new String('this is a string object'); typeof s.split()", |
|
51 "object", |
|
52 eval("var s = new String('this is a string object'); typeof s.split()") ); |
|
53 |
|
54 new TestCase( SECTION, |
|
55 "var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()", |
|
56 "[object Array]", |
|
57 eval("var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()") ); |
|
58 |
|
59 new TestCase( SECTION, |
|
60 "var s = new String('this is a string object'); s.split().length", |
|
61 1, |
|
62 eval("var s = new String('this is a string object'); s.split().length") ); |
|
63 |
|
64 new TestCase( SECTION, |
|
65 "var s = new String('this is a string object'); s.split()[0]", |
|
66 "this is a string object", |
|
67 eval("var s = new String('this is a string object'); s.split()[0]") ); |
|
68 |
|
69 // this is an object object |
|
70 new TestCase( SECTION, |
|
71 "var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()", |
|
72 "object", |
|
73 eval("var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()") ); |
|
74 |
|
75 new TestCase( SECTION, |
|
76 "var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", |
|
77 "[object Array]", |
|
78 eval("var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); |
|
79 |
|
80 new TestCase( SECTION, |
|
81 "var obj = new Object(); obj.split = String.prototype.split; obj.split().length", |
|
82 1, |
|
83 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split().length") ); |
|
84 |
|
85 new TestCase( SECTION, |
|
86 "var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]", |
|
87 "[object Object]", |
|
88 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]") ); |
|
89 |
|
90 // this is a function object |
|
91 new TestCase( SECTION, |
|
92 "var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()", |
|
93 "object", |
|
94 eval("var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()") ); |
|
95 |
|
96 new TestCase( SECTION, |
|
97 "var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", |
|
98 "[object Array]", |
|
99 eval("var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); |
|
100 |
|
101 new TestCase( SECTION, |
|
102 "var obj = new Function(); obj.split = String.prototype.split; obj.split().length", |
|
103 1, |
|
104 eval("var obj = new Function(); obj.split = String.prototype.split; obj.split().length") ); |
|
105 |
|
106 new TestCase( SECTION, |
|
107 "var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]", |
|
108 "[object Function]", |
|
109 eval("var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]") ); |
|
110 |
|
111 // this is a number object |
|
112 new TestCase( SECTION, |
|
113 "var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()", |
|
114 "object", |
|
115 eval("var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()") ); |
|
116 |
|
117 new TestCase( SECTION, |
|
118 "var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", |
|
119 "[object Array]", |
|
120 eval("var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); |
|
121 |
|
122 new TestCase( SECTION, |
|
123 "var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length", |
|
124 1, |
|
125 eval("var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length") ); |
|
126 |
|
127 new TestCase( SECTION, |
|
128 "var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]", |
|
129 "-1e+21", |
|
130 eval("var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]") ); |
|
131 |
|
132 |
|
133 // this is the Math object |
|
134 new TestCase( SECTION, |
|
135 "var obj = Math; obj.split = String.prototype.split; typeof obj.split()", |
|
136 "object", |
|
137 eval("var obj = Math; obj.split = String.prototype.split; typeof obj.split()") ); |
|
138 |
|
139 new TestCase( SECTION, |
|
140 "var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", |
|
141 "[object Array]", |
|
142 eval("var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); |
|
143 |
|
144 new TestCase( SECTION, |
|
145 "var obj = Math; obj.split = String.prototype.split; obj.split().length", |
|
146 1, |
|
147 eval("var obj = Math; obj.split = String.prototype.split; obj.split().length") ); |
|
148 |
|
149 new TestCase( SECTION, |
|
150 "var obj = Math; obj.split = String.prototype.split; obj.split()[0]", |
|
151 "[object Math]", |
|
152 eval("var obj = Math; obj.split = String.prototype.split; obj.split()[0]") ); |
|
153 |
|
154 // this is an array object |
|
155 new TestCase( SECTION, |
|
156 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()", |
|
157 "object", |
|
158 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()") ); |
|
159 |
|
160 new TestCase( SECTION, |
|
161 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", |
|
162 "[object Array]", |
|
163 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); |
|
164 |
|
165 new TestCase( SECTION, |
|
166 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length", |
|
167 1, |
|
168 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length") ); |
|
169 |
|
170 new TestCase( SECTION, |
|
171 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]", |
|
172 "1,2,3,4,5", |
|
173 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]") ); |
|
174 |
|
175 // this is a Boolean object |
|
176 |
|
177 new TestCase( SECTION, |
|
178 "var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()", |
|
179 "object", |
|
180 eval("var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()") ); |
|
181 |
|
182 new TestCase( SECTION, |
|
183 "var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", |
|
184 "[object Array]", |
|
185 eval("var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); |
|
186 |
|
187 new TestCase( SECTION, |
|
188 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length", |
|
189 1, |
|
190 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length") ); |
|
191 |
|
192 new TestCase( SECTION, |
|
193 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]", |
|
194 "false", |
|
195 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]") ); |
|
196 |
|
197 |
|
198 test(); |