From 2390fae5c4b008aa1028ffdddaa071e4084ef8ac Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 23 Dec 2020 22:22:55 +0000 Subject: support default values (#4442) --- test/mocha/getter-setter.js | 59 ++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) (limited to 'test/mocha/getter-setter.js') diff --git a/test/mocha/getter-setter.js b/test/mocha/getter-setter.js index ec811aa1..fc78a25f 100644 --- a/test/mocha/getter-setter.js +++ b/test/mocha/getter-setter.js @@ -3,7 +3,7 @@ var UglifyJS = require("../node"); describe("Getters and setters", function() { it("Should not accept operator symbols as getter/setter name", function() { - var illegalOperators = [ + [ "++", "--", "+", @@ -42,43 +42,26 @@ describe("Getters and setters", function() { "&=", "&&", "||" - ]; - var generator = function() { - var results = []; - - for (var i in illegalOperators) { - results.push({ - code: "var obj = { get " + illegalOperators[i] + "() { return test; }};", - operator: illegalOperators[i], - method: "get" - }); - results.push({ - code: "var obj = { set " + illegalOperators[i] + "(value) { test = value}};", - operator: illegalOperators[i], - method: "set" - }); - } - - return results; - }; - var testCase = function(data) { - return function() { - UglifyJS.parse(data.code); - }; - }; - var fail = function(data) { - return function(e) { + ].reduce(function(tests, illegalOperator) { + tests.push({ + code: "var obj = { get " + illegalOperator + "() { return test; }};", + operator: illegalOperator, + }); + tests.push({ + code: "var obj = { set " + illegalOperator + "(value) { test = value; }};", + operator: illegalOperator, + }); + return tests; + }, []).forEach(function(test) { + assert.throws(function() { + UglifyJS.parse(test.code); + }, test.operator == "=" ? function(e) { + return e instanceof UglifyJS.JS_Parse_Error + && /^Unexpected token: punc «{», expected: punc «.*?»$/.test(e.message); + } : function(e) { return e instanceof UglifyJS.JS_Parse_Error - && e.message === "Unexpected token: operator «" + data.operator + "»"; - }; - }; - var errorMessage = function(data) { - return "Expected but didn't get a syntax error while parsing following line:\n" + data.code; - }; - var tests = generator(); - for (var i = 0; i < tests.length; i++) { - var test = tests[i]; - assert.throws(testCase(test), fail(test), errorMessage(test)); - } + && e.message === "Unexpected token: operator «" + test.operator + "»"; + }, "Expected but didn't get a syntax error while parsing following line:\n" + test.code); + }); }); }); -- cgit v1.2.3