Home | History | Annotate | Download | only in Boolean
      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.6.4.2.js
     24     ECMA Section:       15.6.4.2-1 Boolean.prototype.toString()
     25     Description:        If this boolean value is true, then the string "true"
     26                         is returned; otherwise this boolean value must be false,
     27                         and the string "false" is returned.
     28 
     29                         The toString function is not generic; it generates
     30                         a runtime error if its this value is not a Boolean
     31                         object.  Therefore it cannot be transferred to other
     32                         kinds of objects for use as a method.
     33 
     34     Author:             christine (at) netscape.com
     35     Date:               june 27, 1997
     36 */
     37 
     38     var SECTION = "15.6.4.2-1";
     39     var VERSION = "ECMA_1";
     40     startTest();
     41     var TITLE   = "Boolean.prototype.toString()"
     42     writeHeaderToLog( SECTION + TITLE );
     43 
     44     var testcases = getTestCases();
     45     test();
     46 
     47 function getTestCases() {
     48     var array = new Array();
     49     var item = 0;
     50 
     51     array[item++] = new TestCase( SECTION,   "new Boolean(1)",       "true",   (new Boolean(1)).toString() );
     52     array[item++] = new TestCase( SECTION,   "new Boolean(0)",       "false",  (new Boolean(0)).toString() );
     53     array[item++] = new TestCase( SECTION,   "new Boolean(-1)",      "true",   (new Boolean(-1)).toString() );
     54     array[item++] = new TestCase( SECTION,   "new Boolean('1')",     "true",   (new Boolean("1")).toString() );
     55     array[item++] = new TestCase( SECTION,   "new Boolean('0')",     "true",   (new Boolean("0")).toString() );
     56     array[item++] = new TestCase( SECTION,   "new Boolean(true)",    "true",   (new Boolean(true)).toString() );
     57     array[item++] = new TestCase( SECTION,   "new Boolean(false)",   "false",  (new Boolean(false)).toString() );
     58     array[item++] = new TestCase( SECTION,   "new Boolean('true')",  "true",   (new Boolean('true')).toString() );
     59     array[item++] = new TestCase( SECTION,   "new Boolean('false')", "true",   (new Boolean('false')).toString() );
     60 
     61     array[item++] = new TestCase( SECTION,   "new Boolean('')",      "false",  (new Boolean('')).toString() );
     62     array[item++] = new TestCase( SECTION,   "new Boolean(null)",    "false",  (new Boolean(null)).toString() );
     63     array[item++] = new TestCase( SECTION,   "new Boolean(void(0))", "false",  (new Boolean(void(0))).toString() );
     64     array[item++] = new TestCase( SECTION,   "new Boolean(-Infinity)", "true", (new Boolean(Number.NEGATIVE_INFINITY)).toString() );
     65     array[item++] = new TestCase( SECTION,   "new Boolean(NaN)",     "false",  (new Boolean(Number.NaN)).toString() );
     66     array[item++] = new TestCase( SECTION,   "new Boolean()",        "false",  (new Boolean()).toString() );
     67     array[item++] = new TestCase( SECTION,   "new Boolean(x=1)",     "true",   (new Boolean(x=1)).toString() );
     68     array[item++] = new TestCase( SECTION,   "new Boolean(x=0)",     "false",  (new Boolean(x=0)).toString() );
     69     array[item++] = new TestCase( SECTION,   "new Boolean(x=false)", "false",  (new Boolean(x=false)).toString() );
     70     array[item++] = new TestCase( SECTION,   "new Boolean(x=true)",  "true",   (new Boolean(x=true)).toString() );
     71     array[item++] = new TestCase( SECTION,   "new Boolean(x=null)",  "false",  (new Boolean(x=null)).toString() );
     72     array[item++] = new TestCase( SECTION,   "new Boolean(x='')",    "false",  (new Boolean(x="")).toString() );
     73     array[item++] = new TestCase( SECTION,   "new Boolean(x=' ')",   "true",   (new Boolean(x=" ")).toString() );
     74 
     75     array[item++] = new TestCase( SECTION,   "new Boolean(new MyObject(true))",     "true",   (new Boolean(new MyObject(true))).toString() );
     76     array[item++] = new TestCase( SECTION,   "new Boolean(new MyObject(false))",    "true",   (new Boolean(new MyObject(false))).toString() );
     77 
     78     return ( array );
     79 }
     80 function test() {
     81     for ( tc=0; tc < testcases.length; tc++ ) {
     82         testcases[tc].passed = writeTestCaseResult(
     83                             testcases[tc].expect,
     84                             testcases[tc].actual,
     85                             testcases[tc].description +" = "+
     86                             testcases[tc].actual );
     87 
     88         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
     89     }
     90     stopTest();
     91     return ( testcases );
     92 }
     93 function MyObject( value ) {
     94     this.value = value;
     95     this.valueOf = new Function( "return this.value" );
     96     return this;
     97 }