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.1.js
     24     ECMA Section:   15.6.1 The Boolean Function
     25                     15.6.1.1 Boolean( value )
     26                     15.6.1.2 Boolean ()
     27     Description:    Boolean( value ) should return a Boolean value
     28                     not a Boolean object) computed by
     29                     Boolean.toBooleanValue( value)
     30 
     31                     15.6.1.2 Boolean() returns false
     32 
     33     Author:         christine (at) netscape.com
     34     Date:           27 jun 1997
     35 
     36 
     37     Data File Fields:
     38         VALUE       Argument passed to the Boolean function
     39         TYPE        typeof VALUE (not used, but helpful in understanding
     40                     the data file)
     41         E_RETURN    Expected return value of Boolean( VALUE )
     42 */
     43     var SECTION = "15.6.1";
     44     var VERSION = "ECMA_1";
     45     startTest();
     46     var TITLE   = "The Boolean constructor called as a function: Boolean( value ) and Boolean()";
     47 
     48     writeHeaderToLog( SECTION + " "+ TITLE);
     49 
     50     var testcases = getTestCases();
     51 
     52     test();
     53 
     54 function getTestCases() {
     55     var array = new Array();
     56     var item = 0;
     57 
     58     array[item++] = new TestCase( SECTION,   "Boolean(1)",         true,   Boolean(1) );
     59     array[item++] = new TestCase( SECTION,   "Boolean(0)",         false,  Boolean(0) );
     60     array[item++] = new TestCase( SECTION,   "Boolean(-1)",        true,   Boolean(-1) );
     61     array[item++] = new TestCase( SECTION,   "Boolean('1')",       true,   Boolean("1") );
     62     array[item++] = new TestCase( SECTION,   "Boolean('0')",       true,   Boolean("0") );
     63     array[item++] = new TestCase( SECTION,   "Boolean('-1')",      true,   Boolean("-1") );
     64     array[item++] = new TestCase( SECTION,   "Boolean(true)",      true,   Boolean(true) );
     65     array[item++] = new TestCase( SECTION,   "Boolean(false)",     false,  Boolean(false) );
     66 
     67     array[item++] = new TestCase( SECTION,   "Boolean('true')",    true,   Boolean("true") );
     68     array[item++] = new TestCase( SECTION,   "Boolean('false')",   true,   Boolean("false") );
     69     array[item++] = new TestCase( SECTION,   "Boolean(null)",      false,  Boolean(null) );
     70 
     71     array[item++] = new TestCase( SECTION,   "Boolean(-Infinity)", true,   Boolean(Number.NEGATIVE_INFINITY) );
     72     array[item++] = new TestCase( SECTION,   "Boolean(NaN)",       false,  Boolean(Number.NaN) );
     73     array[item++] = new TestCase( SECTION,   "Boolean(void(0))",   false,  Boolean( void(0) ) );
     74     array[item++] = new TestCase( SECTION,   "Boolean(x=0)",       false,  Boolean( x=0 ) );
     75     array[item++] = new TestCase( SECTION,   "Boolean(x=1)",       true,   Boolean( x=1 ) );
     76     array[item++] = new TestCase( SECTION,   "Boolean(x=false)",   false,  Boolean( x=false ) );
     77     array[item++] = new TestCase( SECTION,   "Boolean(x=true)",    true,   Boolean( x=true ) );
     78     array[item++] = new TestCase( SECTION,   "Boolean(x=null)",    false,  Boolean( x=null ) );
     79     array[item++] = new TestCase( SECTION,   "Boolean()",          false,  Boolean() );
     80 //    array[item++] = new TestCase( SECTION,   "Boolean(var someVar)",     false,  Boolean( someVar ) );
     81 
     82     return ( array );
     83 }
     84 function test() {
     85     for ( tc=0; tc < testcases.length; tc++ ) {
     86         testcases[tc].passed = writeTestCaseResult(
     87                             testcases[tc].expect,
     88                             testcases[tc].actual,
     89                             testcases[tc].description +" = "+
     90                             testcases[tc].actual );
     91 
     92         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
     93     }
     94     stopTest();
     95     return ( testcases );
     96 }
     97