Home | History | Annotate | Download | only in String
      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.5.5.1
     24     ECMA Section:       String.length
     25     Description:
     26 
     27     The number of characters in the String value represented by this String
     28     object.
     29 
     30     Once a String object is created, this property is unchanging. It has the
     31     attributes { DontEnum, DontDelete, ReadOnly }.
     32 
     33     Author:             christine (at) netscape.com
     34     Date:               12 november 1997
     35 */
     36 
     37     var SECTION = "15.5.5.1";
     38     var VERSION = "ECMA_1";
     39     startTest();
     40     var TITLE   = "String.length";
     41 
     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,
     52                                     "var s = new String(); s.length",
     53                                     0,
     54                                     eval("var s = new String(); s.length") );
     55 
     56     array[item++] = new TestCase(   SECTION,
     57                                     "var s = new String(); s.length = 10; s.length",
     58                                     0,
     59                                     eval("var s = new String(); s.length = 10; s.length") );
     60 
     61     array[item++] = new TestCase(   SECTION,
     62                                     "var s = new String(); var props = ''; for ( var p in s ) {  props += p; };  props",
     63                                     "",
     64                                     eval("var s = new String(); var props = ''; for ( var p in s ) {  props += p; };  props") );
     65 
     66     array[item++] = new TestCase(   SECTION,
     67                                     "var s = new String(); delete s.length",
     68                                     false,
     69                                     eval("var s = new String(); delete s.length") );
     70 
     71     array[item++] = new TestCase(   SECTION,
     72                                     "var s = new String('hello'); delete s.length; s.length",
     73                                     5,
     74                                     eval("var s = new String('hello'); delete s.length; s.length") );
     75     return array;
     76 
     77 }
     78 function test() {
     79     for ( tc=0; tc < testcases.length; tc++ ) {
     80         testcases[tc].passed = writeTestCaseResult(
     81                             testcases[tc].expect,
     82                             testcases[tc].actual,
     83                             testcases[tc].description +" = "+
     84                             testcases[tc].actual );
     85 
     86         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
     87     }
     88     stopTest();
     89     return ( testcases );
     90 }
     91