js/src/tests/ecma/String/15.5.4.8-1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/String/15.5.4.8-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,198 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   File Name:          15.5.4.8-1.js
    1.12 +   ECMA Section:       15.5.4.8 String.prototype.split( separator )
    1.13 +   Description:
    1.14 +
    1.15 +   Returns an Array object into which substrings of the result of converting
    1.16 +   this object to a string have been stored. The substrings are determined by
    1.17 +   searching from left to right for occurrences of the given separator; these
    1.18 +   occurrences are not part of any substring in the returned array, but serve
    1.19 +   to divide up this string value. The separator may be a string of any length.
    1.20 +
    1.21 +   As a special case, if the separator is the empty string, the string is split
    1.22 +   up into individual characters; the length of the result array equals the
    1.23 +   length of the string, and each substring contains one character.
    1.24 +
    1.25 +   If the separator is not supplied, then the result array contains just one
    1.26 +   string, which is the string.
    1.27 +
    1.28 +   Author:    christine@netscape.com, pschwartau@netscape.com
    1.29 +   Date:      12 November 1997
    1.30 +   Modified:  14 July 2002
    1.31 +   Reason:    See http://bugzilla.mozilla.org/show_bug.cgi?id=155289
    1.32 +   ECMA-262 Ed.3  Section 15.5.4.14
    1.33 +   The length property of the split method is 2
    1.34 +   *
    1.35 +   */
    1.36 +
    1.37 +var SECTION = "15.5.4.8-1";
    1.38 +var VERSION = "ECMA_1";
    1.39 +startTest();
    1.40 +var TITLE   = "String.prototype.split";
    1.41 +
    1.42 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.43 +
    1.44 +new TestCase( SECTION,  "String.prototype.split.length",        2,          String.prototype.split.length );
    1.45 +new TestCase( SECTION,  "delete String.prototype.split.length", false,      delete String.prototype.split.length );
    1.46 +new TestCase( SECTION,  "delete String.prototype.split.length; String.prototype.split.length", 2,      eval("delete String.prototype.split.length; String.prototype.split.length") );
    1.47 +
    1.48 +// test cases for when split is called with no arguments.
    1.49 +
    1.50 +// this is a string object
    1.51 +
    1.52 +new TestCase(   SECTION,
    1.53 +		"var s = new String('this is a string object'); typeof s.split()",
    1.54 +		"object",
    1.55 +		eval("var s = new String('this is a string object'); typeof s.split()") );
    1.56 +
    1.57 +new TestCase(   SECTION,
    1.58 +		"var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()",
    1.59 +		"[object Array]",
    1.60 +		eval("var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()") );
    1.61 +
    1.62 +new TestCase(   SECTION,
    1.63 +		"var s = new String('this is a string object'); s.split().length",
    1.64 +		1,
    1.65 +		eval("var s = new String('this is a string object'); s.split().length") );
    1.66 +
    1.67 +new TestCase(   SECTION,
    1.68 +		"var s = new String('this is a string object'); s.split()[0]",
    1.69 +		"this is a string object",
    1.70 +		eval("var s = new String('this is a string object'); s.split()[0]") );
    1.71 +
    1.72 +// this is an object object
    1.73 +new TestCase(   SECTION,
    1.74 +		"var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()",
    1.75 +		"object",
    1.76 +		eval("var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()") );
    1.77 +
    1.78 +new TestCase(   SECTION,
    1.79 +		"var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
    1.80 +		"[object Array]",
    1.81 +		eval("var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
    1.82 +
    1.83 +new TestCase(   SECTION,
    1.84 +		"var obj = new Object(); obj.split = String.prototype.split; obj.split().length",
    1.85 +		1,
    1.86 +		eval("var obj = new Object(); obj.split = String.prototype.split; obj.split().length") );
    1.87 +
    1.88 +new TestCase(   SECTION,
    1.89 +		"var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]",
    1.90 +		"[object Object]",
    1.91 +		eval("var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]") );
    1.92 +
    1.93 +// this is a function object
    1.94 +new TestCase(   SECTION,
    1.95 +		"var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()",
    1.96 +		"object",
    1.97 +		eval("var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()") );
    1.98 +
    1.99 +new TestCase(   SECTION,
   1.100 +		"var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
   1.101 +		"[object Array]",
   1.102 +		eval("var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
   1.103 +
   1.104 +new TestCase(   SECTION,
   1.105 +		"var obj = new Function(); obj.split = String.prototype.split; obj.split().length",
   1.106 +		1,
   1.107 +		eval("var obj = new Function(); obj.split = String.prototype.split; obj.split().length") );
   1.108 +
   1.109 +new TestCase(   SECTION,
   1.110 +		"var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]",
   1.111 +		"[object Function]",
   1.112 +		eval("var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]") );
   1.113 +
   1.114 +// this is a number object
   1.115 +new TestCase(   SECTION,
   1.116 +		"var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()",
   1.117 +		"object",
   1.118 +		eval("var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()") );
   1.119 +
   1.120 +new TestCase(   SECTION,
   1.121 +		"var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
   1.122 +		"[object Array]",
   1.123 +		eval("var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
   1.124 +
   1.125 +new TestCase(   SECTION,
   1.126 +		"var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length",
   1.127 +		1,
   1.128 +		eval("var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length") );
   1.129 +
   1.130 +new TestCase(   SECTION,
   1.131 +		"var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]",
   1.132 +		"-1e+21",
   1.133 +		eval("var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]") );
   1.134 +
   1.135 +
   1.136 +// this is the Math object
   1.137 +new TestCase(   SECTION,
   1.138 +		"var obj = Math; obj.split = String.prototype.split; typeof obj.split()",
   1.139 +		"object",
   1.140 +		eval("var obj = Math; obj.split = String.prototype.split; typeof obj.split()") );
   1.141 +
   1.142 +new TestCase(   SECTION,
   1.143 +		"var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
   1.144 +		"[object Array]",
   1.145 +		eval("var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
   1.146 +
   1.147 +new TestCase(   SECTION,
   1.148 +		"var obj = Math; obj.split = String.prototype.split; obj.split().length",
   1.149 +		1,
   1.150 +		eval("var obj = Math; obj.split = String.prototype.split; obj.split().length") );
   1.151 +
   1.152 +new TestCase(   SECTION,
   1.153 +		"var obj = Math; obj.split = String.prototype.split; obj.split()[0]",
   1.154 +		"[object Math]",
   1.155 +		eval("var obj = Math; obj.split = String.prototype.split; obj.split()[0]") );
   1.156 +
   1.157 +// this is an array object
   1.158 +new TestCase(   SECTION,
   1.159 +		"var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()",
   1.160 +		"object",
   1.161 +		eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()") );
   1.162 +
   1.163 +new TestCase(   SECTION,
   1.164 +		"var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
   1.165 +		"[object Array]",
   1.166 +		eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
   1.167 +
   1.168 +new TestCase(   SECTION,
   1.169 +		"var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length",
   1.170 +		1,
   1.171 +		eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length") );
   1.172 +
   1.173 +new TestCase(   SECTION,
   1.174 +		"var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]",
   1.175 +		"1,2,3,4,5",
   1.176 +		eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]") );
   1.177 +
   1.178 +// this is a Boolean object
   1.179 +
   1.180 +new TestCase(   SECTION,
   1.181 +		"var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()",
   1.182 +		"object",
   1.183 +		eval("var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()") );
   1.184 +
   1.185 +new TestCase(   SECTION,
   1.186 +		"var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",
   1.187 +		"[object Array]",
   1.188 +		eval("var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );
   1.189 +
   1.190 +new TestCase(   SECTION,
   1.191 +		"var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length",
   1.192 +		1,
   1.193 +		eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length") );
   1.194 +
   1.195 +new TestCase(   SECTION,
   1.196 +		"var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]",
   1.197 +		"false",
   1.198 +		eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]") );
   1.199 +
   1.200 +
   1.201 +test();

mercurial