Debian Codegraph @

rhino/testsrc/tests/ecma/String/15.5.4.8-1.js

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