aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-08-21 18:34:16 +0800
committerGitHub <noreply@github.com>2018-08-21 18:34:16 +0800
commit57fb58b263677d8667eadc94634c2018934a0f52 (patch)
treeedb923bb88312c9008d311bb8afc74bbd7c81f36 /test/compress
parent18c1c9b38a284279e5370601380a6ef2363e0569 (diff)
downloadtracifyjs-57fb58b263677d8667eadc94634c2018934a0f52.tar.gz
tracifyjs-57fb58b263677d8667eadc94634c2018934a0f52.zip
enhance `if_return` (#3232)
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/if_return.js148
1 files changed, 148 insertions, 0 deletions
diff --git a/test/compress/if_return.js b/test/compress/if_return.js
index c56fa04d..857406d4 100644
--- a/test/compress/if_return.js
+++ b/test/compress/if_return.js
@@ -396,3 +396,151 @@ if_if_return_return: {
}
}
}
+
+if_body_return_1: {
+ options = {
+ if_return: true,
+ }
+ input: {
+ var c = "PASS";
+ function f(a, b) {
+ if (a) {
+ if (b) throw new Error(c);
+ return 42;
+ }
+ return true;
+ }
+ console.log(f(0, 0));
+ console.log(f(0, 1));
+ console.log(f(1, 0));
+ try {
+ f(1, 1);
+ console.log("FAIL");
+ } catch (e) {
+ console.log(e.message);
+ }
+ }
+ expect: {
+ var c = "PASS";
+ function f(a, b) {
+ if (a) {
+ if (b) throw new Error(c);
+ return 42;
+ }
+ return true;
+ }
+ console.log(f(0, 0));
+ console.log(f(0, 1));
+ console.log(f(1, 0));
+ try {
+ f(1, 1);
+ console.log("FAIL");
+ } catch (e) {
+ console.log(e.message);
+ }
+ }
+ expect_stdout: [
+ "true",
+ "true",
+ "42",
+ "PASS",
+ ]
+}
+
+if_body_return_2: {
+ options = {
+ if_return: true,
+ }
+ input: {
+ var c = "PASS";
+ function f(a, b) {
+ if (0 + a) {
+ if (b) throw new Error(c);
+ return 42;
+ }
+ return true;
+ }
+ console.log(f(0, 0));
+ console.log(f(0, 1));
+ console.log(f(1, 0));
+ try {
+ f(1, 1);
+ console.log("FAIL");
+ } catch (e) {
+ console.log(e.message);
+ }
+ }
+ expect: {
+ var c = "PASS";
+ function f(a, b) {
+ if (0 + a) {
+ if (b) throw new Error(c);
+ return 42;
+ }
+ return true;
+ }
+ console.log(f(0, 0));
+ console.log(f(0, 1));
+ console.log(f(1, 0));
+ try {
+ f(1, 1);
+ console.log("FAIL");
+ } catch (e) {
+ console.log(e.message);
+ }
+ }
+ expect_stdout: [
+ "true",
+ "true",
+ "42",
+ "PASS",
+ ]
+}
+
+if_body_return_3: {
+ options = {
+ if_return: true,
+ }
+ input: {
+ var c = "PASS";
+ function f(a, b) {
+ if (1 == a) {
+ if (b) throw new Error(c);
+ return 42;
+ }
+ return true;
+ }
+ console.log(f(0, 0));
+ console.log(f(0, 1));
+ console.log(f(1, 0));
+ try {
+ f(1, 1);
+ console.log("FAIL");
+ } catch (e) {
+ console.log(e.message);
+ }
+ }
+ expect: {
+ var c = "PASS";
+ function f(a, b) {
+ if (1 != a) return true;
+ if (b) throw new Error(c);
+ return 42;
+ }
+ console.log(f(0, 0));
+ console.log(f(0, 1));
+ console.log(f(1, 0));
+ try {
+ f(1, 1);
+ console.log("FAIL");
+ } catch (e) {
+ console.log(e.message);
+ }
+ }
+ expect_stdout: [
+ "true",
+ "true",
+ "42",
+ "PASS",
+ ]
+}