2 * Copyright 2010 Jacek Caban for CodeWeavers
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.
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.
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
19 eval("@_jscript_version");
31 // Standard predefined variabled
33 ok(@_win64 === true, "@_win64 = " + @_win64);
34 ok(@_amd64 === true, "@_amd64 = " + @_amd64);
35 ok(isNaN(@_win32), "@_win32 = " + @_win32);
36 ok(isNaN(@_x86), "@_x86 = " + @_x86);
38 ok(@_win32 === true, "@_win32 = " + @_win32);
39 ok(@_x86 === true, "@_x86 = " + @_x86);
40 ok(isNaN(@_win64), "@_win64 = " + @_win64);
41 ok(isNaN(@_amd64), "@_amd64 = " + @_amd64);
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);
56 ok(isNaN(@xxx), "@xxx = " + @xxx);
57 ok(isNaN(@x$_xx), "@x$_xx = " + @x$_xx);
65 ok(tmp, "expected syntax exception");
69 eval("/*@_jscript_version */");
73 ok(tmp, "expected syntax exception");
75 ok(isNaN(@test), "@test = " + @test);
78 ok(@test === 1, "@test = " + @test);
81 ok(@test === 0, "@test = " + @test);
84 @set @test = @test tmp=true
85 ok(@test === 0, "@test = " + @test);
86 ok(tmp, "expr after @set not evaluated");
89 ok(@test === true, "@test = " + @test);
91 @set @test = (@test+1+true)
92 ok(@test === 3, "@test = " + @test);
98 ok(@test === 2, "@test = " + @test);
108 ok(@test === 4, "@test = " + @test);
111 ok(@test === 2.5, "@test = " + @test);
114 ok(@test === 4, "@test = " + @test);
116 @set @test = (2 + 2/2)
117 ok(@test === 3, "@test = " + @test);
119 @set @test = (false+false)
120 ok(@test === 0, "@test = " + @test);
122 @set @test = ((1+1)*((3)+1))
123 ok(@test === 8, "@test = " + @test);
126 ok(@_test === true, "@_test = " + @_test);
129 ok(@$test === true, "@$test = " + @$test);
131 @set @newtest = (@newtest != @newtest)
132 ok(@newtest === true, "@newtest = " + @newtest);
134 @set @test = (false != 0)
135 ok(@test === false, "@test = " + @test);
137 @set @test = (1 != true)
138 ok(@test === false, "@test = " + @test);
140 @set @test = (0 != true)
141 ok(@test === true, "@test = " + @test);
143 @set @test = (true-2)
144 ok(@test === -1, "@test = " + @test);
146 @set @test = (true-@_jscript)
147 ok(@test === 0, "@test = " + @test);
149 @set @test = (true==1)
150 ok(@test === true, "@test = " + @test);
152 @set @test = (1==false+1)
153 ok(@test === true, "@test = " + @test);
155 function expect(val, exval) {
156 ok(val === exval, "got " + val + " expected " + exval);
159 @set @test = (false < 0.5)
162 @set @test = (true == 0 < 0.5)
165 @set @test = (false < 0)
166 expect(@test, false);
168 @set @test = (false > 0.5)
169 expect(@test, false);
171 @set @test = (1 < true)
172 expect(@test, false);
174 @set @test = (1 <= true)
177 @set @test = (1 >= true)
180 @set @test = (1 >= true-1)
183 @set @test = (true && true)
186 @set @test = (false && true)
187 expect(@test, false);
189 @set @test = (true && false)
190 expect(@test, false);
192 @set @test = (false && false)
193 expect(@test, false);
196 @set @test = (@_win32&&@_jscript_version>=5)
201 this wouldn not parse
206 tmp = "@if (false) @end";
207 ok(tmp.length === 16, "tmp.length = " + tmp.length);
212 ok(tmp === true, "tmp = " + tmp);
215 @if this would not CC parse
218 this will also not parse
220 this also will not parse
221 @if let me complicate things a bit
231 this will not be parsed
235 ok(tmp === 2, "tmp = " + tmp);
242 ok(tmp === 3, "tmp = " + tmp);
252 ok(tmp === 4, "tmp = " + tmp);
264 ok(tmp === 5, "tmp = " + tmp);
278 @if @elif @elif @else @end
283 ok(tmp === 6, "tmp = " + tmp);
293 ok(tmp === 7, "tmp = " + tmp);
295 var exception_map = {
296 JS_E_SYNTAX: {type: "SyntaxError", number: -2146827286},
297 JS_E_MISSING_LBRACKET: {type: "SyntaxError", number: -2146827283},
298 JS_E_EXPECTED_IDENTIFIER: {type: "SyntaxError", number: -2146827278},
299 JS_E_EXPECTED_ASSIGN: {type: "SyntaxError", number: -2146827277},
300 JS_E_EXPECTED_CCEND: {type: "SyntaxError", number: -2146827259},
301 JS_E_EXPECTED_AT: {type: "SyntaxError", number: -2146827256}
304 function testException(src, id) {
305 var ex = exception_map[id];
306 var ret = "", num = "";
315 ok(ret === ex.type, "Exception test, ret = " + ret + ", expected " + ex.type +". Executed code: " + src);
316 ok(num === ex.number, "Exception test, num = " + num + ", expected " + ex.number + ". Executed function: " + src);
319 testException("@set test=true", "JS_E_EXPECTED_AT");
320 testException("@set @1=true", "JS_E_EXPECTED_IDENTIFIER");
321 testException("@set @test x=true", "JS_E_EXPECTED_ASSIGN");
322 testException("@if false\n@end", "JS_E_MISSING_LBRACKET");
323 testException("@if (false)\n", "JS_E_EXPECTED_CCEND");
324 testException("@end\n", "JS_E_SYNTAX");
325 testException("@elif\n", "JS_E_SYNTAX");
326 testException("@else\n", "JS_E_SYNTAX");
327 testException("@if false\n@elif true\n@end", "JS_E_MISSING_LBRACKET");