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: 9.3.1-2.js 24 ECMA Section: 9.3 Type Conversion: ToNumber 25 Description: rules for converting an argument to a number. 26 see 9.3.1 for cases for converting strings to numbers. 27 special cases: 28 undefined NaN 29 Null NaN 30 Boolean 1 if true; +0 if false 31 Number the argument ( no conversion ) 32 String see test 9.3.1 33 Object see test 9.3-1 34 35 This tests special cases of ToNumber(string) that are 36 not covered in 9.3.1-1.js. 37 38 Author: christine (at) netscape.com 39 Date: 10 july 1997 40 41 */ 42 var SECTION = "9.3.1-2"; 43 var VERSION = "ECMA_1"; 44 startTest(); 45 var TITLE = "ToNumber applied to the String type"; 46 47 writeHeaderToLog( SECTION + " "+ TITLE); 48 49 var testcases = getTestCases(); 50 test(); 51 52 53 function test() { 54 for ( tc=0; tc < testcases.length; tc++ ) { 55 testcases[tc].passed = writeTestCaseResult( 56 testcases[tc].expect, 57 testcases[tc].actual, 58 testcases[tc].description +" = "+ 59 testcases[tc].actual ); 60 61 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 62 } 63 stopTest(); 64 return ( testcases ); 65 } 66 function getTestCases() { 67 var array = new Array(); 68 var item = 0; 69 70 // A StringNumericLiteral may not use octal notation 71 72 array[item++] = new TestCase( SECTION, "Number(00)", 0, Number("00")); 73 array[item++] = new TestCase( SECTION, "Number(01)", 1, Number("01")); 74 array[item++] = new TestCase( SECTION, "Number(02)", 2, Number("02")); 75 array[item++] = new TestCase( SECTION, "Number(03)", 3, Number("03")); 76 array[item++] = new TestCase( SECTION, "Number(04)", 4, Number("04")); 77 array[item++] = new TestCase( SECTION, "Number(05)", 5, Number("05")); 78 array[item++] = new TestCase( SECTION, "Number(06)", 6, Number("06")); 79 array[item++] = new TestCase( SECTION, "Number(07)", 7, Number("07")); 80 array[item++] = new TestCase( SECTION, "Number(010)", 10, Number("010")); 81 array[item++] = new TestCase( SECTION, "Number(011)", 11, Number("011")); 82 83 // A StringNumericLIteral may have any number of leading 0 digits 84 85 array[item++] = new TestCase( SECTION, "Number(001)", 1, Number("001")); 86 array[item++] = new TestCase( SECTION, "Number(0001)", 1, Number("0001")); 87 88 return ( array ); 89 } 90