Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Expressions / 11.13.2-1.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 Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
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    File Name:          11.13.2-1.js
42    ECMA Section:       11.13.2 Compound Assignment: *=
43    Description:
44
45    *= /= %= += -= <<= >>= >>>= &= ^= |=
46
47    11.13.2 Compound assignment ( op= )
48
49    The production AssignmentExpression :
50    LeftHandSideExpression @ = AssignmentExpression, where @ represents one of
51    the operators indicated above, is evaluated as follows:
52
53    1.  Evaluate LeftHandSideExpression.
54    2.  Call GetValue(Result(1)).
55    3.  Evaluate AssignmentExpression.
56    4.  Call GetValue(Result(3)).
57    5.  Apply operator @ to Result(2) and Result(4).
58    6.  Call PutValue(Result(1), Result(5)).
59    7.  Return Result(5).
60
61    Author:             christine@netscape.com
62    Date:               12 november 1997
63 */
64 var SECTION = "11.13.2-1";
65 var VERSION = "ECMA_1";
66 startTest();
67
68 writeHeaderToLog( SECTION + " Compound Assignment: *=");
69
70
71 // NaN cases
72
73 new TestCase( SECTION,   
74               "VAR1 = NaN; VAR2=1; VAR1 *= VAR2",      
75               Number.NaN,
76               eval("VAR1 = Number.NaN; VAR2=1; VAR1 *= VAR2") );
77
78 new TestCase( SECTION,   
79               "VAR1 = NaN; VAR2=1; VAR1 *= VAR2; VAR1",
80               Number.NaN,
81               eval("VAR1 = Number.NaN; VAR2=1; VAR1 *= VAR2; VAR1") );
82
83 // number cases
84 new TestCase( SECTION,   
85               "VAR1 = 0; VAR2=1; VAR1 *= VAR2",        
86               0,         
87               eval("VAR1 = 0; VAR2=1; VAR1 *= VAR2") );
88
89 new TestCase( SECTION,   
90               "VAR1 = 0; VAR2=1; VAR1 *= VAR2;VAR1",   
91               0,         
92               eval("VAR1 = 0; VAR2=1; VAR1 *= VAR2;VAR1") );
93
94 new TestCase( SECTION,   
95               "VAR1 = 0xFF; VAR2 = 0xA, VAR1 *= VAR2",
96               2550,     
97               eval("VAR1 = 0XFF; VAR2 = 0XA, VAR1 *= VAR2") );
98
99 // special multiplication cases
100
101 new TestCase( SECTION,   
102               "VAR1 = 0; VAR2= Infinity; VAR1 *= VAR2",   
103               Number.NaN,     
104               eval("VAR1 = 0; VAR2 = Number.POSITIVE_INFINITY; VAR1 *= VAR2; VAR1") );
105
106 new TestCase( SECTION,   
107               "VAR1 = -0; VAR2= Infinity; VAR1 *= VAR2",  
108               Number.NaN,     
109               eval("VAR1 = -0; VAR2 = Number.POSITIVE_INFINITY; VAR1 *= VAR2; VAR1") );
110
111 new TestCase( SECTION,   
112               "VAR1 = -0; VAR2= -Infinity; VAR1 *= VAR2", 
113               Number.NaN,     
114               eval("VAR1 = -0; VAR2 = Number.NEGATIVE_INFINITY; VAR1 *= VAR2; VAR1") );
115
116 new TestCase( SECTION,   
117               "VAR1 = 0; VAR2= -Infinity; VAR1 *= VAR2",  
118               Number.NaN,     
119               eval("VAR1 = 0; VAR2 = Number.NEGATIVE_INFINITY; VAR1 *= VAR2; VAR1") );
120
121 new TestCase( SECTION,   
122               "VAR1 = 0; VAR2= Infinity; VAR2 *= VAR1",   
123               Number.NaN,     
124               eval("VAR1 = 0; VAR2 = Number.POSITIVE_INFINITY; VAR2 *= VAR1; VAR2") );
125
126 new TestCase( SECTION,   
127               "VAR1 = -0; VAR2= Infinity; VAR2 *= VAR1",  
128               Number.NaN,     
129               eval("VAR1 = -0; VAR2 = Number.POSITIVE_INFINITY; VAR2 *= VAR1; VAR2") );
130
131 new TestCase( SECTION,   
132               "VAR1 = -0; VAR2= -Infinity; VAR2 *= VAR1", 
133               Number.NaN,     
134               eval("VAR1 = -0; VAR2 = Number.NEGATIVE_INFINITY; VAR2 *= VAR1; VAR2") );
135
136 new TestCase( SECTION,   
137               "VAR1 = 0; VAR2= -Infinity; VAR2 *= VAR1",  
138               Number.NaN,     
139               eval("VAR1 = 0; VAR2 = Number.NEGATIVE_INFINITY; VAR2 *= VAR1; VAR2") );
140
141 new TestCase( SECTION,   
142               "VAR1 = Infinity; VAR2= Infinity; VAR1 *= VAR2",  
143               Number.POSITIVE_INFINITY,     
144               eval("VAR1 = Number.POSITIVE_INFINITY; VAR2 = Number.POSITIVE_INFINITY; VAR1 *= VAR2; VAR1") );
145
146 new TestCase( SECTION,   
147               "VAR1 = Infinity; VAR2= -Infinity; VAR1 *= VAR2", 
148               Number.NEGATIVE_INFINITY,     
149               eval("VAR1 = Number.POSITIVE_INFINITY; VAR2 = Number.NEGATIVE_INFINITY; VAR1 *= VAR2; VAR1") );
150
151 new TestCase( SECTION,   
152               "VAR1 =-Infinity; VAR2= Infinity; VAR1 *= VAR2",  
153               Number.NEGATIVE_INFINITY,     
154               eval("VAR1 = Number.NEGATIVE_INFINITY; VAR2 = Number.POSITIVE_INFINITY; VAR1 *= VAR2; VAR1") );
155
156 new TestCase( SECTION,   
157               "VAR1 =-Infinity; VAR2=-Infinity; VAR1 *= VAR2",  
158               Number.POSITIVE_INFINITY,     
159               eval("VAR1 = Number.NEGATIVE_INFINITY; VAR2 = Number.NEGATIVE_INFINITY; VAR1 *= VAR2; VAR1") );
160
161 // string cases
162 new TestCase( SECTION,   
163               "VAR1 = 10; VAR2 = '255', VAR1 *= VAR2",
164               2550,      
165               eval("VAR1 = 10; VAR2 = '255', VAR1 *= VAR2") );
166
167 new TestCase( SECTION,   
168               "VAR1 = '255'; VAR2 = 10, VAR1 *= VAR2",
169               2550,      
170               eval("VAR1 = '255'; VAR2 = 10, VAR1 *= VAR2") );
171
172 new TestCase( SECTION,   
173               "VAR1 = 10; VAR2 = '0XFF', VAR1 *= VAR2",
174               2550,      
175               eval("VAR1 = 10; VAR2 = '0XFF', VAR1 *= VAR2") );
176
177 new TestCase( SECTION,   
178               "VAR1 = '0xFF'; VAR2 = 0xA, VAR1 *= VAR2",
179               2550,     
180               eval("VAR1 = '0XFF'; VAR2 = 0XA, VAR1 *= VAR2") );
181
182 new TestCase( SECTION,   
183               "VAR1 = '10'; VAR2 = '255', VAR1 *= VAR2",
184               2550,     
185               eval("VAR1 = '10'; VAR2 = '255', VAR1 *= VAR2") );
186
187 new TestCase( SECTION,   
188               "VAR1 = '10'; VAR2 = '0XFF', VAR1 *= VAR2",
189               2550,    
190               eval("VAR1 = '10'; VAR2 = '0XFF', VAR1 *= VAR2") );
191
192 new TestCase( SECTION,   
193               "VAR1 = '0xFF'; VAR2 = 0xA, VAR1 *= VAR2",
194               2550,     
195               eval("VAR1 = '0XFF'; VAR2 = 0XA, VAR1 *= VAR2") );
196
197 // boolean cases
198 new TestCase( SECTION,   
199               "VAR1 = true; VAR2 = false; VAR1 *= VAR2",   
200               0,     
201               eval("VAR1 = true; VAR2 = false; VAR1 *= VAR2") );
202
203 new TestCase( SECTION,   
204               "VAR1 = true; VAR2 = true; VAR1 *= VAR2",   
205               1,     
206               eval("VAR1 = true; VAR2 = true; VAR1 *= VAR2") );
207
208 // object cases
209 new TestCase( SECTION,   
210               "VAR1 = new Boolean(true); VAR2 = 10; VAR1 *= VAR2;VAR1",   
211               10,     
212               eval("VAR1 = new Boolean(true); VAR2 = 10; VAR1 *= VAR2; VAR1") );
213
214 new TestCase( SECTION,   
215               "VAR1 = new Number(11); VAR2 = 10; VAR1 *= VAR2; VAR1",   
216               110,     
217               eval("VAR1 = new Number(11); VAR2 = 10; VAR1 *= VAR2; VAR1") );
218
219 new TestCase( SECTION,   
220               "VAR1 = new Number(11); VAR2 = new Number(10); VAR1 *= VAR2",   
221               110,     
222               eval("VAR1 = new Number(11); VAR2 = new Number(10); VAR1 *= VAR2") );
223
224 new TestCase( SECTION,   
225               "VAR1 = new String('15'); VAR2 = new String('0xF'); VAR1 *= VAR2",   
226               225,     
227               eval("VAR1 = String('15'); VAR2 = new String('0xF'); VAR1 *= VAR2") );
228
229 test();
230