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:          tostring_1.js
     24     ECMA Section:       Array.toString()
     25     Description:
     26 
     27     This checks the ToString value of Array objects under JavaScript 1.2.
     28 
     29     Author:             christine (at) netscape.com
     30     Date:               12 november 1997
     31 */
     32 
     33     var SECTION = "JS1_2";
     34     var VERSION = "JS1_2";
     35     startTest();
     36     var TITLE   = "Array.toString()";
     37 
     38     writeHeaderToLog( SECTION + " "+ TITLE);
     39 
     40     var testcases = new Array();
     41 
     42     var a = new Array();
     43 
     44     var VERSION = 0;
     45 
     46     /* This test assumes that if version() exists, it can set the JavaScript
     47      * interpreter to an arbitrary version. To prevent unhandled exceptions in
     48      * other tests, jsc implements version() as a stub function, but
     49      * JavaScriptCore doesn't support setting the JavaScript engine's version.
     50 
     51      * Commenting out the following lines forces the test to expect JavaScript
     52      * 1.5 results.
     53 
     54      * If JavaScriptCore changes to support versioning, this test should split
     55      * into a 1.2 test in js1_2/ and a 1.5 test in js1_5/.
     56      */
     57 
     58     /*
     59     if ( typeof version == "function" ) {
     60         version(120);
     61         VERSION = "120";
     62     } else {
     63         function version() { return 0; };
     64     }
     65     */
     66 
     67     testcases[tc++] = new TestCase ( SECTION,
     68                         "var a = new Array(); a.toString()",
     69                         ( VERSION == "120" ? "[]" : "" ),
     70                         a.toString() );
     71 
     72     a[0] = void 0;
     73 
     74     testcases[tc++] = new TestCase ( SECTION,
     75                         "a[0] = void 0; a.toString()",
     76                         ( VERSION == "120" ? "[, ]" : "" ),
     77                         a.toString() );
     78 
     79 
     80     testcases[tc++] = new TestCase( SECTION,
     81                         "a.length",
     82                         1,
     83                         a.length );
     84 
     85     a[1] = void 0;
     86 
     87     testcases[tc++] = new TestCase( SECTION,
     88                         "a[1] = void 0; a.toString()",
     89                         ( VERSION == "120" ? "[, , ]" : ","  ),
     90                         a.toString() );
     91 
     92     a[1] = "hi";
     93 
     94     testcases[tc++] = new TestCase( SECTION,
     95                         "a[1] = \"hi\"; a.toString()",
     96                         ( VERSION == "120" ? "[, \"hi\"]" : ",hi" ),
     97                         a.toString() );
     98 
     99     a[2] = void 0;
    100 
    101     testcases[tc++] = new TestCase( SECTION,
    102                         "a[2] = void 0; a.toString()",
    103                         ( VERSION == "120" ?"[, \"hi\", , ]":",hi,"),
    104                         a.toString() );
    105 
    106     var b = new Array(1000);
    107     var bstring = "";
    108     for ( blen=0; blen<999; blen++) {
    109         bstring += ",";
    110     }
    111 
    112 
    113     testcases[tc++] = new TestCase ( SECTION,
    114                         "var b = new Array(1000); b.toString()",
    115                         ( VERSION == "120" ? "[1000]" : bstring ),
    116                         b.toString() );
    117 
    118 
    119     testcases[tc++] = new TestCase( SECTION,
    120                         "b.length",
    121                         ( VERSION == "120" ? 1 : 1000 ),
    122                         b.length );
    123 
    124     test();
    125 
    126 function test() {
    127     for ( tc=0; tc < testcases.length; tc++ ) {
    128         testcases[tc].passed = writeTestCaseResult(
    129                             testcases[tc].expect,
    130                             testcases[tc].actual,
    131                             testcases[tc].description +" = "+
    132                             testcases[tc].actual );
    133 
    134         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
    135     }
    136     stopTest();
    137     return ( testcases );
    138 }
    139