michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /* michael@0: * Date: 26 November 2000 michael@0: * michael@0: *SUMMARY: Testing numeric literals that begin with 0. michael@0: *This test arose from Bugzilla bug 49233. michael@0: *The best explanation is from jsscan.c: michael@0: * michael@0: * "We permit 08 and 09 as decimal numbers, which makes michael@0: * our behaviour a superset of the ECMA numeric grammar. michael@0: * We might not always be so permissive, so we warn about it." michael@0: * michael@0: *Thus an expression 010 will evaluate, as always, as an octal (to 8). michael@0: *However, 018 will evaluate as a decimal, to 18. Even though the michael@0: *user began the expression as an octal, he later used a non-octal michael@0: *digit. We forgive this and assume he intended a decimal. If the michael@0: *JavaScript "strict" option is set though, we will give a warning. michael@0: */ michael@0: michael@0: //------------------------------------------------------------------------------------------------- michael@0: var BUGNUMBER = '49233'; michael@0: var summary = 'Testing numeric literals that begin with 0'; michael@0: var statprefix = 'Testing '; michael@0: var quote = "'"; michael@0: var asString = new Array(); michael@0: var actual = new Array(); michael@0: var expect = new Array(); michael@0: michael@0: michael@0: asString[0]='01' michael@0: actual[0]=01 michael@0: expect[0]=1 michael@0: michael@0: asString[1]='07' michael@0: actual[1]=07 michael@0: expect[1]=7 michael@0: michael@0: asString[2]='08' michael@0: actual[2]=08 michael@0: expect[2]=8 michael@0: michael@0: asString[3]='09' michael@0: actual[3]=09 michael@0: expect[3]=9 michael@0: michael@0: asString[4]='010' michael@0: actual[4]=010 michael@0: expect[4]=8 michael@0: michael@0: asString[5]='017' michael@0: actual[5]=017 michael@0: expect[5]=15 michael@0: michael@0: asString[6]='018' michael@0: actual[6]=018 michael@0: expect[6]=18 michael@0: michael@0: asString[7]='019' michael@0: actual[7]=019 michael@0: expect[7]=19 michael@0: michael@0: asString[8]='079' michael@0: actual[8]=079 michael@0: expect[8]=79 michael@0: michael@0: asString[9]='0079' michael@0: actual[9]=0079 michael@0: expect[9]=79 michael@0: michael@0: asString[10]='099' michael@0: actual[10]=099 michael@0: expect[10]=99 michael@0: michael@0: asString[11]='0099' michael@0: actual[11]=0099 michael@0: expect[11]=99 michael@0: michael@0: asString[12]='000000000077' michael@0: actual[12]=000000000077 michael@0: expect[12]=63 michael@0: michael@0: asString[13]='000000000078' michael@0: actual[13]=000000000078 michael@0: expect[13]=78 michael@0: michael@0: asString[14]='0000000000770000' michael@0: actual[14]=0000000000770000 michael@0: expect[14]=258048 michael@0: michael@0: asString[15]='0000000000780000' michael@0: actual[15]=0000000000780000 michael@0: expect[15]=780000 michael@0: michael@0: asString[16]='0765432198' michael@0: actual[16]=0765432198 michael@0: expect[16]=765432198 michael@0: michael@0: asString[17]='00076543219800' michael@0: actual[17]=00076543219800 michael@0: expect[17]=76543219800 michael@0: michael@0: asString[18]='0000001001007' michael@0: actual[18]=0000001001007 michael@0: expect[18]=262663 michael@0: michael@0: asString[19]='0000001001009' michael@0: actual[19]=0000001001009 michael@0: expect[19]=1001009 michael@0: michael@0: asString[20]='070' michael@0: actual[20]=070 michael@0: expect[20]=56 michael@0: michael@0: asString[21]='080' michael@0: actual[21]=080 michael@0: expect[21]=80 michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------------------------------- michael@0: test(); michael@0: //------------------------------------------------------------------------------------------------- michael@0: michael@0: michael@0: function showStatus(msg) michael@0: { michael@0: return (statprefix + quote + msg + quote); michael@0: } michael@0: michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: michael@0: for (i=0; i !=asString.length; i++) michael@0: { michael@0: reportCompare (expect[i], actual[i], showStatus(asString[i])); michael@0: } michael@0: michael@0: exitFunc ('test'); michael@0: }