[TASKMGR] Process page: Allow using "Open File Location" functionality without runnin...
[reactos.git] / modules / rostests / winetests / jscript / cc.js
1 /*
2 * Copyright 2010 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 eval("@_jscript_version");
20
21 var tmp;
22
23 /*@ */
24 //@cc_on @*/
25
26 @_jscript_version;
27
28 @cc_on
29 @*/
30
31 // Standard predefined variabled
32 if(isWin64) {
33 ok(@_win64 === true, "@_win64 = " + @_win64);
34 ok(@_amd64 === true, "@_amd64 = " + @_amd64);
35 ok(isNaN(@_win32), "@_win32 = " + @_win32);
36 ok(isNaN(@_x86), "@_x86 = " + @_x86);
37 }else {
38 ok(@_win32 === true, "@_win32 = " + @_win32);
39 ok(@_x86 === true, "@_x86 = " + @_x86);
40 ok(isNaN(@_win64), "@_win64 = " + @_win64);
41 ok(isNaN(@_amd64), "@_amd64 = " + @_amd64);
42 }
43
44 ok(@_jscript === true, "@_jscript = " + @_jscript);
45 ok(@_jscript_build === ScriptEngineBuildVersion(),
46 "@_jscript_build = " + @_jscript_build + " expected " + ScriptEngineBuildVersion());
47 tmp = ScriptEngineMajorVersion() + ScriptEngineMinorVersion()/10;
48 ok(@_jscript_version === tmp, "@_jscript_version = " + @_jscript_version + " expected " + tmp);
49 ok(isNaN(@_win16), "@_win16 = " + @_win16);
50 ok(isNaN(@_mac), "@_mac = " + @_mac);
51 ok(isNaN(@_alpha), "@_alpha = " + @_alpha);
52 ok(isNaN(@_mc680x0), "@_mc680x0 = " + @_mc680x0);
53 ok(isNaN(@_PowerPC), "@_PowerPC = " + @_PowerPC);
54
55 // Undefined variable
56 ok(isNaN(@xxx), "@xxx = " + @xxx);
57 ok(isNaN(@x$_xx), "@x$_xx = " + @x$_xx);
58
59 tmp = false;
60 try {
61 eval("/*@cc_on */");
62 }catch(e) {
63 tmp = true;
64 }
65 ok(tmp, "expected syntax exception");
66
67 tmp = false;
68 try {
69 eval("/*@_jscript_version */");
70 }catch(e) {
71 tmp = true;
72 }
73 ok(tmp, "expected syntax exception");
74
75 ok(isNaN(@test), "@test = " + @test);
76
77 @set @test = 1
78 ok(@test === 1, "@test = " + @test);
79
80 @set @test = 0
81 ok(@test === 0, "@test = " + @test);
82
83 tmp = false
84 @set @test = @test tmp=true
85 ok(@test === 0, "@test = " + @test);
86 ok(tmp, "expr after @set not evaluated");
87
88 @set @test = !@test
89 ok(@test === true, "@test = " + @test);
90
91 @set @test = (@test+1+true)
92 ok(@test === 3, "@test = " + @test);
93
94 @set
95 @test
96 =
97 2
98 ok(@test === 2, "@test = " + @test);
99
100 @set
101 @test
102 =
103 (
104 2
105 +
106 2
107 )
108 ok(@test === 4, "@test = " + @test);
109
110 @set @test = 2.5
111 ok(@test === 2.5, "@test = " + @test);
112
113 @set @test = 0x4
114 ok(@test === 4, "@test = " + @test);
115
116 @set @test = (2 + 2/2)
117 ok(@test === 3, "@test = " + @test);
118
119 @set @test = (false+false)
120 ok(@test === 0, "@test = " + @test);
121
122 @set @test = ((1+1)*((3)+1))
123 ok(@test === 8, "@test = " + @test);
124
125 @set @_test = true
126 ok(@_test === true, "@_test = " + @_test);
127
128 @set @$test = true
129 ok(@$test === true, "@$test = " + @$test);
130
131 @set @newtest = (@newtest != @newtest)
132 ok(@newtest === true, "@newtest = " + @newtest);
133
134 @set @test = (false != 0)
135 ok(@test === false, "@test = " + @test);
136
137 @set @test = (1 != true)
138 ok(@test === false, "@test = " + @test);
139
140 @set @test = (0 != true)
141 ok(@test === true, "@test = " + @test);
142
143 @set @test = (true-2)
144 ok(@test === -1, "@test = " + @test);
145
146 @set @test = (true-@_jscript)
147 ok(@test === 0, "@test = " + @test);
148
149 @set @test = (true==1)
150 ok(@test === true, "@test = " + @test);
151
152 @set @test = (1==false+1)
153 ok(@test === true, "@test = " + @test);
154
155 function expect(val, exval) {
156 ok(val === exval, "got " + val + " expected " + exval);
157 }
158
159 @set @test = (false < 0.5)
160 expect(@test, true);
161
162 @set @test = (true == 0 < 0.5)
163 expect(@test, true);
164
165 @set @test = (false < 0)
166 expect(@test, false);
167
168 @set @test = (false > 0.5)
169 expect(@test, false);
170
171 @set @test = (1 < true)
172 expect(@test, false);
173
174 @set @test = (1 <= true)
175 expect(@test, true);
176
177 @set @test = (1 >= true)
178 expect(@test, true);
179
180 @set @test = (1 >= true-1)
181 expect(@test, true);
182
183 @if (false)
184 this wouldn not parse
185 "@end
186
187 @if (false) "@end
188
189 tmp = "@if (false) @end";
190 ok(tmp.length === 16, "tmp.length = " + tmp.length);
191
192 @if(true)
193 tmp = true
194 @end
195 ok(tmp === true, "tmp = " + tmp);
196
197 @if(false)
198 @if this would not CC parse
199 this will not parse
200 @elif(true)
201 this will also not parse
202 @else
203 this also will not parse
204 @if let me complicate things a bit
205 @end enough
206 @end
207 @end
208
209 @if(false)
210 this will not parse
211 @else
212 tmp = 2
213 @else
214 this will not be parsed
215 @else
216 also this
217 @end
218 ok(tmp === 2, "tmp = " + tmp);
219
220 @if(true)
221 tmp = 3;
222 @else
223 just skip this
224 @end
225 ok(tmp === 3, "tmp = " + tmp);
226
227 @if(true)
228 tmp = 4;
229 @elif(true)
230 this will not parse
231 @elif nor this
232 @else
233 just skip this
234 @end
235 ok(tmp === 4, "tmp = " + tmp);
236
237 @if(false)
238 this will not parse
239 @elif(false)
240 nor this would
241 @elif(true)
242 tmp = 5;
243 @elif nor this
244 @else
245 just skip this
246 @end
247 ok(tmp === 5, "tmp = " + tmp);
248
249 @if (!@_jscript)
250 this would not parse
251 @if(true)
252 @else
253 @if(false)
254 @end
255 @end
256 @elif (@_jscript)
257 tmp = 6;
258 @elif (true)
259 @if xxx
260 @else
261 @if @elif @elif @else @end
262 @end
263 @else
264 this would not parse
265 @end
266 ok(tmp === 6, "tmp = " + tmp);
267
268 @if(true)
269 @if(false)
270 @else
271 tmp = 7;
272 @end
273 @else
274 this would not parse
275 @end
276 ok(tmp === 7, "tmp = " + tmp);
277
278 var exception_map = {
279 JS_E_SYNTAX: {type: "SyntaxError", number: -2146827286},
280 JS_E_MISSING_LBRACKET: {type: "SyntaxError", number: -2146827283},
281 JS_E_EXPECTED_IDENTIFIER: {type: "SyntaxError", number: -2146827278},
282 JS_E_EXPECTED_ASSIGN: {type: "SyntaxError", number: -2146827277},
283 JS_E_EXPECTED_CCEND: {type: "SyntaxError", number: -2146827259},
284 JS_E_EXPECTED_AT: {type: "SyntaxError", number: -2146827256}
285 };
286
287 function testException(src, id) {
288 var ex = exception_map[id];
289 var ret = "", num = "";
290
291 try {
292 eval(src);
293 } catch(e) {
294 ret = e.name;
295 num = e.number;
296 }
297
298 ok(ret === ex.type, "Exception test, ret = " + ret + ", expected " + ex.type +". Executed code: " + src);
299 ok(num === ex.number, "Exception test, num = " + num + ", expected " + ex.number + ". Executed function: " + src);
300 }
301
302 testException("@set test=true", "JS_E_EXPECTED_AT");
303 testException("@set @1=true", "JS_E_EXPECTED_IDENTIFIER");
304 testException("@set @test x=true", "JS_E_EXPECTED_ASSIGN");
305 testException("@if false\n@end", "JS_E_MISSING_LBRACKET");
306 testException("@if (false)\n", "JS_E_EXPECTED_CCEND");
307 testException("@end\n", "JS_E_SYNTAX");
308 testException("@elif\n", "JS_E_SYNTAX");
309 testException("@else\n", "JS_E_SYNTAX");
310 testException("@if false\n@elif true\n@end", "JS_E_MISSING_LBRACKET");
311
312 reportSuccess();