Tests
authorRoberto Raggi <roberto.raggi@nokia.com>
Tue, 29 May 2012 08:20:28 +0000 (10:20 +0200)
committerRoberto Raggi <roberto.raggi@nokia.com>
Tue, 29 May 2012 08:20:28 +0000 (10:20 +0200)
tests/instanceof.1.js [new file with mode: 0644]
tests/prototype.1.js [new file with mode: 0644]
tests/prototype.2.js [new file with mode: 0644]
tests/prototype.3.js [new file with mode: 0644]
tests/switch.1.js [new file with mode: 0644]

diff --git a/tests/instanceof.1.js b/tests/instanceof.1.js
new file mode 100644 (file)
index 0000000..d991574
--- /dev/null
@@ -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 (file)
index 0000000..40db84a
--- /dev/null
@@ -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 (file)
index 0000000..860385d
--- /dev/null
@@ -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 (file)
index 0000000..b76f544
--- /dev/null
@@ -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 (file)
index 0000000..ca29b5f
--- /dev/null
@@ -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))