* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma_3 / Expressions / 11.6.1-1.js
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is JavaScript Engine testing utilities.
15  *
16  * The Initial Developer of the Original Code is
17  * Netscape Communications Corp.
18  * Portions created by the Initial Developer are Copyright (C) 2003
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  *   bzbarsky@mit.edu, pschwartau@netscape.com
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK *****
37  *
38  *
39  * Date:    14 Mar 2003
40  * SUMMARY: Testing left-associativity of the + operator
41  *
42  * See ECMA-262 Ed.3, Section 11.6.1, "The Addition operator"
43  * See http://bugzilla.mozilla.org/show_bug.cgi?id=196290
44  *
45  * The upshot: |a + b + c| should always equal |(a + b) + c|
46  *
47  */
48 //-----------------------------------------------------------------------------
49 var UBound = 0;
50 var bug = 196290;
51 var summary = 'Testing left-associativity of the + operator';
52 var status = '';
53 var statusitems = [];
54 var actual = '';
55 var actualvalues = [];
56 var expect= '';
57 var expectedvalues = [];
58
59
60 status = inSection(1);
61 actual = 1 + 1 + 'px';
62 expect = '2px';
63 addThis();
64
65 status = inSection(2);
66 actual = 'px' + 1 + 1;
67 expect = 'px11';
68 addThis();
69
70 status = inSection(3);
71 actual = 1 + 1 + 1 + 'px';
72 expect = '3px';
73 addThis();
74
75 status = inSection(4);
76 actual = 1 + 1 + 'a' + 1 + 1 + 'b';
77 expect = '2a11b';
78 addThis();
79
80 /*
81  * The next sections test the + operator via eval()
82  */
83 status = inSection(5);
84 actual = sumThese(1, 1, 'a', 1, 1, 'b');
85 expect = '2a11b';
86 addThis();
87
88 status = inSection(6);
89 actual = sumThese(new Number(1), new Number(1), 'a');
90 expect = '2a';
91 addThis();
92
93 status = inSection(7);
94 actual = sumThese('a', new Number(1), new Number(1));
95 expect = 'a11';
96 addThis();
97
98
99
100 //-----------------------------------------------------------------------------
101 test();
102 //-----------------------------------------------------------------------------
103
104
105
106 function addThis()
107 {
108   statusitems[UBound] = status;
109   actualvalues[UBound] = actual;
110   expectedvalues[UBound] = expect;
111   UBound++;
112 }
113
114 /*
115  * Applies the + operator to the provided arguments via eval().
116  *
117  * Form an eval string of the form 'arg1 + arg2 + arg3', but
118  * remember to add double-quotes inside the eval string around
119  * any argument that is of string type. For example, suppose the
120  * arguments were 11, 'a', 22. Then the eval string should be
121  *
122  *              arg1 + quoteThis(arg2) + arg3
123  *
124  * If we didn't put double-quotes around the string argument,
125  * we'd get this for an eval string:
126  *
127  *                     '11 + a + 22'
128  *
129  * If we eval() this, we get 'ReferenceError: a is not defined'.
130  * With proper quoting, we get eval('11 + "a" + 22') as desired.
131  */
132 function sumThese()
133 {
134   var sEval = '';
135   var arg;
136   var i;
137
138   var L = arguments.length;
139   for (i=0; i<L; i++)
140   {
141     arg = arguments[i];
142     if (typeof arg === 'string')
143       arg = quoteThis(arg);
144
145     if (i < L-1)
146       sEval += arg + ' + ';
147     else
148       sEval += arg;
149   }
150
151   return eval(sEval);
152 }
153
154
155 function quoteThis(x)
156 {
157   return '"' + x + '"';
158 }
159
160
161 function test()
162 {
163   enterFunc('test');
164   printBugNumber(bug);
165   printStatus(summary);
166
167   for (var i=0; i<UBound; i++)
168   {
169     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
170   }
171
172   exitFunc ('test');
173 }