aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/asm.js2
-rw-r--r--test/compress/numbers.js353
2 files changed, 349 insertions, 6 deletions
diff --git a/test/compress/asm.js b/test/compress/asm.js
index cebe6838..1f00f8f2 100644
--- a/test/compress/asm.js
+++ b/test/compress/asm.js
@@ -96,7 +96,7 @@ asm_mixed: {
return +sum;
}
function geometricMean(start, end) {
- return start |= 0, end |= 0, +exp(+logSum(start, end) / +(end - start | 0));
+ return start |= 0, end |= 0, +exp(logSum(start, end) / (end - start | 0));
}
var exp = stdlib.Math.exp, log = stdlib.Math.log, values = new stdlib.Float64Array(buffer);
return { geometricMean: geometricMean };
diff --git a/test/compress/numbers.js b/test/compress/numbers.js
index 000b9ab5..3f579781 100644
--- a/test/compress/numbers.js
+++ b/test/compress/numbers.js
@@ -51,17 +51,20 @@ comparisons: {
comparisons: true,
}
input: {
+ var x = "42", y = "0x30";
console.log(
~x === 42,
- x % n === 42
+ x % y === 42
);
}
expect: {
+ var x = "42", y = "0x30";
console.log(
42 == ~x,
- x % n == 42
+ x % y == 42
);
}
+ expect_stdout: "false true"
}
evaluate_1: {
@@ -103,12 +106,94 @@ evaluate_1: {
}
}
+evaluate_1_unsafe_math: {
+ options = {
+ evaluate: true,
+ unsafe_math: true,
+ }
+ input: {
+ console.log(
+ x + 1 + 2,
+ x * 1 * 2,
+ +x + 1 + 2,
+ 1 + x + 2 + 3,
+ 1 | x | 2 | 3,
+ 1 + x-- + 2 + 3,
+ 1 + (x*y + 2) + 3,
+ 1 + (2 + x + 3),
+ 1 + (2 + ~x + 3),
+ -y + (2 + ~x + 3),
+ 1 & (2 & x & 3),
+ 1 + (2 + (x |= 0) + 3)
+ );
+ }
+ expect: {
+ console.log(
+ x + 1 + 2,
+ 2 * x,
+ +x + 3,
+ 1 + x + 2 + 3,
+ 3 | x,
+ 6 + x--,
+ x*y + 6,
+ 1 + (2 + x + 3),
+ 6 + ~x,
+ 5 - y + ~x,
+ 0 & x,
+ 6 + (x |= 0)
+ );
+ }
+}
+
evaluate_2: {
options = {
evaluate: true,
+ unsafe_math: false,
+ }
+ input: {
+ var x = "42", y = null;
+ console.log(
+ x + 1 + 2,
+ x * 1 * 2,
+ +x + 1 + 2,
+ 1 + x + 2 + 3,
+ 1 | x | 2 | 3,
+ 1 + x-- + 2 + 3,
+ 1 + (x*y + 2) + 3,
+ 1 + (2 + x + 3),
+ 1 + (2 + ~x + 3),
+ -y + (2 + ~x + 3),
+ 1 & (2 & x & 3),
+ 1 + (2 + (x |= 0) + 3)
+ );
+ }
+ expect: {
+ var x = "42", y = null;
+ console.log(
+ x + 1 + 2,
+ 1 * x * 2,
+ +x + 1 + 2,
+ 1 + x + 2 + 3,
+ 3 | x,
+ 1 + x-- + 2 + 3,
+ x*y + 2 + 1 + 3,
+ 1 + (2 + x + 3),
+ 2 + ~x + 3 + 1,
+ 2 + ~x + 3 - y,
+ 0 & x,
+ 2 + (x |= 0) + 3 + 1
+ );
+ }
+ expect_stdout: "4212 84 45 14223 43 48 6 47 -36 -37 0 47"
+}
+
+evaluate_2_unsafe_math: {
+ options = {
+ evaluate: true,
unsafe_math: true,
}
input: {
+ var x = "42", y = null;
console.log(
x + 1 + 2,
x * 1 * 2,
@@ -118,24 +203,30 @@ evaluate_2: {
1 + x-- + 2 + 3,
1 + (x*y + 2) + 3,
1 + (2 + x + 3),
+ 1 + (2 + ~x + 3),
+ -y + (2 + ~x + 3),
1 & (2 & x & 3),
1 + (2 + (x |= 0) + 3)
);
}
expect: {
+ var x = "42", y = null;
console.log(
x + 1 + 2,
2 * x,
- 3 + +x,
+ +x + 3,
1 + x + 2 + 3,
3 | x,
6 + x--,
- 6 + x*y,
+ x*y + 6,
1 + (2 + x + 3),
+ 6 + ~x,
+ 5 + ~x - y,
0 & x,
6 + (x |= 0)
);
}
+ expect_stdout: "4212 84 45 14223 43 48 6 47 -36 -37 0 47"
}
evaluate_3: {
@@ -148,7 +239,7 @@ evaluate_3: {
console.log(1 + Number(x) + 2);
}
expect: {
- console.log(3 + +x);
+ console.log(+x + 3);
}
}
@@ -182,6 +273,258 @@ evaluate_4: {
}
}
+evaluate_5: {
+ options = {
+ evaluate: true,
+ unsafe_math: false,
+ }
+ input: {
+ var a = true;
+ console.log(
+ +a + 2 + 3,
+ +a + 2 - 3,
+ +a - 2 + 3,
+ +a - 2 - 3,
+ 2 + +a + 3,
+ 2 + +a - 3,
+ 2 - +a + 3,
+ 2 - +a - 3,
+ 2 + 3 + +a,
+ 2 + 3 - +a,
+ 2 - 3 + +a,
+ 2 - 3 - +a
+ );
+ }
+ expect: {
+ var a = true;
+ console.log(
+ +a + 2 + 3,
+ +a + 2 - 3,
+ a - 2 + 3,
+ a - 2 - 3,
+ +a + 2 + 3,
+ +a + 2 - 3,
+ 2 - a + 3,
+ 2 - a - 3,
+ +a + 5,
+ 5 - a,
+ +a - 1,
+ -1 - a
+ );
+ }
+ expect_stdout: "6 0 2 -4 6 0 4 -2 6 4 0 -2"
+}
+
+evaluate_5_unsafe_math: {
+ options = {
+ evaluate: true,
+ unsafe_math: true,
+ }
+ input: {
+ var a = true;
+ console.log(
+ +a + 2 + 3,
+ +a + 2 - 3,
+ +a - 2 + 3,
+ +a - 2 - 3,
+ 2 + +a + 3,
+ 2 + +a - 3,
+ 2 - +a + 3,
+ 2 - +a - 3,
+ 2 + 3 + +a,
+ 2 + 3 - +a,
+ 2 - 3 + +a,
+ 2 - 3 - +a
+ );
+ }
+ expect: {
+ var a = true;
+ console.log(
+ +a + 5,
+ +a + -1,
+ a - -1,
+ a - 5,
+ +a + 5,
+ +a + -1,
+ 5 - a,
+ -1 - a,
+ +a + 5,
+ 5 - a,
+ +a - 1,
+ -1 - a
+ );
+ }
+ expect_stdout: "6 0 2 -4 6 0 4 -2 6 4 0 -2"
+}
+
+evaluate_6: {
+ options = {
+ evaluate: true,
+ unsafe_math: false,
+ }
+ input: {
+ var a = true;
+ console.log(
+ -a + 2 + 3,
+ -a + 2 - 3,
+ -a - 2 + 3,
+ -a - 2 - 3,
+ 2 + -a + 3,
+ 2 + -a - 3,
+ 2 - -a + 3,
+ 2 - -a - 3,
+ 2 + 3 + -a,
+ 2 + 3 - -a,
+ 2 - 3 + -a,
+ 2 - 3 - -a
+ );
+ }
+ expect: {
+ var a = true;
+ console.log(
+ 2 - a + 3,
+ 2 - a - 3,
+ -a - 2 + 3,
+ -a - 2 - 3,
+ 2 - a + 3,
+ 2 - a - 3,
+ 2 + a + 3,
+ 2 + a - 3,
+ 5 - a,
+ 5 + a,
+ -1 - a,
+ -1 + a
+ );
+ }
+ expect_stdout: "4 -2 0 -6 4 -2 6 0 4 6 -2 0"
+}
+
+evaluate_6_unsafe_math: {
+ options = {
+ evaluate: true,
+ unsafe_math: true,
+ }
+ input: {
+ var a = true;
+ console.log(
+ -a + 2 + 3,
+ -a + 2 - 3,
+ -a - 2 + 3,
+ -a - 2 - 3,
+ 2 + -a + 3,
+ 2 + -a - 3,
+ 2 - -a + 3,
+ 2 - -a - 3,
+ 2 + 3 + -a,
+ 2 + 3 - -a,
+ 2 - 3 + -a,
+ 2 - 3 - -a
+ );
+ }
+ expect: {
+ var a = true;
+ console.log(
+ 5 - a,
+ -1 - a,
+ -a - -1,
+ -a - 5,
+ 5 - a,
+ -1 - a,
+ 2 + a + 3,
+ -1 + a,
+ 5 - a,
+ 5 + a,
+ -1 - a,
+ -1 + a
+ );
+ }
+ expect_stdout: "4 -2 0 -6 4 -2 6 0 4 6 -2 0"
+}
+
+evaluate_7: {
+ options = {
+ evaluate: true,
+ unsafe_math: false,
+ }
+ input: {
+ var x = "42", y;
+ console.log(
+ +x + 2 + (3 + !y),
+ +x + 2 + (3 - !y),
+ +x + 2 - (3 + !y),
+ +x + 2 - (3 - !y),
+ +x - 2 + (3 + !y),
+ +x - 2 + (3 - !y),
+ +x - 2 - (3 + !y),
+ +x - 2 - (3 - !y)
+ );
+ }
+ expect: {
+ var x = "42", y;
+ console.log(
+ +x + 2 + (3 + !y),
+ +x + 2 + (3 - !y),
+ +x + 2 - (3 + !y),
+ +x + 2 - (3 - !y),
+ x - 2 + (3 + !y),
+ x - 2 + (3 - !y),
+ x - 2 - (3 + !y),
+ x - 2 - (3 - !y)
+ );
+ }
+ expect_stdout: "48 46 40 42 44 42 36 38"
+}
+
+evaluate_7_unsafe_math: {
+ options = {
+ evaluate: true,
+ unsafe_math: true,
+ }
+ input: {
+ var x = "42", y;
+ console.log(
+ +x + 2 + (3 + !y),
+ +x + 2 + (3 - !y),
+ +x + 2 - (3 + !y),
+ +x + 2 - (3 - !y),
+ +x - 2 + (3 + !y),
+ +x - 2 + (3 - !y),
+ +x - 2 - (3 + !y),
+ +x - 2 - (3 - !y)
+ );
+ }
+ expect: {
+ var x = "42", y;
+ console.log(
+ +x + 5 + !y,
+ +x + 5 - !y,
+ +x + -1 - !y,
+ +x + -1 + !y,
+ x - -1 + !y,
+ x - -1 - !y,
+ x - 5 - !y,
+ x - 5 + !y
+ );
+ }
+ expect_stdout: "48 46 40 42 44 42 36 38"
+}
+
+NaN_redefined: {
+ options = {
+ evaluate: true,
+ unsafe_math: true,
+ }
+ input: {
+ var NaN;
+ console.log(1 / (0 / 0));
+ }
+ expect: {
+ var NaN;
+ console.log(0 / 0);
+ }
+ expect_stdout: "NaN"
+}
+
issue_1710: {
options = {
evaluate: true,