aboutsummaryrefslogtreecommitdiff
path: root/test/mocha
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-17 05:51:52 +0000
committerGitHub <noreply@github.com>2021-03-17 13:51:52 +0800
commit7d595e2eac14022a66ad501707f3e820b87a617d (patch)
treefd3008216607ecafd555f20ccdb289d0c3e3646e /test/mocha
parent9fc0ff5953ffaebffa179284f82bbb01fb9ada3e (diff)
downloadtracifyjs-7d595e2eac14022a66ad501707f3e820b87a617d.tar.gz
tracifyjs-7d595e2eac14022a66ad501707f3e820b87a617d.zip
improve comment formatting logic (#4794)
Diffstat (limited to 'test/mocha')
-rw-r--r--test/mocha/cli.js6
-rw-r--r--test/mocha/comments.js24
2 files changed, 12 insertions, 18 deletions
diff --git a/test/mocha/cli.js b/test/mocha/cli.js
index 9e5de83f..4d4972ec 100644
--- a/test/mocha/cli.js
+++ b/test/mocha/cli.js
@@ -29,7 +29,7 @@ describe("bin/uglifyjs", function() {
var command = uglifyjscmd + ' test/input/comments/filter.js --comments all';
exec(command, function(err, stdout) {
if (err) throw err;
- assert.strictEqual(stdout, "// foo\n/*@preserve*/\n// bar\n\n");
+ assert.strictEqual(stdout, "// foo\n/*@preserve*/\n// bar\n");
done();
});
});
@@ -37,7 +37,7 @@ describe("bin/uglifyjs", function() {
var command = uglifyjscmd + ' test/input/comments/filter.js --comments /r/';
exec(command, function(err, stdout) {
if (err) throw err;
- assert.strictEqual(stdout, "/*@preserve*/\n// bar\n\n");
+ assert.strictEqual(stdout, "/*@preserve*/\n// bar\n");
done();
});
});
@@ -45,7 +45,7 @@ describe("bin/uglifyjs", function() {
var command = uglifyjscmd + ' test/input/comments/filter.js --comments';
exec(command, function(err, stdout) {
if (err) throw err;
- assert.strictEqual(stdout, "/*@preserve*/\n\n");
+ assert.strictEqual(stdout, "/*@preserve*/\n");
done();
});
});
diff --git a/test/mocha/comments.js b/test/mocha/comments.js
index 88cf08c4..830ca107 100644
--- a/test/mocha/comments.js
+++ b/test/mocha/comments.js
@@ -392,12 +392,12 @@ describe("comments", function() {
describe("comment filters", function() {
it("Should be able to filter comments by passing regexp", function() {
var ast = UglifyJS.parse("/*!test1*/\n/*test2*/\n//!test3\n//test4\n<!--test5\n<!--!test6\n-->test7\n-->!test8");
- assert.strictEqual(ast.print_to_string({comments: /^!/}), "/*!test1*/\n//!test3\n//!test6\n//!test8\n");
+ assert.strictEqual(ast.print_to_string({comments: /^!/}), "/*!test1*/\n//!test3\n//!test6\n//!test8");
});
it("Should be able to filter comments with the 'all' option", function() {
var ast = UglifyJS.parse("/*!test1*/\n/*test2*/\n//!test3\n//test4\n<!--test5\n<!--!test6\n-->test7\n-->!test8");
- assert.strictEqual(ast.print_to_string({comments: "all"}), "/*!test1*/\n/*test2*/\n//!test3\n//test4\n//test5\n//!test6\n//test7\n//!test8\n");
+ assert.strictEqual(ast.print_to_string({comments: "all"}), "/*!test1*/\n/*test2*/\n//!test3\n//test4\n//test5\n//!test6\n//test7\n//!test8");
});
it("Should be able to filter commments with the 'some' option", function() {
@@ -410,13 +410,12 @@ describe("comments", function() {
var f = function(node, comment) {
return comment.value.length === 8;
};
-
- assert.strictEqual(ast.print_to_string({comments: f}), "/*TEST 123*/\n//8 chars.\n");
+ assert.strictEqual(ast.print_to_string({comments: f}), "/*TEST 123*/\n//8 chars.");
});
it("Should be able to filter comments by passing regex in string format", function() {
var ast = UglifyJS.parse("/*!test1*/\n/*test2*/\n//!test3\n//test4\n<!--test5\n<!--!test6\n-->test7\n-->!test8");
- assert.strictEqual(ast.print_to_string({comments: "/^!/"}), "/*!test1*/\n//!test3\n//!test6\n//!test8\n");
+ assert.strictEqual(ast.print_to_string({comments: "/^!/"}), "/*!test1*/\n//!test3\n//!test6\n//!test8");
});
it("Should be able to get the comment and comment type when using a function", function() {
@@ -424,14 +423,12 @@ describe("comments", function() {
var f = function(node, comment) {
return comment.type == "comment1" || comment.type == "comment3";
};
-
- assert.strictEqual(ast.print_to_string({comments: f}), "//!test3\n//test4\n//test5\n//!test6\n");
+ assert.strictEqual(ast.print_to_string({comments: f}), "//!test3\n//test4\n//test5\n//!test6");
});
it("Should be able to filter comments by passing a boolean", function() {
var ast = UglifyJS.parse("/*!test1*/\n/*test2*/\n//!test3\n//test4\n<!--test5\n<!--!test6\n-->test7\n-->!test8");
-
- assert.strictEqual(ast.print_to_string({comments: true}), "/*!test1*/\n/*test2*/\n//!test3\n//test4\n//test5\n//!test6\n//test7\n//!test8\n");
+ assert.strictEqual(ast.print_to_string({comments: true}), "/*!test1*/\n/*test2*/\n//!test3\n//test4\n//test5\n//!test6\n//test7\n//!test8");
assert.strictEqual(ast.print_to_string({comments: false}), "");
});
@@ -439,10 +436,8 @@ describe("comments", function() {
var ast = UglifyJS.parse("#!Random comment\n//test1\n/*test2*/");
var f = function(node, comment) {
assert.strictEqual(comment.type === "comment5", false);
-
return true;
};
-
assert.strictEqual(ast.print_to_string({comments: f}), "#!Random comment\n//test1\n/*test2*/");
});
@@ -453,9 +448,8 @@ describe("comments", function() {
it("Should have no problem on multiple calls", function() {
const options = {
- comments: /ok/
+ comments: /ok/,
};
-
assert.strictEqual(UglifyJS.parse("/* ok */ function a(){}").print_to_string(options), "/* ok */function a(){}");
assert.strictEqual(UglifyJS.parse("/* ok */ function a(){}").print_to_string(options), "/* ok */function a(){}");
assert.strictEqual(UglifyJS.parse("/* ok */ function a(){}").print_to_string(options), "/* ok */function a(){}");
@@ -463,14 +457,14 @@ describe("comments", function() {
it("Should handle shebang and preamble correctly", function() {
var code = UglifyJS.minify("#!/usr/bin/node\nvar x = 10;", {
- output: { preamble: "/* Build */" }
+ output: { preamble: "/* Build */" },
}).code;
assert.strictEqual(code, "#!/usr/bin/node\n/* Build */\nvar x=10;");
});
it("Should handle preamble without shebang correctly", function() {
var code = UglifyJS.minify("var x = 10;", {
- output: { preamble: "/* Build */" }
+ output: { preamble: "/* Build */" },
}).code;
assert.strictEqual(code, "/* Build */\nvar x=10;");
});