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)
184 this wouldn not parse
189 tmp
= "@if (false) @end";
190 ok(tmp
.length
=== 16, "tmp.length = " + tmp
.length
);
195 ok(tmp
=== true, "tmp = " + tmp
);
198 @if this would not CC parse
201 this will also not parse
203 this also will not parse
204 @if let me complicate things a bit
214 this will not be parsed
218 ok(tmp
=== 2, "tmp = " + tmp
);
225 ok(tmp
=== 3, "tmp = " + tmp
);
235 ok(tmp
=== 4, "tmp = " + tmp
);
247 ok(tmp
=== 5, "tmp = " + tmp
);
261 @if @elif
@elif
@else @end
266 ok(tmp
=== 6, "tmp = " + tmp
);
276 ok(tmp
=== 7, "tmp = " + tmp
);
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}
287 function testException(src
, id
) {
288 var ex
= exception_map
[id
];
289 var ret
= "", num
= "";
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
);
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");