From 8fa7463fb20d09f7a663d0d82a45bf1dd1f57f74 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 29 May 2012 10:20:28 +0200 Subject: [PATCH] Tests --- tests/instanceof.1.js | 9 +++++++++ tests/prototype.1.js | 14 ++++++++++++++ tests/prototype.2.js | 13 +++++++++++++ tests/prototype.3.js | 10 ++++++++++ tests/switch.1.js | 16 ++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 tests/instanceof.1.js create mode 100644 tests/prototype.1.js create mode 100644 tests/prototype.2.js create mode 100644 tests/prototype.3.js create mode 100644 tests/switch.1.js diff --git a/tests/instanceof.1.js b/tests/instanceof.1.js new file mode 100644 index 000000000..d991574e6 --- /dev/null +++ b/tests/instanceof.1.js @@ -0,0 +1,9 @@ + +function foo() {} +foo.prototype = {} + +var f = new foo() +print(foo.prototype) +print(f.__proto__) +print(foo.prototype == f.__proto__) +print(f instanceof foo) diff --git a/tests/prototype.1.js b/tests/prototype.1.js new file mode 100644 index 000000000..40db84a0a --- /dev/null +++ b/tests/prototype.1.js @@ -0,0 +1,14 @@ + +function foo() { +} + +print(foo.toString()) +print(foo.__proto__) +print(foo.prototype) + +//foo.prototype.xx = function() { +// print("got xx") +//} + +//f = new foo +//f.xx() diff --git a/tests/prototype.2.js b/tests/prototype.2.js new file mode 100644 index 000000000..860385d97 --- /dev/null +++ b/tests/prototype.2.js @@ -0,0 +1,13 @@ + +var oo = {} +function mk() { + function zoo() { + } + zoo.prototype = oo + return new zoo() +} + +var a = mk() +var b = mk() +print(a.__proto__ == b.__proto__) + diff --git a/tests/prototype.3.js b/tests/prototype.3.js new file mode 100644 index 000000000..b76f544ee --- /dev/null +++ b/tests/prototype.3.js @@ -0,0 +1,10 @@ + +function foo() { + this.stuff() +} + +foo.prototype.stuff = function() { + print("this is cool stuff") +} + +f = new foo() diff --git a/tests/switch.1.js b/tests/switch.1.js new file mode 100644 index 000000000..ca29b5f5d --- /dev/null +++ b/tests/switch.1.js @@ -0,0 +1,16 @@ + +function test(a) { + switch (a) { + default: return "cool" + case "xxx": print("got zero"); break; + case "ciao": case "ciao2": return 123 + case "hello": return 321 + } + return 444 +} + +print(test("xxx")) +print(test("hello")) +print(test("ciao")) +print(test("ciao2")) +print(test(9)) -- 2.34.1