1/* The contents of this file are subject to the Netscape Public 2 * License Version 1.1 (the "License"); you may not use this file 3 * except in compliance with the License. You may obtain a copy of 4 * the License at http://www.mozilla.org/NPL/ 5 * 6 * Software distributed under the License is distributed on an "AS 7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 8 * implied. See the License for the specific language governing 9 * rights and limitations under the License. 10 * 11 * The Original Code is Mozilla Communicator client code, released March 12 * 31, 1998. 13 * 14 * The Initial Developer of the Original Code is Netscape Communications 15 * Corporation. Portions created by Netscape are 16 * Copyright (C) 1998 Netscape Communications Corporation. All 17 * Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 */ 22/** 23 File Name: 15.5.4.8-1.js 24 ECMA Section: 15.5.4.8 String.prototype.split( separator ) 25 Description: 26 27 Returns an Array object into which substrings of the result of converting 28 this object to a string have been stored. The substrings are determined by 29 searching from left to right for occurrences of the given separator; these 30 occurrences are not part of any substring in the returned array, but serve 31 to divide up this string value. The separator may be a string of any length. 32 33 As a special case, if the separator is the empty string, the string is split 34 up into individual characters; the length of the result array equals the 35 length of the string, and each substring contains one character. 36 37 If the separator is not supplied, then the result array contains just one 38 string, which is the string. 39 40 Author: christine@netscape.com, pschwartau@netscape.com 41 Date: 12 November 1997 42 Modified: 14 July 2002 43 Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155289 44 ECMA-262 Ed.3 Section 15.5.4.14 45 The length property of the split method is 2 46* 47*/ 48 49 var SECTION = "15.5.4.8-1"; 50 var VERSION = "ECMA_1"; 51 startTest(); 52 var TITLE = "String.prototype.split"; 53 54 writeHeaderToLog( SECTION + " "+ TITLE); 55 56 var testcases = getTestCases(); 57 test(); 58 59function getTestCases() { 60 var array = new Array(); 61 var item = 0; 62 63 array[item++] = new TestCase( SECTION, "String.prototype.split.length", 2, String.prototype.split.length ); 64 array[item++] = new TestCase( SECTION, "delete String.prototype.split.length", false, delete String.prototype.split.length ); 65 array[item++] = new TestCase( SECTION, "delete String.prototype.split.length; String.prototype.split.length", 2, eval("delete String.prototype.split.length; String.prototype.split.length") ); 66 67 // test cases for when split is called with no arguments. 68 69 // this is a string object 70 71 array[item++] = new TestCase( SECTION, 72 "var s = new String('this is a string object'); typeof s.split()", 73 "object", 74 eval("var s = new String('this is a string object'); typeof s.split()") ); 75 76 array[item++] = new TestCase( SECTION, 77 "var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()", 78 "[object Array]", 79 eval("var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()") ); 80 81 array[item++] = new TestCase( SECTION, 82 "var s = new String('this is a string object'); s.split().length", 83 1, 84 eval("var s = new String('this is a string object'); s.split().length") ); 85 86 array[item++] = new TestCase( SECTION, 87 "var s = new String('this is a string object'); s.split()[0]", 88 "this is a string object", 89 eval("var s = new String('this is a string object'); s.split()[0]") ); 90 91 // this is an object object 92 array[item++] = new TestCase( SECTION, 93 "var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()", 94 "object", 95 eval("var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()") ); 96 97 array[item++] = new TestCase( SECTION, 98 "var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", 99 "[object Array]", 100 eval("var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); 101 102 array[item++] = new TestCase( SECTION, 103 "var obj = new Object(); obj.split = String.prototype.split; obj.split().length", 104 1, 105 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split().length") ); 106 107 array[item++] = new TestCase( SECTION, 108 "var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]", 109 "[object Object]", 110 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]") ); 111 112 // this is a function object 113 array[item++] = new TestCase( SECTION, 114 "var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()", 115 "object", 116 eval("var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()") ); 117 118 array[item++] = new TestCase( SECTION, 119 "var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", 120 "[object Array]", 121 eval("var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); 122 123 array[item++] = new TestCase( SECTION, 124 "var obj = new Function(); obj.split = String.prototype.split; obj.split().length", 125 1, 126 eval("var obj = new Function(); obj.split = String.prototype.split; obj.split().length") ); 127 128 array[item++] = new TestCase( SECTION, 129 "var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]", 130 "[object Function]", 131 eval("var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]") ); 132 133 // this is a number object 134 array[item++] = new TestCase( SECTION, 135 "var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()", 136 "object", 137 eval("var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()") ); 138 139 array[item++] = new TestCase( SECTION, 140 "var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", 141 "[object Array]", 142 eval("var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); 143 144 array[item++] = new TestCase( SECTION, 145 "var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length", 146 1, 147 eval("var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length") ); 148 149 array[item++] = new TestCase( SECTION, 150 "var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]", 151 "-1e+21", 152 eval("var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]") ); 153 154 155 // this is the Math object 156 array[item++] = new TestCase( SECTION, 157 "var obj = Math; obj.split = String.prototype.split; typeof obj.split()", 158 "object", 159 eval("var obj = Math; obj.split = String.prototype.split; typeof obj.split()") ); 160 161 array[item++] = new TestCase( SECTION, 162 "var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", 163 "[object Array]", 164 eval("var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); 165 166 array[item++] = new TestCase( SECTION, 167 "var obj = Math; obj.split = String.prototype.split; obj.split().length", 168 1, 169 eval("var obj = Math; obj.split = String.prototype.split; obj.split().length") ); 170 171 array[item++] = new TestCase( SECTION, 172 "var obj = Math; obj.split = String.prototype.split; obj.split()[0]", 173 "[object Math]", 174 eval("var obj = Math; obj.split = String.prototype.split; obj.split()[0]") ); 175 176 // this is an array object 177 array[item++] = new TestCase( SECTION, 178 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()", 179 "object", 180 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()") ); 181 182 array[item++] = new TestCase( SECTION, 183 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", 184 "[object Array]", 185 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); 186 187 array[item++] = new TestCase( SECTION, 188 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length", 189 1, 190 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length") ); 191 192 array[item++] = new TestCase( SECTION, 193 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]", 194 "1,2,3,4,5", 195 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]") ); 196 197 // this is a Boolean object 198 199 array[item++] = new TestCase( SECTION, 200 "var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()", 201 "object", 202 eval("var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()") ); 203 204 array[item++] = new TestCase( SECTION, 205 "var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()", 206 "[object Array]", 207 eval("var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") ); 208 209 array[item++] = new TestCase( SECTION, 210 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length", 211 1, 212 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length") ); 213 214 array[item++] = new TestCase( SECTION, 215 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]", 216 "false", 217 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]") ); 218 219 220 return array; 221} 222function test() { 223 for ( tc=0; tc < testcases.length; tc++ ) { 224 testcases[tc].passed = writeTestCaseResult( 225 testcases[tc].expect, 226 testcases[tc].actual, 227 testcases[tc].description +" = "+ 228 testcases[tc].actual ); 229 230 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 231 } 232 stopTest(); 233 return ( testcases ); 234} 235