aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkzc <kzc@users.noreply.github.com>2017-12-13 23:12:06 -0500
committerAlex Lam S.L <alexlamsl@gmail.com>2017-12-14 12:12:06 +0800
commitd18979bb23358fbdb153568109a5b564cd984920 (patch)
tree84a53f382747bc979bf437c7872553dca00d7481 /test
parent8266993c6e0a78c4872cbcb81072094a4a7dba2d (diff)
downloadtracifyjs-d18979bb23358fbdb153568109a5b564cd984920.tar.gz
tracifyjs-d18979bb23358fbdb153568109a5b564cd984920.zip
improve `dead_code` tests (#2589)
for #2588
Diffstat (limited to 'test')
-rw-r--r--test/compress/dead-code.js136
1 files changed, 136 insertions, 0 deletions
diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js
index 9612b92b..2d2f9d92 100644
--- a/test/compress/dead-code.js
+++ b/test/compress/dead-code.js
@@ -505,6 +505,30 @@ return_assignment: {
console.log(a);
}
}
+ function y() {
+ console.log("y");
+ }
+ function test(inc) {
+ var counter = 0;
+ x = function() {
+ counter += inc;
+ if (inc < 0) throw counter;
+ return counter;
+ };
+ [ f1, f2, f3, f4, f5, f6 ].forEach(function(f, i) {
+ e = null;
+ try {
+ i += 1;
+ console.log("result " + f(10 * i, 100 * i, 1000 * i));
+ } catch (x) {
+ console.log("caught " + x);
+ }
+ if (null !== e) console.log("e: " + e);
+ });
+ }
+ var x, e;
+ test(1);
+ test(-1);
}
expect: {
function f1(a, b, c) {
@@ -533,7 +557,50 @@ return_assignment: {
console.log(a);
}
}
+ function y() {
+ console.log("y");
+ }
+ function test(inc) {
+ var counter = 0;
+ x = function() {
+ counter += inc;
+ if (inc < 0) throw counter;
+ return counter;
+ };
+ [ f1, f2, f3, f4, f5, f6 ].forEach(function(f, i) {
+ e = null;
+ try {
+ i += 1;
+ console.log("result " + f(10 * i, 100 * i, 1000 * i));
+ } catch (x) {
+ console.log("caught " + x);
+ }
+ if (null !== e) console.log("e: " + e);
+ });
+ }
+ var x, e;
+ test(1);
+ test(-1);
}
+ expect_stdout: [
+ "y",
+ "result 31",
+ "result 2",
+ "e: 2",
+ "result 3",
+ "result 4",
+ "result 5",
+ "6",
+ "result 6",
+ "caught -1",
+ "caught -2",
+ "caught -3",
+ "caught -4",
+ "50",
+ "result undefined",
+ "60",
+ "caught -6",
+ ]
}
throw_assignment: {
@@ -596,6 +663,26 @@ throw_assignment: {
console.log(a);
}
}
+ function test(inc) {
+ var counter = 0;
+ x = function() {
+ counter += inc;
+ if (inc < 0) throw counter;
+ return counter;
+ };
+ [ f1, f2, f3, f4, f5, f6, f7, f8, f9 ].forEach(function(f, i) {
+ a = null;
+ try {
+ f(10 * (1 + i));
+ } catch (x) {
+ console.log("caught " + x);
+ }
+ if (null !== a) console.log("a: " + a);
+ });
+ }
+ var x, a;
+ test(1);
+ test(-1);
}
expect: {
function f1() {
@@ -651,5 +738,54 @@ throw_assignment: {
console.log(a);
}
}
+ function test(inc) {
+ var counter = 0;
+ x = function() {
+ counter += inc;
+ if (inc < 0) throw counter;
+ return counter;
+ };
+ [ f1, f2, f3, f4, f5, f6, f7, f8, f9 ].forEach(function(f, i) {
+ a = null;
+ try {
+ f(10 * (1 + i));
+ } catch (x) {
+ console.log("caught " + x);
+ }
+ if (null !== a) console.log("a: " + a);
+ });
+ }
+ var x, a;
+ test(1);
+ test(-1);
}
+ expect_stdout: [
+ "caught 1",
+ "a: 1",
+ "caught 2",
+ "caught 3",
+ "4",
+ "a: 4",
+ "5",
+ "6",
+ "7",
+ "caught 7",
+ "a: 7",
+ "8",
+ "caught 8",
+ "9",
+ "caught 9",
+ "caught -1",
+ "caught -2",
+ "caught -3",
+ "null",
+ "50",
+ "undefined",
+ "null",
+ "caught -7",
+ "80",
+ "caught -8",
+ "undefined",
+ "caught -9",
+ ]
}