| 1 |
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ |
| 2 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 |
|
| 6 |
|
| 7 |
/* |
| 8 |
* Date: 26 November 2000 |
| 9 |
* |
| 10 |
*SUMMARY: Testing numeric literals that begin with 0. |
| 11 |
*This test arose from Bugzilla bug 49233. |
| 12 |
*The best explanation is from jsscan.c: |
| 13 |
* |
| 14 |
* "We permit 08 and 09 as decimal numbers, which makes |
| 15 |
* our behaviour a superset of the ECMA numeric grammar. |
| 16 |
* We might not always be so permissive, so we warn about it." |
| 17 |
* |
| 18 |
*Thus an expression 010 will evaluate, as always, as an octal (to 8). |
| 19 |
*However, 018 will evaluate as a decimal, to 18. Even though the |
| 20 |
*user began the expression as an octal, he later used a non-octal |
| 21 |
*digit. We forgive this and assume he intended a decimal. If the |
| 22 |
*JavaScript "strict" option is set though, we will give a warning. |
| 23 |
*/ |
| 24 |
|
| 25 |
//------------------------------------------------------------------------------------------------- |
| 26 |
var BUGNUMBER = '49233'; |
| 27 |
var summary = 'Testing numeric literals that begin with 0'; |
| 28 |
var statprefix = 'Testing '; |
| 29 |
var quote = "'"; |
| 30 |
var asString = new Array(); |
| 31 |
var actual = new Array(); |
| 32 |
var expect = new Array(); |
| 33 |
|
| 34 |
|
| 35 |
asString[0]='01' |
| 36 |
actual[0]=01 |
| 37 |
expect[0]=1 |
| 38 |
|
| 39 |
asString[1]='07' |
| 40 |
actual[1]=07 |
| 41 |
expect[1]=7 |
| 42 |
|
| 43 |
asString[2]='08' |
| 44 |
actual[2]=08 |
| 45 |
expect[2]=8 |
| 46 |
|
| 47 |
asString[3]='09' |
| 48 |
actual[3]=09 |
| 49 |
expect[3]=9 |
| 50 |
|
| 51 |
asString[4]='010' |
| 52 |
actual[4]=010 |
| 53 |
expect[4]=8 |
| 54 |
|
| 55 |
asString[5]='017' |
| 56 |
actual[5]=017 |
| 57 |
expect[5]=15 |
| 58 |
|
| 59 |
asString[6]='018' |
| 60 |
actual[6]=018 |
| 61 |
expect[6]=18 |
| 62 |
|
| 63 |
asString[7]='019' |
| 64 |
actual[7]=019 |
| 65 |
expect[7]=19 |
| 66 |
|
| 67 |
asString[8]='079' |
| 68 |
actual[8]=079 |
| 69 |
expect[8]=79 |
| 70 |
|
| 71 |
asString[9]='0079' |
| 72 |
actual[9]=0079 |
| 73 |
expect[9]=79 |
| 74 |
|
| 75 |
asString[10]='099' |
| 76 |
actual[10]=099 |
| 77 |
expect[10]=99 |
| 78 |
|
| 79 |
asString[11]='0099' |
| 80 |
actual[11]=0099 |
| 81 |
expect[11]=99 |
| 82 |
|
| 83 |
asString[12]='000000000077' |
| 84 |
actual[12]=000000000077 |
| 85 |
expect[12]=63 |
| 86 |
|
| 87 |
asString[13]='000000000078' |
| 88 |
actual[13]=000000000078 |
| 89 |
expect[13]=78 |
| 90 |
|
| 91 |
asString[14]='0000000000770000' |
| 92 |
actual[14]=0000000000770000 |
| 93 |
expect[14]=258048 |
| 94 |
|
| 95 |
asString[15]='0000000000780000' |
| 96 |
actual[15]=0000000000780000 |
| 97 |
expect[15]=780000 |
| 98 |
|
| 99 |
asString[16]='0765432198' |
| 100 |
actual[16]=0765432198 |
| 101 |
expect[16]=765432198 |
| 102 |
|
| 103 |
asString[17]='00076543219800' |
| 104 |
actual[17]=00076543219800 |
| 105 |
expect[17]=76543219800 |
| 106 |
|
| 107 |
asString[18]='0000001001007' |
| 108 |
actual[18]=0000001001007 |
| 109 |
expect[18]=262663 |
| 110 |
|
| 111 |
asString[19]='0000001001009' |
| 112 |
actual[19]=0000001001009 |
| 113 |
expect[19]=1001009 |
| 114 |
|
| 115 |
asString[20]='070' |
| 116 |
actual[20]=070 |
| 117 |
expect[20]=56 |
| 118 |
|
| 119 |
asString[21]='080' |
| 120 |
actual[21]=080 |
| 121 |
expect[21]=80 |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
//------------------------------------------------------------------------------------------------- |
| 126 |
test(); |
| 127 |
//------------------------------------------------------------------------------------------------- |
| 128 |
|
| 129 |
|
| 130 |
function showStatus(msg) |
| 131 |
{ |
| 132 |
return (statprefix + quote + msg + quote); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
function test() |
| 137 |
{ |
| 138 |
printBugNumber(BUGNUMBER); |
| 139 |
printStatus (summary); |
| 140 |
|
| 141 |
|
| 142 |
for (i=0; i !=asString.length; i++) |
| 143 |
{ |
| 144 |
reportCompare (expect[i], actual[i], showStatus(asString[i])); |
| 145 |
} |
| 146 |
} |