Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_5 / LexicalConventions / lexical-001.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is mozilla.org code.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   pschwartau@netscape.com
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 /*
41  * Date: 26 November 2000
42  *
43  *SUMMARY: Testing numeric literals that begin with 0.
44  *This test arose from Bugzilla bug 49233.
45  *The best explanation is from jsscan.c:               
46  *
47  *     "We permit 08 and 09 as decimal numbers, which makes
48  *     our behaviour a superset of the ECMA numeric grammar. 
49  *     We might not always be so permissive, so we warn about it."
50  *
51  *Thus an expression 010 will evaluate, as always, as an octal (to 8).
52  *However, 018 will evaluate as a decimal, to 18. Even though the
53  *user began the expression as an octal, he later used a non-octal
54  *digit. We forgive this and assume he intended a decimal. If the
55  *JavaScript "strict" option is set though, we will give a warning.
56  */
57
58 //-------------------------------------------------------------------------------------------------
59 var BUGNUMBER = '49233';
60 var summary = 'Testing numeric literals that begin with 0';
61 var statprefix = 'Testing ';
62 var quote = "'";
63 var status = new Array();
64 var actual = new Array();
65 var expect = new Array();
66
67
68 status[0]=showStatus('01')
69   actual[0]=01
70   expect[0]=1
71
72   status[1]=showStatus('07')
73   actual[1]=07
74   expect[1]=7
75
76   status[2]=showStatus('08')
77   actual[2]=08
78   expect[2]=8
79
80   status[3]=showStatus('09')
81   actual[3]=09
82   expect[3]=9
83
84   status[4]=showStatus('010')
85   actual[4]=010
86   expect[4]=8
87
88   status[5]=showStatus('017')
89   actual[5]=017
90   expect[5]=15
91
92   status[6]=showStatus('018')
93   actual[6]=018
94   expect[6]=18
95
96   status[7]=showStatus('019')
97   actual[7]=019
98   expect[7]=19
99
100   status[8]=showStatus('079')
101   actual[8]=079
102   expect[8]=79
103
104   status[9]=showStatus('0079')
105   actual[9]=0079
106   expect[9]=79
107
108   status[10]=showStatus('099')
109   actual[10]=099
110   expect[10]=99
111
112   status[11]=showStatus('0099')
113   actual[11]=0099
114   expect[11]=99
115
116   status[12]=showStatus('000000000077')
117   actual[12]=000000000077
118   expect[12]=63
119
120   status[13]=showStatus('000000000078')
121   actual[13]=000000000078
122   expect[13]=78
123
124   status[14]=showStatus('0000000000770000')
125   actual[14]=0000000000770000
126   expect[14]=258048
127
128   status[15]=showStatus('0000000000780000')
129   actual[15]=0000000000780000
130   expect[15]=780000
131
132   status[16]=showStatus('0765432198')
133   actual[16]=0765432198
134   expect[16]=765432198
135
136   status[17]=showStatus('00076543219800')
137   actual[17]=00076543219800
138   expect[17]=76543219800
139
140   status[18]=showStatus('0000001001007')
141   actual[18]=0000001001007
142   expect[18]=262663
143
144   status[19]=showStatus('0000001001009')
145   actual[19]=0000001001009
146   expect[19]=1001009
147
148   status[20]=showStatus('070')
149   actual[20]=070
150   expect[20]=56
151
152   status[21]=showStatus('080')
153   actual[21]=080
154   expect[21]=80
155
156
157
158 //-------------------------------------------------------------------------------------------------
159   test();
160 //-------------------------------------------------------------------------------------------------
161
162
163 function showStatus(msg)
164 {
165   return (statprefix  + quote  +  msg  + quote);
166 }
167
168
169 function test()
170 {
171   enterFunc ('test');
172   printBugNumber(BUGNUMBER);
173   printStatus (summary);
174
175
176   for (i=0; i !=status.length; i++)
177   {
178     reportCompare (expect[i], actual[i], status[i]);
179   }
180
181   exitFunc ('test');
182 }