aboutsummaryrefslogtreecommitdiff
path: root/test/mocha
diff options
context:
space:
mode:
Diffstat (limited to 'test/mocha')
-rw-r--r--test/mocha/cli.js39
-rw-r--r--test/mocha/comment.js4
-rw-r--r--test/mocha/directives.js2
-rw-r--r--test/mocha/getter-setter.js2
-rw-r--r--test/mocha/line-endings.js2
-rw-r--r--test/mocha/minify.js19
-rw-r--r--test/mocha/number-literal.js2
-rw-r--r--test/mocha/string-literal.js4
-rw-r--r--test/mocha/with.js2
9 files changed, 65 insertions, 11 deletions
diff --git a/test/mocha/cli.js b/test/mocha/cli.js
index 52c70935..c07eeee7 100644
--- a/test/mocha/cli.js
+++ b/test/mocha/cli.js
@@ -199,4 +199,43 @@ describe("bin/uglifyjs", function () {
done();
});
});
+ it("Should fail with invalid syntax", function(done) {
+ var command = uglifyjscmd + ' test/input/invalid/simple.js';
+
+ exec(command, function (err, stdout, stderr) {
+ assert.ok(err);
+ var lines = stderr.split(/\n/);
+ assert.strictEqual(lines[0], "Parse error at test/input/invalid/simple.js:1,12");
+ assert.strictEqual(lines[1], "function f(a{}");
+ assert.strictEqual(lines[2], " ^");
+ assert.strictEqual(lines[3], "SyntaxError: Unexpected token punc «{», expected punc «,»");
+ done();
+ });
+ });
+ it("Should fail with correct marking of tabs", function(done) {
+ var command = uglifyjscmd + ' test/input/invalid/tab.js';
+
+ exec(command, function (err, stdout, stderr) {
+ assert.ok(err);
+ var lines = stderr.split(/\n/);
+ assert.strictEqual(lines[0], "Parse error at test/input/invalid/tab.js:1,12");
+ assert.strictEqual(lines[1], "\t\tfoo(\txyz, 0abc);");
+ assert.strictEqual(lines[2], "\t\t \t ^");
+ assert.strictEqual(lines[3], "SyntaxError: Invalid syntax: 0abc");
+ done();
+ });
+ });
+ it("Should fail with correct marking at start of line", function(done) {
+ var command = uglifyjscmd + ' test/input/invalid/eof.js';
+
+ exec(command, function (err, stdout, stderr) {
+ assert.ok(err);
+ var lines = stderr.split(/\n/);
+ assert.strictEqual(lines[0], "Parse error at test/input/invalid/eof.js:2,0");
+ assert.strictEqual(lines[1], "foo, bar(");
+ assert.strictEqual(lines[2], " ^");
+ assert.strictEqual(lines[3], "SyntaxError: Unexpected token: eof (undefined)");
+ done();
+ });
+ });
});
diff --git a/test/mocha/comment.js b/test/mocha/comment.js
index 69cdb3d5..56470e0f 100644
--- a/test/mocha/comment.js
+++ b/test/mocha/comment.js
@@ -13,7 +13,7 @@ describe("Comment", function() {
var fail = function(e) {
return e instanceof uglify.JS_Parse_Error &&
- e.message === "SyntaxError: Unexpected token: operator (>)" &&
+ e.message === "Unexpected token: operator (>)" &&
e.line === 2 &&
e.col === 0;
}
@@ -36,7 +36,7 @@ describe("Comment", function() {
var fail = function(e) {
return e instanceof uglify.JS_Parse_Error &&
- e.message === "SyntaxError: Unexpected token: operator (>)" &&
+ e.message === "Unexpected token: operator (>)" &&
e.line === 5 &&
e.col === 0;
}
diff --git a/test/mocha/directives.js b/test/mocha/directives.js
index 82594758..bc763ae0 100644
--- a/test/mocha/directives.js
+++ b/test/mocha/directives.js
@@ -168,7 +168,7 @@ describe("Directives", function() {
throw new Error("Expected parser to fail");
} catch (e) {
assert.strictEqual(e instanceof uglify.JS_Parse_Error, true);
- assert.strictEqual(e.message, "SyntaxError: Unexpected token: punc (])");
+ assert.strictEqual(e.message, "Unexpected token: punc (])");
}
test_directive(tokenizer, tests[i]);
diff --git a/test/mocha/getter-setter.js b/test/mocha/getter-setter.js
index a292fa00..641a2026 100644
--- a/test/mocha/getter-setter.js
+++ b/test/mocha/getter-setter.js
@@ -71,7 +71,7 @@ describe("Getters and setters", function() {
var fail = function(data) {
return function (e) {
return e instanceof UglifyJS.JS_Parse_Error &&
- e.message === "SyntaxError: Invalid getter/setter name: " + data.operator;
+ e.message === "Invalid getter/setter name: " + data.operator;
};
};
diff --git a/test/mocha/line-endings.js b/test/mocha/line-endings.js
index ef46bccd..10e2a1c5 100644
--- a/test/mocha/line-endings.js
+++ b/test/mocha/line-endings.js
@@ -50,7 +50,7 @@ describe("line-endings", function() {
}
var fail = function(e) {
return e instanceof Uglify.JS_Parse_Error &&
- e.message === "SyntaxError: Unexpected line terminator";
+ e.message === "Unexpected line terminator";
}
for (var i = 0; i < inputs.length; i++) {
assert.throws(test(inputs[i]), fail);
diff --git a/test/mocha/minify.js b/test/mocha/minify.js
index 1b830cb5..0cf8c5c1 100644
--- a/test/mocha/minify.js
+++ b/test/mocha/minify.js
@@ -110,7 +110,7 @@ describe("minify", function() {
inSourceMap: "inline",
sourceMapInline: true
});
- }, "multiple input and inline source map");
+ });
});
it("Should fail with SpiderMonkey and inline source map", function() {
assert.throws(function() {
@@ -119,7 +119,7 @@ describe("minify", function() {
sourceMapInline: true,
spidermonkey: true
});
- }, "SpiderMonkey and inline source map");
+ });
});
});
@@ -156,4 +156,19 @@ describe("minify", function() {
});
});
+ describe("JS_Parse_Error", function() {
+ it("should throw syntax error", function() {
+ assert.throws(function() {
+ Uglify.minify("function f(a{}", { fromString: true });
+ }, function(err) {
+ assert.ok(err instanceof Error);
+ assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token punc «{», expected punc «,»");
+ assert.strictEqual(err.filename, 0);
+ assert.strictEqual(err.line, 1);
+ assert.strictEqual(err.col, 12);
+ return true;
+ });
+ });
+ });
+
});
diff --git a/test/mocha/number-literal.js b/test/mocha/number-literal.js
index 8e05574a..e80a5313 100644
--- a/test/mocha/number-literal.js
+++ b/test/mocha/number-literal.js
@@ -15,7 +15,7 @@ describe("Number literals", function () {
}
var error = function(e) {
return e instanceof uglify.JS_Parse_Error &&
- e.message === "SyntaxError: Legacy octal literals are not allowed in strict mode";
+ e.message === "Legacy octal literals are not allowed in strict mode";
}
for (var i = 0; i < inputs.length; i++) {
assert.throws(test(inputs[i]), error, inputs[i]);
diff --git a/test/mocha/string-literal.js b/test/mocha/string-literal.js
index eb9e6f1c..6e337a24 100644
--- a/test/mocha/string-literal.js
+++ b/test/mocha/string-literal.js
@@ -19,7 +19,7 @@ describe("String literals", function() {
var error = function(e) {
return e instanceof UglifyJS.JS_Parse_Error &&
- e.message === "SyntaxError: Unterminated string constant";
+ e.message === "Unterminated string constant";
};
for (var input in inputs) {
@@ -49,7 +49,7 @@ describe("String literals", function() {
var error = function(e) {
return e instanceof UglifyJS.JS_Parse_Error &&
- e.message === "SyntaxError: Legacy octal escape sequences are not allowed in strict mode";
+ e.message === "Legacy octal escape sequences are not allowed in strict mode";
}
for (var input in inputs) {
diff --git a/test/mocha/with.js b/test/mocha/with.js
index 734e1e13..a74ef41a 100644
--- a/test/mocha/with.js
+++ b/test/mocha/with.js
@@ -9,7 +9,7 @@ describe("With", function() {
}
var error = function(e) {
return e instanceof uglify.JS_Parse_Error &&
- e.message === "SyntaxError: Strict mode may not include a with statement";
+ e.message === "Strict mode may not include a with statement";
}
assert.throws(test, error);
});