1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/LexicalConventions/lexical-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/* 1.11 + * Date: 26 November 2000 1.12 + * 1.13 + *SUMMARY: Testing numeric literals that begin with 0. 1.14 + *This test arose from Bugzilla bug 49233. 1.15 + *The best explanation is from jsscan.c: 1.16 + * 1.17 + * "We permit 08 and 09 as decimal numbers, which makes 1.18 + * our behaviour a superset of the ECMA numeric grammar. 1.19 + * We might not always be so permissive, so we warn about it." 1.20 + * 1.21 + *Thus an expression 010 will evaluate, as always, as an octal (to 8). 1.22 + *However, 018 will evaluate as a decimal, to 18. Even though the 1.23 + *user began the expression as an octal, he later used a non-octal 1.24 + *digit. We forgive this and assume he intended a decimal. If the 1.25 + *JavaScript "strict" option is set though, we will give a warning. 1.26 + */ 1.27 + 1.28 +//------------------------------------------------------------------------------------------------- 1.29 +var BUGNUMBER = '49233'; 1.30 +var summary = 'Testing numeric literals that begin with 0'; 1.31 +var statprefix = 'Testing '; 1.32 +var quote = "'"; 1.33 +var asString = new Array(); 1.34 +var actual = new Array(); 1.35 +var expect = new Array(); 1.36 + 1.37 + 1.38 + asString[0]='01' 1.39 + actual[0]=01 1.40 + expect[0]=1 1.41 + 1.42 + asString[1]='07' 1.43 + actual[1]=07 1.44 + expect[1]=7 1.45 + 1.46 + asString[2]='08' 1.47 + actual[2]=08 1.48 + expect[2]=8 1.49 + 1.50 + asString[3]='09' 1.51 + actual[3]=09 1.52 + expect[3]=9 1.53 + 1.54 + asString[4]='010' 1.55 + actual[4]=010 1.56 + expect[4]=8 1.57 + 1.58 + asString[5]='017' 1.59 + actual[5]=017 1.60 + expect[5]=15 1.61 + 1.62 + asString[6]='018' 1.63 + actual[6]=018 1.64 + expect[6]=18 1.65 + 1.66 + asString[7]='019' 1.67 + actual[7]=019 1.68 + expect[7]=19 1.69 + 1.70 + asString[8]='079' 1.71 + actual[8]=079 1.72 + expect[8]=79 1.73 + 1.74 + asString[9]='0079' 1.75 + actual[9]=0079 1.76 + expect[9]=79 1.77 + 1.78 + asString[10]='099' 1.79 + actual[10]=099 1.80 + expect[10]=99 1.81 + 1.82 + asString[11]='0099' 1.83 + actual[11]=0099 1.84 + expect[11]=99 1.85 + 1.86 + asString[12]='000000000077' 1.87 + actual[12]=000000000077 1.88 + expect[12]=63 1.89 + 1.90 + asString[13]='000000000078' 1.91 + actual[13]=000000000078 1.92 + expect[13]=78 1.93 + 1.94 + asString[14]='0000000000770000' 1.95 + actual[14]=0000000000770000 1.96 + expect[14]=258048 1.97 + 1.98 + asString[15]='0000000000780000' 1.99 + actual[15]=0000000000780000 1.100 + expect[15]=780000 1.101 + 1.102 + asString[16]='0765432198' 1.103 + actual[16]=0765432198 1.104 + expect[16]=765432198 1.105 + 1.106 + asString[17]='00076543219800' 1.107 + actual[17]=00076543219800 1.108 + expect[17]=76543219800 1.109 + 1.110 + asString[18]='0000001001007' 1.111 + actual[18]=0000001001007 1.112 + expect[18]=262663 1.113 + 1.114 + asString[19]='0000001001009' 1.115 + actual[19]=0000001001009 1.116 + expect[19]=1001009 1.117 + 1.118 + asString[20]='070' 1.119 + actual[20]=070 1.120 + expect[20]=56 1.121 + 1.122 + asString[21]='080' 1.123 + actual[21]=080 1.124 + expect[21]=80 1.125 + 1.126 + 1.127 + 1.128 +//------------------------------------------------------------------------------------------------- 1.129 + test(); 1.130 +//------------------------------------------------------------------------------------------------- 1.131 + 1.132 + 1.133 +function showStatus(msg) 1.134 +{ 1.135 + return (statprefix + quote + msg + quote); 1.136 +} 1.137 + 1.138 + 1.139 +function test() 1.140 +{ 1.141 + enterFunc ('test'); 1.142 + printBugNumber(BUGNUMBER); 1.143 + printStatus (summary); 1.144 + 1.145 + 1.146 + for (i=0; i !=asString.length; i++) 1.147 + { 1.148 + reportCompare (expect[i], actual[i], showStatus(asString[i])); 1.149 + } 1.150 + 1.151 + exitFunc ('test'); 1.152 +}