From 3d0ca01b9186f6dd36e8c765d763f08d6e98b9aa Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Fri, 14 Jun 2024 16:19:28 +0200 Subject: [PATCH] spotless --- .../javascript/tests/es5/StrictTest.java | 25 +- .../tests/es6/NumericSeparatorTest.java | 2 - .../tests/es6/ObjectSealFreezeTest.java | 228 +++++++++--------- .../javascript/tests/es6/PromiseTest.java | 33 ++- 4 files changed, 145 insertions(+), 143 deletions(-) diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es5/StrictTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es5/StrictTest.java index fdb995649e..1f2f9cae27 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es5/StrictTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es5/StrictTest.java @@ -1,9 +1,6 @@ package org.mozilla.javascript.tests.es5; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import org.mozilla.javascript.Context; import org.mozilla.javascript.tests.Utils; /** @@ -14,21 +11,23 @@ public class StrictTest { @Test public void functionCtor() { - final String script = "(function() {" - + "'use strict';" - + "Function('with(this) { }')();" - + "})();" - + "'done'"; + final String script = + "(function() {" + + "'use strict';" + + "Function('with(this) { }')();" + + "})();" + + "'done'"; Utils.assertWithAllOptimizationLevels("done", script); } @Test public void newFunction() { - final String script = "(function() {" - + "'use strict';" - + "new Function('with(this) { }')();" - + "})();" + - "'done'"; + final String script = + "(function() {" + + "'use strict';" + + "new Function('with(this) { }')();" + + "})();" + + "'done'"; Utils.assertWithAllOptimizationLevels("done", script); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/NumericSeparatorTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/NumericSeparatorTest.java index d245c92e88..b46cf9501d 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/NumericSeparatorTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/NumericSeparatorTest.java @@ -6,10 +6,8 @@ import static org.junit.Assert.assertEquals; -import org.junit.Assert; import org.junit.Test; import org.mozilla.javascript.Context; -import org.mozilla.javascript.EvaluatorException; import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.tests.Utils; diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/ObjectSealFreezeTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/ObjectSealFreezeTest.java index 50272eee6a..71d7de64a3 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/ObjectSealFreezeTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/ObjectSealFreezeTest.java @@ -7,160 +7,168 @@ */ package org.mozilla.javascript.tests.es6; -import static org.junit.Assert.assertEquals; - import org.junit.Test; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.tests.Utils; public class ObjectSealFreezeTest { @Test public void sealWriteToExistingWritableProperty() { - final String script = "foo = function() {" - + " var r = {};" - + " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });" - + " Object.seal(r);" - + " r.a = 'Rhino';" - + " return r.a;" - + "};" - + "try { " - + " foo();" - + "} catch (e) { e.message }"; + final String script = + "foo = function() {" + + " var r = {};" + + " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });" + + " Object.seal(r);" + + " r.a = 'Rhino';" + + " return r.a;" + + "};" + + "try { " + + " foo();" + + "} catch (e) { e.message }"; Utils.assertWithAllOptimizationLevelsES6("Rhino", script); } @Test public void sealWriteToExistingWritablePropertyStrict() { - final String script = "foo = function() {" - + " 'use strict';" - + " var r = {};" - + " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });" - + " Object.seal(r);" - + " r.a='Rhino';" - + " return r.a;" - + "};" - + "try { " - + " foo();" - + "} catch (e) { e.message }"; + final String script = + "foo = function() {" + + " 'use strict';" + + " var r = {};" + + " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });" + + " Object.seal(r);" + + " r.a='Rhino';" + + " return r.a;" + + "};" + + "try { " + + " foo();" + + "} catch (e) { e.message }"; Utils.assertWithAllOptimizationLevelsES6("Rhino", script); } @Test public void sealWriteToExistingSymbolProperty() { - final String script = "foo = function() {" - + " var sym = Symbol('X');" - + " var r = {};" - + " r[sym] = 'abc';" - + " Object.seal(r);" - + " r[sym] = 'Rhino';" - + " return r[sym];" - + "};" - + "try { " - + " foo();" - + "} catch (e) { e.message }"; + final String script = + "foo = function() {" + + " var sym = Symbol('X');" + + " var r = {};" + + " r[sym] = 'abc';" + + " Object.seal(r);" + + " r[sym] = 'Rhino';" + + " return r[sym];" + + "};" + + "try { " + + " foo();" + + "} catch (e) { e.message }"; Utils.assertWithAllOptimizationLevelsES6("Rhino", script); } @Test public void sealWriteToExistingSymbolPropertyStrict() { - final String script = "foo = function() {" - + " 'use strict';" - + " var sym = Symbol('X');" - + " var r = {};" - + " r[sym] = 'abc';" - + " Object.seal(r);" - + " r[sym] = 'Rhino';" - + " return r[sym];" - + "};" - + "try { " - + " foo();" - + "} catch (e) { e.message }"; + final String script = + "foo = function() {" + + " 'use strict';" + + " var sym = Symbol('X');" + + " var r = {};" + + " r[sym] = 'abc';" + + " Object.seal(r);" + + " r[sym] = 'Rhino';" + + " return r[sym];" + + "};" + + "try { " + + " foo();" + + "} catch (e) { e.message }"; Utils.assertWithAllOptimizationLevelsES6("Rhino", script); } @Test public void freezeWriteToExistingWritableProperty() { - final String script = "foo = function() {" - + " var r = {};" - + " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });" - + " Object.freeze(r);" - + " r.a = 'Rhino';" - + " return r.a;" - + "};" - + "try { " - + " foo();" - + "} catch (e) { e.message }"; + final String script = + "foo = function() {" + + " var r = {};" + + " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });" + + " Object.freeze(r);" + + " r.a = 'Rhino';" + + " return r.a;" + + "};" + + "try { " + + " foo();" + + "} catch (e) { e.message }"; Utils.assertWithAllOptimizationLevelsES6("abc", script); } @Test public void freezeWriteToExistingWritablePropertyStrict() { - final String script = "foo = function() {" - + " 'use strict';" - + " var r = {};" - + " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });" - + " Object.freeze(r);" - + " r.a='Rhino';" - + " return r.a;" - + "};" - + "try { " - + " foo();" - + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("Cannot add properties to this object because extensible is false.", script); + final String script = + "foo = function() {" + + " 'use strict';" + + " var r = {};" + + " Object.defineProperties(r, { a: { writable: true, value: 'abc' } });" + + " Object.freeze(r);" + + " r.a='Rhino';" + + " return r.a;" + + "};" + + "try { " + + " foo();" + + "} catch (e) { e.message }"; + Utils.assertWithAllOptimizationLevelsES6( + "Cannot add properties to this object because extensible is false.", script); } @Test public void freezeWriteToExistingSymbolProperty() { - final String script = "foo = function() {" - + " var sym = Symbol('X');" - + " var r = {};" - + " r[sym] = 'abc';" - + " Object.freeze(r);" - + " r[sym] = 'Rhino';" - + " return r[sym];" - + "};" - + "try { " - + " foo();" - + "} catch (e) { e.message }"; + final String script = + "foo = function() {" + + " var sym = Symbol('X');" + + " var r = {};" + + " r[sym] = 'abc';" + + " Object.freeze(r);" + + " r[sym] = 'Rhino';" + + " return r[sym];" + + "};" + + "try { " + + " foo();" + + "} catch (e) { e.message }"; Utils.assertWithAllOptimizationLevelsES6("abc", script); } @Test public void freezeWriteToExistingSymbolPropertyStrict() { - final String script = "foo = function() {" - + " 'use strict';" - + " var sym = Symbol('X');" - + " var r = {};" - + " r[sym] = 'abc';" - + " Object.freeze(r);" - + " r[sym] = 'Rhino';" - + " return r[sym];" - + "};" - + "try { " - + " foo();" - + "} catch (e) { e.message }"; - Utils.assertWithAllOptimizationLevelsES6("Cannot add properties to this object because extensible is false.", script); + final String script = + "foo = function() {" + + " 'use strict';" + + " var sym = Symbol('X');" + + " var r = {};" + + " r[sym] = 'abc';" + + " Object.freeze(r);" + + " r[sym] = 'Rhino';" + + " return r[sym];" + + "};" + + "try { " + + " foo();" + + "} catch (e) { e.message }"; + Utils.assertWithAllOptimizationLevelsES6( + "Cannot add properties to this object because extensible is false.", script); } @Test public void objectConstructorForNonExtensibleFunctions() { - final String script = "foo = function() {" - + " var res = '';\n" - + " var a = JSON.stringify;\n" - + " Object.preventExtensions(a);\n" - + " res += 'a.isExtensible = ' + Object.isExtensible(a);\n" - + " res += '\\n';\n" - + " var b = Object(a);\n" - + " res += typeof b;\n" - + " res += '\\n';\n" - + " res += a===b;\n" - + " res += '\\n';\n" - + " res += 'b.isExtensible = ' + Object.isExtensible(b);\n" - + " return res;\n" - + "};" - + " foo();"; - Utils.assertWithAllOptimizationLevelsES6("a.isExtensible = false\nfunction\ntrue\nb.isExtensible = false", script); + final String script = + "foo = function() {" + + " var res = '';\n" + + " var a = JSON.stringify;\n" + + " Object.preventExtensions(a);\n" + + " res += 'a.isExtensible = ' + Object.isExtensible(a);\n" + + " res += '\\n';\n" + + " var b = Object(a);\n" + + " res += typeof b;\n" + + " res += '\\n';\n" + + " res += a===b;\n" + + " res += '\\n';\n" + + " res += 'b.isExtensible = ' + Object.isExtensible(b);\n" + + " return res;\n" + + "};" + + " foo();"; + Utils.assertWithAllOptimizationLevelsES6( + "a.isExtensible = false\nfunction\ntrue\nb.isExtensible = false", script); } } diff --git a/tests/src/test/java/org/mozilla/javascript/tests/es6/PromiseTest.java b/tests/src/test/java/org/mozilla/javascript/tests/es6/PromiseTest.java index 8c93abd599..0692973303 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/es6/PromiseTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/es6/PromiseTest.java @@ -7,36 +7,33 @@ */ package org.mozilla.javascript.tests.es6; -import static org.junit.Assert.assertEquals; - import org.junit.Test; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.ScriptableObject; -import org.mozilla.javascript.TopLevel; import org.mozilla.javascript.tests.Utils; public class PromiseTest { @Test public void ctorCallableThis() { - final String script = " var r = '';" - + " var p = new Promise(function(resolve, reject) {\n" - + " r += this;\n" - + " });\n" - + " r += ' done';\n" - + " r;"; + final String script = + " var r = '';" + + " var p = new Promise(function(resolve, reject) {\n" + + " r += this;\n" + + " });\n" + + " r += ' done';\n" + + " r;"; Utils.assertWithAllOptimizationLevelsTopLevelScopeES6("[object global] done", script); } @Test public void ctorCallableThisStrict() { - final String script = "'use strict';" - + " var r = '';" - + " var p = new Promise(function(resolve, reject) {\n" - + " r += this === undefined;\n" - + " });\n" - + " r += ' done';\n" - + " r;"; + final String script = + "'use strict';" + + " var r = '';" + + " var p = new Promise(function(resolve, reject) {\n" + + " r += this === undefined;\n" + + " });\n" + + " r += ' done';\n" + + " r;"; Utils.assertWithAllOptimizationLevelsES6("true done", script); } }