[gjs/wip/jsversion-rebase2: 8/8] Add explicit tests of JS version functionality
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/jsversion-rebase2: 8/8] Add explicit tests of JS version functionality
- Date: Mon, 6 Dec 2010 22:07:51 +0000 (UTC)
commit bbb159bafdf6c738915289a429836e859efaf3b7
Author: Colin Walters <walters verbum org>
Date: Sat Dec 4 18:04:56 2010 -0500
Add explicit tests of JS version functionality
Makefile-test.am | 2 +
test/js/testJS1_8.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++
test/js/testJSDefault.js | 14 ++++++++++++
3 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-test.am b/Makefile-test.am
index 78a03af..dcb814a 100644
--- a/Makefile-test.am
+++ b/Makefile-test.am
@@ -180,6 +180,8 @@ EXTRA_DIST += \
test/js/testGI.js \
test/js/testGIMarshalling.js \
test/js/testImporter.js \
+ test/js/testJS1_8.js \
+ test/js/testJSDefault.js \
test/js/testLang.js \
test/js/testLocale.js \
test/js/testMainloop.js \
diff --git a/test/js/testJS1_8.js b/test/js/testJS1_8.js
new file mode 100644
index 0000000..29c83c7
--- /dev/null
+++ b/test/js/testJS1_8.js
@@ -0,0 +1,54 @@
+// application/javascript;version=1.8
+
+// Test SpiderMonkey JS extensions; see
+// https://developer.mozilla.org/en/JavaScript/New_in_JavaScript/1.8
+
+// "const"
+const GLib = imports.gi.GLib;
+
+function testLet() {
+ // "let"
+ let foo = "bar";
+ let cow = "moo";
+
+ assertEquals(foo, "bar");
+}
+
+function testMultiReturn() {
+ const GLib = imports.gi.GLib;
+
+ // "destructuring bind"
+ let [success, content, len] = GLib.file_get_contents('/etc/passwd')
+ assertEquals(success, true);
+}
+
+function testYield() {
+ function fib() {
+ var i = 0, j = 1;
+ while (true) {
+ yield i;
+ var t = i;
+ i = j;
+ j += t;
+ }
+ }
+
+ var v = [];
+ var g = fib();
+ for (var i = 0; i < 10; i++) {
+ v.push(g.next());
+ }
+
+ assertEquals(v[0], 0);
+ assertEquals(v[1], 1);
+ assertEquals(v[2], 1);
+ assertEquals(v[3], 2);
+ assertEquals(v[4], 3);
+ assertEquals(v[5], 5);
+ assertEquals(v[6], 8);
+ assertEquals(v[7], 13);
+ assertEquals(v[8], 21);
+ assertEquals(v[9], 34);
+}
+
+gjstestRun();
diff --git a/test/js/testJSDefault.js b/test/js/testJSDefault.js
new file mode 100644
index 0000000..8231e0f
--- /dev/null
+++ b/test/js/testJSDefault.js
@@ -0,0 +1,14 @@
+// Test that we *don't* get SpiderMonkey extensions; see
+// testJS1_8.js.
+
+var GLib = imports.gi.GLib;
+
+function testLet() {
+ assertRaises('missing ; before statement', function () { eval("let result = 1+1; result;") });
+}
+
+function testYield() {
+ assertRaises('missing ; before statement', function() { eval("function foo () { yield 42; }; foo();"); });
+}
+
+gjstestRun();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]