Home | History | Annotate | Download | only in Array
      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.4.1.js
     24     ECMA Section:       15.4.1 The Array Constructor Called as a Function
     25 
     26     Description:        When Array is called as a function rather than as a
     27                         constructor, it creates and initializes a new array
     28                         object.  Thus, the function call Array(...) is
     29                         equivalent to the object creationi new Array(...) with
     30                         the same arguments.
     31 
     32     Author:             christine (at) netscape.com
     33     Date:               7 october 1997
     34 */
     35 
     36     var SECTION = "15.4.1";
     37     var VERSION = "ECMA_1";
     38     startTest();
     39     var TITLE   = "The Array Constructor Called as a Function";
     40 
     41     writeHeaderToLog( SECTION + " "+ TITLE);
     42 
     43     var testcases = getTestCases();
     44     test();
     45 
     46 function getTestCases() {
     47     var array = new Array();
     48     var item = 0;
     49 
     50     array[item++] = new TestCase(   SECTION,
     51                                     "Array() +''",
     52                                     "",
     53                                     Array() +"" );
     54 
     55     array[item++] = new TestCase(   SECTION,
     56                                     "typeof Array()",
     57                                     "object",
     58                                     typeof Array() );
     59 
     60     array[item++] = new TestCase(   SECTION,
     61                                     "var arr = Array(); arr.getClass = Object.prototype.toString; arr.getClass()",
     62                                     "[object Array]",
     63                                     eval("var arr = Array(); arr.getClass = Object.prototype.toString; arr.getClass()") );
     64 
     65     array[item++] = new TestCase(   SECTION,
     66                                     "var arr = Array(); arr.toString == Array.prototype.toString",
     67                                     true,
     68                                     eval("var arr = Array(); arr.toString == Array.prototype.toString") );
     69 
     70     array[item++] = new TestCase(   SECTION,
     71                                     "Array().length",
     72                                     0,
     73                                     Array().length );
     74 
     75 
     76     array[item++] = new TestCase(   SECTION,
     77                                     "Array(1,2,3) +''",
     78                                     "1,2,3",
     79                                     Array(1,2,3) +"" );
     80 
     81     array[item++] = new TestCase(   SECTION,
     82                                     "typeof Array(1,2,3)",
     83                                     "object",
     84                                     typeof Array(1,2,3) );
     85 
     86     array[item++] = new TestCase(   SECTION,
     87                                     "var arr = Array(1,2,3); arr.getClass = Object.prototype.toString; arr.getClass()",
     88                                     "[object Array]",
     89                                     eval("var arr = Array(1,2,3); arr.getClass = Object.prototype.toString; arr.getClass()") );
     90 
     91     array[item++] = new TestCase(   SECTION,
     92                                     "var arr = Array(1,2,3); arr.toString == Array.prototype.toString",
     93                                     true,
     94                                     eval("var arr = Array(1,2,3); arr.toString == Array.prototype.toString") );
     95 
     96     array[item++] = new TestCase(   SECTION,
     97                                     "Array(1,2,3).length",
     98                                     3,
     99                                     Array(1,2,3).length );
    100 
    101     array[item++] = new TestCase(   SECTION,
    102                                     "typeof Array(12345)",
    103                                     "object",
    104                                     typeof Array(12345) );
    105 
    106     array[item++] = new TestCase(   SECTION,
    107                                     "var arr = Array(12345); arr.getClass = Object.prototype.toString; arr.getClass()",
    108                                     "[object Array]",
    109                                     eval("var arr = Array(12345); arr.getClass = Object.prototype.toString; arr.getClass()") );
    110 
    111     array[item++] = new TestCase(   SECTION,
    112                                     "var arr = Array(1,2,3,4,5); arr.toString == Array.prototype.toString",
    113                                     true,
    114                                     eval("var arr = Array(1,2,3,4,5); arr.toString == Array.prototype.toString") );
    115 
    116     array[item++] = new TestCase(   SECTION,
    117                                     "Array(12345).length",
    118                                     12345,
    119                                     Array(12345).length );
    120 
    121     return ( array );
    122 }
    123 function test() {
    124     for (tc=0 ; tc < testcases.length; tc++ ) {
    125         testcases[tc].passed = writeTestCaseResult(
    126                             testcases[tc].expect,
    127                             testcases[tc].actual,
    128                             testcases[tc].description +" = "+ testcases[tc].actual );
    129         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
    130     }
    131     stopTest();
    132     return ( testcases );
    133 }
    134