js/src/tests/ecma/String/15.5.4.9-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.9-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,168 @@
     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.9-1.js
    1.12 +   ECMA Section:       15.5.4.9 String.prototype.substring( start )
    1.13 +   Description:
    1.14 +
    1.15 +   15.5.4.9 String.prototype.substring(start)
    1.16 +
    1.17 +   Returns a substring of the result of converting this object to a string,
    1.18 +   starting from character position start and running to the end of the
    1.19 +   string. The result is a string value, not a String object.
    1.20 +
    1.21 +   If the argument is NaN or negative, it is replaced with zero; if the
    1.22 +   argument is larger than the length of the string, it is replaced with the
    1.23 +   length of the string.
    1.24 +
    1.25 +   When the substring method is called with one argument start, the following
    1.26 +   steps are taken:
    1.27 +
    1.28 +   1.Call ToString, giving it the this value as its argument.
    1.29 +   2.Call ToInteger(start).
    1.30 +   3.Compute the number of characters in Result(1).
    1.31 +   4.Compute min(max(Result(2), 0), Result(3)).
    1.32 +   5.Return a string whose length is the difference between Result(3) and Result(4),
    1.33 +   containing characters from Result(1), namely the characters with indices Result(4)
    1.34 +   through Result(3)1, in ascending order.
    1.35 +
    1.36 +   Author:             christine@netscape.com
    1.37 +   Date:               12 november 1997
    1.38 +*/
    1.39 +
    1.40 +var SECTION = "15.5.4.9-1";
    1.41 +var VERSION = "ECMA_1";
    1.42 +startTest();
    1.43 +var TITLE   = "String.prototype.substring( start )";
    1.44 +
    1.45 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.46 +
    1.47 +new TestCase( SECTION,  "String.prototype.substring.length",        2,          String.prototype.substring.length );
    1.48 +new TestCase( SECTION,  "delete String.prototype.substring.length", false,      delete String.prototype.substring.length );
    1.49 +new TestCase( SECTION,  "delete String.prototype.substring.length; String.prototype.substring.length", 2,      eval("delete String.prototype.substring.length; String.prototype.substring.length") );
    1.50 +
    1.51 +// test cases for when substring is called with no arguments.
    1.52 +
    1.53 +// this is a string object
    1.54 +
    1.55 +new TestCase(   SECTION,
    1.56 +		"var s = new String('this is a string object'); typeof s.substring()",
    1.57 +		"string",
    1.58 +		eval("var s = new String('this is a string object'); typeof s.substring()") );
    1.59 +
    1.60 +new TestCase(   SECTION,
    1.61 +		"var s = new String(''); s.substring()",
    1.62 +		"",
    1.63 +		eval("var s = new String(''); s.substring()") );
    1.64 +
    1.65 +
    1.66 +new TestCase(   SECTION,
    1.67 +		"var s = new String('this is a string object'); s.substring()",
    1.68 +		"this is a string object",
    1.69 +		eval("var s = new String('this is a string object'); s.substring()") );
    1.70 +
    1.71 +new TestCase(   SECTION,
    1.72 +		"var s = new String('this is a string object'); s.substring(NaN)",
    1.73 +		"this is a string object",
    1.74 +		eval("var s = new String('this is a string object'); s.substring(NaN)") );
    1.75 +
    1.76 +
    1.77 +new TestCase(   SECTION,
    1.78 +		"var s = new String('this is a string object'); s.substring(-0.01)",
    1.79 +		"this is a string object",
    1.80 +		eval("var s = new String('this is a string object'); s.substring(-0.01)") );
    1.81 +
    1.82 +
    1.83 +new TestCase(   SECTION,
    1.84 +		"var s = new String('this is a string object'); s.substring(s.length)",
    1.85 +		"",
    1.86 +		eval("var s = new String('this is a string object'); s.substring(s.length)") );
    1.87 +
    1.88 +new TestCase(   SECTION,
    1.89 +		"var s = new String('this is a string object'); s.substring(s.length+1)",
    1.90 +		"",
    1.91 +		eval("var s = new String('this is a string object'); s.substring(s.length+1)") );
    1.92 +
    1.93 +
    1.94 +new TestCase(   SECTION,
    1.95 +		"var s = new String('this is a string object'); s.substring(Infinity)",
    1.96 +		"",
    1.97 +		eval("var s = new String('this is a string object'); s.substring(Infinity)") );
    1.98 +
    1.99 +new TestCase(   SECTION,
   1.100 +		"var s = new String('this is a string object'); s.substring(-Infinity)",
   1.101 +		"this is a string object",
   1.102 +		eval("var s = new String('this is a string object'); s.substring(-Infinity)") );
   1.103 +
   1.104 +// this is not a String object, start is not an integer
   1.105 +
   1.106 +
   1.107 +new TestCase(   SECTION,
   1.108 +		"var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring()",
   1.109 +		"1,2,3,4,5",
   1.110 +		eval("var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring()") );
   1.111 +
   1.112 +new TestCase(   SECTION,
   1.113 +		"var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring(true)",
   1.114 +		",2,3,4,5",
   1.115 +		eval("var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring(true)") );
   1.116 +
   1.117 +new TestCase(   SECTION,
   1.118 +		"var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring('4')",
   1.119 +		"3,4,5",
   1.120 +		eval("var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring('4')") );
   1.121 +
   1.122 +new TestCase(   SECTION,
   1.123 +		"var s = new Array(); s.substring = String.prototype.substring; s.substring('4')",
   1.124 +		"",
   1.125 +		eval("var s = new Array(); s.substring = String.prototype.substring; s.substring('4')") );
   1.126 +
   1.127 +// this is an object object
   1.128 +new TestCase(   SECTION,
   1.129 +		"var obj = new Object(); obj.substring = String.prototype.substring; obj.substring(8)",
   1.130 +		"Object]",
   1.131 +		eval("var obj = new Object(); obj.substring = String.prototype.substring; obj.substring(8)") );
   1.132 +
   1.133 +// this is a function object
   1.134 +new TestCase(   SECTION,
   1.135 +		"var obj = new Function(); obj.substring = String.prototype.substring; obj.toString = Object.prototype.toString; obj.substring(8)",
   1.136 +		"Function]",
   1.137 +		eval("var obj = new Function(); obj.substring = String.prototype.substring; obj.toString = Object.prototype.toString; obj.substring(8)") );
   1.138 +// this is a number object
   1.139 +new TestCase(   SECTION,
   1.140 +		"var obj = new Number(NaN); obj.substring = String.prototype.substring; obj.substring(false)",
   1.141 +		"NaN",
   1.142 +		eval("var obj = new Number(NaN); obj.substring = String.prototype.substring; obj.substring(false)") );
   1.143 +
   1.144 +// this is the Math object
   1.145 +new TestCase(   SECTION,
   1.146 +		"var obj = Math; obj.substring = String.prototype.substring; obj.substring(Math.PI)",
   1.147 +		"ject Math]",
   1.148 +		eval("var obj = Math; obj.substring = String.prototype.substring; obj.substring(Math.PI)") );
   1.149 +
   1.150 +// this is a Boolean object
   1.151 +
   1.152 +new TestCase(   SECTION,
   1.153 +		"var obj = new Boolean(); obj.substring = String.prototype.substring; obj.substring(new Array())",
   1.154 +		"false",
   1.155 +		eval("var obj = new Boolean(); obj.substring = String.prototype.substring; obj.substring(new Array())") );
   1.156 +
   1.157 +// this is a user defined object
   1.158 +
   1.159 +new TestCase( SECTION,
   1.160 +	      "var obj = new MyObject( null ); obj.substring(0)",
   1.161 +	      "null",
   1.162 +	      eval( "var obj = new MyObject( null ); obj.substring(0)") );
   1.163 +
   1.164 +
   1.165 +test();
   1.166 +
   1.167 +function MyObject( value ) {
   1.168 +  this.value = value;
   1.169 +  this.substring = String.prototype.substring;
   1.170 +  this.toString = new Function ( "return this.value+''" );
   1.171 +}

mercurial