summaryrefslogtreecommitdiffstats
path: root/devtools/shared/acorn/tests/unit
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/shared/acorn/tests/unit
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/shared/acorn/tests/unit')
-rw-r--r--devtools/shared/acorn/tests/unit/head_acorn.js75
-rw-r--r--devtools/shared/acorn/tests/unit/test_import_acorn.js18
-rw-r--r--devtools/shared/acorn/tests/unit/test_lenient_parser.js62
-rw-r--r--devtools/shared/acorn/tests/unit/test_same_ast.js37
-rw-r--r--devtools/shared/acorn/tests/unit/xpcshell.ini10
5 files changed, 202 insertions, 0 deletions
diff --git a/devtools/shared/acorn/tests/unit/head_acorn.js b/devtools/shared/acorn/tests/unit/head_acorn.js
new file mode 100644
index 000000000..3e06ca3c1
--- /dev/null
+++ b/devtools/shared/acorn/tests/unit/head_acorn.js
@@ -0,0 +1,75 @@
+"use strict";
+var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
+
+
+function isObject(value) {
+ return typeof value === "object" && value !== null;
+}
+
+function intersect(a, b) {
+ const seen = new Set(a);
+ return b.filter(value => seen.has(value));
+}
+
+function checkEquivalentASTs(expected, actual, prop = []) {
+ do_print("Checking: " + prop.join(" "));
+
+ if (!isObject(expected)) {
+ return void do_check_eq(expected, actual);
+ }
+
+ do_check_true(isObject(actual));
+
+ if (Array.isArray(expected)) {
+ do_check_true(Array.isArray(actual));
+ do_check_eq(expected.length, actual.length);
+ for (let i = 0; i < expected.length; i++) {
+ checkEquivalentASTs(expected[i], actual[i], prop.concat(i));
+ }
+ } else {
+ // We must intersect the keys since acorn and Reflect have different
+ // extraneous properties on their AST nodes.
+ const keys = intersect(Object.keys(expected), Object.keys(actual));
+ for (let key of keys) {
+ checkEquivalentASTs(expected[key], actual[key], prop.concat(key));
+ }
+ }
+}
+
+
+// Register a console listener, so console messages don't just disappear
+// into the ether.
+var errorCount = 0;
+var listener = {
+ observe: function (aMessage) {
+ errorCount++;
+ try {
+ // If we've been given an nsIScriptError, then we can print out
+ // something nicely formatted, for tools like Emacs to pick up.
+ var scriptError = aMessage.QueryInterface(Ci.nsIScriptError);
+ dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " +
+ scriptErrorFlagsToKind(aMessage.flags) + ": " +
+ aMessage.errorMessage + "\n");
+ var string = aMessage.errorMessage;
+ } catch (x) {
+ // Be a little paranoid with message, as the whole goal here is to lose
+ // no information.
+ try {
+ var string = "" + aMessage.message;
+ } catch (x) {
+ var string = "<error converting error message to string>";
+ }
+ }
+
+ // Ignored until they are fixed in bug 1242968.
+ if (string.includes("JavaScript Warning")) {
+ return;
+ }
+
+ do_throw("head_acorn.js got console message: " + string + "\n");
+ }
+};
+
+var consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
+consoleService.registerListener(listener);
diff --git a/devtools/shared/acorn/tests/unit/test_import_acorn.js b/devtools/shared/acorn/tests/unit/test_import_acorn.js
new file mode 100644
index 000000000..49b2b50cb
--- /dev/null
+++ b/devtools/shared/acorn/tests/unit/test_import_acorn.js
@@ -0,0 +1,18 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that we can require acorn.
+ */
+
+function run_test() {
+ const acorn = require("acorn/acorn");
+ const acorn_loose = require("acorn/acorn_loose");
+ const walk = require("acorn/util/walk");
+ do_check_true(isObject(acorn));
+ do_check_true(isObject(acorn_loose));
+ do_check_true(isObject(walk));
+ do_check_eq(typeof acorn.parse, "function");
+ do_check_eq(typeof acorn_loose.parse_dammit, "function");
+ do_check_eq(typeof walk.simple, "function");
+}
diff --git a/devtools/shared/acorn/tests/unit/test_lenient_parser.js b/devtools/shared/acorn/tests/unit/test_lenient_parser.js
new file mode 100644
index 000000000..7586eb8a3
--- /dev/null
+++ b/devtools/shared/acorn/tests/unit/test_lenient_parser.js
@@ -0,0 +1,62 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that acorn's lenient parser gives something usable.
+ */
+
+const acorn_loose = require("acorn/acorn_loose");
+
+function run_test() {
+ let actualAST = acorn_loose.parse_dammit("let x = 10", {});
+
+ do_print("Actual AST:");
+ do_print(JSON.stringify(actualAST, null, 2));
+ do_print("Expected AST:");
+ do_print(JSON.stringify(expectedAST, null, 2));
+
+ checkEquivalentASTs(expectedAST, actualAST);
+}
+
+const expectedAST = {
+ "type": "Program",
+ "start": 0,
+ "end": 10,
+ "body": [
+ {
+ "type": "ExpressionStatement",
+ "start": 0,
+ "end": 3,
+ "expression": {
+ "type": "Identifier",
+ "start": 0,
+ "end": 3,
+ "name": "let"
+ }
+ },
+ {
+ "type": "ExpressionStatement",
+ "start": 4,
+ "end": 10,
+ "expression": {
+ "type": "AssignmentExpression",
+ "start": 4,
+ "end": 10,
+ "operator": "=",
+ "left": {
+ "type": "Identifier",
+ "start": 4,
+ "end": 5,
+ "name": "x"
+ },
+ "right": {
+ "type": "Literal",
+ "start": 8,
+ "end": 10,
+ "value": 10,
+ "raw": "10"
+ }
+ }
+ }
+ ]
+};
diff --git a/devtools/shared/acorn/tests/unit/test_same_ast.js b/devtools/shared/acorn/tests/unit/test_same_ast.js
new file mode 100644
index 000000000..d1d76bc50
--- /dev/null
+++ b/devtools/shared/acorn/tests/unit/test_same_ast.js
@@ -0,0 +1,37 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that Reflect and acorn create the same AST for ES5.
+ */
+
+const acorn = require("acorn/acorn");
+const { Reflect } = require("resource://gre/modules/reflect.jsm");
+
+const testCode = "" + function main () {
+ function makeAcc(n) {
+ return function () {
+ return ++n;
+ };
+ }
+
+ var acc = makeAcc(10);
+
+ for (var i = 0; i < 10; i++) {
+ acc();
+ }
+
+ console.log(acc());
+};
+
+function run_test() {
+ const reflectAST = Reflect.parse(testCode);
+ const acornAST = acorn.parse(testCode);
+
+ do_print("Reflect AST:");
+ do_print(JSON.stringify(reflectAST, null, 2));
+ do_print("acorn AST:");
+ do_print(JSON.stringify(acornAST, null, 2));
+
+ checkEquivalentASTs(reflectAST, acornAST);
+}
diff --git a/devtools/shared/acorn/tests/unit/xpcshell.ini b/devtools/shared/acorn/tests/unit/xpcshell.ini
new file mode 100644
index 000000000..414dfe567
--- /dev/null
+++ b/devtools/shared/acorn/tests/unit/xpcshell.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+tags = devtools
+head = head_acorn.js
+tail =
+firefox-appdir = browser
+skip-if = toolkit == 'android'
+
+[test_import_acorn.js]
+[test_same_ast.js]
+[test_lenient_parser.js]