Initial release
This commit is contained in:
Vendored
+83
@@ -0,0 +1,83 @@
|
||||
// switch-case-tests
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// switch-test 1: case with break;
|
||||
////////////////////////////////////////////////////
|
||||
var a1 = 5;
|
||||
var b1 = 6;
|
||||
var r1 = 0;
|
||||
|
||||
switch (a1 + 5)
|
||||
{
|
||||
case 6:
|
||||
r1 = 2;
|
||||
break;
|
||||
case b1 + 4:
|
||||
r1 = 42;
|
||||
break;
|
||||
case 7:
|
||||
r1 = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// switch-test 2: case with out break;
|
||||
////////////////////////////////////////////////////
|
||||
var a2 = 5;
|
||||
var b2 = 6;
|
||||
var r2 = 0;
|
||||
|
||||
switch (a2 + 4)
|
||||
{
|
||||
case 6:
|
||||
r2 = 2;
|
||||
break;
|
||||
case b2 + 3:
|
||||
r2 = 40;
|
||||
// break;
|
||||
case 7:
|
||||
r2 += 2;
|
||||
break;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// switch-test 3: case with default;
|
||||
////////////////////////////////////////////////////
|
||||
var a3 = 5;
|
||||
var b3 = 6;
|
||||
var r3 = 0;
|
||||
|
||||
switch (a3 + 44)
|
||||
{
|
||||
case 6:
|
||||
r3 = 2;
|
||||
break;
|
||||
case b3 + 3:
|
||||
r3 = 1;
|
||||
break;
|
||||
default:
|
||||
r3 = 42;
|
||||
break;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// switch-test 4: case default before case;
|
||||
////////////////////////////////////////////////////
|
||||
var a4 = 5;
|
||||
var b4 = 6;
|
||||
var r4 = 0;
|
||||
|
||||
switch (a4 + 44)
|
||||
{
|
||||
default:
|
||||
r4 = 42;
|
||||
break;
|
||||
case 6:
|
||||
r4 = 2;
|
||||
break;
|
||||
case b4 + 3:
|
||||
r4 = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
result = r1 == 42 && r2 == 42 && r3 == 42 && r4 == 42;
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// function-closure
|
||||
|
||||
var a = 40; // a global var
|
||||
|
||||
function closure ()
|
||||
{
|
||||
var a = 39; // a local var;
|
||||
return function () { return a; };
|
||||
}
|
||||
|
||||
var b = closure (); // the local var a is now hidden
|
||||
|
||||
result = b () + 3 == 42 && a + 2 == 42;
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// with-test
|
||||
|
||||
var a;
|
||||
|
||||
with (Math) a = PI;
|
||||
|
||||
var b = {get_member: function () { return this.member; }, member: 41};
|
||||
|
||||
with (b)
|
||||
{
|
||||
let a = get_member (); //<--- a is local for this block
|
||||
var c = a + 1;
|
||||
}
|
||||
|
||||
result = a == Math.PI && c == 42;
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
// generator-test
|
||||
|
||||
function fibonacci ()
|
||||
{
|
||||
var fn1 = 1;
|
||||
var fn2 = 1;
|
||||
while (1)
|
||||
{
|
||||
var current = fn2;
|
||||
fn2 = fn1;
|
||||
fn1 = fn1 + current;
|
||||
var reset = yield current;
|
||||
if (reset)
|
||||
{
|
||||
fn1 = 1;
|
||||
fn2 = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var generator = fibonacci ();
|
||||
|
||||
generator.next(); // 1
|
||||
generator.next(); // 1
|
||||
generator.next(); // 2
|
||||
generator.next(); // 3
|
||||
generator.next(); // 5
|
||||
|
||||
result = generator.next() == 8 && generator.send(true) == 1;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// simply testing we can return the correct value
|
||||
result = 1;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// comparison
|
||||
var a = 42;
|
||||
result = a == 42;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// simple for loop
|
||||
var a = 0;
|
||||
var i;
|
||||
for (i = 1; i < 10; i++)
|
||||
a = a + i;
|
||||
result = a == 45;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// simple if
|
||||
var a = 42;
|
||||
if (a < 43)
|
||||
result = 1;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// simple for loop containing initialisation, using +=
|
||||
var a = 0;
|
||||
for (var i = 1; i < 10; i++)
|
||||
a += i;
|
||||
result = a == 45;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// simple function
|
||||
function add (x, y) { return x + y; }
|
||||
result = add (3, 6) == 9;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// simple function scoping test
|
||||
var a = 7;
|
||||
function add (x, y)
|
||||
{
|
||||
var a = x + y;
|
||||
return a;
|
||||
}
|
||||
result = add (3, 6) == 9 && a == 7;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// functions in variables
|
||||
var bob = {};
|
||||
bob.add = function (x, y) { return x + y; };
|
||||
|
||||
result = bob.add(3, 6) == 9;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// functions in variables using JSON-style initialisation
|
||||
var bob = {add: function (x, y) { return x + y; }};
|
||||
|
||||
result = bob.add(3, 6) == 9;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// double function calls
|
||||
function a (x) { return x + 2; }
|
||||
function b (x) { return a (x) + 1; }
|
||||
result = a (3) == 5 && b (3) == 6;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// recursion
|
||||
function a (x)
|
||||
{
|
||||
if (x > 1)
|
||||
return x * a (x - 1);
|
||||
return 1;
|
||||
}
|
||||
result = a (5) == 1 * 2 * 3 * 4 * 5;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// if .. else
|
||||
var a = 42;
|
||||
if (a != 42)
|
||||
result = 0;
|
||||
else
|
||||
result = 1;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// if .. else with blocks
|
||||
var a = 42;
|
||||
if (a != 42)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// Variable creation and scope from http://en.wikipedia.org/wiki/JavaScript_syntax
|
||||
x = 0; // A global variable
|
||||
var y = 'Hello!'; // Another global variable
|
||||
z = 0; // yet another global variable
|
||||
|
||||
function f ()
|
||||
{
|
||||
var z = 'foxes'; // A local variable
|
||||
twenty = 20; // Global because keyword var is not used
|
||||
return x; // We can use x here because it is global
|
||||
}
|
||||
// The value of z is no longer available
|
||||
|
||||
// testing
|
||||
blah = f ();
|
||||
result = blah == 0 && z != 'foxes' && twenty == 20;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// Number definition from http://en.wikipedia.org/wiki/JavaScript_syntax
|
||||
a = 345; // an "integer", although there is only one numeric type in JavaScript
|
||||
b = 34.5; // a floating-point number
|
||||
c = 3.45e2; // another floating-point, equivalent to 345
|
||||
d = 0377; // an octal integer equal to 255
|
||||
e = 0xFF; // a hexadecimal integer equal to 255, digits represented by the letters A-F may be upper
|
||||
// or lowercase
|
||||
|
||||
result = a == 345 && b * 10 == 345 && c == 345 && d == 255 && e == 255;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// Undefined/null from http://en.wikipedia.org/wiki/JavaScript_syntax
|
||||
var testUndefined; // variable declared but not defined, set to value of undefined
|
||||
var testObj = {};
|
||||
|
||||
result = 1;
|
||||
if (("" + testUndefined) != "undefined")
|
||||
result = 0; // test variable exists but value not defined, displays undefined
|
||||
if (("" + testObj.myProp) != "undefined")
|
||||
result = 0; // testObj exists, property does not, displays undefined
|
||||
if (!(undefined == null))
|
||||
result = 0; // unenforced type during check, displays true
|
||||
if (undefined === null)
|
||||
result = 0; // enforce type during check, displays false
|
||||
|
||||
if (null != undefined)
|
||||
result = 0; // unenforced type during check, displays true
|
||||
if (null === undefined)
|
||||
result = 0; // enforce type during check, displays false
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// references for arrays
|
||||
|
||||
var a = [];
|
||||
a[0] = 10;
|
||||
a[1] = 22;
|
||||
|
||||
b = a;
|
||||
|
||||
b[0] = 5;
|
||||
|
||||
result = a[0] == 5 && a[1] == 22 && b[1] == 22;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// references with functions
|
||||
|
||||
var a = 42;
|
||||
var b = [];
|
||||
b[0] = 43;
|
||||
|
||||
function foo (myarray) { myarray[0]++; }
|
||||
|
||||
function bar (myvalue) { myvalue++; }
|
||||
|
||||
foo (b);
|
||||
bar (a);
|
||||
|
||||
result = a == 42 && b[0] == 44;
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// built-in functions
|
||||
|
||||
foo = "foo bar stuff";
|
||||
// 42-tiny-js change begin --->
|
||||
// in JavaScript this function is called Math.random()
|
||||
// r = Math.rand();
|
||||
r = Math.random();
|
||||
//<--- 42-tiny-js change end
|
||||
|
||||
// 42-tiny-js change begin --->
|
||||
// in JavaScript parseInt is a methode in the global scope (root-scope)
|
||||
// parsed = Integer.parseInt("42");
|
||||
parsed = parseInt ("42");
|
||||
//<--- 42-tiny-js change end
|
||||
|
||||
aStr = "ABCD";
|
||||
aChar = aStr.charAt(0);
|
||||
|
||||
obj1 = new Object ();
|
||||
obj1.food = "cake";
|
||||
obj1.desert = "pie";
|
||||
|
||||
obj2 = obj1.clone();
|
||||
obj2.food = "kittens";
|
||||
|
||||
result = foo.length == 13 && foo.indexOf("bar") == 4 && foo.substring(8, 13) == "stuff" &&
|
||||
parsed == 42 &&
|
||||
// 42-tiny-js change begin --->
|
||||
// in 42tiny-js the Integer-Objecte will be removed
|
||||
// Integer.valueOf can be replaced by String.charCodeAt
|
||||
// Integer.valueOf(aChar)==65 && obj1.food=="cake" && obj2.desert=="pie";
|
||||
aChar.charCodeAt() == 65 && obj1.food == "cake" && obj2.desert == "pie";
|
||||
//<--- 42-tiny-js change end
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// built-in functions
|
||||
|
||||
foo = "foo bar stuff";
|
||||
r = Math.rand();
|
||||
|
||||
parsed = Integer.parseInt("42");
|
||||
parsedHex = Integer.parseInt("0xFF");
|
||||
parsedOct = Integer.parseInt("011");
|
||||
parsedBig = Integer.parseInt("4294967296");
|
||||
|
||||
aStr = "ABCD";
|
||||
aChar = aStr.charAt(0);
|
||||
|
||||
obj1 = new Object ();
|
||||
obj1.food = "cake";
|
||||
obj1.desert = "pie";
|
||||
|
||||
obj2 = obj1.clone();
|
||||
obj2.food = "kittens";
|
||||
|
||||
result = foo.length == 13 && foo.indexOf("bar") == 4 && foo.substring(8, 13) == "stuff" &&
|
||||
parsed == 42 && Integer.valueOf(aChar) == 65 && obj1.food == "cake" &&
|
||||
obj2.desert == "pie" && parsedHex == 255 && parsedOct == 9 && parsedBig == 4294967296;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// Test reported by sterowang, Variable attribute defines conflict with function.
|
||||
/*
|
||||
What steps will reproduce the problem?
|
||||
1. function a (){};
|
||||
2. b = {};
|
||||
3. b.a = {};
|
||||
4. a();
|
||||
|
||||
What is the expected output? What do you see instead?
|
||||
Function "a" should be called. But the error message "Error Expecting 'a'
|
||||
to be a function at (line: 1, col: 1)" received.
|
||||
|
||||
What version of the product are you using? On what operating system?
|
||||
Version 1.6 is used on Cent OS 5.4
|
||||
|
||||
|
||||
Please provide any additional information below.
|
||||
When using dump() to show symbols, found the function "a" is reassigned to
|
||||
"{}" by "b.a = {};" call.
|
||||
*/
|
||||
|
||||
function a () {};
|
||||
b = {};
|
||||
b.a = {};
|
||||
a ();
|
||||
|
||||
result = 1;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/* Javascript eval */
|
||||
|
||||
// 42-tiny-js change begin --->
|
||||
// in JavaScript eval is not JSON.parse
|
||||
// use parentheses or JSON.parse instead
|
||||
// myfoo = eval("{ foo: 42 }");
|
||||
myfoo = eval ("(" +
|
||||
"{ foo: 42 }" +
|
||||
")");
|
||||
//<--- 42-tiny-js change end
|
||||
|
||||
result = eval ("4*10+2") == 42 && myfoo.foo == 42;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
/* Javascript eval */
|
||||
|
||||
myfoo = eval ("{ foo: 42 }");
|
||||
|
||||
result = eval ("4*10+2") == 42 && myfoo.foo == 42;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/* Javascript eval */
|
||||
|
||||
mystructure = {
|
||||
a: 39,
|
||||
b: 3,
|
||||
addStuff: function (c, d) { return c + d; }
|
||||
};
|
||||
|
||||
mystring = JSON.stringify(mystructure, undefined);
|
||||
|
||||
// 42-tiny-js change begin --->
|
||||
// in JavaScript eval is not JSON.parse
|
||||
// use parentheses or JSON.parse instead
|
||||
// mynewstructure = eval(mystring);
|
||||
mynewstructure = eval ("(" + mystring + ")");
|
||||
mynewstructure2 = JSON.parse(mystring);
|
||||
//<--- 42-tiny-js change end
|
||||
|
||||
result = mynewstructure.addStuff(mynewstructure.a, mynewstructure.b) == 42 &&
|
||||
mynewstructure2.addStuff(mynewstructure2.a, mynewstructure2.b) == 42;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/* Javascript eval */
|
||||
|
||||
mystructure = {
|
||||
a: 39,
|
||||
b: 3,
|
||||
addStuff: function (c, d) { return c + d; }
|
||||
};
|
||||
|
||||
mystring = JSON.stringify(mystructure, undefined);
|
||||
|
||||
mynewstructure = eval (mystring);
|
||||
|
||||
result = mynewstructure.addStuff(mynewstructure.a, mynewstructure.b);
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// mikael.kindborg@mobilesorcery.com - Function symbol is evaluated in bracket-less body of false
|
||||
// if-statement
|
||||
var foo; // a var is only created automated by assignment
|
||||
|
||||
if (foo !== undefined)
|
||||
foo ();
|
||||
|
||||
result = 1;
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/* Mandelbrot! */
|
||||
|
||||
X1 = -2.0;
|
||||
Y1 = -2.0;
|
||||
X2 = 2.0;
|
||||
Y2 = 2.0;
|
||||
PX = 32;
|
||||
PY = 32;
|
||||
|
||||
lines = [];
|
||||
for (y = 0; y < PY; y++)
|
||||
{
|
||||
line = "";
|
||||
for (x = 0; x < PX; x++)
|
||||
{
|
||||
Xr = 0;
|
||||
Xi = 0;
|
||||
Cr = X1 + ((X2 - X1) * x / PX);
|
||||
Ci = Y1 + ((Y2 - Y1) * y / PY);
|
||||
iterations = 0;
|
||||
while ((iterations < 32) && ((Xr * Xr + Xi * Xi) < 4))
|
||||
{
|
||||
t = Xr * Xr - Xi * Xi + Cr;
|
||||
Xi = 2 * Xr * Xi + Ci;
|
||||
Xr = t;
|
||||
iterations++;
|
||||
}
|
||||
if (iterations & 1)
|
||||
line += "*";
|
||||
else
|
||||
line += " ";
|
||||
}
|
||||
lines[y] = line;
|
||||
}
|
||||
|
||||
result = lines[0] == "********************************" &&
|
||||
lines[1] == "*********** **********" &&
|
||||
lines[2] == "********* ********" &&
|
||||
lines[3] == "******* ******" &&
|
||||
lines[4] == "****** *****" &&
|
||||
lines[5] == "***** ****" &&
|
||||
lines[6] == "**** ******* ***" &&
|
||||
lines[7] == "*** ******* ** ** **" &&
|
||||
lines[8] == "*** ****** * * * **" &&
|
||||
lines[9] == "** ******* ** ** ** *" &&
|
||||
lines[10] == "** ****** * * ** ** *" &&
|
||||
lines[11] == "* ***** *** ** ** " &&
|
||||
lines[12] == "****** *** ***** " &&
|
||||
lines[13] == "*** * * * ** ** " &&
|
||||
lines[14] == "* * * * * ** " &&
|
||||
lines[15] == "* *** ** ** " &&
|
||||
lines[16] == "* ** ** " &&
|
||||
lines[17] == "* *** ** ** " &&
|
||||
lines[18] == "* * * * * ** " &&
|
||||
lines[19] == "*** * * * ** ** " &&
|
||||
lines[20] == "****** *** ***** " &&
|
||||
lines[21] == "* ***** *** ** ** " &&
|
||||
lines[22] == "** ****** * * ** ** *" &&
|
||||
lines[23] == "** ******* ** ** ** *" &&
|
||||
lines[24] == "*** ****** * * * **" &&
|
||||
lines[25] == "*** ******* ** ** **" &&
|
||||
lines[26] == "**** ******* ***" &&
|
||||
lines[27] == "***** ****" &&
|
||||
lines[28] == "****** *****" &&
|
||||
lines[29] == "******* ******" &&
|
||||
lines[30] == "********* ********" &&
|
||||
lines[31] == "*********** **********";
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// Array length test
|
||||
|
||||
myArray = [1, 2, 3, 4, 5];
|
||||
myArray2 = [1, 2, 3, 4, 5];
|
||||
myArray2[8] = 42;
|
||||
|
||||
result = myArray.length == 5 && myArray2.length == 9;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// check for undefined-ness
|
||||
a = undefined;
|
||||
b = "foo";
|
||||
result = a == undefined && b != undefined;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// test for postincrement working as expected
|
||||
var foo = 5;
|
||||
result = (foo++) == 5;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// test for array contains
|
||||
var a = [1, 2, 4, 5, 7];
|
||||
var b = ["bread", "cheese", "sandwich"];
|
||||
|
||||
result = a.contains(1) && !a.contains(42) && b.contains("cheese") && !b.contains("eggs");
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// test for array remove
|
||||
var a = [1, 2, 4, 5, 7];
|
||||
|
||||
a.remove(2);
|
||||
a.remove(5);
|
||||
|
||||
result = a.length == 3 && a[0] == 1 && a[1] == 4 && a[2] == 7;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// test for array join
|
||||
var a = [1, 2, 4, 5, 7];
|
||||
|
||||
result = a.join(",") == "1,2,4,5,7";
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// test for string split
|
||||
var b = "1,4,7";
|
||||
var a = b.split(",");
|
||||
|
||||
result = a.length == 3 && a[0] == 1 && a[1] == 4 && a[2] == 7;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
function Foo () { this.__proto__ = Foo.prototype; }
|
||||
Foo.prototype = {
|
||||
value: function () { return this.x + this.y; }
|
||||
};
|
||||
|
||||
var a = {__proto__: Foo.prototype, x: 1, y: 2};
|
||||
var b = new Foo ();
|
||||
b.x = 2;
|
||||
b.y = 3;
|
||||
|
||||
var result1 = a.value();
|
||||
var result2 = b.value();
|
||||
result = result1 == 3 && result2 == 5;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
var Foo = {value: function () { return this.x + this.y; }};
|
||||
|
||||
var a = {prototype: Foo, x: 1, y: 2};
|
||||
var b = new Foo ();
|
||||
b.x = 2;
|
||||
b.y = 3;
|
||||
|
||||
var result1 = a.value();
|
||||
var result2 = b.value();
|
||||
result = result1 == 3 && result2 == 5;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// test for shift
|
||||
var a = (2 << 2);
|
||||
var b = (16 >> 3);
|
||||
var c = (-1 >>> 16);
|
||||
result = a == 8 && b == 2 && c == 0xFFFF;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// test for ternary
|
||||
|
||||
result = (true ? 3 : 4) == 3 && (false ? 5 : 6) == 6;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
function Person (name)
|
||||
{
|
||||
this.name = name;
|
||||
this.kill = function () { this.name += " is dead"; };
|
||||
}
|
||||
|
||||
var a = new Person ("Kenny");
|
||||
a.kill();
|
||||
result = a.name == "Kenny is dead";
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// the 'lf' in the printf caused issues writing doubles on some compilers
|
||||
var a = 5.0 / 10.0 * 100.0;
|
||||
var b = 5.0 * 110.0;
|
||||
var c = 50.0 / 10.0;
|
||||
a.dump();
|
||||
b.dump();
|
||||
c.dump();
|
||||
result = a == 50 && b == 550 && c == 5;
|
||||
Reference in New Issue
Block a user