aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-02-09 23:21:46 +0000
committerGitHub <noreply@github.com>2020-02-09 23:21:46 +0000
commitf4c77886e748ff5945b73f2584916ec3b760ee98 (patch)
treec3323a38491bfb8a5df4286b6533ac082fc6201e
parentdf547ffd9711d89782675a118830161dee03fba7 (diff)
downloadtracifyjs-f4c77886e748ff5945b73f2584916ec3b760ee98.tar.gz
tracifyjs-f4c77886e748ff5945b73f2584916ec3b760ee98.zip
add test for `--reduce-test` (#3712)
-rw-r--r--test/input/reduce/input.js18
-rw-r--r--test/input/reduce/output.js15
-rw-r--r--test/mocha/reduce.js18
3 files changed, 51 insertions, 0 deletions
diff --git a/test/input/reduce/input.js b/test/input/reduce/input.js
new file mode 100644
index 00000000..b99ffd0e
--- /dev/null
+++ b/test/input/reduce/input.js
@@ -0,0 +1,18 @@
+var _calls_ = 10, a = 100, b = 10, c = 0;
+
+function f0(b_1, a, undefined_2) {
+ a++ + ++b;
+ {
+ var expr2 = (b + 1 - .1 - .1 - .1 || a || 3).toString();
+ L20778: for (var key2 in expr2) {
+ (c = c + 1) + [ --b + b_1, typeof f0 == "function" && --_calls_ >= 0 && f0(--b + typeof (undefined_2 = 1 === 1 ? a : b), --b + {
+ c: (c = c + 1) + null
+ }, a++ + (typeof f0 == "function" && --_calls_ >= 0 && f0(typeof (c = 1 + c, 3 / "a" * ("c" >>> 23..toString()) >= (b_1 && (b_1[(c = c + 1) + a--] = (- -0,
+ true + {})))), 3, 25))), 1 === 1 ? a : b ];
+ }
+ }
+}
+
+var a_1 = f0([ , 0 ].length === 2);
+
+console.log(null, a, b, c, Infinity, NaN, undefined);
diff --git a/test/input/reduce/output.js b/test/input/reduce/output.js
new file mode 100644
index 00000000..25ea7fec
--- /dev/null
+++ b/test/input/reduce/output.js
@@ -0,0 +1,15 @@
+var b = 0;
+
+function f0() {
+ var expr2 = (0 - 1 - .1 - .1).toString();
+ for (var key2 in expr2) {
+ --b;
+ }
+}
+
+var a_1 = f0();
+
+console.log(b);
+// output: -19
+// minify: -4
+// options: {"compress":{"unsafe_math":true},"mangle":false} \ No newline at end of file
diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js
index 5ab4e5b7..f1537d80 100644
--- a/test/mocha/reduce.js
+++ b/test/mocha/reduce.js
@@ -1,8 +1,26 @@
var assert = require("assert");
var exec = require("child_process").exec;
+var fs = require("fs");
var reduce_test = require("../reduce");
+function read(path) {
+ return fs.readFileSync(path, "utf8");
+}
+
describe("test/reduce.js", function() {
+ it("Should reduce test case", function() {
+ this.timeout(30000);
+ var result = reduce_test(read("test/input/reduce/input.js"), {
+ compress: {
+ unsafe_math: true,
+ },
+ mangle: false,
+ }, {
+ verbose: false,
+ });
+ if (result.error) throw result.error;
+ assert.strictEqual(result.code, read("test/input/reduce/output.js"));
+ });
it("Should handle test cases with --toplevel", function() {
var result = reduce_test([
"var Infinity = 42;",