js/src/tests/ecma/Number/15.7.2.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/Number/15.7.2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,134 @@
     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.7.2.js
    1.12 +   ECMA Section:       15.7.2 The Number Constructor
    1.13 +   15.7.2.1
    1.14 +   15.7.2.2
    1.15 +
    1.16 +   Description:        15.7.2 When Number is called as part of a new
    1.17 +   expression, it is a constructor:  it initializes
    1.18 +   the newly created object.
    1.19 +
    1.20 +   15.7.2.1 The [[Prototype]] property of the newly
    1.21 +   constructed object is set to othe original Number
    1.22 +   prototype object, the one that is the initial value
    1.23 +   of Number.prototype(0).  The [[Class]] property is
    1.24 +   set to "Number".  The [[Value]] property of the
    1.25 +   newly constructed object is set to ToNumber(value)
    1.26 +
    1.27 +   15.7.2.2 new Number().  same as in 15.7.2.1, except
    1.28 +   the [[Value]] property is set to +0.
    1.29 +
    1.30 +   need to add more test cases.  see the testcases for
    1.31 +   TypeConversion ToNumber.
    1.32 +
    1.33 +   Author:             christine@netscape.com
    1.34 +   Date:               29 september 1997
    1.35 +*/
    1.36 +
    1.37 +var SECTION = "15.7.2";
    1.38 +var VERSION = "ECMA_1";
    1.39 +startTest();
    1.40 +var TITLE   = "The Number Constructor";
    1.41 +
    1.42 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.43 +
    1.44 +//  To verify that the object's prototype is the Number.prototype, check to see if the object's
    1.45 +//  constructor property is the same as Number.prototype.constructor.
    1.46 +
    1.47 +new TestCase(SECTION, "(new Number()).constructor",      Number.prototype.constructor,   (new Number()).constructor );
    1.48 +
    1.49 +new TestCase(SECTION, "typeof (new Number())",         "object",           typeof (new Number()) );
    1.50 +new TestCase(SECTION,  "(new Number()).valueOf()",     0,                   (new Number()).valueOf() );
    1.51 +new TestCase(SECTION,
    1.52 +	     "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
    1.53 +	     "[object Number]",
    1.54 +	     eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
    1.55 +
    1.56 +new TestCase(SECTION, "(new Number(0)).constructor",     Number.prototype.constructor,    (new Number(0)).constructor );
    1.57 +new TestCase(SECTION, "typeof (new Number(0))",         "object",           typeof (new Number(0)) );
    1.58 +new TestCase(SECTION,  "(new Number(0)).valueOf()",     0,                   (new Number(0)).valueOf() );
    1.59 +new TestCase(SECTION,
    1.60 +	     "NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()",
    1.61 +	     "[object Number]",
    1.62 +	     eval("NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
    1.63 +
    1.64 +new TestCase(SECTION, "(new Number(1)).constructor",     Number.prototype.constructor,    (new Number(1)).constructor );
    1.65 +new TestCase(SECTION, "typeof (new Number(1))",         "object",           typeof (new Number(1)) );
    1.66 +new TestCase(SECTION,  "(new Number(1)).valueOf()",     1,                   (new Number(1)).valueOf() );
    1.67 +new TestCase(SECTION,
    1.68 +	     "NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
    1.69 +	     "[object Number]",
    1.70 +	     eval("NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
    1.71 +
    1.72 +new TestCase(SECTION, "(new Number(-1)).constructor",     Number.prototype.constructor,    (new Number(-1)).constructor );
    1.73 +new TestCase(SECTION, "typeof (new Number(-1))",         "object",           typeof (new Number(-1)) );
    1.74 +new TestCase(SECTION,  "(new Number(-1)).valueOf()",     -1,                   (new Number(-1)).valueOf() );
    1.75 +new TestCase(SECTION,
    1.76 +	     "NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
    1.77 +	     "[object Number]",
    1.78 +	     eval("NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
    1.79 +
    1.80 +new TestCase(SECTION, "(new Number(Number.NaN)).constructor",     Number.prototype.constructor,    (new Number(Number.NaN)).constructor );
    1.81 +new TestCase(SECTION, "typeof (new Number(Number.NaN))",         "object",           typeof (new Number(Number.NaN)) );
    1.82 +new TestCase(SECTION,  "(new Number(Number.NaN)).valueOf()",     Number.NaN,                   (new Number(Number.NaN)).valueOf() );
    1.83 +new TestCase(SECTION,
    1.84 +	     "NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()",
    1.85 +	     "[object Number]",
    1.86 +	     eval("NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
    1.87 +
    1.88 +new TestCase(SECTION, "(new Number('string')).constructor",     Number.prototype.constructor,    (new Number('string')).constructor );
    1.89 +new TestCase(SECTION, "typeof (new Number('string'))",         "object",           typeof (new Number('string')) );
    1.90 +new TestCase(SECTION,  "(new Number('string')).valueOf()",     Number.NaN,                   (new Number('string')).valueOf() );
    1.91 +new TestCase(SECTION,
    1.92 +	     "NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()",
    1.93 +	     "[object Number]",
    1.94 +	     eval("NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
    1.95 +
    1.96 +new TestCase(SECTION, "(new Number(new String())).constructor",     Number.prototype.constructor,    (new Number(new String())).constructor );
    1.97 +new TestCase(SECTION, "typeof (new Number(new String()))",         "object",           typeof (new Number(new String())) );
    1.98 +new TestCase(SECTION,  "(new Number(new String())).valueOf()",     0,                   (new Number(new String())).valueOf() );
    1.99 +new TestCase(SECTION,
   1.100 +	     "NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()",
   1.101 +	     "[object Number]",
   1.102 +	     eval("NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()") );
   1.103 +
   1.104 +new TestCase(SECTION, "(new Number('')).constructor",     Number.prototype.constructor,    (new Number('')).constructor );
   1.105 +new TestCase(SECTION, "typeof (new Number(''))",         "object",           typeof (new Number('')) );
   1.106 +new TestCase(SECTION,  "(new Number('')).valueOf()",     0,                   (new Number('')).valueOf() );
   1.107 +new TestCase(SECTION,
   1.108 +	     "NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()",
   1.109 +	     "[object Number]",
   1.110 +	     eval("NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
   1.111 +
   1.112 +new TestCase(SECTION, "(new Number(Number.POSITIVE_INFINITY)).constructor",     Number.prototype.constructor,    (new Number(Number.POSITIVE_INFINITY)).constructor );
   1.113 +new TestCase(SECTION, "typeof (new Number(Number.POSITIVE_INFINITY))",         "object",           typeof (new Number(Number.POSITIVE_INFINITY)) );
   1.114 +new TestCase(SECTION,  "(new Number(Number.POSITIVE_INFINITY)).valueOf()",     Number.POSITIVE_INFINITY,    (new Number(Number.POSITIVE_INFINITY)).valueOf() );
   1.115 +new TestCase(SECTION,
   1.116 +	     "NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()",
   1.117 +	     "[object Number]",
   1.118 +	     eval("NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
   1.119 +
   1.120 +new TestCase(SECTION, "(new Number(Number.NEGATIVE_INFINITY)).constructor",     Number.prototype.constructor,    (new Number(Number.NEGATIVE_INFINITY)).constructor );
   1.121 +new TestCase(SECTION, "typeof (new Number(Number.NEGATIVE_INFINITY))",         "object",           typeof (new Number(Number.NEGATIVE_INFINITY)) );
   1.122 +new TestCase(SECTION,  "(new Number(Number.NEGATIVE_INFINITY)).valueOf()",     Number.NEGATIVE_INFINITY,                   (new Number(Number.NEGATIVE_INFINITY)).valueOf() );
   1.123 +new TestCase(SECTION,
   1.124 +	     "NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()",
   1.125 +	     "[object Number]",
   1.126 +	     eval("NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
   1.127 +
   1.128 +
   1.129 +new TestCase(SECTION, "(new Number()).constructor",     Number.prototype.constructor,    (new Number()).constructor );
   1.130 +new TestCase(SECTION, "typeof (new Number())",         "object",           typeof (new Number()) );
   1.131 +new TestCase(SECTION,  "(new Number()).valueOf()",     0,                   (new Number()).valueOf() );
   1.132 +new TestCase(SECTION,
   1.133 +	     "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
   1.134 +	     "[object Number]",
   1.135 +	     eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
   1.136 +
   1.137 +test();

mercurial