diff --git a/tests/42tests/test001.js b/tests/42tests/test001.js new file mode 100644 index 0000000..82c176d --- /dev/null +++ b/tests/42tests/test001.js @@ -0,0 +1,80 @@ +// 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; diff --git a/tests/test019.42.js b/tests/test019.42.js new file mode 100644 index 0000000..d2caa6f --- /dev/null +++ b/tests/test019.42.js @@ -0,0 +1,23 @@ +// 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 + +parsed = Integer.parseInt("42"); + +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"; diff --git a/tests/test021.42.js b/tests/test021.42.js index a11cc73..99ef7ff 100644 --- a/tests/test021.42.js +++ b/tests/test021.42.js @@ -1,9 +1,10 @@ /* Javascript eval */ // 42-tiny-js change begin ---> -// in JavaScript eval is not a JSON-parser +// in JavaScript eval is not JSON.parse +// use parentheses or JSON.parse instead //myfoo = eval("{ foo: 42 }"); -myfoo = eval("tmp = { foo: 42 }"); +myfoo = eval("("+"{ foo: 42 }"+")"); //<--- 42-tiny-js change end result = eval("4*10+2")==42 && myfoo.foo==42; diff --git a/tests/test022.42.js b/tests/test022.42.js new file mode 100644 index 0000000..e2fd636 --- /dev/null +++ b/tests/test022.42.js @@ -0,0 +1,15 @@ +/* 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; diff --git a/tests/test032.42.js b/tests/test032.42.js new file mode 100644 index 0000000..b4179ea --- /dev/null +++ b/tests/test032.42.js @@ -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;