js/src/tests/ecma/String/15.5.2.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.2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     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.2.js
    1.12 +   ECMA Section:       15.5.2 The String Constructor
    1.13 +   15.5.2.1 new String(value)
    1.14 +   15.5.2.2 new String()
    1.15 +
    1.16 +   Description:	When String is called as part of a new expression, it
    1.17 +   is a constructor; it initializes the newly constructed
    1.18 +   object.
    1.19 +
    1.20 +   - The prototype property of the newly constructed
    1.21 +   object is set to the original String prototype object,
    1.22 +   the one that is the intial value of String.prototype
    1.23 +   - The internal [[Class]] property of the object is "String"
    1.24 +   - The value of the object is ToString(value).
    1.25 +   - If no value is specified, its value is the empty string.
    1.26 +
    1.27 +   Author:             christine@netscape.com
    1.28 +   Date:               1 october 1997
    1.29 +*/
    1.30 +
    1.31 +var SECTION = "15.5.2";
    1.32 +var VERSION = "ECMA_1";
    1.33 +startTest();
    1.34 +var TITLE   = "The String Constructor";
    1.35 +
    1.36 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.37 +
    1.38 +
    1.39 +new TestCase( SECTION,	"typeof new String('string primitive')",	    "object",	        typeof new String('string primitive') );
    1.40 +new TestCase( SECTION,	"var TESTSTRING = new String('string primitive'); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]",   eval("var TESTSTRING = new String('string primitive'); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
    1.41 +new TestCase( SECTION,  "(new String('string primitive')).valueOf()",   'string primitive', (new String('string primitive')).valueOf() );
    1.42 +new TestCase( SECTION,  "(new String('string primitive')).substring",   String.prototype.substring,   (new String('string primitive')).substring );
    1.43 +
    1.44 +new TestCase( SECTION,	"typeof new String(void 0)",	                "object",	        typeof new String(void 0) );
    1.45 +new TestCase( SECTION,	"var TESTSTRING = new String(void 0); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]",   eval("var TESTSTRING = new String(void 0); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
    1.46 +new TestCase( SECTION,  "(new String(void 0)).valueOf()",               "undefined", (new String(void 0)).valueOf() );
    1.47 +new TestCase( SECTION,  "(new String(void 0)).toString",               String.prototype.toString,   (new String(void 0)).toString );
    1.48 +
    1.49 +new TestCase( SECTION,	"typeof new String(null)",	            "object",	        typeof new String(null) );
    1.50 +new TestCase( SECTION,	"var TESTSTRING = new String(null); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]",   eval("var TESTSTRING = new String(null); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
    1.51 +new TestCase( SECTION,  "(new String(null)).valueOf()",         "null",             (new String(null)).valueOf() );
    1.52 +new TestCase( SECTION,  "(new String(null)).valueOf",         String.prototype.valueOf,   (new String(null)).valueOf );
    1.53 +
    1.54 +new TestCase( SECTION,	"typeof new String(true)",	            "object",	        typeof new String(true) );
    1.55 +new TestCase( SECTION,	"var TESTSTRING = new String(true); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]",   eval("var TESTSTRING = new String(true); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
    1.56 +new TestCase( SECTION,  "(new String(true)).valueOf()",         "true",             (new String(true)).valueOf() );
    1.57 +new TestCase( SECTION,  "(new String(true)).charAt",         String.prototype.charAt,   (new String(true)).charAt );
    1.58 +
    1.59 +new TestCase( SECTION,	"typeof new String(false)",	            "object",	        typeof new String(false) );
    1.60 +new TestCase( SECTION,	"var TESTSTRING = new String(false); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]",   eval("var TESTSTRING = new String(false); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
    1.61 +new TestCase( SECTION,  "(new String(false)).valueOf()",        "false",            (new String(false)).valueOf() );
    1.62 +new TestCase( SECTION,  "(new String(false)).charCodeAt",        String.prototype.charCodeAt,   (new String(false)).charCodeAt );
    1.63 +
    1.64 +new TestCase( SECTION,	"typeof new String(new Boolean(true))",	       "object",	        typeof new String(new Boolean(true)) );
    1.65 +new TestCase( SECTION,	"var TESTSTRING = new String(new Boolean(true)); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]",   eval("var TESTSTRING = new String(new Boolean(true)); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
    1.66 +new TestCase( SECTION,  "(new String(new Boolean(true))).valueOf()",   "true",              (new String(new Boolean(true))).valueOf() );
    1.67 +new TestCase( SECTION,  "(new String(new Boolean(true))).indexOf",   String.prototype.indexOf,    (new String(new Boolean(true))).indexOf );
    1.68 +
    1.69 +new TestCase( SECTION,	"typeof new String()",	                        "object",	        typeof new String() );
    1.70 +new TestCase( SECTION,	"var TESTSTRING = new String(); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]",   eval("var TESTSTRING = new String(); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
    1.71 +new TestCase( SECTION,  "(new String()).valueOf()",   '',                 (new String()).valueOf() );
    1.72 +new TestCase( SECTION,  "(new String()).lastIndexOf",   String.prototype.lastIndexOf,   (new String()).lastIndexOf );
    1.73 +
    1.74 +new TestCase( SECTION,	"typeof new String('')",	    "object",	        typeof new String('') );
    1.75 +new TestCase( SECTION,	"var TESTSTRING = new String(''); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]",   eval("var TESTSTRING = new String(''); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
    1.76 +new TestCase( SECTION,  "(new String('')).valueOf()",   '',                 (new String('')).valueOf() );
    1.77 +new TestCase( SECTION,  "(new String('')).split",   String.prototype.split,   (new String('')).split );
    1.78 +
    1.79 +test();

mercurial