From a942dc07c40105ae92236d0cb0aa80d7ee554d96 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Tue, 28 Feb 2017 03:58:01 +0800 Subject: [PATCH] fix parser tests update exception messages --- test/mocha/arrow.js | 8 ++++---- test/mocha/class.js | 2 +- test/mocha/eof.js | 3 +-- test/mocha/expression.js | 2 +- test/mocha/function.js | 6 +++--- test/mocha/getter-setter.js | 2 +- test/mocha/lhs-expressions.js | 10 +++++----- test/mocha/new.js | 2 +- test/mocha/object.js | 6 +++--- test/mocha/template-string.js | 2 +- test/mocha/unicode.js | 10 +++++----- test/mocha/yield.js | 8 ++++---- 12 files changed, 30 insertions(+), 31 deletions(-) diff --git a/test/mocha/arrow.js b/test/mocha/arrow.js index 7de4c1fa..62cfc0a3 100644 --- a/test/mocha/arrow.js +++ b/test/mocha/arrow.js @@ -15,7 +15,7 @@ describe("Arrow functions", function() { } var error = function(e) { return e instanceof uglify.JS_Parse_Error && - e.message === "SyntaxError: Unexpected token: expand (...)"; + e.message === "Unexpected token: expand (...)"; } for (var i = 0; i < tests.length; i++) { @@ -33,7 +33,7 @@ describe("Arrow functions", function() { } var error = function(e) { return e instanceof uglify.JS_Parse_Error && - e.message === "SyntaxError: Unexpected token: punc (,)"; + e.message === "Unexpected token: punc (,)"; } for (var i = 0; i < tests.length; i++) { @@ -54,7 +54,7 @@ describe("Arrow functions", function() { } var error = function(e) { return e instanceof uglify.JS_Parse_Error && - e.message === "SyntaxError: Unexpected newline before arrow (=>)"; + e.message === "Unexpected newline before arrow (=>)"; } for (var i = 0; i < tests.length; i++) { @@ -73,7 +73,7 @@ describe("Arrow functions", function() { } var error = function(e) { return e instanceof uglify.JS_Parse_Error && - e.message === "SyntaxError: Unexpected token: arrow (=>)"; + e.message === "Unexpected token: arrow (=>)"; } for (var i = 0; i < tests.length; i++) { diff --git a/test/mocha/class.js b/test/mocha/class.js index a81d631a..fcad6278 100644 --- a/test/mocha/class.js +++ b/test/mocha/class.js @@ -16,7 +16,7 @@ describe("Class", function() { } var error = function(e) { return e instanceof uglify.JS_Parse_Error && - e.message.substr(0, 31) === "SyntaxError: Unexpected token: "; + /^Unexpected token: /.test(e.message); } for (var i = 0; i < tests.length; i++) { diff --git a/test/mocha/eof.js b/test/mocha/eof.js index d5a245eb..e15a32c9 100644 --- a/test/mocha/eof.js +++ b/test/mocha/eof.js @@ -4,8 +4,7 @@ var uglify = require("../../"); describe("EOF", function() { it("Should test code for at least throwing syntax error when incomplete", function() { var error = function(e) { - return e instanceof uglify.JS_Parse_Error && - /^SyntaxError: /.test(e.message); + return e instanceof uglify.JS_Parse_Error; } var parse = function(test) { return function() { diff --git a/test/mocha/expression.js b/test/mocha/expression.js index 178cff22..5e2fdcc6 100644 --- a/test/mocha/expression.js +++ b/test/mocha/expression.js @@ -16,7 +16,7 @@ describe("Expression", function() { var fail = function(e) { return e instanceof uglify.JS_Parse_Error && - /^SyntaxError: Unexpected token: operator \((?:[!+~-]|void|typeof|delete)\)/.test(e.message); + /^Unexpected token: operator \((?:[!+~-]|void|typeof|delete)\)/.test(e.message); } var exec = function(test) { diff --git a/test/mocha/function.js b/test/mocha/function.js index 01206f49..b636271c 100644 --- a/test/mocha/function.js +++ b/test/mocha/function.js @@ -177,7 +177,7 @@ describe("Function", function() { } var error = function(e) { return e instanceof uglify.JS_Parse_Error && - e.message.substr(0, 31) === "SyntaxError: Unexpected token: "; + /^Unexpected token: /.test(e.message); } for (var i = 0; i < tests.length; i++) { @@ -196,7 +196,7 @@ describe("Function", function() { } var error = function(e) { return e instanceof uglify.JS_Parse_Error && - e.message === "SyntaxError: Invalid function parameter"; + e.message === "Invalid function parameter"; } for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error); @@ -243,7 +243,7 @@ describe("Function", function() { } var error = function (e) { return e instanceof uglify.JS_Parse_Error && - /^SyntaxError: Parameter [a-zA-Z]+ was used already$/.test(e.message); + /^Parameter [a-zA-Z]+ was used already$/.test(e.message); } for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error, tests[i]); diff --git a/test/mocha/getter-setter.js b/test/mocha/getter-setter.js index 641a2026..fa38f5f2 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 === "Invalid getter/setter name: " + data.operator; + /^Unexpected token: /.test(e.message); }; }; diff --git a/test/mocha/lhs-expressions.js b/test/mocha/lhs-expressions.js index 32b88883..95fda952 100644 --- a/test/mocha/lhs-expressions.js +++ b/test/mocha/lhs-expressions.js @@ -248,18 +248,18 @@ describe("Left-hand side expressions", function () { } // Spreads are not allowed in destructuring array if it's not the last element - expect("[...a, ...b] = [1, 2, 3, 4]", "SyntaxError: Spread must the be last element in destructuring array"); + expect("[...a, ...b] = [1, 2, 3, 4]", "Spread must the be last element in destructuring array"); // Multiple spreads are not allowed in destructuring array - expect("[...a, ...b] = [1, 2, 3, 4]", "SyntaxError: Spread must the be last element in destructuring array"); + expect("[...a, ...b] = [1, 2, 3, 4]", "Spread must the be last element in destructuring array"); // Spread in obvious object pattern - expect("({...a} = foo)", "SyntaxError: Unexpected token: expand (...)"); + expect("({...a} = foo)", "Unexpected token: expand (...)"); // Spread in block should not be allowed - expect("{...a} = foo", "SyntaxError: Unexpected token: expand (...)"); + expect("{...a} = foo", "Unexpected token: expand (...)"); // Not in standard yet - expect("let foo = {bar: 42}, bar; bar = {...foo}", "SyntaxError: Unexpected token: expand (...)"); + expect("let foo = {bar: 42}, bar; bar = {...foo}", "Unexpected token: expand (...)"); }); }); diff --git a/test/mocha/new.js b/test/mocha/new.js index cc193d3d..16c81db1 100644 --- a/test/mocha/new.js +++ b/test/mocha/new.js @@ -89,7 +89,7 @@ describe("New", function() { it("Should check target in new.target", function() { assert.throws(function() {uglify.parse("new.blah")}, function(e) { return e instanceof uglify.JS_Parse_Error - && e.message === "SyntaxError: Unexpected token name «blah», expected name «target»"; + && e.message === "Unexpected token name «blah», expected name «target»"; }); }); }); \ No newline at end of file diff --git a/test/mocha/object.js b/test/mocha/object.js index cabe8a9a..ca09a463 100644 --- a/test/mocha/object.js +++ b/test/mocha/object.js @@ -107,9 +107,9 @@ describe("Object", function() { var fail = function(data) { return function (e) { return e instanceof Uglify.JS_Parse_Error && ( - e.message === "SyntaxError: Unexpected token: operator (" + data.operator + ")" || - (e.message === "SyntaxError: Unterminated regular expression" && data.operator[0] === "/") || - (e.message === "SyntaxError: Unexpected token: punc (()" && data.operator === "*") + e.message === "Unexpected token: operator (" + data.operator + ")" || + (e.message === "Unterminated regular expression" && data.operator[0] === "/") || + (e.message === "Unexpected token: punc (()" && data.operator === "*") ); }; }; diff --git a/test/mocha/template-string.js b/test/mocha/template-string.js index cc6ba7ab..44e0dba6 100644 --- a/test/mocha/template-string.js +++ b/test/mocha/template-string.js @@ -23,7 +23,7 @@ describe("Template string", function() { var fail = function(e) { return e instanceof uglify.JS_Parse_Error - && /^SyntaxError: Unexpected token: /.test(e.message); + && /^Unexpected token: /.test(e.message); }; for (var i = 0; i < tests.length; i++) { diff --git a/test/mocha/unicode.js b/test/mocha/unicode.js index eb29e4a5..01fa71d0 100644 --- a/test/mocha/unicode.js +++ b/test/mocha/unicode.js @@ -17,7 +17,7 @@ describe("Unicode", function() { var fail = function(e) { return e instanceof uglify.JS_Parse_Error - && e.message === "SyntaxError: Unicode reference out of bounce"; + && e.message === "Unicode reference out of bounce"; } for (var i = 0; i < tests.length; i++) { @@ -40,7 +40,7 @@ describe("Unicode", function() { var fail = function(e) { return e instanceof uglify.JS_Parse_Error - && e.message === "SyntaxError: Invalid hex-character pattern in string"; + && e.message === "Invalid hex-character pattern in string"; } for (var i = 0; i < tests.length; i++) { @@ -67,7 +67,7 @@ describe("Unicode", function() { var fail = function(e) { return e instanceof uglify.JS_Parse_Error - && e.message === "SyntaxError: First identifier char is an invalid identifier char"; + && e.message === "First identifier char is an invalid identifier char"; } for (var i = 0; i < tests.length; i++) { @@ -90,7 +90,7 @@ describe("Unicode", function() { var fail = function(e) { return e instanceof uglify.JS_Parse_Error - && e.message === "SyntaxError: Invalid escaped identifier char"; + && e.message === "Invalid escaped identifier char"; } for (var i = 0; i < tests.length; i++) { @@ -115,7 +115,7 @@ describe("Unicode", function() { var fail = function(e) { return e instanceof uglify.JS_Parse_Error - && e.message === "SyntaxError: Escaped characters are not allowed in keywords"; + && e.message === "Escaped characters are not allowed in keywords"; } for (var i = 0; i < tests.length; i++) { diff --git a/test/mocha/yield.js b/test/mocha/yield.js index 676ed832..cf0339b1 100644 --- a/test/mocha/yield.js +++ b/test/mocha/yield.js @@ -15,7 +15,7 @@ describe("Yield", function() { } var expect = function(e) { return e instanceof UglifyJS.JS_Parse_Error && - e.message === "SyntaxError: Yield cannot be used as label inside generators"; + e.message === "Yield cannot be used as label inside generators"; } assert.throws(test, expect); }); @@ -27,7 +27,7 @@ describe("Yield", function() { } var expect = function(e) { return e instanceof UglifyJS.JS_Parse_Error && - e.message === "SyntaxError: Unexpected token: punc (;)"; + e.message === "Unexpected token: punc (;)"; } assert.throws(test, expect); }); @@ -39,7 +39,7 @@ describe("Yield", function() { } var expect = function(e) { return e instanceof UglifyJS.JS_Parse_Error && - e.message === "SyntaxError: Unexpected token: operator (*)"; + e.message === "Unexpected token: operator (*)"; } assert.throws(test, expect); }); @@ -90,7 +90,7 @@ describe("Yield", function() { var fail = function(e) { return e instanceof UglifyJS.JS_Parse_Error && - /SyntaxError: Unexpected yield identifier (?:as parameter )?inside strict mode/.test(e.message); + /^Unexpected yield identifier (?:as parameter )?inside strict mode/.test(e.message); } var test = function(input) {