aboutsummaryrefslogtreecommitdiff
path: root/test/mocha
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-23 22:22:55 +0000
committerGitHub <noreply@github.com>2020-12-24 06:22:55 +0800
commit2390fae5c4b008aa1028ffdddaa071e4084ef8ac (patch)
tree962a3258aa0d53d66dda3c6736a3750b46f3f0a3 /test/mocha
parent56fce2131c86ed58ac00bb27b308054b1c2a669f (diff)
downloadtracifyjs-2390fae5c4b008aa1028ffdddaa071e4084ef8ac.tar.gz
tracifyjs-2390fae5c4b008aa1028ffdddaa071e4084ef8ac.zip
support default values (#4442)
Diffstat (limited to 'test/mocha')
-rw-r--r--test/mocha/getter-setter.js59
1 files changed, 21 insertions, 38 deletions
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);
+ });
});
});