diff options
author | Anthony Van de Gejuchte <anthonyvdgent@gmail.com> | 2016-09-03 23:26:31 +0200 |
---|---|---|
committer | Anthony Van de Gejuchte <anthonyvdgent@gmail.com> | 2016-09-06 17:54:45 +0200 |
commit | 0111497fc98d5098f81bc749f77da5734add37bb (patch) | |
tree | c0d7e4da363639a4c68457d2f90e2eebc61796e8 /test | |
parent | 7d8dea3b2675f9d86ea15bb031b7fe166858d67e (diff) | |
download | tracifyjs-0111497fc98d5098f81bc749f77da5734add37bb.tar.gz tracifyjs-0111497fc98d5098f81bc749f77da5734add37bb.zip |
Make all comment options in cli available in js api
Also removing more code within "loop" while at it.
Diffstat (limited to 'test')
-rw-r--r-- | test/input/comments/filter.js | 3 | ||||
-rw-r--r-- | test/mocha/cli.js | 34 | ||||
-rw-r--r-- | test/mocha/comment-filter.js | 15 |
3 files changed, 50 insertions, 2 deletions
diff --git a/test/input/comments/filter.js b/test/input/comments/filter.js new file mode 100644 index 00000000..c752080f --- /dev/null +++ b/test/input/comments/filter.js @@ -0,0 +1,3 @@ +// foo +/*@preserve*/ +// bar diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 38b57cd7..495b0076 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -2,11 +2,11 @@ var assert = require("assert"); var exec = require("child_process").exec; describe("bin/uglifyjs", function () { + var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs'; it("should produce a functional build when using --self", function (done) { this.timeout(5000); - var uglifyjs = '"' + process.argv[0] + '" bin/uglifyjs'; - var command = uglifyjs + ' --self -cm --wrap WrappedUglifyJS'; + var command = uglifyjscmd + ' --self -cm --wrap WrappedUglifyJS'; exec(command, function (err, stdout) { if (err) throw err; @@ -19,4 +19,34 @@ describe("bin/uglifyjs", function () { done(); }); }); + it("Should be able to filter comments correctly with `--comment all`", function (done) { + 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"); + done(); + }); + }); + it("Should be able to filter comments correctly with `--comment <RegExp>`", function (done) { + 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"); + done(); + }); + }); + it("Should be able to filter comments correctly with just `--comment`", function (done) { + var command = uglifyjscmd + ' test/input/comments/filter.js --comments'; + + exec(command, function (err, stdout) { + if (err) throw err; + + assert.strictEqual(stdout, "/*@preserve*/\n\n"); + done(); + }); + }); }); diff --git a/test/mocha/comment-filter.js b/test/mocha/comment-filter.js index ea2ec2eb..4330d1eb 100644 --- a/test/mocha/comment-filter.js +++ b/test/mocha/comment-filter.js @@ -7,6 +7,16 @@ describe("comment filters", function() { assert.strictEqual(ast.print_to_string({comments: /^!/}), "/*!test1*/\n//!test3\n//!test6\n//!test8\n"); }); + 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"); + }); + + it("Should be able to filter commments with the 'some' option", function() { + var ast = UglifyJS.parse("// foo\n/*@preserve*/\n// bar\n/*@license*/\n//@license with the wrong comment type\n/*@cc_on something*/"); + assert.strictEqual(ast.print_to_string({comments: "some"}), "/*@preserve*/\n/*@license*/\n/*@cc_on something*/\n"); + }); + it("Should be able to filter comments by passing a function", function() { var ast = UglifyJS.parse("/*TEST 123*/\n//An other comment\n//8 chars."); var f = function(node, comment) { @@ -16,6 +26,11 @@ describe("comment filters", function() { assert.strictEqual(ast.print_to_string({comments: f}), "/*TEST 123*/\n//8 chars.\n"); }); + 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"); + }); + it("Should be able to get the comment and comment type when using a function", function() { var ast = UglifyJS.parse("/*!test1*/\n/*test2*/\n//!test3\n//test4\n<!--test5\n<!--!test6\n-->test7\n-->!test8"); var f = function(node, comment) { |