From a246195412e2864993f00e32aade193234d0aa68 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 17 May 2019 01:28:18 +0800 Subject: enhance `unsafe` `comparisons` (#3419) --- test/compress/comparisons.js | 51 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/compress/comparisons.js b/test/compress/comparisons.js index 461f415c..bb140fd8 100644 --- a/test/compress/comparisons.js +++ b/test/compress/comparisons.js @@ -373,12 +373,55 @@ unsafe_indexOf: { unsafe: true, } input: { - if (Object.keys({ foo: 42 }).indexOf("foo") >= 0) console.log("PASS"); + var a = Object.keys({ foo: 42 }); + if (a.indexOf("bar") < 0) console.log("PASS"); + if (0 > a.indexOf("bar")) console.log("PASS"); + if (a.indexOf("foo") >= 0) console.log("PASS"); + if (0 <= a.indexOf("foo")) console.log("PASS"); + if (a.indexOf("foo") > -1) console.log("PASS"); + if (-1 < a.indexOf("foo")) console.log("PASS"); + if (a.indexOf("bar") == -1) console.log("PASS"); + if (-1 == a.indexOf("bar")) console.log("PASS"); + if (a.indexOf("bar") === -1) console.log("PASS"); + if (-1 === a.indexOf("bar")) console.log("PASS"); + if (a.indexOf("foo") != -1) console.log("PASS"); + if (-1 != a.indexOf("foo")) console.log("PASS"); + if (a.indexOf("foo") !== -1) console.log("PASS"); + if (-1 !== a.indexOf("foo")) console.log("PASS"); } expect: { - if (~Object.keys({ foo: 42 }).indexOf("foo")) console.log("PASS"); - } - expect_stdout: "PASS" + var a = Object.keys({ foo: 42 }); + if (!~a.indexOf("bar")) console.log("PASS"); + if (!~a.indexOf("bar")) console.log("PASS"); + if (~a.indexOf("foo")) console.log("PASS"); + if (~a.indexOf("foo")) console.log("PASS"); + if (~a.indexOf("foo")) console.log("PASS"); + if (~a.indexOf("foo")) console.log("PASS"); + if (!~a.indexOf("bar")) console.log("PASS"); + if (!~a.indexOf("bar")) console.log("PASS"); + if (!~a.indexOf("bar")) console.log("PASS"); + if (!~a.indexOf("bar")) console.log("PASS"); + if (~a.indexOf("foo")) console.log("PASS"); + if (~a.indexOf("foo")) console.log("PASS"); + if (~a.indexOf("foo")) console.log("PASS"); + if (~a.indexOf("foo")) console.log("PASS"); + } + expect_stdout: [ + "PASS", + "PASS", + "PASS", + "PASS", + "PASS", + "PASS", + "PASS", + "PASS", + "PASS", + "PASS", + "PASS", + "PASS", + "PASS", + "PASS", + ] } issue_3413: { -- cgit v1.2.3