diff --git a/Libraries/LibJS/Tests/.prettierrc b/Libraries/LibJS/Tests/.prettierrc new file mode 100644 index 0000000000..24f9031ebc --- /dev/null +++ b/Libraries/LibJS/Tests/.prettierrc @@ -0,0 +1,13 @@ +{ + "arrowParens": "avoid", + "bracketSpacing": true, + "endOfLine": "lf", + "insertPragma": false, + "printWidth": 100, + "quoteProps": "as-needed", + "semi": true, + "singleQuote": false, + "tabWidth": 2, + "trailingComma": "es5", + "useTabs": false +} diff --git a/Libraries/LibJS/Tests/add-values-to-primitive.js b/Libraries/LibJS/Tests/add-values-to-primitive.js index 3bef2209ba..7d10739183 100644 --- a/Libraries/LibJS/Tests/add-values-to-primitive.js +++ b/Libraries/LibJS/Tests/add-values-to-primitive.js @@ -1,6 +1,6 @@ test("adding objects", () => { - expect([] + []).toBe(""); - expect([] + {}).toBe("[object Object]"); - expect({} + {}).toBe("[object Object][object Object]"); - expect({} + []).toBe("[object Object]"); + expect([] + []).toBe(""); + expect([] + {}).toBe("[object Object]"); + expect({} + {}).toBe("[object Object][object Object]"); + expect({} + []).toBe("[object Object]"); }); diff --git a/Libraries/LibJS/Tests/automatic-semicolon-insertion.js b/Libraries/LibJS/Tests/automatic-semicolon-insertion.js index 92ba35a3e5..ba971aa31f 100644 --- a/Libraries/LibJS/Tests/automatic-semicolon-insertion.js +++ b/Libraries/LibJS/Tests/automatic-semicolon-insertion.js @@ -1,6 +1,5 @@ test("Issue #1829, if-else without braces or semicolons", () => { - const source = -`if (1) + const source = `if (1) return 1; else return 0; @@ -15,12 +14,11 @@ if (1) else return 0;`; - expect(source).toEval(); + expect(source).toEval(); }); test("break/continue, variable declaration, do-while, and return asi", () => { - const source = -`function foo() { + const source = `function foo() { label: for (var i = 0; i < 4; i++) { break // semicolon inserted here @@ -41,12 +39,11 @@ var curly/* semicolon inserted here */} return foo();`; - expect(source).toEvalTo(undefined); + expect(source).toEvalTo(undefined); }); test("more break and continue asi", () => { - const source = -`let counter = 0; + const source = `let counter = 0; let outer; outer: @@ -60,9 +57,9 @@ for (let i = 0; i < 5; ++i) { return counter;`; - expect(source).toEvalTo(5); + expect(source).toEvalTo(5); }); test("eof with no semicolon", () => { - expect("var eof").toEval(); + expect("var eof").toEval(); }); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js b/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js index 714f6e08ea..7216ca4c34 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js @@ -1,28 +1,28 @@ load("test-common.js"); try { - assert(Array.isArray.length === 1); + assert(Array.isArray.length === 1); - assert(Array.isArray() === false); - assert(Array.isArray("1") === false); - assert(Array.isArray("foo") === false); - assert(Array.isArray(1) === false); - assert(Array.isArray(1, 2, 3) === false); - assert(Array.isArray(undefined) === false); - assert(Array.isArray(null) === false); - assert(Array.isArray(Infinity) === false); - assert(Array.isArray({}) === false); + assert(Array.isArray() === false); + assert(Array.isArray("1") === false); + assert(Array.isArray("foo") === false); + assert(Array.isArray(1) === false); + assert(Array.isArray(1, 2, 3) === false); + assert(Array.isArray(undefined) === false); + assert(Array.isArray(null) === false); + assert(Array.isArray(Infinity) === false); + assert(Array.isArray({}) === false); - assert(Array.isArray([]) === true); - assert(Array.isArray([1]) === true); - assert(Array.isArray([1, 2, 3]) === true); - assert(Array.isArray(new Array()) === true); - assert(Array.isArray(new Array(10)) === true); - assert(Array.isArray(new Array("a", "b", "c")) === true); - // FIXME: Array.prototype is supposed to be an array! - // assert(Array.isArray(Array.prototype) === true); + assert(Array.isArray([]) === true); + assert(Array.isArray([1]) === true); + assert(Array.isArray([1, 2, 3]) === true); + assert(Array.isArray(new Array()) === true); + assert(Array.isArray(new Array(10)) === true); + assert(Array.isArray(new Array("a", "b", "c")) === true); + // FIXME: Array.prototype is supposed to be an array! + // assert(Array.isArray(Array.prototype) === true); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.js b/Libraries/LibJS/Tests/builtins/Array/Array.js index a96388a006..0fa6e4dd20 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.js @@ -1,48 +1,55 @@ load("test-common.js"); try { - assert(Array.length === 1); - assert(Array.name === "Array"); - assert(Array.prototype.length === 0); + assert(Array.length === 1); + assert(Array.name === "Array"); + assert(Array.prototype.length === 0); - assert(typeof Array() === "object"); - assert(typeof new Array() === "object"); + assert(typeof Array() === "object"); + assert(typeof new Array() === "object"); - var a; + var a; - a = new Array(5); - assert(a.length === 5); + a = new Array(5); + assert(a.length === 5); - a = new Array("5"); - assert(a.length === 1); - assert(a[0] === "5"); + a = new Array("5"); + assert(a.length === 1); + assert(a[0] === "5"); - a = new Array(1, 2, 3); - assert(a.length === 3); - assert(a[0] === 1); - assert(a[1] === 2); - assert(a[2] === 3); + a = new Array(1, 2, 3); + assert(a.length === 3); + assert(a[0] === 1); + assert(a[1] === 2); + assert(a[2] === 3); - a = new Array([1, 2, 3]); - assert(a.length === 1); - assert(a[0][0] === 1); - assert(a[0][1] === 2); - assert(a[0][2] === 3); + a = new Array([1, 2, 3]); + assert(a.length === 1); + assert(a[0][0] === 1); + assert(a[0][1] === 2); + assert(a[0][2] === 3); - a = new Array(1, 2, 3); - Object.defineProperty(a, 3, { get() { return 10; } }); - assert(a.toString() === "1,2,3,10"); + a = new Array(1, 2, 3); + Object.defineProperty(a, 3, { + get() { + return 10; + }, + }); + assert(a.toString() === "1,2,3,10"); - [-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => { - assertThrowsError(() => { - new Array(value); - }, { - error: TypeError, - message: "Invalid array length" - }); - }); + [-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => { + assertThrowsError( + () => { + new Array(value); + }, + { + error: TypeError, + message: "Invalid array length", + } + ); + }); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.of.js b/Libraries/LibJS/Tests/builtins/Array/Array.of.js index 49b1561d88..e8e60c23a0 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.of.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.of.js @@ -1,46 +1,50 @@ load("test-common.js"); try { - assert(Array.of.length === 0); + assert(Array.of.length === 0); - assert(typeof Array.of() === "object"); + assert(typeof Array.of() === "object"); - var a; + var a; - a = Array.of(5); - assert(a.length === 1); - assert(a[0] === 5); + a = Array.of(5); + assert(a.length === 1); + assert(a[0] === 5); - a = Array.of("5"); - assert(a.length === 1); - assert(a[0] === "5"); + a = Array.of("5"); + assert(a.length === 1); + assert(a[0] === "5"); - a = Array.of(Infinity); - assert(a.length === 1); - assert(a[0] === Infinity); + a = Array.of(Infinity); + assert(a.length === 1); + assert(a[0] === Infinity); - a = Array.of(1, 2, 3); - assert(a.length === 3); - assert(a[0] === 1); - assert(a[1] === 2); - assert(a[2] === 3); + a = Array.of(1, 2, 3); + assert(a.length === 3); + assert(a[0] === 1); + assert(a[1] === 2); + assert(a[2] === 3); - a = Array.of([1, 2, 3]); - assert(a.length === 1); - assert(a[0][0] === 1); - assert(a[0][1] === 2); - assert(a[0][2] === 3); + a = Array.of([1, 2, 3]); + assert(a.length === 1); + assert(a[0][0] === 1); + assert(a[0][1] === 2); + assert(a[0][2] === 3); - let t = [1, 2, 3]; - Object.defineProperty(t, 3, { get() { return 4; } }); - a = Array.of(...t); - assert(a.length === 4); - assert(a[0] === 1); - assert(a[1] === 2); - assert(a[2] === 3); - assert(a[3] === 4); + let t = [1, 2, 3]; + Object.defineProperty(t, 3, { + get() { + return 4; + }, + }); + a = Array.of(...t); + assert(a.length === 4); + assert(a[0] === 1); + assert(a[1] === 2); + assert(a[2] === 3); + assert(a[3] === 4); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js index 7f00edcae7..778e9fe619 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js @@ -1,134 +1,159 @@ load("test-common.js"); try { - [undefined, "foo", -42, 0].forEach(length => { - const o = { length }; + [undefined, "foo", -42, 0].forEach(length => { + const o = { length }; - assert(Array.prototype.push.call(o, "foo") === 1); - assert(o.length === 1); - assert(o[0] === "foo"); - assert(Array.prototype.push.call(o, "bar", "baz") === 3); - assert(o.length === 3); - assert(o[0] === "foo"); - assert(o[1] === "bar"); - assert(o[2] === "baz"); + assert(Array.prototype.push.call(o, "foo") === 1); + assert(o.length === 1); + assert(o[0] === "foo"); + assert(Array.prototype.push.call(o, "bar", "baz") === 3); + assert(o.length === 3); + assert(o[0] === "foo"); + assert(o[1] === "bar"); + assert(o[2] === "baz"); - assert(Array.prototype.pop.call(o) === "baz"); - assert(o.length === 2); - assert(Array.prototype.pop.call(o) === "bar"); - assert(o.length === 1); - assert(Array.prototype.pop.call(o) === "foo"); - assert(o.length === 0); - assert(Array.prototype.pop.call(o) === undefined); - assert(o.length === 0); + assert(Array.prototype.pop.call(o) === "baz"); + assert(o.length === 2); + assert(Array.prototype.pop.call(o) === "bar"); + assert(o.length === 1); + assert(Array.prototype.pop.call(o) === "foo"); + assert(o.length === 0); + assert(Array.prototype.pop.call(o) === undefined); + assert(o.length === 0); - o.length = length; - assert(Array.prototype.pop.call(o) === undefined); - assert(o.length === 0); - }); + o.length = length; + assert(Array.prototype.pop.call(o) === undefined); + assert(o.length === 0); + }); - { - const o = { length: 3, 0: "hello", 2: "serenity" }; - const removed = Array.prototype.splice.call(o, 0, 2, "hello", "friends"); - assert(o.length === 3); - assert(o[0] === "hello"); - assert(o[1] === "friends"); - assert(o[2] === "serenity"); - assert(removed.length === 2); - assert(removed[0] === "hello"); - assert(removed[1] === undefined); - } + { + const o = { length: 3, 0: "hello", 2: "serenity" }; + const removed = Array.prototype.splice.call(o, 0, 2, "hello", "friends"); + assert(o.length === 3); + assert(o[0] === "hello"); + assert(o[1] === "friends"); + assert(o[2] === "serenity"); + assert(removed.length === 2); + assert(removed[0] === "hello"); + assert(removed[1] === undefined); + } - { - assert(Array.prototype.join.call({}) === ""); - assert(Array.prototype.join.call({ length: "foo" }) === ""); - assert(Array.prototype.join.call({ length: 3 }) === ",,"); - assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" }) === "foo,bar"); - assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" }) === "foo,bar"); - assert(Array.prototype.join.call({ length: 3, 1: "bar" }, "~") === "~bar~"); - assert(Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~") === "foo~bar~baz"); - } + { + assert(Array.prototype.join.call({}) === ""); + assert(Array.prototype.join.call({ length: "foo" }) === ""); + assert(Array.prototype.join.call({ length: 3 }) === ",,"); + assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" }) === "foo,bar"); + assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" }) === "foo,bar"); + assert(Array.prototype.join.call({ length: 3, 1: "bar" }, "~") === "~bar~"); + assert( + Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~") === "foo~bar~baz" + ); + } - { - assert(Array.prototype.toString.call({}) === "[object Object]"); - assert(Array.prototype.toString.call({ join: "foo" }) === "[object Object]"); - assert(Array.prototype.toString.call({ join: () => "foo" }) === "foo"); - } + { + assert(Array.prototype.toString.call({}) === "[object Object]"); + assert(Array.prototype.toString.call({ join: "foo" }) === "[object Object]"); + assert(Array.prototype.toString.call({ join: () => "foo" }) === "foo"); + } - { - assert(Array.prototype.indexOf.call({}) === -1); - assert(Array.prototype.indexOf.call({ 0: undefined }) === -1); - assert(Array.prototype.indexOf.call({ length: 1, 0: undefined }) === 0); - assert(Array.prototype.indexOf.call({ length: 1, 2: "foo" }, "foo") === -1); - assert(Array.prototype.indexOf.call({ length: 5, 2: "foo" }, "foo") === 2); - assert(Array.prototype.indexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", 3) === 4); - } + { + assert(Array.prototype.indexOf.call({}) === -1); + assert(Array.prototype.indexOf.call({ 0: undefined }) === -1); + assert(Array.prototype.indexOf.call({ length: 1, 0: undefined }) === 0); + assert(Array.prototype.indexOf.call({ length: 1, 2: "foo" }, "foo") === -1); + assert(Array.prototype.indexOf.call({ length: 5, 2: "foo" }, "foo") === 2); + assert(Array.prototype.indexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", 3) === 4); + } - { - assert(Array.prototype.lastIndexOf.call({}) === -1); - assert(Array.prototype.lastIndexOf.call({ 0: undefined }) === -1); - assert(Array.prototype.lastIndexOf.call({ length: 1, 0: undefined }) === 0); - assert(Array.prototype.lastIndexOf.call({ length: 1, 2: "foo" }, "foo") === -1); - assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo" }, "foo") === 2); - assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo") === 4); - assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", -2) === 2); - } + { + assert(Array.prototype.lastIndexOf.call({}) === -1); + assert(Array.prototype.lastIndexOf.call({ 0: undefined }) === -1); + assert(Array.prototype.lastIndexOf.call({ length: 1, 0: undefined }) === 0); + assert(Array.prototype.lastIndexOf.call({ length: 1, 2: "foo" }, "foo") === -1); + assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo" }, "foo") === 2); + assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo") === 4); + assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", -2) === 2); + } - { - assert(Array.prototype.includes.call({}) === false); - assert(Array.prototype.includes.call({ 0: undefined }) === false); - assert(Array.prototype.includes.call({ length: 1, 0: undefined }) === true); - assert(Array.prototype.includes.call({ length: 1, 2: "foo" }, "foo") === false); - assert(Array.prototype.includes.call({ length: 5, 2: "foo" }, "foo") === true); - } + { + assert(Array.prototype.includes.call({}) === false); + assert(Array.prototype.includes.call({ 0: undefined }) === false); + assert(Array.prototype.includes.call({ length: 1, 0: undefined }) === true); + assert(Array.prototype.includes.call({ length: 1, 2: "foo" }, "foo") === false); + assert(Array.prototype.includes.call({ length: 5, 2: "foo" }, "foo") === true); + } - const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" }; + const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" }; - { - assertVisitsAll(visit => { - Array.prototype.every.call(o, function (value) { - visit(value); - return true; - }); - }, ["foo", "bar", "baz"]); - } + { + assertVisitsAll( + visit => { + Array.prototype.every.call(o, function (value) { + visit(value); + return true; + }); + }, + ["foo", "bar", "baz"] + ); + } - ["find", "findIndex"].forEach(name => { - assertVisitsAll(visit => { - Array.prototype[name].call(o, function (value) { - visit(value); - return false; - }); - }, ["foo", "bar", undefined, "baz", undefined]); - }); + ["find", "findIndex"].forEach(name => { + assertVisitsAll( + visit => { + Array.prototype[name].call(o, function (value) { + visit(value); + return false; + }); + }, + ["foo", "bar", undefined, "baz", undefined] + ); + }); - ["filter", "forEach", "map", "some"].forEach(name => { - assertVisitsAll(visit => { - Array.prototype[name].call(o, function (value) { - visit(value); - return false; - }); - }, ["foo", "bar", "baz"]); - }); - { - assertVisitsAll(visit => { - Array.prototype.reduce.call(o, function (_, value) { - visit(value); - return false; - }, "initial"); - }, ["foo", "bar", "baz"]); - } + ["filter", "forEach", "map", "some"].forEach(name => { + assertVisitsAll( + visit => { + Array.prototype[name].call(o, function (value) { + visit(value); + return false; + }); + }, + ["foo", "bar", "baz"] + ); + }); + { + assertVisitsAll( + visit => { + Array.prototype.reduce.call( + o, + function (_, value) { + visit(value); + return false; + }, + "initial" + ); + }, + ["foo", "bar", "baz"] + ); + } - { - assertVisitsAll(visit => { - Array.prototype.reduceRight.call(o, function (_, value) { - visit(value); - return false; - }, "initial"); - }, ["baz", "bar", "foo"]); - } + { + assertVisitsAll( + visit => { + Array.prototype.reduceRight.call( + o, + function (_, value) { + visit(value); + return false; + }, + "initial" + ); + }, + ["baz", "bar", "foo"] + ); + } - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.concat.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.concat.js index da311b5bc8..55e9a96bd5 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.concat.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.concat.js @@ -1,37 +1,36 @@ load("test-common.js"); try { - assert(Array.prototype.concat.length === 1); + assert(Array.prototype.concat.length === 1); - var array = ["hello", "friends"]; + var array = ["hello", "friends"]; - var array_concat = array.concat(); - assert(array_concat.length === array.length); + var array_concat = array.concat(); + assert(array_concat.length === array.length); - array_concat = array.concat(1) - assert(array_concat.length === 3); - assert(array_concat[2] === 1); + array_concat = array.concat(1); + assert(array_concat.length === 3); + assert(array_concat[2] === 1); - array_concat = array.concat([1, 2, 3]) - assert(array_concat.length === 5); - assert(array_concat[2] === 1); - assert(array_concat[3] === 2); - assert(array_concat[4] === 3); + array_concat = array.concat([1, 2, 3]); + assert(array_concat.length === 5); + assert(array_concat[2] === 1); + assert(array_concat[3] === 2); + assert(array_concat[4] === 3); - array_concat = array.concat(false, "serenity"); - assert(array_concat.length === 4); - assert(array_concat[2] === false); - assert(array_concat[3] === "serenity"); + array_concat = array.concat(false, "serenity"); + assert(array_concat.length === 4); + assert(array_concat[2] === false); + assert(array_concat[3] === "serenity"); - array_concat = array.concat({ name: "libjs" }, [1, [2, 3]]); - assert(array_concat.length === 5); - assert(array_concat[2].name === "libjs"); - assert(array_concat[3] === 1); - assert(array_concat[4][0] === 2); - assert(array_concat[4][1] === 3); + array_concat = array.concat({ name: "libjs" }, [1, [2, 3]]); + assert(array_concat.length === 5); + assert(array_concat[2].name === "libjs"); + assert(array_concat[3] === 1); + assert(array_concat[4][0] === 2); + assert(array_concat[4][1] === 3); - - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.every.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.every.js index f660c0166f..cf71b5ec8a 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.every.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.every.js @@ -1,44 +1,49 @@ load("test-common.js"); try { - assert(Array.prototype.every.length === 1); + assert(Array.prototype.every.length === 1); - assertThrowsError(() => { - [].every(undefined); - }, { - error: TypeError, - message: "undefined is not a function" - }); + assertThrowsError( + () => { + [].every(undefined); + }, + { + error: TypeError, + message: "undefined is not a function", + } + ); - var arrayOne = ["serenity", { test: "serenity"} ]; - var arrayTwo = [true, false, 1, 2, 3, "3"]; + var arrayOne = ["serenity", { test: "serenity" }]; + var arrayTwo = [true, false, 1, 2, 3, "3"]; - assert(arrayOne.every(value => value === "hello") === false); - assert(arrayOne.every(value => value === "serenity") === false); - assert(arrayOne.every((value, index, arr) => index < 2) === true); - assert(arrayOne.every(value => typeof(value) === "string") === false); - assert(arrayOne.every(value => arrayOne.pop()) === true); + assert(arrayOne.every(value => value === "hello") === false); + assert(arrayOne.every(value => value === "serenity") === false); + assert(arrayOne.every((value, index, arr) => index < 2) === true); + assert(arrayOne.every(value => typeof value === "string") === false); + assert(arrayOne.every(value => arrayOne.pop()) === true); - assert(arrayTwo.every((value, index, arr) => index > 0) === false); - assert(arrayTwo.every((value, index, arr) => index >= 0) === true); - assert(arrayTwo.every(value => typeof(value) !== "string") === false); - assert(arrayTwo.every(value => typeof(value) === "number") === false); - assert(arrayTwo.every(value => value > 0) === false); - assert(arrayTwo.every(value => value >= 0 && value < 4) === true); - assert(arrayTwo.every(value => arrayTwo.pop()) === true); + assert(arrayTwo.every((value, index, arr) => index > 0) === false); + assert(arrayTwo.every((value, index, arr) => index >= 0) === true); + assert(arrayTwo.every(value => typeof value !== "string") === false); + assert(arrayTwo.every(value => typeof value === "number") === false); + assert(arrayTwo.every(value => value > 0) === false); + assert(arrayTwo.every(value => value >= 0 && value < 4) === true); + assert(arrayTwo.every(value => arrayTwo.pop()) === true); - assert(["", "hello", "friends", "serenity"].every(value => value.length >= 0) === true); - assert([].every(value => value === 1) === true); + assert(["", "hello", "friends", "serenity"].every(value => value.length >= 0) === true); + assert([].every(value => value === 1) === true); - arrayTwo = [true, false, 1, 2, 3, "3"]; + arrayTwo = [true, false, 1, 2, 3, "3"]; - // Every only goes up to the original length. - assert(arrayTwo.every((value, index, arr) => { - arr.push("serenity"); - return value < 4; - }) === true); + // Every only goes up to the original length. + assert( + arrayTwo.every((value, index, arr) => { + arr.push("serenity"); + return value < 4; + }) === true + ); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.fill.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.fill.js index c70960b802..0cb58ced9c 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.fill.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.fill.js @@ -1,24 +1,23 @@ load("test-common.js"); try { - assert(Array.prototype.fill.length === 1); + assert(Array.prototype.fill.length === 1); - var array = [1, 2, 3, 4]; - assertArrayEquals(array.fill(0, 2, 4), [1, 2, 0, 0]); - assertArrayEquals(array.fill(5, 1), [1, 5, 5, 5]); - assertArrayEquals(array.fill(6), [6, 6, 6, 6]); + var array = [1, 2, 3, 4]; + assertArrayEquals(array.fill(0, 2, 4), [1, 2, 0, 0]); + assertArrayEquals(array.fill(5, 1), [1, 5, 5, 5]); + assertArrayEquals(array.fill(6), [6, 6, 6, 6]); - assertArrayEquals([1, 2, 3].fill(4), [4, 4, 4]); - assertArrayEquals([1, 2, 3].fill(4, 1), [1, 4, 4]); - assertArrayEquals([1, 2, 3].fill(4, 1, 2), [1, 4, 3]); - assertArrayEquals([1, 2, 3].fill(4, 3, 3), [1, 2, 3]); - assertArrayEquals([1, 2, 3].fill(4, -3, -2), [4, 2, 3]); - assertArrayEquals([1, 2, 3].fill(4, NaN, NaN), [1, 2, 3]); - assertArrayEquals([1, 2, 3].fill(4, 3, 5), [1, 2, 3]); - assertArrayEquals(Array(3).fill(4), [4, 4, 4]); + assertArrayEquals([1, 2, 3].fill(4), [4, 4, 4]); + assertArrayEquals([1, 2, 3].fill(4, 1), [1, 4, 4]); + assertArrayEquals([1, 2, 3].fill(4, 1, 2), [1, 4, 3]); + assertArrayEquals([1, 2, 3].fill(4, 3, 3), [1, 2, 3]); + assertArrayEquals([1, 2, 3].fill(4, -3, -2), [4, 2, 3]); + assertArrayEquals([1, 2, 3].fill(4, NaN, NaN), [1, 2, 3]); + assertArrayEquals([1, 2, 3].fill(4, 3, 5), [1, 2, 3]); + assertArrayEquals(Array(3).fill(4), [4, 4, 4]); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } - diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.filter.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.filter.js index 9d738e4464..06c0b754dc 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.filter.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.filter.js @@ -1,59 +1,78 @@ load("test-common.js"); try { - assert(Array.prototype.filter.length === 1); + assert(Array.prototype.filter.length === 1); - assertThrowsError(() => { - [].filter(); - }, { - error: TypeError, - message: "Array.prototype.filter() requires at least one argument" - }); + assertThrowsError( + () => { + [].filter(); + }, + { + error: TypeError, + message: "Array.prototype.filter() requires at least one argument", + } + ); - assertThrowsError(() => { - [].filter(undefined); - }, { - error: TypeError, - message: "undefined is not a function" - }); + assertThrowsError( + () => { + [].filter(undefined); + }, + { + error: TypeError, + message: "undefined is not a function", + } + ); - var callbackCalled = 0; - var callback = () => { callbackCalled++; }; + var callbackCalled = 0; + var callback = () => { + callbackCalled++; + }; - assert([].filter(callback).length === 0); - assert(callbackCalled === 0); + assert([].filter(callback).length === 0); + assert(callbackCalled === 0); - assert([1, 2, 3].filter(callback).length === 0); - assert(callbackCalled === 3); + assert([1, 2, 3].filter(callback).length === 0); + assert(callbackCalled === 3); - var evenNumbers = [0, 1, 2, 3, 4, 5, 6, 7].filter(x => x % 2 === 0); - assert(evenNumbers.length === 4); - assert(evenNumbers[0] === 0); - assert(evenNumbers[1] === 2); - assert(evenNumbers[2] === 4); - assert(evenNumbers[3] === 6); + var evenNumbers = [0, 1, 2, 3, 4, 5, 6, 7].filter(x => x % 2 === 0); + assert(evenNumbers.length === 4); + assert(evenNumbers[0] === 0); + assert(evenNumbers[1] === 2); + assert(evenNumbers[2] === 4); + assert(evenNumbers[3] === 6); - var fruits = ["Apple", "Banana", "Blueberry", "Grape", "Mango", "Orange", "Peach", "Pineapple", "Raspberry", "Watermelon"]; - const filterItems = (arr, query) => { - return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1) - }; + var fruits = [ + "Apple", + "Banana", + "Blueberry", + "Grape", + "Mango", + "Orange", + "Peach", + "Pineapple", + "Raspberry", + "Watermelon", + ]; + const filterItems = (arr, query) => { + return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1); + }; - var results; + var results; - results = filterItems(fruits, "Berry"); - assert(results.length === 2); - assert(results[0] === "Blueberry"); - assert(results[1] === "Raspberry"); + results = filterItems(fruits, "Berry"); + assert(results.length === 2); + assert(results[0] === "Blueberry"); + assert(results[1] === "Raspberry"); - results = filterItems(fruits, "P"); - assert(results.length === 5); - assert(results[0] === "Apple"); - assert(results[1] === "Grape"); - assert(results[2] === "Peach"); - assert(results[3] === "Pineapple"); - assert(results[4] === "Raspberry"); + results = filterItems(fruits, "P"); + assert(results.length === 5); + assert(results[0] === "Apple"); + assert(results[1] === "Grape"); + assert(results[2] === "Peach"); + assert(results[3] === "Pineapple"); + assert(results[4] === "Raspberry"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.find.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.find.js index 309b45cfdf..638ff2a5b7 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.find.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.find.js @@ -1,49 +1,54 @@ load("test-common.js"); try { - assert(Array.prototype.find.length === 1); + assert(Array.prototype.find.length === 1); - assertThrowsError(() => { - [].find(undefined); - }, { - error: TypeError, - message: "undefined is not a function" - }); + assertThrowsError( + () => { + [].find(undefined); + }, + { + error: TypeError, + message: "undefined is not a function", + } + ); - var array = ["hello", "friends", 1, 2, false]; + var array = ["hello", "friends", 1, 2, false]; - assert(array.find(value => value === "hello") === "hello"); - assert(array.find((value, index, arr) => index === 1) === "friends"); - assert(array.find(value => value == "1") === 1); - assert(array.find(value => value === 1) === 1); - assert(array.find(value => typeof(value) !== "string") === 1); - assert(array.find(value => typeof(value) === "boolean") === false); - assert(array.find(value => value > 1) === 2); - assert(array.find(value => value > 1 && value < 3) === 2); - assert(array.find(value => value > 100) === undefined); - assert([].find(value => value === 1) === undefined); + assert(array.find(value => value === "hello") === "hello"); + assert(array.find((value, index, arr) => index === 1) === "friends"); + assert(array.find(value => value == "1") === 1); + assert(array.find(value => value === 1) === 1); + assert(array.find(value => typeof value !== "string") === 1); + assert(array.find(value => typeof value === "boolean") === false); + assert(array.find(value => value > 1) === 2); + assert(array.find(value => value > 1 && value < 3) === 2); + assert(array.find(value => value > 100) === undefined); + assert([].find(value => value === 1) === undefined); - var callbackCalled = 0; - var callback = () => { callbackCalled++; }; + var callbackCalled = 0; + var callback = () => { + callbackCalled++; + }; - [].find(callback) - assert(callbackCalled === 0); + [].find(callback); + assert(callbackCalled === 0); - [1, 2, 3].find(callback); - assert(callbackCalled === 3); + [1, 2, 3].find(callback); + assert(callbackCalled === 3); - callbackCalled = 0; - [1, , , "foo", , undefined, , ,].find(callback); - assert(callbackCalled === 8); + callbackCalled = 0; + [1, , , "foo", , undefined, , ,].find(callback); + assert(callbackCalled === 8); - callbackCalled = 0; - [1, , , "foo", , undefined, , ,].find(value => { - callbackCalled++; - return value === undefined; - }); - assert(callbackCalled === 2); + callbackCalled = 0; + [1, , , "foo", , undefined, , ,].find(value => { + callbackCalled++; + return value === undefined; + }); + assert(callbackCalled === 2); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.findIndex.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.findIndex.js index f5b2295930..f2c0e8d01e 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.findIndex.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.findIndex.js @@ -1,49 +1,54 @@ load("test-common.js"); try { - assert(Array.prototype.findIndex.length === 1); + assert(Array.prototype.findIndex.length === 1); - assertThrowsError(() => { - [].findIndex(undefined); - }, { - error: TypeError, - message: "undefined is not a function" - }); + assertThrowsError( + () => { + [].findIndex(undefined); + }, + { + error: TypeError, + message: "undefined is not a function", + } + ); - var array = ["hello", "friends", 1, 2, false]; + var array = ["hello", "friends", 1, 2, false]; - assert(array.findIndex(value => value === "hello") === 0); - assert(array.findIndex((value, index, arr) => index === 1) === 1); - assert(array.findIndex(value => value == "1") === 2); - assert(array.findIndex(value => value === 1) === 2); - assert(array.findIndex(value => typeof(value) !== "string") === 2); - assert(array.findIndex(value => typeof(value) === "boolean") === 4); - assert(array.findIndex(value => value > 1) === 3); - assert(array.findIndex(value => value > 1 && value < 3) === 3); - assert(array.findIndex(value => value > 100) === -1); - assert([].findIndex(value => value === 1) === -1); + assert(array.findIndex(value => value === "hello") === 0); + assert(array.findIndex((value, index, arr) => index === 1) === 1); + assert(array.findIndex(value => value == "1") === 2); + assert(array.findIndex(value => value === 1) === 2); + assert(array.findIndex(value => typeof value !== "string") === 2); + assert(array.findIndex(value => typeof value === "boolean") === 4); + assert(array.findIndex(value => value > 1) === 3); + assert(array.findIndex(value => value > 1 && value < 3) === 3); + assert(array.findIndex(value => value > 100) === -1); + assert([].findIndex(value => value === 1) === -1); - var callbackCalled = 0; - var callback = () => { callbackCalled++; }; + var callbackCalled = 0; + var callback = () => { + callbackCalled++; + }; - [].findIndex(callback) - assert(callbackCalled === 0); + [].findIndex(callback); + assert(callbackCalled === 0); - [1, 2, 3].findIndex(callback); - assert(callbackCalled === 3); + [1, 2, 3].findIndex(callback); + assert(callbackCalled === 3); - callbackCalled = 0; - [1, , , "foo", , undefined, , ,].findIndex(callback); - assert(callbackCalled === 8); + callbackCalled = 0; + [1, , , "foo", , undefined, , ,].findIndex(callback); + assert(callbackCalled === 8); - callbackCalled = 0; - [1, , , "foo", , undefined, , ,].findIndex(value => { - callbackCalled++; - return value === undefined; - }); - assert(callbackCalled === 2); + callbackCalled = 0; + [1, , , "foo", , undefined, , ,].findIndex(value => { + callbackCalled++; + return value === undefined; + }); + assert(callbackCalled === 2); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.forEach.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.forEach.js index 65f4205ab7..beeb929475 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.forEach.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.forEach.js @@ -1,62 +1,70 @@ load("test-common.js"); try { - assert(Array.prototype.forEach.length === 1); + assert(Array.prototype.forEach.length === 1); - assertThrowsError(() => { - [].forEach(); - }, { - error: TypeError, - message: "Array.prototype.forEach() requires at least one argument" - }); + assertThrowsError( + () => { + [].forEach(); + }, + { + error: TypeError, + message: "Array.prototype.forEach() requires at least one argument", + } + ); - assertThrowsError(() => { - [].forEach(undefined); - }, { - error: TypeError, - message: "undefined is not a function" - }); + assertThrowsError( + () => { + [].forEach(undefined); + }, + { + error: TypeError, + message: "undefined is not a function", + } + ); - var a = [1, 2, 3]; - var o = {}; - var callbackCalled = 0; - var callback = () => { callbackCalled++; }; + var a = [1, 2, 3]; + var o = {}; + var callbackCalled = 0; + var callback = () => { + callbackCalled++; + }; - assert([].forEach(callback) === undefined); - assert(callbackCalled === 0); + assert([].forEach(callback) === undefined); + assert(callbackCalled === 0); - assert(a.forEach(callback) === undefined); - assert(callbackCalled === 3); + assert(a.forEach(callback) === undefined); + assert(callbackCalled === 3); - callbackCalled = 0; - a.forEach(function(value, index) { - assert(value === a[index]); - assert(index === a[index] - 1); - }); + callbackCalled = 0; + a.forEach(function (value, index) { + assert(value === a[index]); + assert(index === a[index] - 1); + }); - callbackCalled = 0; - a.forEach(function(_, _, array) { - callbackCalled++; - assert(a.length === array.length); - a.push("test"); - }); - assert(callbackCalled === 3); - assert(a.length === 6); + callbackCalled = 0; + a.forEach(function (_, _, array) { + callbackCalled++; + assert(a.length === array.length); + a.push("test"); + }); + assert(callbackCalled === 3); + assert(a.length === 6); - callbackCalled = 0; - a.forEach(function(value, index) { - callbackCalled++; - this[index] = value; - }, o); - assert(callbackCalled === 6); - assert(o[0] === 1); - assert(o[1] === 2); - assert(o[2] === 3); - assert(o[3] === "test"); - assert(o[4] === "test"); - assert(o[5] === "test"); + callbackCalled = 0; + a.forEach(function (value, index) { + callbackCalled++; + this[index] = value; + }, o); + assert(callbackCalled === 6); + assert(o[0] === 1); + assert(o[1] === 2); + assert(o[2] === 3); + assert(o[3] === "test"); + assert(o[4] === "test"); + assert(o[5] === "test"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.includes.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.includes.js index 3c1df81bbd..433abe78b0 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.includes.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.includes.js @@ -1,22 +1,22 @@ load("test-common.js"); try { - assert(Array.prototype.includes.length === 1); + assert(Array.prototype.includes.length === 1); - var array = ['hello', 'friends', 1, 2, false]; + var array = ["hello", "friends", 1, 2, false]; - assert([].includes() === false); - assert([undefined].includes() === true); - assert(array.includes('hello') === true); - assert(array.includes(1) === true); - assert(array.includes(1, -3) === true); - assert(array.includes('serenity') === false); - assert(array.includes(false, -1) === true); - assert(array.includes(2, -1) === false); - assert(array.includes(2, -100) === true); - assert(array.includes('friends', 100) === false); + assert([].includes() === false); + assert([undefined].includes() === true); + assert(array.includes("hello") === true); + assert(array.includes(1) === true); + assert(array.includes(1, -3) === true); + assert(array.includes("serenity") === false); + assert(array.includes(false, -1) === true); + assert(array.includes(2, -1) === false); + assert(array.includes(2, -100) === true); + assert(array.includes("friends", 100) === false); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.indexOf.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.indexOf.js index 12cc3e7333..b6c6077d11 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.indexOf.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.indexOf.js @@ -1,29 +1,29 @@ load("test-common.js"); try { - assert(Array.prototype.indexOf.length === 1); + assert(Array.prototype.indexOf.length === 1); - var array = ['hello', 'friends', 1, 2, false]; + var array = ["hello", "friends", 1, 2, false]; - assert(array.indexOf('hello') === 0); - assert(array.indexOf('friends') === 1); - assert(array.indexOf(false) === 4); - assert(array.indexOf(false, 2) === 4); - assert(array.indexOf(false, -2) === 4); - assert(array.indexOf(1) === 2); - assert(array.indexOf(1, 1000) === -1); - assert(array.indexOf(1, -1000) === 2); - assert(array.indexOf('serenity') === -1); - assert(array.indexOf(false, -1) === 4); - assert(array.indexOf(2, -1) === -1); - assert(array.indexOf(2, -2) === 3); - assert([].indexOf('serenity') === -1); - assert([].indexOf('serenity', 10) === -1); - assert([].indexOf('serenity', -10) === -1); - assert([].indexOf() === -1); - assert([undefined].indexOf() === 0); + assert(array.indexOf("hello") === 0); + assert(array.indexOf("friends") === 1); + assert(array.indexOf(false) === 4); + assert(array.indexOf(false, 2) === 4); + assert(array.indexOf(false, -2) === 4); + assert(array.indexOf(1) === 2); + assert(array.indexOf(1, 1000) === -1); + assert(array.indexOf(1, -1000) === 2); + assert(array.indexOf("serenity") === -1); + assert(array.indexOf(false, -1) === 4); + assert(array.indexOf(2, -1) === -1); + assert(array.indexOf(2, -2) === 3); + assert([].indexOf("serenity") === -1); + assert([].indexOf("serenity", 10) === -1); + assert([].indexOf("serenity", -10) === -1); + assert([].indexOf() === -1); + assert([undefined].indexOf() === 0); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.join.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.join.js index fc82deb20c..52219e1bfe 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.join.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.join.js @@ -1,19 +1,19 @@ load("test-common.js"); try { - assert(Array.prototype.join.length === 1); + assert(Array.prototype.join.length === 1); - assert(["hello", "friends"].join() === "hello,friends"); - assert(["hello", "friends"].join(" ") === "hello friends"); - assert(["hello", "friends", "foo"].join("~", "#") === "hello~friends~foo"); - assert([].join() === ""); - assert([null].join() === ""); - assert([undefined].join() === ""); - assert([undefined, null, ""].join() === ",,"); - assert([1, null, 2, undefined, 3].join() === "1,,2,,3"); - assert(Array(3).join() === ",,"); + assert(["hello", "friends"].join() === "hello,friends"); + assert(["hello", "friends"].join(" ") === "hello friends"); + assert(["hello", "friends", "foo"].join("~", "#") === "hello~friends~foo"); + assert([].join() === ""); + assert([null].join() === ""); + assert([undefined].join() === ""); + assert([undefined, null, ""].join() === ",,"); + assert([1, null, 2, undefined, 3].join() === "1,,2,,3"); + assert(Array(3).join() === ",,"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.lastIndexOf.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.lastIndexOf.js index c2b1df8d4b..91d5e6c025 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.lastIndexOf.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.lastIndexOf.js @@ -1,26 +1,26 @@ load("test-common.js"); try { - assert(Array.prototype.lastIndexOf.length === 1); + assert(Array.prototype.lastIndexOf.length === 1); - var array = [1, 2, 3, 1, "hello"]; + var array = [1, 2, 3, 1, "hello"]; - assert(array.lastIndexOf("hello") === 4); - assert(array.lastIndexOf("hello", 1000) === 4); - assert(array.lastIndexOf(1) === 3); - assert(array.lastIndexOf(1, -1) === 3); - assert(array.lastIndexOf(1, -2) === 3); - assert(array.lastIndexOf(2) === 1); - assert(array.lastIndexOf(2, -3) === 1); - assert(array.lastIndexOf(2, -4) === 1); - assert([].lastIndexOf('hello') === -1); - assert([].lastIndexOf('hello', 10) === -1); - assert([].lastIndexOf('hello', -10) === -1); - assert([].lastIndexOf() === -1); - assert([undefined].lastIndexOf() === 0); - assert([undefined, undefined, undefined].lastIndexOf() === 2); + assert(array.lastIndexOf("hello") === 4); + assert(array.lastIndexOf("hello", 1000) === 4); + assert(array.lastIndexOf(1) === 3); + assert(array.lastIndexOf(1, -1) === 3); + assert(array.lastIndexOf(1, -2) === 3); + assert(array.lastIndexOf(2) === 1); + assert(array.lastIndexOf(2, -3) === 1); + assert(array.lastIndexOf(2, -4) === 1); + assert([].lastIndexOf("hello") === -1); + assert([].lastIndexOf("hello", 10) === -1); + assert([].lastIndexOf("hello", -10) === -1); + assert([].lastIndexOf() === -1); + assert([undefined].lastIndexOf() === 0); + assert([undefined, undefined, undefined].lastIndexOf() === 2); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.map.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.map.js index c7239e23a1..d04c687df1 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.map.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.map.js @@ -1,53 +1,63 @@ load("test-common.js"); try { - assert(Array.prototype.map.length === 1); + assert(Array.prototype.map.length === 1); - assertThrowsError(() => { - [].map(); - }, { - error: TypeError, - message: "Array.prototype.map() requires at least one argument" - }); + assertThrowsError( + () => { + [].map(); + }, + { + error: TypeError, + message: "Array.prototype.map() requires at least one argument", + } + ); - assertThrowsError(() => { - [].map(undefined); - }, { - error: TypeError, - message: "undefined is not a function" - }); + assertThrowsError( + () => { + [].map(undefined); + }, + { + error: TypeError, + message: "undefined is not a function", + } + ); - var callbackCalled = 0; - var callback = () => { callbackCalled++; }; + var callbackCalled = 0; + var callback = () => { + callbackCalled++; + }; - assert([].map(callback).length === 0); - assert(callbackCalled === 0); + assert([].map(callback).length === 0); + assert(callbackCalled === 0); - assert([1, 2, 3].map(callback).length === 3); - assert(callbackCalled === 3); + assert([1, 2, 3].map(callback).length === 3); + assert(callbackCalled === 3); - callbackCalled = 0; - assert([1, , , "foo", , undefined, , ,].map(callback).length === 8); - assert(callbackCalled === 3); + callbackCalled = 0; + assert([1, , , "foo", , undefined, , ,].map(callback).length === 8); + assert(callbackCalled === 3); - var results = [undefined, null, true, "foo", 42, {}].map((value, index) => "" + index + " -> " + value); - assert(results.length === 6); - assert(results[0] === "0 -> undefined"); - assert(results[1] === "1 -> null"); - assert(results[2] === "2 -> true"); - assert(results[3] === "3 -> foo"); - assert(results[4] === "4 -> 42"); - assert(results[5] === "5 -> [object Object]"); + var results = [undefined, null, true, "foo", 42, {}].map( + (value, index) => "" + index + " -> " + value + ); + assert(results.length === 6); + assert(results[0] === "0 -> undefined"); + assert(results[1] === "1 -> null"); + assert(results[2] === "2 -> true"); + assert(results[3] === "3 -> foo"); + assert(results[4] === "4 -> 42"); + assert(results[5] === "5 -> [object Object]"); - var squaredNumbers = [0, 1, 2, 3, 4].map(x => x ** 2); - assert(squaredNumbers.length === 5); - assert(squaredNumbers[0] === 0); - assert(squaredNumbers[1] === 1); - assert(squaredNumbers[2] === 4); - assert(squaredNumbers[3] === 9); - assert(squaredNumbers[4] === 16); + var squaredNumbers = [0, 1, 2, 3, 4].map(x => x ** 2); + assert(squaredNumbers.length === 5); + assert(squaredNumbers[0] === 0); + assert(squaredNumbers[1] === 1); + assert(squaredNumbers[2] === 4); + assert(squaredNumbers[3] === 9); + assert(squaredNumbers[4] === 16); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.pop.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.pop.js index a4d09a2311..2b1c5d6e41 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.pop.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.pop.js @@ -1,21 +1,21 @@ load("test-common.js"); try { - var a = [1, 2, 3]; - var value = a.pop(); - assert(value === 3); - assert(a.length === 2); - assert(a[0] === 1); - assert(a[1] === 2); + var a = [1, 2, 3]; + var value = a.pop(); + assert(value === 3); + assert(a.length === 2); + assert(a[0] === 1); + assert(a[1] === 2); - var a = []; - var value = a.pop(); - assert(value === undefined); - assert(a.length === 0); + var a = []; + var value = a.pop(); + assert(value === undefined); + assert(a.length === 0); - assert([,].pop() === undefined); + assert([,].pop() === undefined); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.push.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.push.js index f739aec463..722ee62ecc 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.push.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.push.js @@ -1,30 +1,30 @@ load("test-common.js"); try { - assert(Array.prototype.push.length === 1); + assert(Array.prototype.push.length === 1); - var a = ["hello"]; - var length = a.push(); - assert(length === 1); - assert(a.length === 1); - assert(a[0] === "hello"); + var a = ["hello"]; + var length = a.push(); + assert(length === 1); + assert(a.length === 1); + assert(a[0] === "hello"); - length = a.push("friends"); - assert(length === 2); - assert(a.length === 2); - assert(a[0] === "hello"); - assert(a[1] === "friends"); + length = a.push("friends"); + assert(length === 2); + assert(a.length === 2); + assert(a[0] === "hello"); + assert(a[1] === "friends"); - length = a.push(1, 2, 3); - assert(length === 5); - assert(a.length === 5); - assert(a[0] === "hello"); - assert(a[1] === "friends"); - assert(a[2] === 1); - assert(a[3] === 2); - assert(a[4] === 3); + length = a.push(1, 2, 3); + assert(length === 5); + assert(a.length === 5); + assert(a[0] === "hello"); + assert(a[1] === "friends"); + assert(a[2] === 1); + assert(a[3] === 2); + assert(a[4] === 3); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduce.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduce.js index eeaf5a423d..cd0e291d9e 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduce.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduce.js @@ -1,104 +1,132 @@ load("test-common.js"); try { - assert(Array.prototype.reduce.length === 1); + assert(Array.prototype.reduce.length === 1); - assertThrowsError(() => { - [1].reduce(); - }, { - error: TypeError, - message: "Array.prototype.reduce() requires at least one argument" - }); + assertThrowsError( + () => { + [1].reduce(); + }, + { + error: TypeError, + message: "Array.prototype.reduce() requires at least one argument", + } + ); - assertThrowsError(() => { - [1].reduce(undefined); - }, { - error: TypeError, - message: "undefined is not a function" - }); + assertThrowsError( + () => { + [1].reduce(undefined); + }, + { + error: TypeError, + message: "undefined is not a function", + } + ); - assertThrowsError(() => { - [].reduce((a, x) => x); - }, { - error: TypeError, - message: "Reduce of empty array with no initial value" - }); + assertThrowsError( + () => { + [].reduce((a, x) => x); + }, + { + error: TypeError, + message: "Reduce of empty array with no initial value", + } + ); - assertThrowsError(() => { - [, ,].reduce((a, x) => x); - }, { - error: TypeError, - message: "Reduce of empty array with no initial value" - }); + assertThrowsError( + () => { + [, ,].reduce((a, x) => x); + }, + { + error: TypeError, + message: "Reduce of empty array with no initial value", + } + ); - [1, 2].reduce(function () { assert(this === undefined) }); + [1, 2].reduce(function () { + assert(this === undefined); + }); - var callbackCalled = 0; - var callback = () => { callbackCalled++; return true }; + var callbackCalled = 0; + var callback = () => { + callbackCalled++; + return true; + }; - assert([1].reduce(callback) === 1); - assert(callbackCalled === 0); + assert([1].reduce(callback) === 1); + assert(callbackCalled === 0); - assert([, 1].reduce(callback) === 1); - assert(callbackCalled === 0); + assert([, 1].reduce(callback) === 1); + assert(callbackCalled === 0); - callbackCalled = 0; - assert([1, 2, 3].reduce(callback) === true); - assert(callbackCalled === 2); + callbackCalled = 0; + assert([1, 2, 3].reduce(callback) === true); + assert(callbackCalled === 2); - callbackCalled = 0; - assert([, , 1, 2, 3].reduce(callback) === true); - assert(callbackCalled === 2); + callbackCalled = 0; + assert([, , 1, 2, 3].reduce(callback) === true); + assert(callbackCalled === 2); - callbackCalled = 0; - assert([1, , , 10, , 100, , ,].reduce(callback) === true); - assert(callbackCalled === 2); + callbackCalled = 0; + assert([1, , , 10, , 100, , ,].reduce(callback) === true); + assert(callbackCalled === 2); - var constantlySad = () => ":^("; - var result = [].reduce(constantlySad, ":^)"); - assert(result === ":^)"); + var constantlySad = () => ":^("; + var result = [].reduce(constantlySad, ":^)"); + assert(result === ":^)"); - result = [":^0"].reduce(constantlySad, ":^)"); - assert(result === ":^("); + result = [":^0"].reduce(constantlySad, ":^)"); + assert(result === ":^("); - result = [":^0"].reduce(constantlySad); - assert(result === ":^0"); + result = [":^0"].reduce(constantlySad); + assert(result === ":^0"); - result = [5, 4, 3, 2, 1].reduce((accum, elem) => accum + elem); - assert(result === 15); + result = [5, 4, 3, 2, 1].reduce((accum, elem) => accum + elem); + assert(result === 15); - result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100); - assert(result === 121); + result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100); + assert(result === 121); - result = [6, 5, 4, 3, 2, 1].reduce((accum, elem) => { return accum + elem }, 100); - assert(result === 121); + result = [6, 5, 4, 3, 2, 1].reduce((accum, elem) => { + return accum + elem; + }, 100); + assert(result === 121); - var indexes = []; - result = ["foo", 1, true].reduce((a, v, i) => { indexes.push(i) }); - assert(result === undefined); - assert(indexes.length === 2); - assert(indexes[0] === 1); - assert(indexes[1] === 2); + var indexes = []; + result = ["foo", 1, true].reduce((a, v, i) => { + indexes.push(i); + }); + assert(result === undefined); + assert(indexes.length === 2); + assert(indexes[0] === 1); + assert(indexes[1] === 2); - indexes = []; - result = ["foo", 1, true].reduce((a, v, i) => { indexes.push(i) }, "foo"); - assert(result === undefined); - assert(indexes.length === 3); - assert(indexes[0] === 0); - assert(indexes[1] === 1); - assert(indexes[2] === 2); + indexes = []; + result = ["foo", 1, true].reduce((a, v, i) => { + indexes.push(i); + }, "foo"); + assert(result === undefined); + assert(indexes.length === 3); + assert(indexes[0] === 0); + assert(indexes[1] === 1); + assert(indexes[2] === 2); - var mutable = { prop: 0 }; - result = ["foo", 1, true].reduce((a, v) => { a.prop = v; return a; }, mutable); - assert(result === mutable); - assert(result.prop === true); + var mutable = { prop: 0 }; + result = ["foo", 1, true].reduce((a, v) => { + a.prop = v; + return a; + }, mutable); + assert(result === mutable); + assert(result.prop === true); - var a1 = [1, 2]; - var a2 = null; - a1.reduce((a, v, i, t) => { a2 = t }); - assert(a1 === a2); + var a1 = [1, 2]; + var a2 = null; + a1.reduce((a, v, i, t) => { + a2 = t; + }); + assert(a1 === a2); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reverse.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reverse.js index 2b782fa154..049562395e 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reverse.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reverse.js @@ -1,31 +1,31 @@ load("test-common.js"); try { - assert(Array.prototype.reverse.length === 0); + assert(Array.prototype.reverse.length === 0); - var array = [1, 2, 3]; - - assert(array[0] === 1); - assert(array[1] === 2); - assert(array[2] === 3); - - array.reverse(); - - assert(array[0] === 3); - assert(array[1] === 2); - assert(array[2] === 1); - - var array_ref = array.reverse(); - - assert(array_ref[0] === 1); - assert(array_ref[1] === 2); - assert(array_ref[2] === 3); + var array = [1, 2, 3]; - assert(array[0] === 1); - assert(array[1] === 2); - assert(array[2] === 3); + assert(array[0] === 1); + assert(array[1] === 2); + assert(array[2] === 3); - console.log("PASS"); + array.reverse(); + + assert(array[0] === 3); + assert(array[1] === 2); + assert(array[2] === 1); + + var array_ref = array.reverse(); + + assert(array_ref[0] === 1); + assert(array_ref[1] === 2); + assert(array_ref[2] === 3); + + assert(array[0] === 1); + assert(array[1] === 2); + assert(array[2] === 3); + + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js index 2b48e7bf20..7332615431 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js @@ -1,21 +1,21 @@ load("test-common.js"); try { - var a = [1, 2, 3]; - var value = a.shift(); - assert(value === 1); - assert(a.length === 2); - assert(a[0] === 2); - assert(a[1] === 3); + var a = [1, 2, 3]; + var value = a.shift(); + assert(value === 1); + assert(a.length === 2); + assert(a[0] === 2); + assert(a[1] === 3); - var a = []; - var value = a.shift(); - assert(value === undefined); - assert(a.length === 0); + var a = []; + var value = a.shift(); + assert(value === undefined); + assert(a.length === 0); - assert([,].shift() === undefined); + assert([,].shift() === undefined); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.slice.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.slice.js index e34f2c1a1b..8b6c00670c 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.slice.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.slice.js @@ -1,53 +1,53 @@ load("test-common.js"); try { - assert(Array.prototype.slice.length === 2); + assert(Array.prototype.slice.length === 2); - var array = ["hello", "friends", "serenity", 1]; + var array = ["hello", "friends", "serenity", 1]; - var array_slice = array.slice(); - assert(array_slice.length === array.length); - assert(array_slice.length === 4); - assert(array_slice[0] === "hello"); - assert(array_slice[1] === "friends"); - assert(array_slice[2] === "serenity"); - assert(array_slice[3] === 1); + var array_slice = array.slice(); + assert(array_slice.length === array.length); + assert(array_slice.length === 4); + assert(array_slice[0] === "hello"); + assert(array_slice[1] === "friends"); + assert(array_slice[2] === "serenity"); + assert(array_slice[3] === 1); - array_slice = array.slice(1) - assert(array_slice.length === 3); - assert(array_slice[0] === "friends"); - assert(array_slice[1] === "serenity"); - assert(array_slice[2] === 1); + array_slice = array.slice(1); + assert(array_slice.length === 3); + assert(array_slice[0] === "friends"); + assert(array_slice[1] === "serenity"); + assert(array_slice[2] === 1); - array_slice = array.slice(0, 2); - assert(array_slice.length === 2); - assert(array_slice[0] === "hello"); - assert(array_slice[1] === "friends"); + array_slice = array.slice(0, 2); + assert(array_slice.length === 2); + assert(array_slice[0] === "hello"); + assert(array_slice[1] === "friends"); - array_slice = array.slice(-1); - assert(array_slice.length === 1); - assert(array_slice[0] === 1); + array_slice = array.slice(-1); + assert(array_slice.length === 1); + assert(array_slice[0] === 1); - array_slice = array.slice(1, 1); - assert(array_slice.length === 0); - - array_slice = array.slice(1, -1); - assert(array_slice.length === 2); - assert(array_slice[0] === "friends"); - assert(array_slice[1] === "serenity"); - - array_slice = array.slice(2, -1); - assert(array_slice.length === 1); - assert(array_slice[0] === "serenity"); + array_slice = array.slice(1, 1); + assert(array_slice.length === 0); - array_slice = array.slice(0, 100); - assert(array_slice.length === 4); - assert(array_slice[0] === "hello"); - assert(array_slice[1] === "friends"); - assert(array_slice[2] === "serenity"); - assert(array_slice[3] === 1); + array_slice = array.slice(1, -1); + assert(array_slice.length === 2); + assert(array_slice[0] === "friends"); + assert(array_slice[1] === "serenity"); - console.log("PASS"); + array_slice = array.slice(2, -1); + assert(array_slice.length === 1); + assert(array_slice[0] === "serenity"); + + array_slice = array.slice(0, 100); + assert(array_slice.length === 4); + assert(array_slice[0] === "hello"); + assert(array_slice[1] === "friends"); + assert(array_slice[2] === "serenity"); + assert(array_slice[3] === 1); + + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.some.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.some.js index 28d5676d35..7fb7fb8467 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.some.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.some.js @@ -1,34 +1,37 @@ load("test-common.js"); try { - assert(Array.prototype.some.length === 1); + assert(Array.prototype.some.length === 1); - assertThrowsError(() => { - [].some(undefined); - }, { - error: TypeError, - message: "undefined is not a function" - }); + assertThrowsError( + () => { + [].some(undefined); + }, + { + error: TypeError, + message: "undefined is not a function", + } + ); - var array = ["hello", "friends", 1, 2, false, -42, { name: "serenityos"}]; + var array = ["hello", "friends", 1, 2, false, -42, { name: "serenityos" }]; - assert(array.some(value => value === "hello") === true); - assert(array.some(value => value === "serenity") === false); - assert(array.some((value, index, arr) => index === 1) === true); - assert(array.some(value => value == "1") === true); - assert(array.some(value => value === 1) === true); - assert(array.some(value => value === 13) === false); - assert(array.some(value => typeof(value) !== "string") === true); - assert(array.some(value => typeof(value) === "boolean") === true); - assert(array.some(value => value > 1) === true); - assert(array.some(value => value > 1 && value < 3) === true); - assert(array.some(value => value > 100) === false); - assert(array.some(value => value < 0) === true); - assert(array.some(value => array.pop()) === true); - assert(["", "hello", "friends", "serenity"].some(value => value.length === 0) === true); - assert([].some(value => value === 1) === false); + assert(array.some(value => value === "hello") === true); + assert(array.some(value => value === "serenity") === false); + assert(array.some((value, index, arr) => index === 1) === true); + assert(array.some(value => value == "1") === true); + assert(array.some(value => value === 1) === true); + assert(array.some(value => value === 13) === false); + assert(array.some(value => typeof value !== "string") === true); + assert(array.some(value => typeof value === "boolean") === true); + assert(array.some(value => value > 1) === true); + assert(array.some(value => value > 1 && value < 3) === true); + assert(array.some(value => value > 100) === false); + assert(array.some(value => value < 0) === true); + assert(array.some(value => array.pop()) === true); + assert(["", "hello", "friends", "serenity"].some(value => value.length === 0) === true); + assert([].some(value => value === 1) === false); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.splice.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.splice.js index e140631430..ff7173aca0 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.splice.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.splice.js @@ -1,87 +1,87 @@ load("test-common.js"); try { - assert(Array.prototype.splice.length === 2); + assert(Array.prototype.splice.length === 2); - var array = ["hello", "friends", "serenity", 1, 2]; - var removed = array.splice(3); - assert(array.length === 3); - assert(array[0] === "hello"); - assert(array[1] === "friends"); - assert(array[2] === "serenity"); - assert(removed.length === 2); - assert(removed[0] === 1); - assert(removed[1] === 2); + var array = ["hello", "friends", "serenity", 1, 2]; + var removed = array.splice(3); + assert(array.length === 3); + assert(array[0] === "hello"); + assert(array[1] === "friends"); + assert(array[2] === "serenity"); + assert(removed.length === 2); + assert(removed[0] === 1); + assert(removed[1] === 2); - array = ["hello", "friends", "serenity", 1, 2]; - removed = array.splice(-2); - assert(array.length === 3); - assert(array[0] === "hello"); - assert(array[1] === "friends"); - assert(array[2] === "serenity"); - assert(removed.length === 2); - assert(removed[0] === 1); - assert(removed[1] === 2); + array = ["hello", "friends", "serenity", 1, 2]; + removed = array.splice(-2); + assert(array.length === 3); + assert(array[0] === "hello"); + assert(array[1] === "friends"); + assert(array[2] === "serenity"); + assert(removed.length === 2); + assert(removed[0] === 1); + assert(removed[1] === 2); - array = ["hello", "friends", "serenity", 1, 2]; - removed = array.splice(-2, 1); - assert(array.length === 4); - assert(array[0] === "hello"); - assert(array[1] === "friends"); - assert(array[2] === "serenity"); - assert(array[3] === 2); - assert(removed.length === 1); - assert(removed[0] === 1); + array = ["hello", "friends", "serenity", 1, 2]; + removed = array.splice(-2, 1); + assert(array.length === 4); + assert(array[0] === "hello"); + assert(array[1] === "friends"); + assert(array[2] === "serenity"); + assert(array[3] === 2); + assert(removed.length === 1); + assert(removed[0] === 1); - array = ["serenity"]; - removed = array.splice(0, 0, "hello", "friends"); - assert(array.length === 3); - assert(array[0] === "hello"); - assert(array[1] === "friends"); - assert(array[2] === "serenity"); - assert(removed.length === 0); + array = ["serenity"]; + removed = array.splice(0, 0, "hello", "friends"); + assert(array.length === 3); + assert(array[0] === "hello"); + assert(array[1] === "friends"); + assert(array[2] === "serenity"); + assert(removed.length === 0); - array = ["goodbye", "friends", "serenity"]; - removed = array.splice(0, 1, "hello"); - assert(array.length === 3); - assert(array[0] === "hello"); - assert(array[1] === "friends"); - assert(array[2] === "serenity"); - assert(removed.length === 1); - assert(removed[0] === "goodbye"); + array = ["goodbye", "friends", "serenity"]; + removed = array.splice(0, 1, "hello"); + assert(array.length === 3); + assert(array[0] === "hello"); + assert(array[1] === "friends"); + assert(array[2] === "serenity"); + assert(removed.length === 1); + assert(removed[0] === "goodbye"); - array = ["foo", "bar", "baz"]; - removed = array.splice(); - assert(array.length === 3); - assert(array[0] === "foo"); - assert(array[1] === "bar"); - assert(array[2] === "baz"); - assert(removed.length === 0); + array = ["foo", "bar", "baz"]; + removed = array.splice(); + assert(array.length === 3); + assert(array[0] === "foo"); + assert(array[1] === "bar"); + assert(array[2] === "baz"); + assert(removed.length === 0); - removed = array.splice(0, 123); - assert(array.length === 0); - assert(removed.length === 3); - assert(removed[0] === "foo"); - assert(removed[1] === "bar"); - assert(removed[2] === "baz"); + removed = array.splice(0, 123); + assert(array.length === 0); + assert(removed.length === 3); + assert(removed[0] === "foo"); + assert(removed[1] === "bar"); + assert(removed[2] === "baz"); - array = ["foo", "bar", "baz"]; - removed = array.splice(123, 123); - assert(array.length === 3); - assert(array[0] === "foo"); - assert(array[1] === "bar"); - assert(array[2] === "baz"); - assert(removed.length === 0); + array = ["foo", "bar", "baz"]; + removed = array.splice(123, 123); + assert(array.length === 3); + assert(array[0] === "foo"); + assert(array[1] === "bar"); + assert(array[2] === "baz"); + assert(removed.length === 0); - array = ["foo", "bar", "baz"]; - removed = array.splice(-123, 123); - assert(array.length === 0); - assert(removed.length === 3); - assert(removed[0] === "foo"); - assert(removed[1] === "bar"); - assert(removed[2] === "baz"); + array = ["foo", "bar", "baz"]; + removed = array.splice(-123, 123); + assert(array.length === 0); + assert(removed.length === 3); + assert(removed[0] === "foo"); + assert(removed[1] === "bar"); + assert(removed[2] === "baz"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toLocaleString.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toLocaleString.js index c0a8932e6e..f2a650d6b9 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toLocaleString.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toLocaleString.js @@ -1,24 +1,24 @@ load("test-common.js"); try { - assert(Array.prototype.toLocaleString.length === 0); + assert(Array.prototype.toLocaleString.length === 0); - assert([].toLocaleString() === ""); - assert(["foo"].toLocaleString() === "foo"); - assert(["foo", "bar"].toLocaleString() === "foo,bar"); - assert(["foo", undefined, "bar", null, "baz"].toLocaleString() === "foo,,bar,,baz"); + assert([].toLocaleString() === ""); + assert(["foo"].toLocaleString() === "foo"); + assert(["foo", "bar"].toLocaleString() === "foo,bar"); + assert(["foo", undefined, "bar", null, "baz"].toLocaleString() === "foo,,bar,,baz"); - var toStringCalled = 0; - var o = { - toString: () => { - toStringCalled++; - return "o"; - } - }; - assert([o, undefined, o, null, o].toLocaleString() === "o,,o,,o"); - assert(toStringCalled === 3); + var toStringCalled = 0; + var o = { + toString: () => { + toStringCalled++; + return "o"; + }, + }; + assert([o, undefined, o, null, o].toLocaleString() === "o,,o,,o"); + assert(toStringCalled === 3); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toString.js index c103d51281..3243c0f7e4 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toString.js @@ -1,22 +1,22 @@ load("test-common.js"); try { - var a = [1, 2, 3]; - assert(a.toString() === '1,2,3'); - assert([].toString() === ''); - assert([5].toString() === '5'); + var a = [1, 2, 3]; + assert(a.toString() === "1,2,3"); + assert([].toString() === ""); + assert([5].toString() === "5"); - assert("rgb(" + [10, 11, 12] + ")" === "rgb(10,11,12)"); + assert("rgb(" + [10, 11, 12] + ")" === "rgb(10,11,12)"); - assert([undefined, null].toString() === ","); + assert([undefined, null].toString() === ","); - a = new Array(5); - assert(a.toString() === ",,,,"); - a[2] = "foo"; - a[4] = "bar"; - assert(a.toString() === ",,foo,,bar"); + a = new Array(5); + assert(a.toString() === ",,,,"); + a[2] = "foo"; + a[4] = "bar"; + assert(a.toString() === ",,foo,,bar"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.unshift.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.unshift.js index 3bae2736b1..d6e1f46144 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.unshift.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.unshift.js @@ -1,30 +1,30 @@ load("test-common.js"); try { - assert(Array.prototype.unshift.length === 1); + assert(Array.prototype.unshift.length === 1); - var a = ["hello"]; - var length = a.unshift(); - assert(length === 1); - assert(a.length === 1); - assert(a[0] === "hello"); + var a = ["hello"]; + var length = a.unshift(); + assert(length === 1); + assert(a.length === 1); + assert(a[0] === "hello"); - length = a.unshift("friends"); - assert(length === 2); - assert(a.length === 2); - assert(a[0] === "friends"); - assert(a[1] === "hello"); + length = a.unshift("friends"); + assert(length === 2); + assert(a.length === 2); + assert(a[0] === "friends"); + assert(a[1] === "hello"); - length = a.unshift(1, 2, 3); - assert(length === 5); - assert(a.length === 5); - assert(a[0] === 1); - assert(a[1] === 2); - assert(a[2] === 3); - assert(a[3] === "friends"); - assert(a[4] === "hello"); + length = a.unshift(1, 2, 3); + assert(length === 5); + assert(a.length === 5); + assert(a[0] === 1); + assert(a[1] === 2); + assert(a[2] === 3); + assert(a[3] === "friends"); + assert(a[4] === "hello"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/array-basic.js b/Libraries/LibJS/Tests/builtins/Array/array-basic.js index 57e0b5d624..d25c2f17fc 100644 --- a/Libraries/LibJS/Tests/builtins/Array/array-basic.js +++ b/Libraries/LibJS/Tests/builtins/Array/array-basic.js @@ -1,63 +1,63 @@ load("test-common.js"); try { - var a = [1, 2, 3]; + var a = [1, 2, 3]; - assert(typeof a === "object"); - assert(a.length === 3); - assert(a[0] === 1); - assert(a[1] === 2); - assert(a[2] === 3); + assert(typeof a === "object"); + assert(a.length === 3); + assert(a[0] === 1); + assert(a[1] === 2); + assert(a[2] === 3); - a[1] = 5; - assert(a[1] === 5); - assert(a.length === 3); + a[1] = 5; + assert(a[1] === 5); + assert(a.length === 3); - a.push(7); - assert(a[3] === 7); - assert(a.length === 4); + a.push(7); + assert(a[3] === 7); + assert(a.length === 4); - a = [,]; - assert(a.length === 1); - assert(a.toString() === ""); - assert(a[0] === undefined); + a = [,]; + assert(a.length === 1); + assert(a.toString() === ""); + assert(a[0] === undefined); - a = [,,,,]; - assert(a.length === 4); - assert(a.toString() === ",,,"); - assert(a[0] === undefined); - assert(a[1] === undefined); - assert(a[2] === undefined); - assert(a[3] === undefined); + a = [, , , ,]; + assert(a.length === 4); + assert(a.toString() === ",,,"); + assert(a[0] === undefined); + assert(a[1] === undefined); + assert(a[2] === undefined); + assert(a[3] === undefined); - a = [1,,2,,,3,]; - assert(a.length === 6); - assert(a.toString() === "1,,2,,,3"); - assert(a[0] === 1); - assert(a[1] === undefined); - assert(a[2] === 2); - assert(a[3] === undefined); - assert(a[4] === undefined); - assert(a[5] === 3); + a = [1, , 2, , , 3]; + assert(a.length === 6); + assert(a.toString() === "1,,2,,,3"); + assert(a[0] === 1); + assert(a[1] === undefined); + assert(a[2] === 2); + assert(a[3] === undefined); + assert(a[4] === undefined); + assert(a[5] === 3); - a = [1,,2,,,3,]; - Object.defineProperty(a, 1, { - get() { - return this.secret_prop; - }, - set(value) { - this.secret_prop = value; - }, - }); - assert(a.length === 6); - assert(a.toString() === "1,,2,,,3"); - assert(a.secret_prop === undefined); - a[1] = 20; - assert(a.length === 6); - assert(a.toString() === "1,20,2,,,3"); - assert(a.secret_prop === 20); + a = [1, , 2, , , 3]; + Object.defineProperty(a, 1, { + get() { + return this.secret_prop; + }, + set(value) { + this.secret_prop = value; + }, + }); + assert(a.length === 6); + assert(a.toString() === "1,,2,,,3"); + assert(a.secret_prop === undefined); + a[1] = 20; + assert(a.length === 6); + assert(a.toString() === "1,20,2,,,3"); + assert(a.secret_prop === 20); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/array-length-setter.js b/Libraries/LibJS/Tests/builtins/Array/array-length-setter.js index d4c2d49460..6ea47cb4cf 100644 --- a/Libraries/LibJS/Tests/builtins/Array/array-length-setter.js +++ b/Libraries/LibJS/Tests/builtins/Array/array-length-setter.js @@ -1,48 +1,51 @@ load("test-common.js"); try { - var a = [1, 2, 3]; + var a = [1, 2, 3]; - assert(a.length === 3); - assert(a[0] === 1); - assert(a[1] === 2); - assert(a[2] === 3); + assert(a.length === 3); + assert(a[0] === 1); + assert(a[1] === 2); + assert(a[2] === 3); - a.length = 5; - assert(a.length === 5); - assert(a[0] === 1); - assert(a[1] === 2); - assert(a[2] === 3); - assert(a[3] === undefined); - assert(a[4] === undefined); + a.length = 5; + assert(a.length === 5); + assert(a[0] === 1); + assert(a[1] === 2); + assert(a[2] === 3); + assert(a[3] === undefined); + assert(a[4] === undefined); - a.length = 1; + a.length = 1; + assert(a.length === 1); + assert(a[0] === 1); + + a.length = 0; + assert(a.length === 0); + + a.length = "42"; + assert(a.length === 42); + + a.length = []; + assert(a.length === 0); + + a.length = true; + assert(a.length === 1); + + [undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => { + assertThrowsError( + () => { + a.length = value; + }, + { + error: RangeError, + message: "Invalid array length", + } + ); assert(a.length === 1); - assert(a[0] === 1); + }); - a.length = 0; - assert(a.length === 0); - - a.length = "42"; - assert(a.length === 42); - - a.length = []; - assert(a.length === 0); - - a.length = true; - assert(a.length === 1); - - [undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => { - assertThrowsError(() => { - a.length = value; - }, { - error: RangeError, - message: "Invalid array length" - }); - assert(a.length === 1); - }); - - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/array-shrink-during-find-crash.js b/Libraries/LibJS/Tests/builtins/Array/array-shrink-during-find-crash.js index 16a041a8e7..6586d69c51 100644 --- a/Libraries/LibJS/Tests/builtins/Array/array-shrink-during-find-crash.js +++ b/Libraries/LibJS/Tests/builtins/Array/array-shrink-during-find-crash.js @@ -1,25 +1,25 @@ load("test-common.js"); try { - var a, callbackCalled; + var a, callbackCalled; - callbackCalled = 0; - a = [1, 2, 3, 4, 5]; - a.find(() => { - callbackCalled++; - a.pop(); - }); - assert(callbackCalled === 5); + callbackCalled = 0; + a = [1, 2, 3, 4, 5]; + a.find(() => { + callbackCalled++; + a.pop(); + }); + assert(callbackCalled === 5); - callbackCalled = 0; - a = [1, 2, 3, 4, 5]; - a.findIndex(() => { - callbackCalled++; - a.pop(); - }); - assert(callbackCalled === 5); + callbackCalled = 0; + a = [1, 2, 3, 4, 5]; + a.findIndex(() => { + callbackCalled++; + a.pop(); + }); + assert(callbackCalled === 5); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Array/array-spread.js b/Libraries/LibJS/Tests/builtins/Array/array-spread.js index c9425671b4..0b114d329f 100644 --- a/Libraries/LibJS/Tests/builtins/Array/array-spread.js +++ b/Libraries/LibJS/Tests/builtins/Array/array-spread.js @@ -1,44 +1,45 @@ load("test-common.js"); function testArray(arr) { - return arr.length === 4 && - arr[0] === 0 && - arr[1] === 1 && - arr[2] === 2 && - arr[3] === 3; + return arr.length === 4 && arr[0] === 0 && arr[1] === 1 && arr[2] === 2 && arr[3] === 3; } try { - let arr = [0, ...[1, 2], 3]; - assert(testArray(arr)); + let arr = [0, ...[1, 2], 3]; + assert(testArray(arr)); - let a = [1, 2]; - arr = [0, ...a, 3]; - assert(testArray(arr)); + let a = [1, 2]; + arr = [0, ...a, 3]; + assert(testArray(arr)); - let obj = { a: [1, 2] }; - arr = [0, ...obj.a, 3]; - assert(testArray(arr)); + let obj = { a: [1, 2] }; + arr = [0, ...obj.a, 3]; + assert(testArray(arr)); - arr = [...[], ...[...[0, 1, 2]], 3]; - assert(testArray(arr)); + arr = [...[], ...[...[0, 1, 2]], 3]; + assert(testArray(arr)); - assertThrowsError(() => { - [...1]; - }, { - error: TypeError, - message: "1 is not iterable", - }); + assertThrowsError( + () => { + [...1]; + }, + { + error: TypeError, + message: "1 is not iterable", + } + ); + assertThrowsError( + () => { + [...{}]; + }, + { + error: TypeError, + message: "[object Object] is not iterable", + } + ); - assertThrowsError(() => { - [...{}]; - }, { - error: TypeError, - message: "[object Object] is not iterable", - }); - - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.asIntN.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.asIntN.js index 82deab3be4..c2d78976f5 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.asIntN.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.asIntN.js @@ -1,9 +1,9 @@ load("test-common.js"); try { - assert(BigInt.asIntN.length === 2); + assert(BigInt.asIntN.length === 2); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.asUintN.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.asUintN.js index d63b261ce3..0255cad0ad 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.asUintN.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.asUintN.js @@ -1,9 +1,9 @@ load("test-common.js"); try { - assert(BigInt.asUintN.length === 2); + assert(BigInt.asUintN.length === 2); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.js index 6d0cdebc52..eeda8fb8cc 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.js @@ -1,62 +1,78 @@ load("test-common.js"); try { - assert(BigInt.length === 1); - assert(BigInt.name === "BigInt"); + assert(BigInt.length === 1); + assert(BigInt.name === "BigInt"); - assert(BigInt(0) === 0n); - assert(BigInt(1) === 1n); - assert(BigInt(+1) === 1n); - assert(BigInt(-1) === -1n); - assert(BigInt("") === 0n); - assert(BigInt("0") === 0n); - assert(BigInt("1") === 1n); - assert(BigInt("+1") === 1n); - assert(BigInt("-1") === -1n); - assert(BigInt("-1") === -1n); - assert(BigInt([]) === 0n); - assert(BigInt("42") === 42n); - assert(BigInt(" \n 00100 \n ") === 100n); - assert(BigInt(123n) === 123n); - assert(BigInt("3323214327642987348732109829832143298746432437532197321") === 3323214327642987348732109829832143298746432437532197321n); + assert(BigInt(0) === 0n); + assert(BigInt(1) === 1n); + assert(BigInt(+1) === 1n); + assert(BigInt(-1) === -1n); + assert(BigInt("") === 0n); + assert(BigInt("0") === 0n); + assert(BigInt("1") === 1n); + assert(BigInt("+1") === 1n); + assert(BigInt("-1") === -1n); + assert(BigInt("-1") === -1n); + assert(BigInt([]) === 0n); + assert(BigInt("42") === 42n); + assert(BigInt(" \n 00100 \n ") === 100n); + assert(BigInt(123n) === 123n); + assert( + BigInt("3323214327642987348732109829832143298746432437532197321") === + 3323214327642987348732109829832143298746432437532197321n + ); - assertThrowsError(() => { - new BigInt(); - }, { + assertThrowsError( + () => { + new BigInt(); + }, + { + error: TypeError, + message: "BigInt is not a constructor", + } + ); + + [null, undefined, Symbol()].forEach(value => { + assertThrowsError( + () => { + BigInt(value); + }, + { error: TypeError, - message: "BigInt is not a constructor" - }); + message: + typeof value === "symbol" + ? "Cannot convert symbol to BigInt" + : `Cannot convert ${value} to BigInt`, + } + ); + }); - [null, undefined, Symbol()].forEach(value => { - assertThrowsError(() => { - BigInt(value); - }, { - error: TypeError, - message: typeof value === "symbol" - ? "Cannot convert symbol to BigInt" - : `Cannot convert ${value} to BigInt` - }); - }); + ["foo", "123n", "1+1", {}, function () {}].forEach(value => { + assertThrowsError( + () => { + BigInt(value); + }, + { + error: SyntaxError, + message: `Invalid value for BigInt: ${value}`, + } + ); + }); - ["foo", "123n", "1+1", {}, function () { }].forEach(value => { - assertThrowsError(() => { - BigInt(value); - }, { - error: SyntaxError, - message: `Invalid value for BigInt: ${value}` - }); - }); + [1.23, Infinity, -Infinity, NaN].forEach(value => { + assertThrowsError( + () => { + BigInt(value); + }, + { + error: RangeError, + message: "BigInt argument must be an integer", + } + ); + }); - [1.23, Infinity, -Infinity, NaN].forEach(value => { - assertThrowsError(() => { - BigInt(value); - }, { - error: RangeError, - message: "BigInt argument must be an integer" - }); - }); - - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js index bbde955404..d3d96961af 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js @@ -1,18 +1,21 @@ load("test-common.js"); try { - assert(BigInt.prototype.toLocaleString.length === 0); + assert(BigInt.prototype.toLocaleString.length === 0); - assertThrowsError(() => { - BigInt.prototype.toLocaleString.call("foo"); - }, { - error: TypeError, - message: "Not a BigInt object" - }); - - assert(BigInt(123).toLocaleString() === "123"); + assertThrowsError( + () => { + BigInt.prototype.toLocaleString.call("foo"); + }, + { + error: TypeError, + message: "Not a BigInt object", + } + ); - console.log("PASS"); + assert(BigInt(123).toLocaleString() === "123"); + + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js index 8729784ebc..2e18260baa 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js @@ -1,18 +1,21 @@ load("test-common.js"); try { - assert(BigInt.prototype.toString.length === 0); + assert(BigInt.prototype.toString.length === 0); - assertThrowsError(() => { - BigInt.prototype.toString.call("foo"); - }, { - error: TypeError, - message: "Not a BigInt object" - }); - - assert(BigInt(123).toString() === "123"); + assertThrowsError( + () => { + BigInt.prototype.toString.call("foo"); + }, + { + error: TypeError, + message: "Not a BigInt object", + } + ); - console.log("PASS"); + assert(BigInt(123).toString() === "123"); + + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js index b3bd798eaa..bf71fd93cd 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js @@ -1,20 +1,23 @@ load("test-common.js"); try { - assert(BigInt.prototype.valueOf.length === 0); + assert(BigInt.prototype.valueOf.length === 0); - assertThrowsError(() => { - BigInt.prototype.valueOf.call("foo"); - }, { - error: TypeError, - message: "Not a BigInt object" - }); + assertThrowsError( + () => { + BigInt.prototype.valueOf.call("foo"); + }, + { + error: TypeError, + message: "Not a BigInt object", + } + ); - assert(typeof BigInt(123).valueOf() === "bigint"); - // FIXME: Uncomment once we support Object() with argument - // assert(typeof Object(123n).valueOf() === "bigint"); + assert(typeof BigInt(123).valueOf() === "bigint"); + // FIXME: Uncomment once we support Object() with argument + // assert(typeof Object(123n).valueOf() === "bigint"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js b/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js index 15ba0245cf..841b60008f 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js @@ -1,68 +1,74 @@ load("test-common.js"); try { - var bigint = 123n; + var bigint = 123n; - assert(typeof bigint === "bigint"); - assert(-bigint === -123n); - assert("" + bigint === "123") + assert(typeof bigint === "bigint"); + assert(-bigint === -123n); + assert("" + bigint === "123"); - assertThrowsError(() => { - +bigint; - }, { - error: TypeError, - message: "Cannot convert BigInt to number" - }); + assertThrowsError( + () => { + +bigint; + }, + { + error: TypeError, + message: "Cannot convert BigInt to number", + } + ); - assert(12n + 34n === 46n); - assert(12n - 34n === -22n); - assert(8n * 12n === 96n); - assert(123n / 10n === 12n); - assert(2n ** 3n === 8n); - assert(5n % 3n === 2n); - assert(45977665298704210987n + 714320987142450987412098743217984576n / 4598741987421098765327980n * 987498743n === 199365500239020623962n); + assert(12n + 34n === 46n); + assert(12n - 34n === -22n); + assert(8n * 12n === 96n); + assert(123n / 10n === 12n); + assert(2n ** 3n === 8n); + assert(5n % 3n === 2n); + assert( + 45977665298704210987n + + (714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n === + 199365500239020623962n + ); - assert((12n & 5n) === 4n); - assert((1n | 2n) === 3n); - assert((5n ^ 3n) === 6n); - assert(~1n === -2n); + assert((12n & 5n) === 4n); + assert((1n | 2n) === 3n); + assert((5n ^ 3n) === 6n); + assert(~1n === -2n); - bigint = 1n; - assert(bigint++ === 1n); - assert(bigint === 2n); - assert(bigint-- === 2n); - assert(bigint === 1n); - assert(++bigint === 2n); - assert(bigint === 2n); - assert(--bigint === 1n); - assert(bigint === 1n); + bigint = 1n; + assert(bigint++ === 1n); + assert(bigint === 2n); + assert(bigint-- === 2n); + assert(bigint === 1n); + assert(++bigint === 2n); + assert(bigint === 2n); + assert(--bigint === 1n); + assert(bigint === 1n); + assert((1n == 1n) === true); + assert((1n == 1) === true); + assert((1 == 1n) === true); + assert((1n == 1.23) === false); + assert((1.23 == 1n) === false); - assert((1n == 1n) === true); - assert((1n == 1) === true); - assert((1 == 1n) === true); - assert((1n == 1.23) === false); - assert((1.23 == 1n) === false); + assert((1n != 1n) === false); + assert((1n != 1) === false); + assert((1 != 1n) === false); + assert((1n != 1.23) === true); + assert((1.23 != 1n) === true); - assert((1n != 1n) === false); - assert((1n != 1) === false); - assert((1 != 1n) === false); - assert((1n != 1.23) === true); - assert((1.23 != 1n) === true); + assert((1n === 1n) === true); + assert((1n === 1) == false); + assert((1 === 1n) === false); + assert((1n === 1.23) === false); + assert((1.23 === 1n) === false); - assert((1n === 1n) === true); - assert((1n === 1) == false); - assert((1 === 1n) === false); - assert((1n === 1.23) === false); - assert((1.23 === 1n) === false); + assert((1n !== 1n) === false); + assert((1n !== 1) === true); + assert((1 !== 1n) === true); + assert((1n !== 1.23) === true); + assert((1.23 !== 1n) === true); - assert((1n !== 1n) === false); - assert((1n !== 1) === true); - assert((1 !== 1n) === true); - assert((1n !== 1.23) === true); - assert((1.23 !== 1n) === true); - - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/BigInt/bigint-number-mix-errors.js b/Libraries/LibJS/Tests/builtins/BigInt/bigint-number-mix-errors.js index 1fc2b40093..8097ff0ca1 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/bigint-number-mix-errors.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/bigint-number-mix-errors.js @@ -1,82 +1,118 @@ load("test-common.js"); try { - [1, null, undefined].forEach(value => { - assertThrowsError(() => { - 1n + value; - }, { - error: TypeError, - message: "Cannot use addition operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n - value; - }, { - error: TypeError, - message: "Cannot use subtraction operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n * value; - }, { - error: TypeError, - message: "Cannot use multiplication operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n / value; - }, { - error: TypeError, - message: "Cannot use division operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n % value; - }, { - error: TypeError, - message: "Cannot use modulo operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n ** value; - }, { - error: TypeError, - message: "Cannot use exponentiation operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n | value; - }, { - error: TypeError, - message: "Cannot use bitwise OR operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n & value; - }, { - error: TypeError, - message: "Cannot use bitwise AND operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n ^ value; - }, { - error: TypeError, - message: "Cannot use bitwise XOR operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n << value; - }, { - error: TypeError, - message: "Cannot use left-shift operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n >> value; - }, { - error: TypeError, - message: "Cannot use right-shift operator with BigInt and other type" - }); - assertThrowsError(() => { - 1n >>> value; - }, { - error: TypeError, - message: "Cannot use unsigned right-shift operator with BigInt" - }); - }); + [1, null, undefined].forEach(value => { + assertThrowsError( + () => { + 1n + value; + }, + { + error: TypeError, + message: "Cannot use addition operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n - value; + }, + { + error: TypeError, + message: "Cannot use subtraction operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n * value; + }, + { + error: TypeError, + message: "Cannot use multiplication operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n / value; + }, + { + error: TypeError, + message: "Cannot use division operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n % value; + }, + { + error: TypeError, + message: "Cannot use modulo operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n ** value; + }, + { + error: TypeError, + message: "Cannot use exponentiation operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n | value; + }, + { + error: TypeError, + message: "Cannot use bitwise OR operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n & value; + }, + { + error: TypeError, + message: "Cannot use bitwise AND operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n ^ value; + }, + { + error: TypeError, + message: "Cannot use bitwise XOR operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n << value; + }, + { + error: TypeError, + message: "Cannot use left-shift operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n >> value; + }, + { + error: TypeError, + message: "Cannot use right-shift operator with BigInt and other type", + } + ); + assertThrowsError( + () => { + 1n >>> value; + }, + { + error: TypeError, + message: "Cannot use unsigned right-shift operator with BigInt", + } + ); + }); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js index c7415afe1a..944cf1d79c 100644 --- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js +++ b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js @@ -1,32 +1,32 @@ test("constructor properties", () => { - expect(Boolean).toHaveLength(1); - expect(Boolean.name).toBe("Boolean"); + expect(Boolean).toHaveLength(1); + expect(Boolean.name).toBe("Boolean"); }); test("typeof", () => { - expect(typeof new Boolean()).toBe("object"); - expect(typeof Boolean()).toBe("boolean"); - expect(typeof Boolean(true)).toBe("boolean"); -}) + expect(typeof new Boolean()).toBe("object"); + expect(typeof Boolean()).toBe("boolean"); + expect(typeof Boolean(true)).toBe("boolean"); +}); test("basic functionality", () => { - var foo = new Boolean(true); - var bar = new Boolean(true); + var foo = new Boolean(true); + var bar = new Boolean(true); - expect(foo).not.toBe(bar); - expect(foo.valueOf()).toBe(bar.valueOf()); + expect(foo).not.toBe(bar); + expect(foo.valueOf()).toBe(bar.valueOf()); - expect(Boolean()).toBeFalse(); - expect(Boolean(false)).toBeFalse(); - expect(Boolean(null)).toBeFalse(); - expect(Boolean(undefined)).toBeFalse(); - expect(Boolean(NaN)).toBeFalse(); - expect(Boolean("")).toBeFalse(); - expect(Boolean(0.0)).toBeFalse(); - expect(Boolean(-0.0)).toBeFalse(); - expect(Boolean(true)).toBeTrue(); - expect(Boolean("0")).toBeTrue(); - expect(Boolean({})).toBeTrue(); - expect(Boolean([])).toBeTrue(); - expect(Boolean(1)).toBeTrue(); + expect(Boolean()).toBeFalse(); + expect(Boolean(false)).toBeFalse(); + expect(Boolean(null)).toBeFalse(); + expect(Boolean(undefined)).toBeFalse(); + expect(Boolean(NaN)).toBeFalse(); + expect(Boolean("")).toBeFalse(); + expect(Boolean(0.0)).toBeFalse(); + expect(Boolean(-0.0)).toBeFalse(); + expect(Boolean(true)).toBeTrue(); + expect(Boolean("0")).toBeTrue(); + expect(Boolean({})).toBeTrue(); + expect(Boolean([])).toBeTrue(); + expect(Boolean(1)).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js index ba06a1a423..dd5a4e6abd 100644 --- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js +++ b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js @@ -1,5 +1,5 @@ test("basic functionality", () => { - expect(typeof Boolean.prototype).toBe("object"); - expect(Boolean.prototype.valueOf()).toBeFalse(); - expect(Boolean.prototype.length).toBeUndefined(); + expect(typeof Boolean.prototype).toBe("object"); + expect(Boolean.prototype.valueOf()).toBeFalse(); + expect(Boolean.prototype).not.toHaveProperty("length"); }); diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.toString.js index 506b23feac..8e652e5851 100644 --- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.toString.js @@ -1,17 +1,17 @@ test("basic functionality", () => { - var foo = true; - expect(foo.toString()).toBe("true"); - expect(true.toString()).toBe("true"); + var foo = true; + expect(foo.toString()).toBe("true"); + expect(true.toString()).toBe("true"); - expect(Boolean.prototype.toString.call(true)).toBe("true"); - expect(Boolean.prototype.toString.call(false)).toBe("false"); + expect(Boolean.prototype.toString.call(true)).toBe("true"); + expect(Boolean.prototype.toString.call(false)).toBe("false"); - expect(new Boolean(true).toString()).toBe("true"); - expect(new Boolean(false).toString()).toBe("false"); + expect(new Boolean(true).toString()).toBe("true"); + expect(new Boolean(false).toString()).toBe("false"); }); test("errors on non-boolean |this|", () => { - expect(() => { - Boolean.prototype.toString.call("foo"); - }).toThrowWithMessage(TypeError, "Not a Boolean object"); + expect(() => { + Boolean.prototype.toString.call("foo"); + }).toThrowWithMessage(TypeError, "Not a Boolean object"); }); diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js index d510523c5b..82515e6a19 100644 --- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js +++ b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js @@ -1,16 +1,16 @@ test("basic functionality", () => { - var foo = true; - expect(foo.valueOf()).toBeTrue(); - expect(true.valueOf()).toBeTrue(); + var foo = true; + expect(foo.valueOf()).toBeTrue(); + expect(true.valueOf()).toBeTrue(); - expect(Boolean.prototype.valueOf.call(true)).toBeTrue(); - expect(Boolean.prototype.valueOf.call(false)).toBeFalse(); + expect(Boolean.prototype.valueOf.call(true)).toBeTrue(); + expect(Boolean.prototype.valueOf.call(false)).toBeFalse(); - expect(new Boolean().valueOf()).toBeFalse(); + expect(new Boolean().valueOf()).toBeFalse(); }); test("errors on non-boolean |this|", () => { - expect(() => { - Boolean.prototype.valueOf.call("foo"); - }).toThrowWithMessage(TypeError, "Not a Boolean object"); + expect(() => { + Boolean.prototype.valueOf.call("foo"); + }).toThrowWithMessage(TypeError, "Not a Boolean object"); }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.js b/Libraries/LibJS/Tests/builtins/Date/Date.js index 3934fb5142..2d50f22c88 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.js @@ -1,5 +1,5 @@ test("basic functionality", () => { - expect(Date).toHaveLength(7); - expect(Date.name === "Date"); - expect(Date.prototype).not.toHaveProperty("length"); + expect(Date).toHaveLength(7); + expect(Date.name === "Date"); + expect(Date.prototype).not.toHaveProperty("length"); }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.now.js b/Libraries/LibJS/Tests/builtins/Date/Date.now.js index 46c1b6d8cd..323ac46c8d 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.now.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.now.js @@ -1,10 +1,10 @@ test("basic functionality", () => { - var last = 0; - for (var i = 0; i < 100; ++i) { - var now = Date.now(); - expect(now).not.toBeNaN(); - expect(now).toBeGreaterThan(1580000000000); - expect(now).toBeGreaterThanOrEqual(last); - last = now; - } + var last = 0; + for (var i = 0; i < 100; ++i) { + var now = Date.now(); + expect(now).not.toBeNaN(); + expect(now).toBeGreaterThan(1580000000000); + expect(now).toBeGreaterThanOrEqual(last); + last = now; + } }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js index 647e43a997..20d1957aa8 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js @@ -1,7 +1,7 @@ test("basic functionality", () => { - let d = new Date(); - expect(d.getDate()).toBe(d.getDate()); - expect(d.getDate()).not.toBeNaN(); - expect(d.getDate()).toBeGreaterThanOrEqual(1); - expect(d.getDate()).toBeLessThanOrEqual(31); + let d = new Date(); + expect(d.getDate()).toBe(d.getDate()); + expect(d.getDate()).not.toBeNaN(); + expect(d.getDate()).toBeGreaterThanOrEqual(1); + expect(d.getDate()).toBeLessThanOrEqual(31); }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js index 534efeeee5..65e15776b6 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js @@ -1,7 +1,7 @@ test("basic functionality", () => { - var d = new Date(); - expect(d.getDay()).toBe(d.getDay()); - expect(d.getDay()).not.toBeNaN(); - expect(d.getDay()).toBeGreaterThanOrEqual(0); - expect(d.getDay()).toBeLessThanOrEqual(6); + var d = new Date(); + expect(d.getDay()).toBe(d.getDay()); + expect(d.getDay()).not.toBeNaN(); + expect(d.getDay()).toBeGreaterThanOrEqual(0); + expect(d.getDay()).toBeLessThanOrEqual(6); }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js index 3748e835cf..c495f78f4b 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js @@ -1,7 +1,7 @@ test("basic functionality", () => { - var d = new Date(); - expect(d.getFullYear()).toBe(d.getFullYear()); - expect(d.getFullYear()).not.toBeNaN(); - expect(d.getFullYear()).toBe(d.getFullYear()); - expect(d.getFullYear()).toBeGreaterThanOrEqual(2020); + var d = new Date(); + expect(d.getFullYear()).toBe(d.getFullYear()); + expect(d.getFullYear()).not.toBeNaN(); + expect(d.getFullYear()).toBe(d.getFullYear()); + expect(d.getFullYear()).toBeGreaterThanOrEqual(2020); }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js index 7e562288f2..fe69137273 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js @@ -1,7 +1,7 @@ test("basic functionality", () => { - var d = new Date(); - expect(d.getHours()).toBe(d.getHours()); - expect(d.getHours()).not.toBeNaN(); - expect(d.getHours()).toBeGreaterThanOrEqual(0); - expect(d.getHours()).toBeLessThanOrEqual(23); + var d = new Date(); + expect(d.getHours()).toBe(d.getHours()); + expect(d.getHours()).not.toBeNaN(); + expect(d.getHours()).toBeGreaterThanOrEqual(0); + expect(d.getHours()).toBeLessThanOrEqual(23); }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js index 90c686f729..c10b3f8c6e 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js @@ -1,7 +1,7 @@ test("basic functionality", () => { - var d = new Date(); - expect(d.getMilliseconds()).toBe(d.getMilliseconds()); - expect(d.getMilliseconds()).not.toBeNaN(); - expect(d.getMilliseconds()).toBeGreaterThanOrEqual(0); - expect(d.getMilliseconds()).toBeLessThanOrEqual(999); + var d = new Date(); + expect(d.getMilliseconds()).toBe(d.getMilliseconds()); + expect(d.getMilliseconds()).not.toBeNaN(); + expect(d.getMilliseconds()).toBeGreaterThanOrEqual(0); + expect(d.getMilliseconds()).toBeLessThanOrEqual(999); }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js index 5b87b8251d..b862339916 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js @@ -1,7 +1,7 @@ test("basic functionality", () => { - var d = new Date(); - expect(d.getMinutes()).toBe(d.getMinutes()); - expect(d.getMinutes()).not.toBeNaN(); - expect(d.getMinutes()).toBeGreaterThanOrEqual(0); - expect(d.getMinutes()).toBeLessThanOrEqual(59); + var d = new Date(); + expect(d.getMinutes()).toBe(d.getMinutes()); + expect(d.getMinutes()).not.toBeNaN(); + expect(d.getMinutes()).toBeGreaterThanOrEqual(0); + expect(d.getMinutes()).toBeLessThanOrEqual(59); }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js index 7d52866ce7..0bd5efa5be 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js @@ -1,7 +1,7 @@ test("basic functionality", () => { - var d = new Date(); - expect(d.getMonth()).toBe(d.getMonth()); - expect(d.getMonth()).not.toBeNaN(); - expect(d.getMonth()).toBeGreaterThanOrEqual(0); - expect(d.getMonth()).toBeLessThanOrEqual(11); + var d = new Date(); + expect(d.getMonth()).toBe(d.getMonth()); + expect(d.getMonth()).not.toBeNaN(); + expect(d.getMonth()).toBeGreaterThanOrEqual(0); + expect(d.getMonth()).toBeLessThanOrEqual(11); }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js index df30881c9a..09b2fd3000 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js @@ -1,7 +1,7 @@ test("basic functionality", () => { - var d = new Date(); - expect(d.getSeconds()).toBe(d.getSeconds()); - expect(d.getSeconds()).not.toBeNaN(); - expect(d.getSeconds()).toBeGreaterThanOrEqual(0); - expect(d.getSeconds()).toBeLessThanOrEqual(59); + var d = new Date(); + expect(d.getSeconds()).toBe(d.getSeconds()); + expect(d.getSeconds()).not.toBeNaN(); + expect(d.getSeconds()).toBeGreaterThanOrEqual(0); + expect(d.getSeconds()).toBeLessThanOrEqual(59); }); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js index b9ada6fcc9..9956dec489 100644 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js +++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js @@ -1,6 +1,6 @@ test("basic functionality", () => { - var d = new Date(); - expect(d.getTime()).toBe(d.getTime()); - expect(d.getTime()).not.toBeNaN(); - expect(d.getTime()).toBeGreaterThanOrEqual(1580000000000); + var d = new Date(); + expect(d.getTime()).toBe(d.getTime()); + expect(d.getTime()).not.toBeNaN(); + expect(d.getTime()).toBeGreaterThanOrEqual(1580000000000); }); diff --git a/Libraries/LibJS/Tests/builtins/Error/Error.js b/Libraries/LibJS/Tests/builtins/Error/Error.js index a452bd7a88..11b609c7ba 100644 --- a/Libraries/LibJS/Tests/builtins/Error/Error.js +++ b/Libraries/LibJS/Tests/builtins/Error/Error.js @@ -1,18 +1,18 @@ test("basic functionality", () => { - expect(Error).toHaveLength(1); - expect(Error.name).toBe("Error"); + expect(Error).toHaveLength(1); + expect(Error.name).toBe("Error"); }); test("name", () => { - [Error(), Error(undefined), Error("test"), Error(42), Error(null)].forEach(error => { - expect(error.name).toBe("Error"); - }); + [Error(), Error(undefined), Error("test"), Error(42), Error(null)].forEach(error => { + expect(error.name).toBe("Error"); + }); }); test("message", () => { - expect(Error().message).toBe(""); - expect(Error(undefined).message).toBe(""); - expect(Error("test").message).toBe("test"); - expect(Error(42).message).toBe("42"); - expect(Error(null).message).toBe("null"); + expect(Error().message).toBe(""); + expect(Error(undefined).message).toBe(""); + expect(Error("test").message).toBe("test"); + expect(Error(42).message).toBe("42"); + expect(Error(null).message).toBe("null"); }); diff --git a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js b/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js index 9e64eda1a3..cc4e0a5623 100644 --- a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js +++ b/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js @@ -1,10 +1,10 @@ test("basic functionality", () => { - expect(Error.prototype).not.toHaveProperty("length"); - - var changedInstance = new Error(""); - changedInstance.name = "NewCustomError"; - expect(changedInstance.name).toBe("NewCustomError"); + expect(Error.prototype).not.toHaveProperty("length"); - var normalInstance = new Error(""); - expect(normalInstance.name).toBe("Error"); + var changedInstance = new Error(""); + changedInstance.name = "NewCustomError"; + expect(changedInstance.name).toBe("NewCustomError"); + + var normalInstance = new Error(""); + expect(normalInstance.name).toBe("Error"); }); diff --git a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js index b5d2f7dceb..c09570fbe2 100644 --- a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js @@ -1,7 +1,7 @@ test("basic functionality", () => { - expect(Error().toString()).toBe("Error"); - expect(Error(undefined).toString()).toBe("Error"); - expect(Error(null).toString()).toBe("Error: null"); - expect(Error("test").toString()).toBe("Error: test"); - expect(Error(42).toString()).toBe("Error: 42"); + expect(Error().toString()).toBe("Error"); + expect(Error(undefined).toString()).toBe("Error"); + expect(Error(null).toString()).toBe("Error: null"); + expect(Error("test").toString()).toBe("Error: test"); + expect(Error(42).toString()).toBe("Error: 42"); }); diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.js b/Libraries/LibJS/Tests/builtins/Function/Function.js index e56b5e4738..6f239f2a3e 100644 --- a/Libraries/LibJS/Tests/builtins/Function/Function.js +++ b/Libraries/LibJS/Tests/builtins/Function/Function.js @@ -1,44 +1,49 @@ describe("correct behavior", () => { - test("constructor properties", () => { - expect(Function).toHaveLength(1); - expect(Function.name).toBe("Function"); - expect(Function.prototype).toHaveLength(0); - expect(Function.prototype.name).toBe(""); - }); + test("constructor properties", () => { + expect(Function).toHaveLength(1); + expect(Function.name).toBe("Function"); + expect(Function.prototype).toHaveLength(0); + expect(Function.prototype.name).toBe(""); + }); - test("typeof", () => { - expect(typeof Function()).toBe("function"); - expect(typeof new Function()).toBe("function"); - }); + test("typeof", () => { + expect(typeof Function()).toBe("function"); + expect(typeof new Function()).toBe("function"); + }); - test("basic functionality", () => { - expect(Function()()).toBe(undefined); - expect(new Function()()).toBe(undefined); - expect(Function("return 42")()).toBe(42); - expect(new Function("return 42")()).toBe(42); - expect(new Function("foo", "return foo")(42)).toBe(42); - expect(new Function("foo,bar", "return foo + bar")(1, 2)).toBe(3); - expect(new Function("foo", "bar", "return foo + bar")(1, 2)).toBe(3); - expect(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3)).toBe(6); - expect(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3)).toBe(6); - expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true)).toBe(42); - expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe("bar"); - expect(new Function("return typeof Function()")()).toBe("function"); - expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3); + test("basic functionality", () => { + expect(Function()()).toBeUndefined(); + expect(new Function()()).toBeUndefined(); + expect(Function("return 42")()).toBe(42); + expect(new Function("return 42")()).toBe(42); + expect(new Function("foo", "return foo")(42)).toBe(42); + expect(new Function("foo,bar", "return foo + bar")(1, 2)).toBe(3); + expect(new Function("foo", "bar", "return foo + bar")(1, 2)).toBe(3); + expect(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3)).toBe(6); + expect(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3)).toBe(6); + expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true)).toBe(42); + expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe( + "bar" + ); + expect(new Function("return typeof Function()")()).toBe("function"); + expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3); - expect(new Function().name).toBe("anonymous"); - expect(new Function().toString()).toBe("function anonymous() {\n ???\n}"); - }); + expect(new Function().name).toBe("anonymous"); + expect(new Function().toString()).toBe("function anonymous() {\n ???\n}"); + }); }); describe("errors", () => { - test("syntax error", () => { - expect(() => { - new Function("["); - }) - // This might be confusing at first but keep in mind it's actually parsing - // function anonymous() { [ } - // This is in line with what other engines are reporting. - .toThrowWithMessage(SyntaxError, "Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)"); - }); + test("syntax error", () => { + expect(() => { + new Function("["); + }) + // This might be confusing at first but keep in mind it's actually parsing + // function anonymous() { [ } + // This is in line with what other engines are reporting. + .toThrowWithMessage( + SyntaxError, + "Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js index c13ec7e7e7..a09d166ce7 100644 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js +++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js @@ -1,49 +1,51 @@ test("basic functionality", () => { - function Foo(arg) { - this.foo = arg; - } - function Bar(arg) { - this.bar = arg; - } - function FooBar(arg) { - Foo.apply(this, [arg]); - Bar.apply(this, [arg]); - } - function FooBarBaz(arg) { - Foo.apply(this, [arg]); - Bar.apply(this, [arg]); - this.baz = arg; - } + function Foo(arg) { + this.foo = arg; + } + function Bar(arg) { + this.bar = arg; + } + function FooBar(arg) { + Foo.apply(this, [arg]); + Bar.apply(this, [arg]); + } + function FooBarBaz(arg) { + Foo.apply(this, [arg]); + Bar.apply(this, [arg]); + this.baz = arg; + } - expect(Function.prototype.apply).toHaveLength(2); + expect(Function.prototype.apply).toHaveLength(2); - var foo = new Foo("test"); - expect(foo.foo).toBe("test"); - expect(foo.bar).toBeUndefined(); - expect(foo.baz).toBeUndefined(); + var foo = new Foo("test"); + expect(foo.foo).toBe("test"); + expect(foo.bar).toBeUndefined(); + expect(foo.baz).toBeUndefined(); - var bar = new Bar("test"); - expect(bar.foo).toBeUndefined(); - expect(bar.bar).toBe("test"); - expect(bar.baz).toBeUndefined(); + var bar = new Bar("test"); + expect(bar.foo).toBeUndefined(); + expect(bar.bar).toBe("test"); + expect(bar.baz).toBeUndefined(); - var foobar = new FooBar("test"); - expect(foobar.foo).toBe("test"); - expect(foobar.bar).toBe("test"); - expect(foobar.baz).toBeUndefined(); + var foobar = new FooBar("test"); + expect(foobar.foo).toBe("test"); + expect(foobar.bar).toBe("test"); + expect(foobar.baz).toBeUndefined(); - var foobarbaz = new FooBarBaz("test"); - expect(foobarbaz.foo).toBe("test"); - expect(foobarbaz.bar).toBe("test"); - expect(foobarbaz.baz).toBe("test"); + var foobarbaz = new FooBarBaz("test"); + expect(foobarbaz.foo).toBe("test"); + expect(foobarbaz.bar).toBe("test"); + expect(foobarbaz.baz).toBe("test"); - expect(Math.abs.apply(null, [-1])).toBe(1); + expect(Math.abs.apply(null, [-1])).toBe(1); - var add = (x, y) => x + y; - expect(add.apply(null, [1, 2])).toBe(3); + var add = (x, y) => x + y; + expect(add.apply(null, [1, 2])).toBe(3); - var multiply = function (x, y) { return x * y; }; - expect(multiply.apply(null, [3, 4])).toBe(12); + var multiply = function (x, y) { + return x * y; + }; + expect(multiply.apply(null, [3, 4])).toBe(12); - expect((() => this).apply("foo")).toBe(globalThis); + expect((() => this).apply("foo")).toBe(globalThis); }); diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js index fd3d9abaf6..d6189e849e 100644 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js +++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js @@ -1,138 +1,149 @@ describe("basic behavior", () => { - test("basic binding", () => { - expect(Function.prototype.bind.length).toBe(1); + test("basic binding", () => { + expect(Function.prototype.bind).toHaveLength(1); - var charAt = String.prototype.charAt.bind("bar"); - expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar"); + var charAt = String.prototype.charAt.bind("bar"); + expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar"); - function getB() { - return this.toUpperCase().charAt(0); - } - expect(getB.bind("bar")()).toBe("B"); - }); + function getB() { + return this.toUpperCase().charAt(0); + } + expect(getB.bind("bar")()).toBe("B"); + }); - test("bound functions work with array functions", () => { - var Make3 = Number.bind(null, 3); - expect([55].map(Make3)[0]).toBe(3); + test("bound functions work with array functions", () => { + var Make3 = Number.bind(null, 3); + expect([55].map(Make3)[0]).toBe(3); - var MakeTrue = Boolean.bind(null, true); + var MakeTrue = Boolean.bind(null, true); - expect([1, 2, 3].filter(MakeTrue).length).toBe(3); - expect([1, 2, 3].reduce((function (acc, x) { return acc + x }).bind(null, 4, 5))).toBe(9); - expect([1, 2, 3].reduce((function (acc, x) { return acc + x + this; }).bind(3))).toBe(12); - }); + expect([1, 2, 3].filter(MakeTrue)).toHaveLength(3); + expect( + [1, 2, 3].reduce( + function (acc, x) { + return acc + x; + }.bind(null, 4, 5) + ) + ).toBe(9); + expect( + [1, 2, 3].reduce( + function (acc, x) { + return acc + x + this; + }.bind(3) + ) + ).toBe(12); + }); }); describe("bound function arguments", () => { - function sum(a, b, c) { - return a + b + c; - } - var boundSum = sum.bind(null, 10, 5); + function sum(a, b, c) { + return a + b + c; + } + var boundSum = sum.bind(null, 10, 5); - test("arguments are bound to the function", () => { - expect(boundSum()).toBeNaN(); - expect(boundSum(5)).toBe(20); - expect(boundSum(5, 6, 7)).toBe(20); - }); + test("arguments are bound to the function", () => { + expect(boundSum()).toBeNaN(); + expect(boundSum(5)).toBe(20); + expect(boundSum(5, 6, 7)).toBe(20); + }); - test("arguments are appended to a BoundFunction's bound arguments", () => { - expect(boundSum.bind(null, 5)()).toBe(20); - }); + test("arguments are appended to a BoundFunction's bound arguments", () => { + expect(boundSum.bind(null, 5)()).toBe(20); + }); - test("binding a constructor's arguments", () => { - var Make5 = Number.bind(null, 5); - expect(Make5()).toBe(5); - expect(new Make5().valueOf()).toBe(5); - }); + test("binding a constructor's arguments", () => { + var Make5 = Number.bind(null, 5); + expect(Make5()).toBe(5); + expect(new Make5().valueOf()).toBe(5); + }); - test("length property", () => { - expect(sum).toHaveLength(3); - expect(boundSum).toHaveLength(1); - expect(boundSum.bind(null, 5)).toHaveLength(0); - expect(boundSum.bind(null, 5, 6, 7, 8)).toHaveLength(0); - }); -}) + test("length property", () => { + expect(sum).toHaveLength(3); + expect(boundSum).toHaveLength(1); + expect(boundSum.bind(null, 5)).toHaveLength(0); + expect(boundSum.bind(null, 5, 6, 7, 8)).toHaveLength(0); + }); +}); describe("bound function |this|", () => { - function identity() { - return this; + function identity() { + return this; + } + + test("captures global object as |this| if |this| is null or undefined", () => { + expect(identity.bind()()).toBe(globalThis); + expect(identity.bind(null)()).toBe(globalThis); + expect(identity.bind(undefined)()).toBe(globalThis); + + function Foo() { + expect(identity.bind()()).toBe(globalThis); + expect(identity.bind(this)()).toBe(this); + } + new Foo(); + }); + + test("does not capture global object as |this| if |this| is null or undefined in strict mode", () => { + "use strict"; + + function strictIdentity() { + return this; } - test("captures global object as |this| if |this| is null or undefined", () => { - expect(identity.bind()()).toBe(globalThis); - expect(identity.bind(null)()).toBe(globalThis); - expect(identity.bind(undefined)()).toBe(globalThis); + expect(strictIdentity.bind()()).toBeUndefined(); + expect(strictIdentity.bind(null)()).toBeNull(); + expect(strictIdentity.bind(undefined)()).toBeUndefined(); + }); - function Foo() { - expect(identity.bind()()).toBe(globalThis); - expect(identity.bind(this)()).toBe(this); - } - new Foo(); - }); + test("primitive |this| values are converted to objects", () => { + expect(identity.bind("foo")()).toBeInstanceOf(String); + expect(identity.bind(123)()).toBeInstanceOf(Number); + expect(identity.bind(true)()).toBeInstanceOf(Boolean); + }); - test("does not capture global object as |this| if |this| is null or undefined in strict mode", () => { - "use strict"; + test("bound functions retain |this| values passed to them", () => { + var obj = { foo: "bar" }; + expect(identity.bind(obj)()).toBe(obj); + }); - function strictIdentity() { - return this; - } + test("bound |this| cannot be changed after being set", () => { + expect(identity.bind("foo").bind(123)()).toBeInstanceOf(String); + }); - expect(strictIdentity.bind()()).toBeUndefined(); - expect(strictIdentity.bind(null)()).toBeNull(); - expect(strictIdentity.bind(undefined)()).toBeUndefined(); - }); - - test("primitive |this| values are converted to objects", () => { - expect(identity.bind("foo")()).toBeInstanceOf(String); - expect(identity.bind(123)()).toBeInstanceOf(Number); - expect(identity.bind(true)()).toBeInstanceOf(Boolean); - }); - - test("bound functions retain |this| values passed to them", () => { - var obj = { foo: "bar" }; - expect(identity.bind(obj)()).toBe(obj); - }); - - test("bound |this| cannot be changed after being set", () => { - expect(identity.bind("foo").bind(123)()).toBeInstanceOf(String); - }); - - test("arrow functions cannot be bound", () => { - expect((() => this).bind("foo")()).toBe(globalThis) - }); -}) + test("arrow functions cannot be bound", () => { + expect((() => this).bind("foo")()).toBe(globalThis); + }); +}); describe("bound function constructors", () => { - function Bar() { - this.x = 3; - this.y = 4; - } + function Bar() { + this.x = 3; + this.y = 4; + } - Bar.prototype.baz = "baz"; - var BoundBar = Bar.bind({ u: 5, v: 6 }); - var bar = new BoundBar(); + Bar.prototype.baz = "baz"; + var BoundBar = Bar.bind({ u: 5, v: 6 }); + var bar = new BoundBar(); + test("bound |this| value does not affect constructor", () => { + expect(bar.x).toBe(3); + expect(bar.y).toBe(4); + expect(typeof bar.u).toBe("undefined"); + expect(typeof bar.v).toBe("undefined"); + }); - test("bound |this| value does not affect constructor", () => { - expect(bar.x).toBe(3); - expect(bar.y).toBe(4); - expect(typeof bar.u).toBe("undefined"); - expect(typeof bar.v).toBe("undefined"); - }); + test("bound functions retain original prototype", () => { + expect(bar.baz).toBe("baz"); + }); - test("bound functions retain original prototype", () => { - expect(bar.baz).toBe("baz"); - }); - - test("bound functions do not have a prototype property", () => { - expect(BoundBar).not.toHaveProperty("prototype"); - }); + test("bound functions do not have a prototype property", () => { + expect(BoundBar).not.toHaveProperty("prototype"); + }); }); describe("errors", () => { - test("does not accept non-function values", () => { - expect(() => { - Function.prototype.bind.call("foo"); - }).toThrowWithMessage(TypeError, "Not a Function object"); - }); + test("does not accept non-function values", () => { + expect(() => { + Function.prototype.bind.call("foo"); + }).toThrowWithMessage(TypeError, "Not a Function object"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js index b36195592c..e7c2e4e8e1 100644 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js +++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js @@ -1,51 +1,53 @@ test("length", () => { - expect(Function.prototype.call).toHaveLength(1); + expect(Function.prototype.call).toHaveLength(1); }); test("basic functionality", () => { - function Foo(arg) { - this.foo = arg; - } - function Bar(arg) { - this.bar = arg; - } - function FooBar(arg) { - Foo.call(this, arg); - Bar.call(this, arg); - } - function FooBarBaz(arg) { - Foo.call(this, arg); - Bar.call(this, arg); - this.baz = arg; - } + function Foo(arg) { + this.foo = arg; + } + function Bar(arg) { + this.bar = arg; + } + function FooBar(arg) { + Foo.call(this, arg); + Bar.call(this, arg); + } + function FooBarBaz(arg) { + Foo.call(this, arg); + Bar.call(this, arg); + this.baz = arg; + } - var foo = new Foo("test"); - expect(foo.foo).toBe("test"); - expect(foo.bar).toBeUndefined(); - expect(foo.baz).toBeUndefined(); + var foo = new Foo("test"); + expect(foo.foo).toBe("test"); + expect(foo.bar).toBeUndefined(); + expect(foo.baz).toBeUndefined(); - var bar = new Bar("test"); - expect(bar.foo).toBeUndefined(); - expect(bar.bar).toBe("test"); - expect(bar.baz).toBeUndefined(); + var bar = new Bar("test"); + expect(bar.foo).toBeUndefined(); + expect(bar.bar).toBe("test"); + expect(bar.baz).toBeUndefined(); - var foobar = new FooBar("test"); - expect(foobar.foo).toBe("test"); - expect(foobar.bar).toBe("test"); - expect(foobar.baz).toBeUndefined(); + var foobar = new FooBar("test"); + expect(foobar.foo).toBe("test"); + expect(foobar.bar).toBe("test"); + expect(foobar.baz).toBeUndefined(); - var foobarbaz = new FooBarBaz("test"); - expect(foobarbaz.foo).toBe("test"); - expect(foobarbaz.bar).toBe("test"); - expect(foobarbaz.baz).toBe("test"); + var foobarbaz = new FooBarBaz("test"); + expect(foobarbaz.foo).toBe("test"); + expect(foobarbaz.bar).toBe("test"); + expect(foobarbaz.baz).toBe("test"); - expect(Math.abs.call(null, -1)).toBe(1); + expect(Math.abs.call(null, -1)).toBe(1); - var add = (x, y) => x + y; - expect(add.call(null, 1, 2)).toBe(3); + var add = (x, y) => x + y; + expect(add.call(null, 1, 2)).toBe(3); - var multiply = function (x, y) { return x * y; }; - expect(multiply.call(null, 3, 4)).toBe(12); + var multiply = function (x, y) { + return x * y; + }; + expect(multiply.call(null, 3, 4)).toBe(12); - expect((() => this).call("foo")).toBe(globalThis); + expect((() => this).call("foo")).toBe(globalThis); }); diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js index 4ef56c1102..66bddb9867 100644 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js @@ -1,15 +1,17 @@ test("basic functionality", () => { - expect((function() {}).toString()).toBe("function () {\n ???\n}"); - expect((function(foo) {}).toString()).toBe("function (foo) {\n ???\n}"); - expect((function(foo, bar, baz) {}).toString()).toBe("function (foo, bar, baz) {\n ???\n}"); - expect((function(foo, bar, baz) { - if (foo) { - return baz; - } else if (bar) { - return foo; - } - return bar + 42; - }).toString()).toBe("function (foo, bar, baz) {\n ???\n}"); - expect(console.debug.toString()).toBe("function debug() {\n [NativeFunction]\n}"); - expect(Function.toString()).toBe("function Function() {\n [FunctionConstructor]\n}"); + expect(function () {}.toString()).toBe("function () {\n ???\n}"); + expect(function (foo) {}.toString()).toBe("function (foo) {\n ???\n}"); + expect(function (foo, bar, baz) {}.toString()).toBe("function (foo, bar, baz) {\n ???\n}"); + expect( + function (foo, bar, baz) { + if (foo) { + return baz; + } else if (bar) { + return foo; + } + return bar + 42; + }.toString() + ).toBe("function (foo, bar, baz) {\n ???\n}"); + expect(console.debug.toString()).toBe("function debug() {\n [NativeFunction]\n}"); + expect(Function.toString()).toBe("function Function() {\n [FunctionConstructor]\n}"); }); diff --git a/Libraries/LibJS/Tests/builtins/Infinity/Infinity.js b/Libraries/LibJS/Tests/builtins/Infinity/Infinity.js index 0c88544f7f..78c1020a7e 100644 --- a/Libraries/LibJS/Tests/builtins/Infinity/Infinity.js +++ b/Libraries/LibJS/Tests/builtins/Infinity/Infinity.js @@ -1,22 +1,22 @@ test("basic functionality", () => { - expect(Infinity + "").toBe("Infinity"); - expect(-Infinity + "").toBe("-Infinity"); - expect(Infinity).toBe(Infinity); - expect(Infinity - 1).toBe(Infinity); - expect(Infinity + 1).toBe(Infinity); - expect(-Infinity).toBe(-Infinity); - expect(-Infinity - 1).toBe(-Infinity); - expect(-Infinity + 1).toBe(-Infinity); - expect(1 / Infinity).toBe(0); - expect(1 / -Infinity).toBe(-0); - expect(1 / 0).toBe(Infinity); - expect(-1 / 0).toBe(-Infinity); - expect(-100).toBeLessThan(Infinity); - expect(0).toBeLessThan(Infinity); - expect(100).toBeLessThan(Infinity); - expect(-Infinity).toBeLessThan(Infinity); - expect(-100).toBeGreaterThan(-Infinity); - expect(0).toBeGreaterThan(-Infinity); - expect(100).toBeGreaterThan(-Infinity); - expect(Infinity).toBeGreaterThan(-Infinity); + expect(Infinity + "").toBe("Infinity"); + expect(-Infinity + "").toBe("-Infinity"); + expect(Infinity).toBe(Infinity); + expect(Infinity - 1).toBe(Infinity); + expect(Infinity + 1).toBe(Infinity); + expect(-Infinity).toBe(-Infinity); + expect(-Infinity - 1).toBe(-Infinity); + expect(-Infinity + 1).toBe(-Infinity); + expect(1 / Infinity).toBe(0); + expect(1 / -Infinity).toBe(-0); + expect(1 / 0).toBe(Infinity); + expect(-1 / 0).toBe(-Infinity); + expect(-100).toBeLessThan(Infinity); + expect(0).toBeLessThan(Infinity); + expect(100).toBeLessThan(Infinity); + expect(-Infinity).toBeLessThan(Infinity); + expect(-100).toBeGreaterThan(-Infinity); + expect(0).toBeGreaterThan(-Infinity); + expect(100).toBeGreaterThan(-Infinity); + expect(Infinity).toBeGreaterThan(-Infinity); }); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js index db77a1b17b..cbd810352b 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js @@ -1,9 +1,9 @@ test("basic functionality", () => { - let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`; + let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`; - let object = JSON.parse(string, (key, value) => typeof value === "number" ? value * 2 : value); - expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } }); + let object = JSON.parse(string, (key, value) => (typeof value === "number" ? value * 2 : value)); + expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } }); - object = JSON.parse(string, (key, value) => typeof value === "number" ? undefined : value); - expect(object).toEqual({ var2: "hello", var3: {} }); + object = JSON.parse(string, (key, value) => (typeof value === "number" ? undefined : value)); + expect(object).toEqual({ var2: "hello", var3: {} }); }); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js index 7f82392666..4f21c11728 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js @@ -1,37 +1,37 @@ test("basic functionality", () => { - expect(JSON.parse).toHaveLength(2); + expect(JSON.parse).toHaveLength(2); - const properties = [ - ["5", 5], - ["null", null], - ["true", true], - ["false", false], - ['"test"', "test"], - ['[1,2,"foo"]', [1, 2, "foo"]], - ['{"foo":1,"bar":"baz"}', { foo: 1, bar: "baz" }], - ]; + const properties = [ + ["5", 5], + ["null", null], + ["true", true], + ["false", false], + ['"test"', "test"], + ['[1,2,"foo"]', [1, 2, "foo"]], + ['{"foo":1,"bar":"baz"}', { foo: 1, bar: "baz" }], + ]; - properties.forEach(testCase => { - expect(JSON.parse(testCase[0])).toEqual(testCase[1]); - }); + properties.forEach(testCase => { + expect(JSON.parse(testCase[0])).toEqual(testCase[1]); + }); }); test("syntax errors", () => { - [ - undefined, - NaN, - -NaN, - Infinity, - -Infinity, - '{ "foo" }', - '{ foo: "bar" }', - "[1,2,3,]", - "[1,2,3, ]", - '{ "foo": "bar",}', - '{ "foo": "bar", }', - ].forEach(test => { - expect(() => { - JSON.parse(test); - }).toThrow(SyntaxError); - }); + [ + undefined, + NaN, + -NaN, + Infinity, + -Infinity, + '{ "foo" }', + '{ foo: "bar" }', + "[1,2,3,]", + "[1,2,3, ]", + '{ "foo": "bar",}', + '{ "foo": "bar", }', + ].forEach(test => { + expect(() => { + JSON.parse(test); + }).toThrow(SyntaxError); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js index 3edede22f1..ddab27212e 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js @@ -1,28 +1,30 @@ test("basic functionality", () => { - let o = { - key1: "key1", - key2: "key2", - key3: "key3", - }; + let o = { + key1: "key1", + key2: "key2", + key3: "key3", + }; - Object.defineProperty(o, "defined", { - enumerable: true, - get() { - o.prop = "prop"; - return "defined"; - }, - }); + Object.defineProperty(o, "defined", { + enumerable: true, + get() { + o.prop = "prop"; + return "defined"; + }, + }); - o.key4 = "key4"; + o.key4 = "key4"; - o[2] = 2; - o[0] = 0; - o[1] = 1; + o[2] = 2; + o[0] = 0; + o[1] = 1; - delete o.key1; - delete o.key3; + delete o.key1; + delete o.key3; - o.key1 = "key1"; + o.key1 = "key1"; - expect(JSON.stringify(o)).toBe('{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}'); + expect(JSON.stringify(o)).toBe( + '{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}' + ); }); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js index 3d483a01e8..805d49fc61 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js @@ -1,12 +1,11 @@ test("basic functionality", () => { - let p = new Proxy([], { - get(_, key) { - if (key === "length") - return 3; - return Number(key); - }, - }); + let p = new Proxy([], { + get(_, key) { + if (key === "length") return 3; + return Number(key); + }, + }); - expect(JSON.stringify(p)).toBe("[0,1,2]"); - expect(JSON.stringify([[new Proxy(p, {})]])).toBe("[[[0,1,2]]]"); + expect(JSON.stringify(p)).toBe("[0,1,2]"); + expect(JSON.stringify([[new Proxy(p, {})]])).toBe("[[[0,1,2]]]"); }); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js index b0f6eda72b..007e558ef9 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js @@ -1,33 +1,38 @@ test("basic functionality", () => { - let o = { - var1: "foo", - var2: 42, - arr: [1, 2, { - nested: { - hello: "world", - }, - get x() { return 10; } - }], - obj: { - subarr: [3], + let o = { + var1: "foo", + var2: 42, + arr: [ + 1, + 2, + { + nested: { + hello: "world", }, - }; + get x() { + return 10; + }, + }, + ], + obj: { + subarr: [3], + }, + }; - let string = JSON.stringify(o, (key, value) => { - if (key === "hello") - return undefined; - if (value === 10) - return 20; - if (key === "subarr") - return [3, 4, 5]; - return value; - }); + let string = JSON.stringify(o, (key, value) => { + if (key === "hello") return undefined; + if (value === 10) return 20; + if (key === "subarr") return [3, 4, 5]; + return value; + }); - expect(string).toBe('{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}'); + expect(string).toBe( + '{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}' + ); - string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]); - expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}'); + string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]); + expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}'); - string = JSON.stringify(o, ["var1", "var1", "var2", "obj", "subarr"]); - expect(string).toBe('{"var1":"foo","var2":42,"obj":{"subarr":[3]}}'); + string = JSON.stringify(o, ["var1", "var1", "var2", "obj", "subarr"]); + expect(string).toBe('{"var1":"foo","var2":42,"obj":{"subarr":[3]}}'); }); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js index a1401560cf..251f033d69 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js @@ -1,17 +1,20 @@ test("basic functionality", () => { - let o = { - foo: 1, - bar: "baz", - qux: { - get x() { return 10; }, - y() { return 20; }, - arr: [1, 2, 3], - } - }; + let o = { + foo: 1, + bar: "baz", + qux: { + get x() { + return 10; + }, + y() { + return 20; + }, + arr: [1, 2, 3], + }, + }; - let string = JSON.stringify(o, null, 4); - let expected = -`{ + let string = JSON.stringify(o, null, 4); + let expected = `{ "foo": 1, "bar": "baz", "qux": { @@ -24,11 +27,10 @@ test("basic functionality", () => { } }`; - expect(string).toBe(expected); + expect(string).toBe(expected); - string = JSON.stringify(o, null, "abcd"); - expected = -`{ + string = JSON.stringify(o, null, "abcd"); + expected = `{ abcd"foo": 1, abcd"bar": "baz", abcd"qux": { @@ -41,5 +43,5 @@ abcdabcd] abcd} }`; - expect(string).toBe(expected); + expect(string).toBe(expected); }); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js index 7b9925b0e3..912053b94c 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js @@ -1,71 +1,71 @@ describe("correct behavior", () => { - test("length", () => { - expect(JSON.stringify).toHaveLength(3); - }); + test("length", () => { + expect(JSON.stringify).toHaveLength(3); + }); - test("basic functionality", () => { - [ - [5, "5"], - [undefined, undefined], - [null, "null"], - [NaN, "null"], - [-NaN, "null"], - [Infinity, "null"], - [-Infinity, "null"], - [true, "true"], - [false, "false"], - ["test", '"test"'], - [new Number(5), "5"], - [new Boolean(false), "false"], - [new String("test"), '"test"'], - [() => {}, undefined], - [[1, 2, "foo"], '[1,2,"foo"]'], - [{ foo: 1, bar: "baz", qux() {} }, '{"foo":1,"bar":"baz"}'], - [ - { - var1: 1, - var2: 2, - toJSON(key) { - let o = this; - o.var2 = 10; - return o; - } - }, - '{"var1":1,"var2":10}', - ], - ].forEach(testCase => { - expect(JSON.stringify(testCase[0])).toEqual(testCase[1]); - }); + test("basic functionality", () => { + [ + [5, "5"], + [undefined, undefined], + [null, "null"], + [NaN, "null"], + [-NaN, "null"], + [Infinity, "null"], + [-Infinity, "null"], + [true, "true"], + [false, "false"], + ["test", '"test"'], + [new Number(5), "5"], + [new Boolean(false), "false"], + [new String("test"), '"test"'], + [() => {}, undefined], + [[1, 2, "foo"], '[1,2,"foo"]'], + [{ foo: 1, bar: "baz", qux() {} }, '{"foo":1,"bar":"baz"}'], + [ + { + var1: 1, + var2: 2, + toJSON(key) { + let o = this; + o.var2 = 10; + return o; + }, + }, + '{"var1":1,"var2":10}', + ], + ].forEach(testCase => { + expect(JSON.stringify(testCase[0])).toEqual(testCase[1]); }); + }); - test("ignores non-enumerable properties", () => { - let o = { foo: "bar" }; - Object.defineProperty(o, "baz", { value: "qux", enumerable: false }); - expect(JSON.stringify(o)).toBe('{"foo":"bar"}'); - }); + test("ignores non-enumerable properties", () => { + let o = { foo: "bar" }; + Object.defineProperty(o, "baz", { value: "qux", enumerable: false }); + expect(JSON.stringify(o)).toBe('{"foo":"bar"}'); + }); }); describe("errors", () => { - test("cannot serialize BigInt", () => { - expect(() => { - JSON.stringify(5n); - }).toThrow(TypeError, "Cannot serialize BigInt value to JSON"); - }); - - test("cannot serialize circular structures", () => { - let bad1 = {}; - bad1.foo = bad1; - let bad2 = []; - bad2[5] = [[[bad2]]]; - - let bad3a = { foo: "bar" }; - let bad3b = [1, 2, bad3a]; - bad3a.bad = bad3b; - - [bad1, bad2, bad3a].forEach(bad => { - expect(() => { - JSON.stringify(bad); - }).toThrow(TypeError, "Cannot stringify circular object"); - }); + test("cannot serialize BigInt", () => { + expect(() => { + JSON.stringify(5n); + }).toThrow(TypeError, "Cannot serialize BigInt value to JSON"); + }); + + test("cannot serialize circular structures", () => { + let bad1 = {}; + bad1.foo = bad1; + let bad2 = []; + bad2[5] = [[[bad2]]]; + + let bad3a = { foo: "bar" }; + let bad3b = [1, 2, bad3a]; + bad3a.bad = bad3b; + + [bad1, bad2, bad3a].forEach(bad => { + expect(() => { + JSON.stringify(bad); + }).toThrow(TypeError, "Cannot stringify circular object"); }); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math-constants.js b/Libraries/LibJS/Tests/builtins/Math/Math-constants.js index f8c75c269b..c58b901c67 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math-constants.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math-constants.js @@ -1,10 +1,10 @@ test("basic functionality", () => { - expect(Math.E).toBeCloseTo(2.718281); - expect(Math.LN2).toBeCloseTo(0.693147); - expect(Math.LN10).toBeCloseTo(2.302585); - expect(Math.LOG2E).toBeCloseTo(1.442695); - expect(Math.LOG10E).toBeCloseTo(0.434294); - expect(Math.PI).toBeCloseTo(3.1415926); - expect(Math.SQRT1_2).toBeCloseTo(0.707106); - expect(Math.SQRT2).toBeCloseTo(1.414213); + expect(Math.E).toBeCloseTo(2.718281); + expect(Math.LN2).toBeCloseTo(0.693147); + expect(Math.LN10).toBeCloseTo(2.302585); + expect(Math.LOG2E).toBeCloseTo(1.442695); + expect(Math.LOG10E).toBeCloseTo(0.434294); + expect(Math.PI).toBeCloseTo(3.1415926); + expect(Math.SQRT1_2).toBeCloseTo(0.707106); + expect(Math.SQRT2).toBeCloseTo(1.414213); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.abs.js b/Libraries/LibJS/Tests/builtins/Math/Math.abs.js index e051337c2c..1bf4b526b4 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.abs.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.abs.js @@ -1,14 +1,14 @@ test("basic functionality", () => { - expect(Math.abs).toHaveLength(1); + expect(Math.abs).toHaveLength(1); - expect(Math.abs('-1')).toBe(1); - expect(Math.abs(-2)).toBe(2); - expect(Math.abs(null)).toBe(0); - expect(Math.abs('')).toBe(0); - expect(Math.abs([])).toBe(0); - expect(Math.abs([2])).toBe(2); - expect(Math.abs([1, 2])).toBeNaN(); - expect(Math.abs({})).toBeNaN(); - expect(Math.abs('string')).toBeNaN(); - expect(Math.abs()).toBeNaN(); + expect(Math.abs("-1")).toBe(1); + expect(Math.abs(-2)).toBe(2); + expect(Math.abs(null)).toBe(0); + expect(Math.abs("")).toBe(0); + expect(Math.abs([])).toBe(0); + expect(Math.abs([2])).toBe(2); + expect(Math.abs([1, 2])).toBeNaN(); + expect(Math.abs({})).toBeNaN(); + expect(Math.abs("string")).toBeNaN(); + expect(Math.abs()).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js b/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js index e7705e1e2e..9e91b15eff 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js @@ -1,9 +1,9 @@ test("basic functionality", () => { - expect(Math.acosh).toHaveLength(1); + expect(Math.acosh).toHaveLength(1); - expect(Math.acosh(-1)).toBeNaN(); - expect(Math.acosh(0)).toBeNaN(); - expect(Math.acosh(0.5)).toBeNaN(); - expect(Math.acosh(1)).toBeCloseTo(0); - // FIXME: expect(Math.acosh(2)).toBeCloseTo(1.316957); + expect(Math.acosh(-1)).toBeNaN(); + expect(Math.acosh(0)).toBeNaN(); + expect(Math.acosh(0.5)).toBeNaN(); + expect(Math.acosh(1)).toBeCloseTo(0); + // FIXME: expect(Math.acosh(2)).toBeCloseTo(1.316957); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js b/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js index 84502b9420..13d9bc8ccc 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js @@ -1,6 +1,6 @@ test("basic functionality", () => { - expect(Math.asinh).toHaveLength(1); + expect(Math.asinh).toHaveLength(1); - expect(Math.asinh(0)).toBeCloseTo(0); - // FIXME: expect(Math.asinh(1)).toBeCloseTo(0.881373); + expect(Math.asinh(0)).toBeCloseTo(0); + // FIXME: expect(Math.asinh(1)).toBeCloseTo(0.881373); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js b/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js index 1403f207cf..a9bf482708 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js @@ -1,10 +1,10 @@ test("basic functionality", () => { - expect(Math.atanh).toHaveLength(1); + expect(Math.atanh).toHaveLength(1); - expect(Math.atanh(-2)).toBeNaN(); - expect(Math.atanh(2)).toBeNaN(); - expect(Math.atanh(-1)).toBe(-Infinity); - // FIXME: expect(Math.atanh(0)).toBe(0); - expect(Math.atanh(0.5)).toBeCloseTo(0.549306); - // FIXME: expect(Math.atanh(1)).toBe(Infinity); + expect(Math.atanh(-2)).toBeNaN(); + expect(Math.atanh(2)).toBeNaN(); + expect(Math.atanh(-1)).toBe(-Infinity); + // FIXME: expect(Math.atanh(0)).toBe(0); + expect(Math.atanh(0.5)).toBeCloseTo(0.549306); + // FIXME: expect(Math.atanh(1)).toBe(Infinity); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.cbrt.js b/Libraries/LibJS/Tests/builtins/Math/Math.cbrt.js index a77ed22322..75eb0b71d6 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.cbrt.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.cbrt.js @@ -1,12 +1,12 @@ test("basic functionality", () => { - expect(Math.cbrt).toHaveLength(1); + expect(Math.cbrt).toHaveLength(1); - expect(Math.cbrt(NaN)).toBeNaN(); - // FIXME: expect(Math.cbrt(-1)).toBe(-1); - expect(Math.cbrt(-0)).toBe(-0); - // FIXME: expect(Math.cbrt(-Infinity)).toBe(-Infinity); - // FIXME: expect(Math.cbrt(1)).toBe(1); - // FIXME: expect(Math.cbrt(Infinity)).toBe(Infinity); - expect(Math.cbrt(null)).toBe(0); - // FIXME: expect(Math.cbrt(2)).toBeCloseTo(1.259921)); + expect(Math.cbrt(NaN)).toBeNaN(); + // FIXME: expect(Math.cbrt(-1)).toBe(-1); + expect(Math.cbrt(-0)).toBe(-0); + // FIXME: expect(Math.cbrt(-Infinity)).toBe(-Infinity); + // FIXME: expect(Math.cbrt(1)).toBe(1); + // FIXME: expect(Math.cbrt(Infinity)).toBe(Infinity); + expect(Math.cbrt(null)).toBe(0); + // FIXME: expect(Math.cbrt(2)).toBeCloseTo(1.259921)); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.ceil.js b/Libraries/LibJS/Tests/builtins/Math/Math.ceil.js index 8d6208f40c..9a49226513 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.ceil.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.ceil.js @@ -1,13 +1,13 @@ test("basic functionality", () => { - expect(Math.ceil).toHaveLength(1); + expect(Math.ceil).toHaveLength(1); - expect(Math.ceil(0.95)).toBe(1); - expect(Math.ceil(4)).toBe(4); - expect(Math.ceil(7.004)).toBe(8); - expect(Math.ceil(-0.95)).toBe(-0); - expect(Math.ceil(-4) ).toBe(-4); - expect(Math.ceil(-7.004)).toBe(-7); + expect(Math.ceil(0.95)).toBe(1); + expect(Math.ceil(4)).toBe(4); + expect(Math.ceil(7.004)).toBe(8); + expect(Math.ceil(-0.95)).toBe(-0); + expect(Math.ceil(-4)).toBe(-4); + expect(Math.ceil(-7.004)).toBe(-7); - expect(Math.ceil()).toBeNaN(); - expect(Math.ceil(NaN)).toBeNaN(); + expect(Math.ceil()).toBeNaN(); + expect(Math.ceil(NaN)).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.clz32.js b/Libraries/LibJS/Tests/builtins/Math/Math.clz32.js index e80f9f023e..f39e8736e4 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.clz32.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.clz32.js @@ -1,44 +1,44 @@ test("basic functionality", () => { - expect(Math.clz32).toHaveLength(1); + expect(Math.clz32).toHaveLength(1); - expect(Math.clz32(0)).toBe(32); - expect(Math.clz32(1)).toBe(31); - expect(Math.clz32(2)).toBe(30); - expect(Math.clz32(3)).toBe(30); - expect(Math.clz32(4)).toBe(29); - expect(Math.clz32(5)).toBe(29); - expect(Math.clz32(-1)).toBe(0); - expect(Math.clz32(-10)).toBe(0); - expect(Math.clz32(-100)).toBe(0); - expect(Math.clz32(-1000)).toBe(0); - expect(Math.clz32(-0.123)).toBe(32); - expect(Math.clz32(0.123)).toBe(32); - expect(Math.clz32(1.23)).toBe(31); - expect(Math.clz32(12)).toBe(28); - expect(Math.clz32(123)).toBe(25); - expect(Math.clz32(1234)).toBe(21); - expect(Math.clz32(12345)).toBe(18); - expect(Math.clz32(123456)).toBe(15); - expect(Math.clz32(1234567)).toBe(11); - expect(Math.clz32(12345678)).toBe(8); - expect(Math.clz32(123456789)).toBe(5); - expect(Math.clz32(999999999)).toBe(2); - expect(Math.clz32(9999999999)).toBe(1); - expect(Math.clz32(99999999999)).toBe(1); - expect(Math.clz32(999999999999)).toBe(0); - expect(Math.clz32(9999999999999)).toBe(1); - expect(Math.clz32(99999999999999)).toBe(3); - expect(Math.clz32(999999999999999)).toBe(0); + expect(Math.clz32(0)).toBe(32); + expect(Math.clz32(1)).toBe(31); + expect(Math.clz32(2)).toBe(30); + expect(Math.clz32(3)).toBe(30); + expect(Math.clz32(4)).toBe(29); + expect(Math.clz32(5)).toBe(29); + expect(Math.clz32(-1)).toBe(0); + expect(Math.clz32(-10)).toBe(0); + expect(Math.clz32(-100)).toBe(0); + expect(Math.clz32(-1000)).toBe(0); + expect(Math.clz32(-0.123)).toBe(32); + expect(Math.clz32(0.123)).toBe(32); + expect(Math.clz32(1.23)).toBe(31); + expect(Math.clz32(12)).toBe(28); + expect(Math.clz32(123)).toBe(25); + expect(Math.clz32(1234)).toBe(21); + expect(Math.clz32(12345)).toBe(18); + expect(Math.clz32(123456)).toBe(15); + expect(Math.clz32(1234567)).toBe(11); + expect(Math.clz32(12345678)).toBe(8); + expect(Math.clz32(123456789)).toBe(5); + expect(Math.clz32(999999999)).toBe(2); + expect(Math.clz32(9999999999)).toBe(1); + expect(Math.clz32(99999999999)).toBe(1); + expect(Math.clz32(999999999999)).toBe(0); + expect(Math.clz32(9999999999999)).toBe(1); + expect(Math.clz32(99999999999999)).toBe(3); + expect(Math.clz32(999999999999999)).toBe(0); - expect(Math.clz32()).toBe(32); - expect(Math.clz32(NaN)).toBe(32); - expect(Math.clz32(Infinity)).toBe(32); - expect(Math.clz32(-Infinity)).toBe(32); - expect(Math.clz32(false)).toBe(32); - expect(Math.clz32(true)).toBe(31); - expect(Math.clz32(null)).toBe(32); - expect(Math.clz32(undefined)).toBe(32); - expect(Math.clz32([])).toBe(32); - expect(Math.clz32({})).toBe(32); - expect(Math.clz32("foo")).toBe(32); + expect(Math.clz32()).toBe(32); + expect(Math.clz32(NaN)).toBe(32); + expect(Math.clz32(Infinity)).toBe(32); + expect(Math.clz32(-Infinity)).toBe(32); + expect(Math.clz32(false)).toBe(32); + expect(Math.clz32(true)).toBe(31); + expect(Math.clz32(null)).toBe(32); + expect(Math.clz32(undefined)).toBe(32); + expect(Math.clz32([])).toBe(32); + expect(Math.clz32({})).toBe(32); + expect(Math.clz32("foo")).toBe(32); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.cos.js b/Libraries/LibJS/Tests/builtins/Math/Math.cos.js index 020a438498..39b04d25f6 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.cos.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.cos.js @@ -1,14 +1,14 @@ test("basic functionality", () => { - expect(Math.cos).toHaveLength(1); + expect(Math.cos).toHaveLength(1); - expect(Math.cos(0)).toBe(1); - expect(Math.cos(null)).toBe(1); - expect(Math.cos('')).toBe(1); - expect(Math.cos([])).toBe(1); - expect(Math.cos(Math.PI)).toBe(-1); - expect(Math.cos()).toBeNaN(); - expect(Math.cos(undefined)).toBeNaN(); - expect(Math.cos([1, 2, 3])).toBeNaN(); - expect(Math.cos({})).toBeNaN(); - expect(Math.cos("foo")).toBeNaN(); + expect(Math.cos(0)).toBe(1); + expect(Math.cos(null)).toBe(1); + expect(Math.cos("")).toBe(1); + expect(Math.cos([])).toBe(1); + expect(Math.cos(Math.PI)).toBe(-1); + expect(Math.cos()).toBeNaN(); + expect(Math.cos(undefined)).toBeNaN(); + expect(Math.cos([1, 2, 3])).toBeNaN(); + expect(Math.cos({})).toBeNaN(); + expect(Math.cos("foo")).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.exp.js b/Libraries/LibJS/Tests/builtins/Math/Math.exp.js index d7111be916..ac35ccec53 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.exp.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.exp.js @@ -1,13 +1,13 @@ test("basic functionality", () => { - expect(Math.exp).toHaveLength(1); + expect(Math.exp).toHaveLength(1); - expect(Math.exp(0)).toBe(1); - expect(Math.exp(-2)).toBeCloseTo(0.135335); - expect(Math.exp(-1)).toBeCloseTo(0.367879); - expect(Math.exp(1)).toBeCloseTo(2.718281); - expect(Math.exp(2)).toBeCloseTo(7.389056); + expect(Math.exp(0)).toBe(1); + expect(Math.exp(-2)).toBeCloseTo(0.135335); + expect(Math.exp(-1)).toBeCloseTo(0.367879); + expect(Math.exp(1)).toBeCloseTo(2.718281); + expect(Math.exp(2)).toBeCloseTo(7.389056); - expect(Math.exp()).toBeNaN(); - expect(Math.exp(undefined)).toBeNaN(); - expect(Math.exp("foo")).toBeNaN(); + expect(Math.exp()).toBeNaN(); + expect(Math.exp(undefined)).toBeNaN(); + expect(Math.exp("foo")).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.expm1.js b/Libraries/LibJS/Tests/builtins/Math/Math.expm1.js index 4d7c31b922..6efde6278a 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.expm1.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.expm1.js @@ -1,13 +1,13 @@ test("basic functionality", () => { - expect(Math.expm1).toHaveLength(1); + expect(Math.expm1).toHaveLength(1); - expect(Math.expm1(0)).toBe(0); - expect(Math.expm1(-2)).toBeCloseTo(-0.864664); - expect(Math.expm1(-1)).toBeCloseTo(-0.632120); - expect(Math.expm1(1)).toBeCloseTo(1.718281); - expect(Math.expm1(2)).toBeCloseTo(6.389056); + expect(Math.expm1(0)).toBe(0); + expect(Math.expm1(-2)).toBeCloseTo(-0.864664); + expect(Math.expm1(-1)).toBeCloseTo(-0.63212); + expect(Math.expm1(1)).toBeCloseTo(1.718281); + expect(Math.expm1(2)).toBeCloseTo(6.389056); - expect(Math.expm1()).toBeNaN(); - expect(Math.expm1(undefined)).toBeNaN(); - expect(Math.expm1("foo")).toBeNaN(); + expect(Math.expm1()).toBeNaN(); + expect(Math.expm1(undefined)).toBeNaN(); + expect(Math.expm1("foo")).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.floor.js b/Libraries/LibJS/Tests/builtins/Math/Math.floor.js index f1420fe202..5f95ea559f 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.floor.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.floor.js @@ -1,13 +1,13 @@ test("basic functionality", () => { - expect(Math.floor).toHaveLength(1); + expect(Math.floor).toHaveLength(1); - expect(Math.floor(0.95)).toBe(0); - expect(Math.floor(4)).toBe(4); - expect(Math.floor(7.004)).toBe(7); - expect(Math.floor(-0.95)).toBe(-1); - expect(Math.floor(-4)).toBe(-4); - expect(Math.floor(-7.004)).toBe(-8); + expect(Math.floor(0.95)).toBe(0); + expect(Math.floor(4)).toBe(4); + expect(Math.floor(7.004)).toBe(7); + expect(Math.floor(-0.95)).toBe(-1); + expect(Math.floor(-4)).toBe(-4); + expect(Math.floor(-7.004)).toBe(-8); - expect(Math.floor()).toBeNaN(); - expect(Math.floor(NaN)).toBeNaN(); + expect(Math.floor()).toBeNaN(); + expect(Math.floor(NaN)).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js b/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js index 6b15c29b31..908cd7ccff 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js @@ -1,8 +1,8 @@ test("basic functionality", () => { - expect(Math.log1p).toHaveLength(1); + expect(Math.log1p).toHaveLength(1); - expect(Math.log1p(-2)).toBeNaN(); - expect(Math.log1p(-1)).toBe(-Infinity); - // FIXME: expect(Math.log1p(0)).toBe(0); - // FIXME: expect(Math.log1p(1)).toBeCloseTo(0.693147); + expect(Math.log1p(-2)).toBeNaN(); + expect(Math.log1p(-1)).toBe(-Infinity); + // FIXME: expect(Math.log1p(0)).toBe(0); + // FIXME: expect(Math.log1p(1)).toBeCloseTo(0.693147); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.max.js b/Libraries/LibJS/Tests/builtins/Math/Math.max.js index f99a39cc9c..5632e4490e 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.max.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.max.js @@ -1,10 +1,10 @@ test("basic functionality", () => { - expect(Math.max).toHaveLength(2); + expect(Math.max).toHaveLength(2); - expect(Math.max()).toBe(-Infinity); - expect(Math.max(1)).toBe(1); - expect(Math.max(2, 1)).toBe(2); - expect(Math.max(1, 2, 3)).toBe(3); - expect(Math.max(NaN)).toBeNaN(); - expect(Math.max("String", 1)).toBeNaN(); + expect(Math.max()).toBe(-Infinity); + expect(Math.max(1)).toBe(1); + expect(Math.max(2, 1)).toBe(2); + expect(Math.max(1, 2, 3)).toBe(3); + expect(Math.max(NaN)).toBeNaN(); + expect(Math.max("String", 1)).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.min.js b/Libraries/LibJS/Tests/builtins/Math/Math.min.js index fedfcabe27..320728f636 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.min.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.min.js @@ -1,9 +1,9 @@ test("basic functionality", () => { - expect(Math.min).toHaveLength(2); + expect(Math.min).toHaveLength(2); - expect(Math.min(1)).toBe(1); - expect(Math.min(2, 1)).toBe(1); - expect(Math.min(1, 2, 3)).toBe(1); - expect(Math.min(NaN)).toBeNaN(); - expect(Math.min("String", 1)).toBeNaN(); + expect(Math.min(1)).toBe(1); + expect(Math.min(2, 1)).toBe(1); + expect(Math.min(1, 2, 3)).toBe(1); + expect(Math.min(NaN)).toBeNaN(); + expect(Math.min("String", 1)).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.pow.js b/Libraries/LibJS/Tests/builtins/Math/Math.pow.js index 036060b238..124e48e055 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.pow.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.pow.js @@ -1,25 +1,25 @@ test("basic functionality", () => { - expect(Math.pow).toHaveLength(2); + expect(Math.pow).toHaveLength(2); - expect(Math.pow(2, 0)).toBe(1); - expect(Math.pow(2, 1)).toBe(2); - expect(Math.pow(2, 2)).toBe(4); - expect(Math.pow(2, 3)).toBe(8); - expect(Math.pow(2, -3)).toBe(0.125); - expect(Math.pow(3, 2)).toBe(9); - expect(Math.pow(0, 0)).toBe(1); - expect(Math.pow(2, Math.pow(3, 2))).toBe(512); - expect(Math.pow(Math.pow(2, 3), 2)).toBe(64); - expect(Math.pow("2", "3")).toBe(8); - expect(Math.pow("", [])).toBe(1); - expect(Math.pow([], null)).toBe(1); - expect(Math.pow(null, null)).toBe(1); - expect(Math.pow(undefined, null)).toBe(1); - expect(Math.pow(NaN, 2)).toBeNaN(); - expect(Math.pow(2, NaN)).toBeNaN(); - expect(Math.pow(undefined, 2)).toBeNaN(); - expect(Math.pow(2, undefined)).toBeNaN(); - expect(Math.pow(null, undefined)).toBeNaN(); - expect(Math.pow(2, "foo")).toBeNaN(); - expect(Math.pow("foo", 2)).toBeNaN(); + expect(Math.pow(2, 0)).toBe(1); + expect(Math.pow(2, 1)).toBe(2); + expect(Math.pow(2, 2)).toBe(4); + expect(Math.pow(2, 3)).toBe(8); + expect(Math.pow(2, -3)).toBe(0.125); + expect(Math.pow(3, 2)).toBe(9); + expect(Math.pow(0, 0)).toBe(1); + expect(Math.pow(2, Math.pow(3, 2))).toBe(512); + expect(Math.pow(Math.pow(2, 3), 2)).toBe(64); + expect(Math.pow("2", "3")).toBe(8); + expect(Math.pow("", [])).toBe(1); + expect(Math.pow([], null)).toBe(1); + expect(Math.pow(null, null)).toBe(1); + expect(Math.pow(undefined, null)).toBe(1); + expect(Math.pow(NaN, 2)).toBeNaN(); + expect(Math.pow(2, NaN)).toBeNaN(); + expect(Math.pow(undefined, 2)).toBeNaN(); + expect(Math.pow(2, undefined)).toBeNaN(); + expect(Math.pow(null, undefined)).toBeNaN(); + expect(Math.pow(2, "foo")).toBeNaN(); + expect(Math.pow("foo", 2)).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sign.js b/Libraries/LibJS/Tests/builtins/Math/Math.sign.js index 1a62b7fc9f..b7e3d9f892 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.sign.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.sign.js @@ -1,38 +1,36 @@ function isPositiveZero(value) { - return value === 0 && 1 / value === Infinity; + return value === 0 && 1 / value === Infinity; } function isNegativeZero(value) { - return value === 0 && 1 / value === -Infinity; + return value === 0 && 1 / value === -Infinity; } test("basic functionality", () => { - expect(Math.sign).toHaveLength(1); + expect(Math.sign).toHaveLength(1); - expect(Math.sign.length).toBe(1); + expect(Math.sign(0.0001)).toBe(1); + expect(Math.sign(1)).toBe(1); + expect(Math.sign(42)).toBe(1); + expect(Math.sign(Infinity)).toBe(1); + expect(isPositiveZero(Math.sign(0))).toBeTrue(); + expect(isPositiveZero(Math.sign(null))).toBeTrue(); + expect(isPositiveZero(Math.sign(""))).toBeTrue(); + expect(isPositiveZero(Math.sign([]))).toBeTrue(); - expect(Math.sign(0.0001)).toBe(1); - expect(Math.sign(1)).toBe(1); - expect(Math.sign(42)).toBe(1); - expect(Math.sign(Infinity)).toBe(1); - expect(isPositiveZero(Math.sign(0))).toBeTrue(); - expect(isPositiveZero(Math.sign(null))).toBeTrue(); - expect(isPositiveZero(Math.sign(''))).toBeTrue(); - expect(isPositiveZero(Math.sign([]))).toBeTrue(); + expect(Math.sign(-0.0001)).toBe(-1); + expect(Math.sign(-1)).toBe(-1); + expect(Math.sign(-42)).toBe(-1); + expect(Math.sign(-Infinity)).toBe(-1); + expect(isNegativeZero(Math.sign(-0))).toBeTrue(); + expect(isNegativeZero(Math.sign(-null))).toBeTrue(); + expect(isNegativeZero(Math.sign(-""))).toBeTrue(); + expect(isNegativeZero(Math.sign(-[]))).toBeTrue(); - expect(Math.sign(-0.0001)).toBe(-1); - expect(Math.sign(-1)).toBe(-1); - expect(Math.sign(-42)).toBe(-1); - expect(Math.sign(-Infinity)).toBe(-1); - expect(isNegativeZero(Math.sign(-0))).toBeTrue(); - expect(isNegativeZero(Math.sign(-null))).toBeTrue(); - expect(isNegativeZero(Math.sign(-''))).toBeTrue(); - expect(isNegativeZero(Math.sign(-[]))).toBeTrue(); - - expect(Math.sign()).toBeNaN(); - expect(Math.sign(undefined)).toBeNaN(); - expect(Math.sign([1, 2, 3])).toBeNaN(); - expect(Math.sign({})).toBeNaN(); - expect(Math.sign(NaN)).toBeNaN(); - expect(Math.sign("foo")).toBeNaN(); + expect(Math.sign()).toBeNaN(); + expect(Math.sign(undefined)).toBeNaN(); + expect(Math.sign([1, 2, 3])).toBeNaN(); + expect(Math.sign({})).toBeNaN(); + expect(Math.sign(NaN)).toBeNaN(); + expect(Math.sign("foo")).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sin.js b/Libraries/LibJS/Tests/builtins/Math/Math.sin.js index cc590592b5..6f179f0e1b 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.sin.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.sin.js @@ -1,15 +1,15 @@ test("basic functionality", () => { - expect(Math.sin).toHaveLength(1); + expect(Math.sin).toHaveLength(1); - expect(Math.sin(0)).toBe(0); - expect(Math.sin(null)).toBe(0); - expect(Math.sin('')).toBe(0); - expect(Math.sin([])).toBe(0); - expect(Math.sin(Math.PI * 3 / 2)).toBe(-1); - expect(Math.sin(Math.PI / 2)).toBe(1); - expect(Math.sin()).toBeNaN(); - expect(Math.sin(undefined)).toBeNaN(); - expect(Math.sin([1, 2, 3])).toBeNaN(); - expect(Math.sin({})).toBeNaN(); - expect(Math.sin("foo")).toBeNaN(); + expect(Math.sin(0)).toBe(0); + expect(Math.sin(null)).toBe(0); + expect(Math.sin("")).toBe(0); + expect(Math.sin([])).toBe(0); + expect(Math.sin((Math.PI * 3) / 2)).toBe(-1); + expect(Math.sin(Math.PI / 2)).toBe(1); + expect(Math.sin()).toBeNaN(); + expect(Math.sin(undefined)).toBeNaN(); + expect(Math.sin([1, 2, 3])).toBeNaN(); + expect(Math.sin({})).toBeNaN(); + expect(Math.sin("foo")).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js b/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js index 1e7b2115e0..3e218992f0 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js @@ -1,4 +1,4 @@ test("basic functionality", () => { - expect(Math.sqrt).toHaveLength(1); - expect(Math.sqrt(9)).toBe(3); + expect(Math.sqrt).toHaveLength(1); + expect(Math.sqrt(9)).toBe(3); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.tan.js b/Libraries/LibJS/Tests/builtins/Math/Math.tan.js index d74a103178..5eb0906349 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.tan.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.tan.js @@ -1,14 +1,14 @@ test("basic functionality", () => { - expect(Math.tan).toHaveLength(1); + expect(Math.tan).toHaveLength(1); - expect(Math.tan(0)).toBe(0); - expect(Math.tan(null)).toBe(0); - expect(Math.tan('')).toBe(0); - expect(Math.tan([])).toBe(0); - expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1); - expect(Math.tan()).toBeNaN(); - expect(Math.tan(undefined)).toBeNaN(); - expect(Math.tan([1, 2, 3])).toBeNaN(); - expect(Math.tan({})).toBeNaN(); - expect(Math.tan("foo")).toBeNaN(); + expect(Math.tan(0)).toBe(0); + expect(Math.tan(null)).toBe(0); + expect(Math.tan("")).toBe(0); + expect(Math.tan([])).toBe(0); + expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1); + expect(Math.tan()).toBeNaN(); + expect(Math.tan(undefined)).toBeNaN(); + expect(Math.tan([1, 2, 3])).toBeNaN(); + expect(Math.tan({})).toBeNaN(); + expect(Math.tan("foo")).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js b/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js index b3e4eafaeb..3fd2530673 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js @@ -1,12 +1,12 @@ test("basic functionality", () => { - expect(Math.trunc).toHaveLength(1); + expect(Math.trunc).toHaveLength(1); - expect(Math.trunc(13.37)).toBe(13); - expect(Math.trunc(42.84)).toBe(42); - expect(Math.trunc(0.123)).toBe( 0); - expect(Math.trunc(-0.123)).toBe(-0); + expect(Math.trunc(13.37)).toBe(13); + expect(Math.trunc(42.84)).toBe(42); + expect(Math.trunc(0.123)).toBe(0); + expect(Math.trunc(-0.123)).toBe(-0); - expect(Math.trunc(NaN)).toBeNaN(); - expect(Math.trunc('foo')).toBeNaN(); - expect(Math.trunc()).toBeNaN(); + expect(Math.trunc(NaN)).toBeNaN(); + expect(Math.trunc("foo")).toBeNaN(); + expect(Math.trunc()).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/NaN/NaN.js b/Libraries/LibJS/Tests/builtins/NaN/NaN.js index 9c496238b9..1372eb5135 100644 --- a/Libraries/LibJS/Tests/builtins/NaN/NaN.js +++ b/Libraries/LibJS/Tests/builtins/NaN/NaN.js @@ -1,13 +1,13 @@ test("basic functionality", () => { - const nan = undefined + 1; + const nan = undefined + 1; - expect(nan + "").toBe("NaN"); - expect(NaN + "").toBe("NaN"); - expect(nan !== nan).toBeTrue(); - expect(NaN !== NaN).toBeTrue(); - expect(nan).toBeNaN(); - expect(NaN).toBeNaN(); - expect(0).not.toBeNaN(); - expect(!!nan).toBeFalse(); - expect(!!NaN).toBeFalse(); + expect(nan + "").toBe("NaN"); + expect(NaN + "").toBe("NaN"); + expect(nan !== nan).toBeTrue(); + expect(NaN !== NaN).toBeTrue(); + expect(nan).toBeNaN(); + expect(NaN).toBeNaN(); + expect(0).not.toBeNaN(); + expect(!!nan).toBeFalse(); + expect(!!NaN).toBeFalse(); }); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number-constants.js b/Libraries/LibJS/Tests/builtins/Number/Number-constants.js index 2958821546..586469e046 100644 --- a/Libraries/LibJS/Tests/builtins/Number/Number-constants.js +++ b/Libraries/LibJS/Tests/builtins/Number/Number-constants.js @@ -1,11 +1,11 @@ test("basic functionality", () => { - expect(Number.EPSILON).toBe(2 ** -52); - expect(Number.EPSILON).toBeGreaterThan(0); - expect(Number.MAX_SAFE_INTEGER).toBe(2 ** 53 - 1); - expect(Number.MAX_SAFE_INTEGER + 1).toBe(Number.MAX_SAFE_INTEGER + 2); - expect(Number.MIN_SAFE_INTEGER).toBe(-(2 ** 53 - 1)); - expect(Number.MIN_SAFE_INTEGER - 1).toBe(Number.MIN_SAFE_INTEGER - 2); - expect(Number.POSITIVE_INFINITY).toBe(Infinity); - expect(Number.NEGATIVE_INFINITY).toBe(-Infinity); - expect(Number.NaN).toBeNaN(); + expect(Number.EPSILON).toBe(2 ** -52); + expect(Number.EPSILON).toBeGreaterThan(0); + expect(Number.MAX_SAFE_INTEGER).toBe(2 ** 53 - 1); + expect(Number.MAX_SAFE_INTEGER + 1).toBe(Number.MAX_SAFE_INTEGER + 2); + expect(Number.MIN_SAFE_INTEGER).toBe(-(2 ** 53 - 1)); + expect(Number.MIN_SAFE_INTEGER - 1).toBe(Number.MIN_SAFE_INTEGER - 2); + expect(Number.POSITIVE_INFINITY).toBe(Infinity); + expect(Number.NEGATIVE_INFINITY).toBe(-Infinity); + expect(Number.NaN).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js b/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js index 19a23c0292..d9ecfc4638 100644 --- a/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js +++ b/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js @@ -1,24 +1,24 @@ test("basic functionality", () => { - expect(Number.isFinite).toHaveLength(1); - expect(Number.isFinite).not.toBe(isFinite); + expect(Number.isFinite).toHaveLength(1); + expect(Number.isFinite).not.toBe(isFinite); - expect(Number.isFinite(0)).toBeTrue(); - expect(Number.isFinite(1.23)).toBeTrue(); - expect(Number.isFinite(42)).toBeTrue(); + expect(Number.isFinite(0)).toBeTrue(); + expect(Number.isFinite(1.23)).toBeTrue(); + expect(Number.isFinite(42)).toBeTrue(); - expect(Number.isFinite("")).toBeFalse(); - expect(Number.isFinite("0")).toBeFalse(); - expect(Number.isFinite("42")).toBeFalse(); - expect(Number.isFinite(true)).toBeFalse(); - expect(Number.isFinite(false)).toBeFalse(); - expect(Number.isFinite(null)).toBeFalse(); - expect(Number.isFinite([])).toBeFalse(); - expect(Number.isFinite()).toBeFalse(); - expect(Number.isFinite(NaN)).toBeFalse(); - expect(Number.isFinite(undefined)).toBeFalse(); - expect(Number.isFinite(Infinity)).toBeFalse(); - expect(Number.isFinite(-Infinity)).toBeFalse(); - expect(Number.isFinite("foo")).toBeFalse(); - expect(Number.isFinite({})).toBeFalse(); - expect(Number.isFinite([1, 2, 3])).toBeFalse(); + expect(Number.isFinite("")).toBeFalse(); + expect(Number.isFinite("0")).toBeFalse(); + expect(Number.isFinite("42")).toBeFalse(); + expect(Number.isFinite(true)).toBeFalse(); + expect(Number.isFinite(false)).toBeFalse(); + expect(Number.isFinite(null)).toBeFalse(); + expect(Number.isFinite([])).toBeFalse(); + expect(Number.isFinite()).toBeFalse(); + expect(Number.isFinite(NaN)).toBeFalse(); + expect(Number.isFinite(undefined)).toBeFalse(); + expect(Number.isFinite(Infinity)).toBeFalse(); + expect(Number.isFinite(-Infinity)).toBeFalse(); + expect(Number.isFinite("foo")).toBeFalse(); + expect(Number.isFinite({})).toBeFalse(); + expect(Number.isFinite([1, 2, 3])).toBeFalse(); }); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.isInteger.js b/Libraries/LibJS/Tests/builtins/Number/Number.isInteger.js index 54eafdfc6f..a586a4ab5f 100644 --- a/Libraries/LibJS/Tests/builtins/Number/Number.isInteger.js +++ b/Libraries/LibJS/Tests/builtins/Number/Number.isInteger.js @@ -1,32 +1,32 @@ test("basic functionality", () => { - expect(Number.isInteger).toHaveLength(1); + expect(Number.isInteger).toHaveLength(1); - expect(Number.isInteger(0)).toBeTrue(); - expect(Number.isInteger(42)).toBeTrue(); - expect(Number.isInteger(-10000)).toBeTrue(); - expect(Number.isInteger(5)).toBeTrue(); - expect(Number.isInteger(5.0)).toBeTrue(); - expect(Number.isInteger(5 + 1/10000000000000000)).toBeTrue(); - // FIXME: values outside of i32's range should still return true - // expect(Number.isInteger(+2147483647 + 1)).toBeTrue(); - // expect(Number.isInteger(-2147483648 - 1)).toBeTrue(); - // expect(Number.isInteger(99999999999999999999999999999999999)).toBeTrue(); + expect(Number.isInteger(0)).toBeTrue(); + expect(Number.isInteger(42)).toBeTrue(); + expect(Number.isInteger(-10000)).toBeTrue(); + expect(Number.isInteger(5)).toBeTrue(); + expect(Number.isInteger(5.0)).toBeTrue(); + expect(Number.isInteger(5 + 1 / 10000000000000000)).toBeTrue(); + // FIXME: values outside of i32's range should still return true + // expect(Number.isInteger(+2147483647 + 1)).toBeTrue(); + // expect(Number.isInteger(-2147483648 - 1)).toBeTrue(); + // expect(Number.isInteger(99999999999999999999999999999999999)).toBeTrue(); - expect(Number.isInteger(5 + 1/1000000000000000)).toBeFalse(); - expect(Number.isInteger(1.23)).toBeFalse(); - expect(Number.isInteger("")).toBeFalse(); - expect(Number.isInteger("0")).toBeFalse(); - expect(Number.isInteger("42")).toBeFalse(); - expect(Number.isInteger(true)).toBeFalse(); - expect(Number.isInteger(false)).toBeFalse(); - expect(Number.isInteger(null)).toBeFalse(); - expect(Number.isInteger([])).toBeFalse(); - expect(Number.isInteger(Infinity)).toBeFalse(); - expect(Number.isInteger(-Infinity)).toBeFalse(); - expect(Number.isInteger(NaN)).toBeFalse(); - expect(Number.isInteger()).toBeFalse(); - expect(Number.isInteger(undefined)).toBeFalse(); - expect(Number.isInteger("foo")).toBeFalse(); - expect(Number.isInteger({})).toBeFalse(); - expect(Number.isInteger([1, 2, 3])).toBeFalse(); + expect(Number.isInteger(5 + 1 / 1000000000000000)).toBeFalse(); + expect(Number.isInteger(1.23)).toBeFalse(); + expect(Number.isInteger("")).toBeFalse(); + expect(Number.isInteger("0")).toBeFalse(); + expect(Number.isInteger("42")).toBeFalse(); + expect(Number.isInteger(true)).toBeFalse(); + expect(Number.isInteger(false)).toBeFalse(); + expect(Number.isInteger(null)).toBeFalse(); + expect(Number.isInteger([])).toBeFalse(); + expect(Number.isInteger(Infinity)).toBeFalse(); + expect(Number.isInteger(-Infinity)).toBeFalse(); + expect(Number.isInteger(NaN)).toBeFalse(); + expect(Number.isInteger()).toBeFalse(); + expect(Number.isInteger(undefined)).toBeFalse(); + expect(Number.isInteger("foo")).toBeFalse(); + expect(Number.isInteger({})).toBeFalse(); + expect(Number.isInteger([1, 2, 3])).toBeFalse(); }); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.isNaN.js b/Libraries/LibJS/Tests/builtins/Number/Number.isNaN.js index 6a7df463df..238f1b6430 100644 --- a/Libraries/LibJS/Tests/builtins/Number/Number.isNaN.js +++ b/Libraries/LibJS/Tests/builtins/Number/Number.isNaN.js @@ -1,25 +1,25 @@ test("basic functionality", () => { - expect(Number.isNaN).toHaveLength(1); - expect(Number.isNaN).not.toBe(isNaN); + expect(Number.isNaN).toHaveLength(1); + expect(Number.isNaN).not.toBe(isNaN); - expect(Number.isNaN(0)).toBeFalse(); - expect(Number.isNaN(42)).toBeFalse(); - expect(Number.isNaN("")).toBeFalse(); - expect(Number.isNaN("0")).toBeFalse(); - expect(Number.isNaN("42")).toBeFalse(); - expect(Number.isNaN(true)).toBeFalse(); - expect(Number.isNaN(false)).toBeFalse(); - expect(Number.isNaN(null)).toBeFalse(); - expect(Number.isNaN([])).toBeFalse(); - expect(Number.isNaN(Infinity)).toBeFalse(); - expect(Number.isNaN(-Infinity)).toBeFalse(); - expect(Number.isNaN()).toBeFalse(); - expect(Number.isNaN(undefined)).toBeFalse(); - expect(Number.isNaN("foo")).toBeFalse(); - expect(Number.isNaN({})).toBeFalse(); - expect(Number.isNaN([1, 2, 3])).toBeFalse(); + expect(Number.isNaN(0)).toBeFalse(); + expect(Number.isNaN(42)).toBeFalse(); + expect(Number.isNaN("")).toBeFalse(); + expect(Number.isNaN("0")).toBeFalse(); + expect(Number.isNaN("42")).toBeFalse(); + expect(Number.isNaN(true)).toBeFalse(); + expect(Number.isNaN(false)).toBeFalse(); + expect(Number.isNaN(null)).toBeFalse(); + expect(Number.isNaN([])).toBeFalse(); + expect(Number.isNaN(Infinity)).toBeFalse(); + expect(Number.isNaN(-Infinity)).toBeFalse(); + expect(Number.isNaN()).toBeFalse(); + expect(Number.isNaN(undefined)).toBeFalse(); + expect(Number.isNaN("foo")).toBeFalse(); + expect(Number.isNaN({})).toBeFalse(); + expect(Number.isNaN([1, 2, 3])).toBeFalse(); - expect(Number.isNaN(NaN)).toBeTrue(); - expect(Number.isNaN(Number.NaN)).toBeTrue(); - expect(Number.isNaN(0 / 0)).toBeTrue(); + expect(Number.isNaN(NaN)).toBeTrue(); + expect(Number.isNaN(Number.NaN)).toBeTrue(); + expect(Number.isNaN(0 / 0)).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.isSafeInteger.js b/Libraries/LibJS/Tests/builtins/Number/Number.isSafeInteger.js index 3bba1682a6..b6f982a991 100644 --- a/Libraries/LibJS/Tests/builtins/Number/Number.isSafeInteger.js +++ b/Libraries/LibJS/Tests/builtins/Number/Number.isSafeInteger.js @@ -1,24 +1,24 @@ test("basic functionality", () => { - expect(Number.isSafeInteger).toHaveLength(1); + expect(Number.isSafeInteger).toHaveLength(1); - expect(Number.isSafeInteger(0)).toBeTrue(); - expect(Number.isSafeInteger(1)).toBeTrue(); - expect(Number.isSafeInteger(2.0)).toBeTrue(); - expect(Number.isSafeInteger(42)).toBeTrue(); - expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER)).toBeTrue(); - expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER)).toBeTrue(); + expect(Number.isSafeInteger(0)).toBeTrue(); + expect(Number.isSafeInteger(1)).toBeTrue(); + expect(Number.isSafeInteger(2.0)).toBeTrue(); + expect(Number.isSafeInteger(42)).toBeTrue(); + expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER)).toBeTrue(); + expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER)).toBeTrue(); - expect(Number.isSafeInteger()).toBeFalse(); - expect(Number.isSafeInteger("1")).toBeFalse(); - expect(Number.isSafeInteger(2.1)).toBeFalse(); - expect(Number.isSafeInteger(42.42)).toBeFalse(); - expect(Number.isSafeInteger("")).toBeFalse(); - expect(Number.isSafeInteger([])).toBeFalse(); - expect(Number.isSafeInteger(null)).toBeFalse(); - expect(Number.isSafeInteger(undefined)).toBeFalse(); - expect(Number.isSafeInteger(NaN)).toBeFalse(); - expect(Number.isSafeInteger(Infinity)).toBeFalse(); - expect(Number.isSafeInteger(-Infinity)).toBeFalse(); - expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1)).toBeFalse(); - expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1)).toBeFalse(); + expect(Number.isSafeInteger()).toBeFalse(); + expect(Number.isSafeInteger("1")).toBeFalse(); + expect(Number.isSafeInteger(2.1)).toBeFalse(); + expect(Number.isSafeInteger(42.42)).toBeFalse(); + expect(Number.isSafeInteger("")).toBeFalse(); + expect(Number.isSafeInteger([])).toBeFalse(); + expect(Number.isSafeInteger(null)).toBeFalse(); + expect(Number.isSafeInteger(undefined)).toBeFalse(); + expect(Number.isSafeInteger(NaN)).toBeFalse(); + expect(Number.isSafeInteger(Infinity)).toBeFalse(); + expect(Number.isSafeInteger(-Infinity)).toBeFalse(); + expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1)).toBeFalse(); + expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1)).toBeFalse(); }); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.js b/Libraries/LibJS/Tests/builtins/Number/Number.js index 2ee0476a9e..d9ff9a911b 100644 --- a/Libraries/LibJS/Tests/builtins/Number/Number.js +++ b/Libraries/LibJS/Tests/builtins/Number/Number.js @@ -1,33 +1,33 @@ test("basic functionality", () => { - expect(Number).toHaveLength(1); - expect(Number.name).toBe("Number"); - expect(Number.prototype).not.toHaveProperty("length"); + expect(Number).toHaveLength(1); + expect(Number.name).toBe("Number"); + expect(Number.prototype).not.toHaveProperty("length"); - expect(typeof Number()).toBe("number"); - expect(typeof new Number()).toBe("object"); + expect(typeof Number()).toBe("number"); + expect(typeof new Number()).toBe("object"); - expect(Number()).toBe(0); - expect(new Number().valueOf()).toBe(0); - expect(Number("42")).toBe(42); - expect(new Number("42").valueOf()).toBe(42); - expect(Number(null)).toBe(0); - expect(new Number(null).valueOf()).toBe(0); - expect(Number(true)).toBe(1); - expect(new Number(true).valueOf()).toBe(1); - expect(Number("Infinity")).toBe(Infinity); - expect(new Number("Infinity").valueOf()).toBe(Infinity); - expect(Number("+Infinity")).toBe(Infinity); - expect(new Number("+Infinity").valueOf()).toBe(Infinity); - expect(Number("-Infinity")).toBe(-Infinity); - expect(new Number("-Infinity").valueOf()).toBe(-Infinity); - expect(Number(undefined)).toBeNaN(); - expect(new Number(undefined).valueOf()).toBeNaN(); - expect(Number({})).toBeNaN(); - expect(new Number({}).valueOf()).toBeNaN(); - expect(Number({a: 1})).toBeNaN(); - expect(new Number({a: 1}).valueOf()).toBeNaN(); - expect(Number([1, 2, 3])).toBeNaN(); - expect(new Number([1, 2, 3]).valueOf()).toBeNaN(); - expect(Number("foo")).toBeNaN(); - expect(new Number("foo").valueOf()).toBeNaN(); + expect(Number()).toBe(0); + expect(new Number().valueOf()).toBe(0); + expect(Number("42")).toBe(42); + expect(new Number("42").valueOf()).toBe(42); + expect(Number(null)).toBe(0); + expect(new Number(null).valueOf()).toBe(0); + expect(Number(true)).toBe(1); + expect(new Number(true).valueOf()).toBe(1); + expect(Number("Infinity")).toBe(Infinity); + expect(new Number("Infinity").valueOf()).toBe(Infinity); + expect(Number("+Infinity")).toBe(Infinity); + expect(new Number("+Infinity").valueOf()).toBe(Infinity); + expect(Number("-Infinity")).toBe(-Infinity); + expect(new Number("-Infinity").valueOf()).toBe(-Infinity); + expect(Number(undefined)).toBeNaN(); + expect(new Number(undefined).valueOf()).toBeNaN(); + expect(Number({})).toBeNaN(); + expect(new Number({}).valueOf()).toBeNaN(); + expect(Number({ a: 1 })).toBeNaN(); + expect(new Number({ a: 1 }).valueOf()).toBeNaN(); + expect(Number([1, 2, 3])).toBeNaN(); + expect(new Number([1, 2, 3]).valueOf()).toBeNaN(); + expect(Number("foo")).toBeNaN(); + expect(new Number("foo").valueOf()).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.parseFloat.js b/Libraries/LibJS/Tests/builtins/Number/Number.parseFloat.js index 89de9ff0d9..f1fb4c41ae 100644 --- a/Libraries/LibJS/Tests/builtins/Number/Number.parseFloat.js +++ b/Libraries/LibJS/Tests/builtins/Number/Number.parseFloat.js @@ -1,5 +1,5 @@ test("basic functionality", () => { - // Ensuring it's the same function as the global - // parseFloat() is enough as that already has tests :^) - expect(Number.parseFloat).toBe(parseFloat); + // Ensuring it's the same function as the global + // parseFloat() is enough as that already has tests :^) + expect(Number.parseFloat).toBe(parseFloat); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js b/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js index 0553623379..2b1b78f6b9 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js @@ -1,127 +1,137 @@ describe("normal functionality", () => { - test("non-configurable property", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 1, writable: false, enumerable: false }); + test("non-configurable property", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: 1, writable: false, enumerable: false }); - expect(o.foo).toBe(1); - o.foo = 2; - expect(o.foo).toBe(1); + expect(o.foo).toBe(1); + o.foo = 2; + expect(o.foo).toBe(1); - expect(o).not.toHaveConfigurableProperty("foo"); - expect(o).not.toHaveEnumerableProperty("foo"); - expect(o).not.toHaveWritableProperty("foo"); - expect(o).toHaveValueProperty("foo", 1); + expect(o).not.toHaveConfigurableProperty("foo"); + expect(o).not.toHaveEnumerableProperty("foo"); + expect(o).not.toHaveWritableProperty("foo"); + expect(o).toHaveValueProperty("foo", 1); + }); + + test("array index getter", () => { + let o = {}; + Object.defineProperty(o, 2, { + get() { + return 10; + }, + }); + expect(o[2]).toBe(10); + }); + + test("configurable property", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: "hi", writable: true, enumerable: true }); + + expect(o.foo).toBe("hi"); + o.foo = "ho"; + expect(o.foo).toBe("ho"); + + expect(o).not.toHaveConfigurableProperty("foo"); + expect(o).toHaveEnumerableProperty("foo"); + expect(o).toHaveWritableProperty("foo"); + expect(o).toHaveValueProperty("foo", "ho"); + }); + + test("reconfigure configurable property", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: 9, configurable: true, writable: false }); + Object.defineProperty(o, "foo", { configurable: true, writable: true }); + + expect(o).toHaveConfigurableProperty("foo"); + expect(o).toHaveWritableProperty("foo"); + expect(o).not.toHaveEnumerableProperty("foo"); + expect(o).toHaveValueProperty("foo", 9); + }); + + test("define accessor", () => { + let o = {}; + + Object.defineProperty(o, "foo", { + configurable: true, + get() { + return o.secret_foo + 1; + }, + set(value) { + this.secret_foo = value + 1; + }, }); - test("array index getter", () => { - let o = {}; - Object.defineProperty(o, 2, { get() { return 10; } }); - expect(o[2]).toBe(10); - }); + o.foo = 10; + expect(o.foo).toBe(12); + o.foo = 20; + expect(o.foo).toBe(22); - test("configurable property", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: "hi", writable: true, enumerable: true }); + Object.defineProperty(o, "foo", { configurable: true, value: 4 }); - expect(o.foo).toBe("hi"); - o.foo = "ho"; - expect(o.foo).toBe("ho"); - - expect(o).not.toHaveConfigurableProperty("foo"); - expect(o).toHaveEnumerableProperty("foo"); - expect(o).toHaveWritableProperty("foo"); - expect(o).toHaveValueProperty("foo", "ho"); - }); - - test("reconfigure configurable property", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 9, configurable: true, writable: false }); - Object.defineProperty(o, "foo", { configurable: true, writable: true }); - - expect(o).toHaveConfigurableProperty("foo"); - expect(o).toHaveWritableProperty("foo"); - expect(o).not.toHaveEnumerableProperty("foo"); - expect(o).toHaveValueProperty("foo", 9); - }); - - test("define accessor", () => { - let o = {}; - - Object.defineProperty(o, "foo", { - configurable: true, - get() { - return o.secret_foo + 1; - }, - set(value) { - this.secret_foo = value + 1; - }, - }); - - o.foo = 10; - expect(o.foo).toBe(12); - o.foo = 20; - expect(o.foo).toBe(22); - - Object.defineProperty(o, "foo", { configurable: true, value: 4 }); - - expect(o.foo).toBe(4); - expect(o.foo = 5).toBe(5); - expect(o.foo = 4).toBe(4); - }); + expect(o.foo).toBe(4); + expect((o.foo = 5)).toBe(5); + expect((o.foo = 4)).toBe(4); + }); }); describe("errors", () => { - test("redefine non-configurable property", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 1, writable: true, enumerable: true }); + test("redefine non-configurable property", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: 1, writable: true, enumerable: true }); - expect(() => { - Object.defineProperty(o, "foo", { value: 2, writable: false, enumerable: true }); - }).toThrowWithMessage(TypeError, "Cannot change attributes of non-configurable property 'foo'"); + expect(() => { + Object.defineProperty(o, "foo", { value: 2, writable: false, enumerable: true }); + }).toThrowWithMessage(TypeError, "Cannot change attributes of non-configurable property 'foo'"); + }); + + test("cannot define 'value' and 'get' in the same descriptor", () => { + let o = {}; + + expect(() => { + Object.defineProperty(o, "a", { + get() {}, + value: 9, + }); + }).toThrowWithMessage( + TypeError, + "Accessor property descriptor cannot specify a value or writable key" + ); + }); + + test("cannot define 'value' and 'set' in the same descriptor", () => { + let o = {}; + + expect(() => { + Object.defineProperty(o, "a", { + set() {}, + writable: true, + }); + }).toThrowWithMessage( + TypeError, + "Accessor property descriptor cannot specify a value or writable key" + ); + }); + + test("redefine non-configurable accessor", () => { + let o = {}; + + Object.defineProperty(o, "foo", { + configurable: false, + get() { + return this.secret_foo + 2; + }, + set(value) { + o.secret_foo = value + 2; + }, }); - test("cannot define 'value' and 'get' in the same descriptor", () => { - let o = {}; - - expect(() => { - Object.defineProperty(o, "a", { - get() {}, - value: 9, - }); - }).toThrowWithMessage(TypeError, "Accessor property descriptor cannot specify a value or writable key"); - }); - - test("cannot define 'value' and 'set' in the same descriptor", () => { - let o = {}; - - expect(() => { - Object.defineProperty(o, "a", { - set() {}, - writable: true, - }); - }).toThrowWithMessage(TypeError, "Accessor property descriptor cannot specify a value or writable key"); - }); - - test("redefine non-configurable accessor", () => { - let o = {}; - - Object.defineProperty(o, "foo", { - configurable: false, - get() { - return this.secret_foo + 2; - }, - set(value) { - o.secret_foo = value + 2; - }, - }); - - expect(() => { - Object.defineProperty(o, "foo", { - configurable: false, - get() { - return this.secret_foo + 2; - }, - }); - }).toThrowWithMessage(TypeError, "Cannot change attributes of non-configurable property 'foo'"); - }); + expect(() => { + Object.defineProperty(o, "foo", { + configurable: false, + get() { + return this.secret_foo + 2; + }, + }); + }).toThrowWithMessage(TypeError, "Cannot change attributes of non-configurable property 'foo'"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.entries.js b/Libraries/LibJS/Tests/builtins/Object/Object.entries.js index 11eb145308..2a48d6468a 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.entries.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.entries.js @@ -1,45 +1,55 @@ describe("basic functionality", () => { - test("length", () => { - expect(Object.entries).toHaveLength(1); - expect(Object.entries(true)).toHaveLength(0); - expect(Object.entries(45)).toHaveLength(0); - expect(Object.entries(-998)).toHaveLength(0); - expect(Object.entries("abcd")).toHaveLength(4); - expect(Object.entries([1, 2, 3])).toHaveLength(3); - expect(Object.entries({ a: 1, b: 2, c: 3 })).toHaveLength(3); - }); + test("length", () => { + expect(Object.entries).toHaveLength(1); + expect(Object.entries(true)).toHaveLength(0); + expect(Object.entries(45)).toHaveLength(0); + expect(Object.entries(-998)).toHaveLength(0); + expect(Object.entries("abcd")).toHaveLength(4); + expect(Object.entries([1, 2, 3])).toHaveLength(3); + expect(Object.entries({ a: 1, b: 2, c: 3 })).toHaveLength(3); + }); - test("entries with object", () => { - let entries = Object.entries({ foo: 1, bar: 2, baz: 3 }); + test("entries with object", () => { + let entries = Object.entries({ foo: 1, bar: 2, baz: 3 }); - expect(entries).toEqual([["foo", 1], ["bar", 2], ["baz", 3]]); - }); + expect(entries).toEqual([ + ["foo", 1], + ["bar", 2], + ["baz", 3], + ]); + }); - test("entries with array", () => { - entries = Object.entries(["a", "b", "c"]); - expect(entries).toEqual([["0", "a"], ["1", "b"], ["2", "c"]]); - }); + test("entries with array", () => { + entries = Object.entries(["a", "b", "c"]); + expect(entries).toEqual([ + ["0", "a"], + ["1", "b"], + ["2", "c"], + ]); + }); - test("ignores non-enumerable properties", () => { - let obj = { foo: 1 }; - Object.defineProperty(obj, "getFoo", { - value: function() { return this.foo; }, - }); - let entries = Object.entries(obj); - expect(entries).toEqual([["foo", 1]]); + test("ignores non-enumerable properties", () => { + let obj = { foo: 1 }; + Object.defineProperty(obj, "getFoo", { + value: function () { + return this.foo; + }, }); + let entries = Object.entries(obj); + expect(entries).toEqual([["foo", 1]]); + }); }); describe("errors", () => { - test("null argument", () => { - expect(() => { - Object.entries(null); - }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); - }); + test("null argument", () => { + expect(() => { + Object.entries(null); + }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); + }); - test("undefined argument", () => { - expect(() => { - Object.entries(undefined); - }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); - }) + test("undefined argument", () => { + expect(() => { + Object.entries(undefined); + }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js b/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js index a1783add2c..46dec2a485 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js @@ -1,49 +1,49 @@ test("plain property", () => { - let o = { foo: "bar" }; + let o = { foo: "bar" }; - expect(o).toHaveConfigurableProperty("foo"); - expect(o).toHaveEnumerableProperty("foo"); - expect(o).toHaveWritableProperty("foo"); - expect(o).toHaveValueProperty("foo", "bar"); - expect(o).not.toHaveGetterProperty("foo"); - expect(o).not.toHaveSetterProperty("foo"); + expect(o).toHaveConfigurableProperty("foo"); + expect(o).toHaveEnumerableProperty("foo"); + expect(o).toHaveWritableProperty("foo"); + expect(o).toHaveValueProperty("foo", "bar"); + expect(o).not.toHaveGetterProperty("foo"); + expect(o).not.toHaveSetterProperty("foo"); }); test("getter property", () => { - let o = { get foo() {} }; + let o = { get foo() {} }; - expect(o).toHaveConfigurableProperty("foo"); - expect(o).toHaveEnumerableProperty("foo"); - expect(o).not.toHaveWritableProperty("foo"); - expect(o).not.toHaveValueProperty("foo"); - expect(o).toHaveGetterProperty("foo"); - expect(o).not.toHaveSetterProperty("foo"); + expect(o).toHaveConfigurableProperty("foo"); + expect(o).toHaveEnumerableProperty("foo"); + expect(o).not.toHaveWritableProperty("foo"); + expect(o).not.toHaveValueProperty("foo"); + expect(o).toHaveGetterProperty("foo"); + expect(o).not.toHaveSetterProperty("foo"); }); test("setter property", () => { - let o = { set foo(_) {} }; + let o = { set foo(_) {} }; - expect(o).toHaveConfigurableProperty("foo"); - expect(o).toHaveEnumerableProperty("foo"); - expect(o).not.toHaveWritableProperty("foo"); - expect(o).not.toHaveValueProperty("foo"); - expect(o).not.toHaveGetterProperty("foo"); - expect(o).toHaveSetterProperty("foo"); + expect(o).toHaveConfigurableProperty("foo"); + expect(o).toHaveEnumerableProperty("foo"); + expect(o).not.toHaveWritableProperty("foo"); + expect(o).not.toHaveValueProperty("foo"); + expect(o).not.toHaveGetterProperty("foo"); + expect(o).toHaveSetterProperty("foo"); }); test("defined property", () => { - let o = {}; + let o = {}; - Object.defineProperty(o, "foo", { - enumerable: false, - writable: true, - value: 10, - }); + Object.defineProperty(o, "foo", { + enumerable: false, + writable: true, + value: 10, + }); - expect(o).not.toHaveConfigurableProperty("foo"); - expect(o).not.toHaveEnumerableProperty("foo"); - expect(o).toHaveWritableProperty("foo"); - expect(o).toHaveValueProperty("foo", 10); - expect(o).not.toHaveGetterProperty("foo"); - expect(o).not.toHaveSetterProperty("foo"); + expect(o).not.toHaveConfigurableProperty("foo"); + expect(o).not.toHaveEnumerableProperty("foo"); + expect(o).toHaveWritableProperty("foo"); + expect(o).toHaveValueProperty("foo", 10); + expect(o).not.toHaveGetterProperty("foo"); + expect(o).not.toHaveSetterProperty("foo"); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js b/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js index 69ab0685df..9c319fced3 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js @@ -1,9 +1,9 @@ test("use with array", () => { - let names = Object.getOwnPropertyNames([1, 2, 3]); - expect(names).toEqual(["0", "1", "2", "length"]); + let names = Object.getOwnPropertyNames([1, 2, 3]); + expect(names).toEqual(["0", "1", "2", "length"]); }); test("use with object", () => { - let names = Object.getOwnPropertyNames({ foo: 1, bar: 2, baz: 3 }); - expect(names).toEqual(["foo", "bar", "baz"]); + let names = Object.getOwnPropertyNames({ foo: 1, bar: 2, baz: 3 }); + expect(names).toEqual(["foo", "bar", "baz"]); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js index 331ee5079f..23d08332ea 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js @@ -1,10 +1,10 @@ test("basic functionality", () => { - let o1 = new Object(); - let o2 = {}; + let o1 = new Object(); + let o2 = {}; - expect(Object.getPrototypeOf(o1)).toBe(Object.getPrototypeOf(o2)); - expect(Object.getPrototypeOf(Object.getPrototypeOf(o1))).toBe(null); + expect(Object.getPrototypeOf(o1)).toBe(Object.getPrototypeOf(o2)); + expect(Object.getPrototypeOf(Object.getPrototypeOf(o1))).toBeNull(); - Object.setPrototypeOf(o1, o2); - expect(Object.getPrototypeOf(o1)).toBe(o2); + Object.setPrototypeOf(o1, o2); + expect(Object.getPrototypeOf(o1)).toBe(o2); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.is.js b/Libraries/LibJS/Tests/builtins/Object/Object.is.js index 9f748f65b8..c4effe6807 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.is.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.is.js @@ -1,54 +1,54 @@ test("length", () => { - expect(Object.is).toHaveLength(2); + expect(Object.is).toHaveLength(2); }); test("arguments that evaluate to true", () => { - let a = [1, 2, 3]; - let o = { foo: "bar" }; + let a = [1, 2, 3]; + let o = { foo: "bar" }; - expect(Object.is("", "")).toBeTrue(); - expect(Object.is("foo", "foo")).toBeTrue(); - expect(Object.is(0, 0)).toBeTrue(); - expect(Object.is(+0, +0)).toBeTrue(); - expect(Object.is(-0, -0)).toBeTrue(); - expect(Object.is(1.23, 1.23)).toBeTrue(); - expect(Object.is(42, 42)).toBeTrue(); - expect(Object.is(NaN, NaN)).toBeTrue(); - expect(Object.is(Infinity, Infinity)).toBeTrue(); - expect(Object.is(+Infinity, +Infinity)).toBeTrue(); - expect(Object.is(-Infinity, -Infinity)).toBeTrue(); - expect(Object.is(true, true)).toBeTrue(); - expect(Object.is(false, false)).toBeTrue(); - expect(Object.is(null, null)).toBeTrue(); - expect(Object.is(undefined, undefined)).toBeTrue(); - expect(Object.is(undefined)).toBeTrue(); - expect(Object.is()).toBeTrue(); - expect(Object.is(a, a)).toBeTrue(); - expect(Object.is(o, o)).toBeTrue(); + expect(Object.is("", "")).toBeTrue(); + expect(Object.is("foo", "foo")).toBeTrue(); + expect(Object.is(0, 0)).toBeTrue(); + expect(Object.is(+0, +0)).toBeTrue(); + expect(Object.is(-0, -0)).toBeTrue(); + expect(Object.is(1.23, 1.23)).toBeTrue(); + expect(Object.is(42, 42)).toBeTrue(); + expect(Object.is(NaN, NaN)).toBeTrue(); + expect(Object.is(Infinity, Infinity)).toBeTrue(); + expect(Object.is(+Infinity, +Infinity)).toBeTrue(); + expect(Object.is(-Infinity, -Infinity)).toBeTrue(); + expect(Object.is(true, true)).toBeTrue(); + expect(Object.is(false, false)).toBeTrue(); + expect(Object.is(null, null)).toBeTrue(); + expect(Object.is(undefined, undefined)).toBeTrue(); + expect(Object.is(undefined)).toBeTrue(); + expect(Object.is()).toBeTrue(); + expect(Object.is(a, a)).toBeTrue(); + expect(Object.is(o, o)).toBeTrue(); }); test("arguments that evaluate to false", () => { - let a = [1, 2, 3]; - let o = { foo: "bar" }; + let a = [1, 2, 3]; + let o = { foo: "bar" }; - expect(Object.is("test")).toBeFalse(); - expect(Object.is("foo", "bar")).toBeFalse(); - expect(Object.is(1, "1")).toBeFalse(); - expect(Object.is(+0, -0)).toBeFalse(); - expect(Object.is(-0, +0)).toBeFalse(); - expect(Object.is(42, 24)).toBeFalse(); - expect(Object.is(Infinity, -Infinity)).toBeFalse(); - expect(Object.is(-Infinity, +Infinity)).toBeFalse(); - expect(Object.is(true, false)).toBeFalse(); - expect(Object.is(false, true)).toBeFalse(); - expect(Object.is(undefined, null)).toBeFalse(); - expect(Object.is(null, undefined)).toBeFalse(); - expect(Object.is([], [])).toBeFalse(); - expect(Object.is(a, [1, 2, 3])).toBeFalse(); - expect(Object.is([1, 2, 3], a)).toBeFalse(); - expect(Object.is({}, {})).toBeFalse(); - expect(Object.is(o, {foo: "bar"})).toBeFalse(); - expect(Object.is({foo: "bar"}, o)).toBeFalse(); - expect(Object.is(a, o)).toBeFalse(); - expect(Object.is(o, a)).toBeFalse(); + expect(Object.is("test")).toBeFalse(); + expect(Object.is("foo", "bar")).toBeFalse(); + expect(Object.is(1, "1")).toBeFalse(); + expect(Object.is(+0, -0)).toBeFalse(); + expect(Object.is(-0, +0)).toBeFalse(); + expect(Object.is(42, 24)).toBeFalse(); + expect(Object.is(Infinity, -Infinity)).toBeFalse(); + expect(Object.is(-Infinity, +Infinity)).toBeFalse(); + expect(Object.is(true, false)).toBeFalse(); + expect(Object.is(false, true)).toBeFalse(); + expect(Object.is(undefined, null)).toBeFalse(); + expect(Object.is(null, undefined)).toBeFalse(); + expect(Object.is([], [])).toBeFalse(); + expect(Object.is(a, [1, 2, 3])).toBeFalse(); + expect(Object.is([1, 2, 3], a)).toBeFalse(); + expect(Object.is({}, {})).toBeFalse(); + expect(Object.is(o, { foo: "bar" })).toBeFalse(); + expect(Object.is({ foo: "bar" }, o)).toBeFalse(); + expect(Object.is(a, o)).toBeFalse(); + expect(Object.is(o, a)).toBeFalse(); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js b/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js index b426114f20..5fad4bde4b 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js @@ -1,18 +1,18 @@ test("basic functionality", () => { - expect(Object.isExtensible).toHaveLength(1); + expect(Object.isExtensible).toHaveLength(1); - expect(Object.isExtensible()).toBeFalse(); - expect(Object.isExtensible(undefined)).toBeFalse(); - expect(Object.isExtensible(null)).toBeFalse(); - expect(Object.isExtensible(true)).toBeFalse(); - expect(Object.isExtensible(6)).toBeFalse(); - expect(Object.isExtensible("test")).toBeFalse(); + expect(Object.isExtensible()).toBeFalse(); + expect(Object.isExtensible(undefined)).toBeFalse(); + expect(Object.isExtensible(null)).toBeFalse(); + expect(Object.isExtensible(true)).toBeFalse(); + expect(Object.isExtensible(6)).toBeFalse(); + expect(Object.isExtensible("test")).toBeFalse(); - let s = Symbol(); - expect(Object.isExtensible(s)).toBeFalse(); + let s = Symbol(); + expect(Object.isExtensible(s)).toBeFalse(); - let o = { foo: "foo" }; - expect(Object.isExtensible(o)).toBeTrue(); - Object.preventExtensions(o); - expect(Object.isExtensible(o)).toBeFalse(); + let o = { foo: "foo" }; + expect(Object.isExtensible(o)).toBeTrue(); + Object.preventExtensions(o); + expect(Object.isExtensible(o)).toBeFalse(); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.js b/Libraries/LibJS/Tests/builtins/Object/Object.js index 0b4ed04b50..3134ff324d 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.js @@ -1,8 +1,8 @@ test("basic functionality", () => { - expect(Object).toHaveLength(1); - expect(Object.name).toBe("Object"); - expect(Object.prototype.length).toBe(undefined); + expect(Object).toHaveLength(1); + expect(Object.name).toBe("Object"); + expect(Object.prototype).not.toHaveProperty("length"); - expect(typeof Object()).toBe("object"); - expect(typeof new Object()).toBe("object"); + expect(typeof Object()).toBe("object"); + expect(typeof new Object()).toBe("object"); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.keys.js b/Libraries/LibJS/Tests/builtins/Object/Object.keys.js index 620d7af97d..2c2e163fe3 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.keys.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.keys.js @@ -1,44 +1,46 @@ describe("correct behavior", () => { - test("length", () => { - expect(Object.keys).toHaveLength(1); - expect(Object.keys(true)).toHaveLength(0); - expect(Object.keys(45)).toHaveLength(0); - expect(Object.keys(-998)).toHaveLength(0); - expect(Object.keys("abcd")).toHaveLength(4); - expect(Object.keys([1, 2, 3])).toHaveLength(3); - expect(Object.keys({ a: 1, b: 2, c: 3 })).toHaveLength(3); - }); + test("length", () => { + expect(Object.keys).toHaveLength(1); + expect(Object.keys(true)).toHaveLength(0); + expect(Object.keys(45)).toHaveLength(0); + expect(Object.keys(-998)).toHaveLength(0); + expect(Object.keys("abcd")).toHaveLength(4); + expect(Object.keys([1, 2, 3])).toHaveLength(3); + expect(Object.keys({ a: 1, b: 2, c: 3 })).toHaveLength(3); + }); - test("object argument", () => { - let keys = Object.keys({ foo: 1, bar: 2, baz: 3 }); - expect(keys).toEqual(["foo", "bar", "baz"]); - }); + test("object argument", () => { + let keys = Object.keys({ foo: 1, bar: 2, baz: 3 }); + expect(keys).toEqual(["foo", "bar", "baz"]); + }); - test("array argument", () => { - let keys = Object.keys(["a", "b", "c"]); - expect(keys).toEqual(["0", "1", "2"]); - }); + test("array argument", () => { + let keys = Object.keys(["a", "b", "c"]); + expect(keys).toEqual(["0", "1", "2"]); + }); - test("ignores non-enumerable properties", () => { - let obj = { foo: 1 }; - Object.defineProperty(obj, "getFoo", { - value: function() { return this.foo; }, - }); - keys = Object.keys(obj); - expect(keys).toEqual(["foo"]); + test("ignores non-enumerable properties", () => { + let obj = { foo: 1 }; + Object.defineProperty(obj, "getFoo", { + value: function () { + return this.foo; + }, }); + keys = Object.keys(obj); + expect(keys).toEqual(["foo"]); + }); }); describe("errors", () => { - test("null argument value", () => { - expect(() => { - Object.keys(null); - }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); - }); + test("null argument value", () => { + expect(() => { + Object.keys(null); + }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); + }); - test("undefined argument value", () => { - expect(() => { - Object.keys(undefined); - }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); - }); + test("undefined argument value", () => { + expect(() => { + Object.keys(undefined); + }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js b/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js index 6752c1b19a..e063dedd65 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js @@ -1,53 +1,53 @@ describe("correct behavior", () => { - test("non-object arguments", () => { - expect(Object.preventExtensions()).toBeUndefined(); - expect(Object.preventExtensions(undefined)).toBeUndefined(); - expect(Object.preventExtensions(null)).toBeNull(); - expect(Object.preventExtensions(true)).toBeTrue(); - expect(Object.preventExtensions(6)).toBe(6); - expect(Object.preventExtensions("test")).toBe("test"); + test("non-object arguments", () => { + expect(Object.preventExtensions()).toBeUndefined(); + expect(Object.preventExtensions(undefined)).toBeUndefined(); + expect(Object.preventExtensions(null)).toBeNull(); + expect(Object.preventExtensions(true)).toBeTrue(); + expect(Object.preventExtensions(6)).toBe(6); + expect(Object.preventExtensions("test")).toBe("test"); - let s = Symbol(); - expect(Object.preventExtensions(s)).toBe(s); - }); + let s = Symbol(); + expect(Object.preventExtensions(s)).toBe(s); + }); - test("basic functionality", () => { - let o = { foo: "foo" }; - expect(o.foo).toBe("foo"); - o.bar = "bar"; - expect(o.bar).toBe("bar"); + test("basic functionality", () => { + let o = { foo: "foo" }; + expect(o.foo).toBe("foo"); + o.bar = "bar"; + expect(o.bar).toBe("bar"); - expect(Object.preventExtensions(o)).toBe(o); - expect(o.foo).toBe("foo"); - expect(o.bar).toBe("bar"); + expect(Object.preventExtensions(o)).toBe(o); + expect(o.foo).toBe("foo"); + expect(o.bar).toBe("bar"); - o.baz = "baz"; - expect(o.baz).toBeUndefined(); - }); + o.baz = "baz"; + expect(o.baz).toBeUndefined(); + }); }); describe("errors", () => { - test("defining a property on a non-extensible object", () => { - let o = {}; - Object.preventExtensions(o); + test("defining a property on a non-extensible object", () => { + let o = {}; + Object.preventExtensions(o); - expect(() => { - Object.defineProperty(o, "baz", { value: "baz" }); - }).toThrowWithMessage(TypeError, "Cannot define property baz on non-extensible object"); + expect(() => { + Object.defineProperty(o, "baz", { value: "baz" }); + }).toThrowWithMessage(TypeError, "Cannot define property baz on non-extensible object"); - expect(o.baz).toBeUndefined(); - }); + expect(o.baz).toBeUndefined(); + }); - test("putting property on a non-extensible object", () => { - let o = {}; - Object.preventExtensions(o); + test("putting property on a non-extensible object", () => { + let o = {}; + Object.preventExtensions(o); - expect(() => { - "use strict"; - o.foo = "foo"; - }).toThrowWithMessage(TypeError, "Cannot define property foo on non-extensible object"); + expect(() => { + "use strict"; + o.foo = "foo"; + }).toThrowWithMessage(TypeError, "Cannot define property foo on non-extensible object"); - expect(o.foo = "foo").toBe("foo"); - expect(o.foo).toBeUndefined(); - }); + expect((o.foo = "foo")).toBe("foo"); + expect(o.foo).toBeUndefined(); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.constructor.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.constructor.js index 50e4935c75..2fe5e51fb3 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.constructor.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.constructor.js @@ -1,18 +1,18 @@ test("basic functionality", () => { - [Array, BigInt, Boolean, Date, Error, Function, Number, Object, String].forEach(constructor => { - expect(constructor.prototype.constructor).toBe(constructor); - if (constructor !== BigInt) - expect(Reflect.construct(constructor, []).constructor).toBe(constructor); - }); + [Array, BigInt, Boolean, Date, Error, Function, Number, Object, String].forEach(constructor => { + expect(constructor.prototype.constructor).toBe(constructor); + if (constructor !== BigInt) + expect(Reflect.construct(constructor, []).constructor).toBe(constructor); + }); - let o = {}; - expect(o.constructor).toBe(Object); + let o = {}; + expect(o.constructor).toBe(Object); - a = []; - expect(a.constructor).toBe(Array); + a = []; + expect(a.constructor).toBe(Array); - expect(Object.prototype).toHaveConfigurableProperty("constructor"); - expect(Object.prototype).not.toHaveEnumerableProperty("constructor"); - expect(Object.prototype).toHaveWritableProperty("constructor"); - expect(Object.prototype).toHaveValueProperty("constructor", Object); + expect(Object.prototype).toHaveConfigurableProperty("constructor"); + expect(Object.prototype).not.toHaveEnumerableProperty("constructor"); + expect(Object.prototype).toHaveWritableProperty("constructor"); + expect(Object.prototype).toHaveValueProperty("constructor", Object); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js index 11063f42ec..ec14384baa 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js @@ -1,13 +1,13 @@ test("basic functionality", () => { - var o = {}; + var o = {}; - o.foo = 1; - expect(o.hasOwnProperty("foo")).toBeTrue(); - expect(o.hasOwnProperty("bar")).toBeFalse(); - expect(o.hasOwnProperty()).toBeFalse(); - expect(o.hasOwnProperty(undefined)).toBeFalse(); + o.foo = 1; + expect(o.hasOwnProperty("foo")).toBeTrue(); + expect(o.hasOwnProperty("bar")).toBeFalse(); + expect(o.hasOwnProperty()).toBeFalse(); + expect(o.hasOwnProperty(undefined)).toBeFalse(); - o.undefined = 2; - expect(o.hasOwnProperty()).toBeTrue(); - expect(o.hasOwnProperty(undefined)).toBeTrue(); + o.undefined = 2; + expect(o.hasOwnProperty()).toBeTrue(); + expect(o.hasOwnProperty(undefined)).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js index eab7093b3b..e04787de3f 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js @@ -1,5 +1,5 @@ test("basic functionality", () => { - var o = new Object(); - Object.prototype.foo = 123; - expect(o.foo).toBe(123); + var o = new Object(); + Object.prototype.foo = 123; + expect(o.foo).toBe(123); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js index ee5ccd2fad..082545c9de 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js @@ -1,31 +1,35 @@ describe("correct behavior", () => { - test("length", () => { - expect(Object.prototype.toLocaleString).toHaveLength(0); - }) + test("length", () => { + expect(Object.prototype.toLocaleString).toHaveLength(0); + }); - test("basic functionality", () => { - let o; + test("basic functionality", () => { + let o; - o = {}; - expect(o.toString()).toBe(o.toLocaleString()); + o = {}; + expect(o.toString()).toBe(o.toLocaleString()); - o = { toString: () => 42 }; - expect(o.toString()).toBe(42); - }); + o = { toString: () => 42 }; + expect(o.toString()).toBe(42); + }); }); describe("errors", () => { - test("toString that throws error", () => { - let o = { toString: () => { throw new Error(); } }; - expect(() => { - o.toLocaleString(); - }).toThrow(Error); - }); + test("toString that throws error", () => { + let o = { + toString: () => { + throw new Error(); + }, + }; + expect(() => { + o.toLocaleString(); + }).toThrow(Error); + }); - test("toString that is not a function", () => { - let o = { toString: "foo" }; - expect(() => { - o.toLocaleString(); - }).toThrowWithMessage(TypeError, "foo is not a function"); - }); + test("toString that is not a function", () => { + let o = { toString: "foo" }; + expect(() => { + o.toLocaleString(); + }).toThrowWithMessage(TypeError, "foo is not a function"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js index 95001ed3f6..e1a1a29cfc 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js @@ -1,8 +1,8 @@ test("basic functionality", () => { - expect(Object.prototype.toString).toHaveLength(0); - // FIXME: The tag is ObjectPrototype, but should be Object - // expect(Object.prototype.toString()).toBe("[object Object]"); - expect({ foo: 1 }.toString()).toBe("[object Object]"); - expect([].toString()).toBe(""); - expect(Object.prototype.toString.call([])).toBe("[object Array]"); + expect(Object.prototype.toString).toHaveLength(0); + // FIXME: The tag is ObjectPrototype, but should be Object + // expect(Object.prototype.toString()).toBe("[object Object]"); + expect({ foo: 1 }.toString()).toBe("[object Object]"); + expect([].toString()).toBe(""); + expect(Object.prototype.toString.call([])).toBe("[object Array]"); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js index 69a7b24ab3..33ee035bb5 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js @@ -1,43 +1,43 @@ describe("correct behavior", () => { - test("length", () => { - expect(Object.setPrototypeOf).toHaveLength(2); - }); + test("length", () => { + expect(Object.setPrototypeOf).toHaveLength(2); + }); - test("basic functionality", () => { - let o = {}; - let p = {}; - expect(Object.setPrototypeOf(o, p)).toBe(o); - expect(Object.getPrototypeOf(o)).toBe(p); - }); + test("basic functionality", () => { + let o = {}; + let p = {}; + expect(Object.setPrototypeOf(o, p)).toBe(o); + expect(Object.getPrototypeOf(o)).toBe(p); + }); }); describe("errors", () => { - test("requires two arguments", () => { - expect(() => { - Object.setPrototypeOf(); - }).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments"); + test("requires two arguments", () => { + expect(() => { + Object.setPrototypeOf(); + }).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments"); - expect(() => { - Object.setPrototypeOf({}); - }).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments"); - }); + expect(() => { + Object.setPrototypeOf({}); + }).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments"); + }); - test("prototype must be an object", () => { - expect(() => { - Object.setPrototypeOf({}, "foo"); - }).toThrowWithMessage(TypeError, "Prototype must be an object or null"); - }); + test("prototype must be an object", () => { + expect(() => { + Object.setPrototypeOf({}, "foo"); + }).toThrowWithMessage(TypeError, "Prototype must be an object or null"); + }); - test("non-extensible target", () => { - let o = {}; - let p = {}; - Object.setPrototypeOf(o, p); - Object.preventExtensions(o); + test("non-extensible target", () => { + let o = {}; + let p = {}; + Object.setPrototypeOf(o, p); + Object.preventExtensions(o); - expect(() => { - Object.setPrototypeOf(o, {}); - }).toThrowWithMessage(TypeError, "Object's [[SetPrototypeOf]] method returned false"); + expect(() => { + Object.setPrototypeOf(o, {}); + }).toThrowWithMessage(TypeError, "Object's [[SetPrototypeOf]] method returned false"); - expect(Object.setPrototypeOf(o, p)).toBe(o); - }); + expect(Object.setPrototypeOf(o, p)).toBe(o); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.values.js b/Libraries/LibJS/Tests/builtins/Object/Object.values.js index da3e3a635c..8ae5f68af2 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.values.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.values.js @@ -1,44 +1,46 @@ describe("correct behavior", () => { - test("lengths", () => { - expect(Object.values).toHaveLength(1); - expect(Object.values(true)).toHaveLength(0); - expect(Object.values(45)).toHaveLength(0); - expect(Object.values(-998)).toHaveLength(0); - expect(Object.values("abcd")).toHaveLength(4); - expect(Object.values([1, 2, 3])).toHaveLength(3); - expect(Object.values({ a: 1, b: 2, c: 3 })).toHaveLength(3); - }); + test("lengths", () => { + expect(Object.values).toHaveLength(1); + expect(Object.values(true)).toHaveLength(0); + expect(Object.values(45)).toHaveLength(0); + expect(Object.values(-998)).toHaveLength(0); + expect(Object.values("abcd")).toHaveLength(4); + expect(Object.values([1, 2, 3])).toHaveLength(3); + expect(Object.values({ a: 1, b: 2, c: 3 })).toHaveLength(3); + }); - test("object argument", () => { - let values = Object.values({ foo: 1, bar: 2, baz: 3 }); - expect(values).toEqual([1, 2, 3]); - }); + test("object argument", () => { + let values = Object.values({ foo: 1, bar: 2, baz: 3 }); + expect(values).toEqual([1, 2, 3]); + }); - test("array argument", () => { - let values = Object.values(["a", "b", "c"]); - expect(values).toEqual(["a", "b", "c"]); - }); + test("array argument", () => { + let values = Object.values(["a", "b", "c"]); + expect(values).toEqual(["a", "b", "c"]); + }); - test("ignores non-enumerable properties", () => { - let obj = { foo: 1 }; - Object.defineProperty(obj, 'getFoo', { - value: function() { return this.foo; }, - }); - let values = Object.values(obj); - expect(values).toEqual([1]); + test("ignores non-enumerable properties", () => { + let obj = { foo: 1 }; + Object.defineProperty(obj, "getFoo", { + value: function () { + return this.foo; + }, }); + let values = Object.values(obj); + expect(values).toEqual([1]); + }); }); describe("errors", () => { - test("null argument", () => { - expect(() => { - Object.values(null); - }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); - }); + test("null argument", () => { + expect(() => { + Object.values(null); + }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); + }); - test("undefined argument", () => { - expect(() => { - Object.values(undefined); - }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); - }); + test("undefined argument", () => { + expect(() => { + Object.values(undefined); + }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-apply.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-apply.js index a22d9729b4..4c2664e927 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-apply.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-apply.js @@ -1,37 +1,36 @@ describe("[[Call]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - let p = new Proxy(() => 5, { apply: null }); - expect(p()).toBe(5); - p = new Proxy(() => 5, { apply: undefined }); - expect(p()).toBe(5); - p = new Proxy(() => 5, {}); - expect(p()).toBe(5); - }); + test("forwarding when not defined in handler", () => { + let p = new Proxy(() => 5, { apply: null }); + expect(p()).toBe(5); + p = new Proxy(() => 5, { apply: undefined }); + expect(p()).toBe(5); + p = new Proxy(() => 5, {}); + expect(p()).toBe(5); + }); - test("correct arguments supplied to trap", () => { - const f = (a, b) => a + b; - const handler = { - apply(target, this_, arguments) { - expect(target).toBe(f); - expect(this_).toBe(handler); - if (arguments[2]) - return arguments[0] * arguments[1]; - return f(...arguments); - }, - }; - p = new Proxy(f, handler); + test("correct arguments supplied to trap", () => { + const f = (a, b) => a + b; + const handler = { + apply(target, this_, arguments) { + expect(target).toBe(f); + expect(this_).toBe(handler); + if (arguments[2]) return arguments[0] * arguments[1]; + return f(...arguments); + }, + }; + p = new Proxy(f, handler); - expect(p(2, 4)).toBe(6); - expect(p(2, 4, true)).toBe(8); - }); + expect(p(2, 4)).toBe(6); + expect(p(2, 4, true)).toBe(8); + }); }); describe("[[Call]] invariants", () => { - test("target must have a [[Call]] slot", () => { - [{}, [], new Proxy({}, {})].forEach(item => { - expect(() => { - new Proxy(item, {})(); - }).toThrowWithMessage(TypeError, "[object ProxyObject] is not a function"); - }); + test("target must have a [[Call]] slot", () => { + [{}, [], new Proxy({}, {})].forEach(item => { + expect(() => { + new Proxy(item, {})(); + }).toThrowWithMessage(TypeError, "[object ProxyObject] is not a function"); }); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-construct.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-construct.js index b5ff0beda7..834dc8abc3 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-construct.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-construct.js @@ -1,62 +1,72 @@ describe("[[Construct]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - let p = new Proxy(function() { this.x = 5; }, { construct: null }); - expect((new p).x).toBe(5); - p = new Proxy(function() { this.x = 5; }, { construct: undefined }); - expect((new p).x).toBe(5); - p = new Proxy(function() { this.x = 5; }, {}); - expect((new p).x).toBe(5); - }); + test("forwarding when not defined in handler", () => { + let p = new Proxy( + function () { + this.x = 5; + }, + { construct: null } + ); + expect(new p().x).toBe(5); + p = new Proxy( + function () { + this.x = 5; + }, + { construct: undefined } + ); + expect(new p().x).toBe(5); + p = new Proxy(function () { + this.x = 5; + }, {}); + expect(new p().x).toBe(5); + }); - test("trapping 'new'", () => { - function f(value) { - this.x = value; - } + test("trapping 'new'", () => { + function f(value) { + this.x = value; + } - let p; - const handler = { - construct(target, arguments, newTarget) { - expect(target).toBe(f); - expect(newTarget).toBe(p); - if (arguments[1]) - return Reflect.construct(target, [arguments[0] * 2], newTarget); - return Reflect.construct(target, arguments, newTarget); - }, - }; - p = new Proxy(f, handler); + let p; + const handler = { + construct(target, arguments, newTarget) { + expect(target).toBe(f); + expect(newTarget).toBe(p); + if (arguments[1]) return Reflect.construct(target, [arguments[0] * 2], newTarget); + return Reflect.construct(target, arguments, newTarget); + }, + }; + p = new Proxy(f, handler); - expect(new p(15).x).toBe(15); - expect(new p(15, true).x).toBe(30); - }); + expect(new p(15).x).toBe(15); + expect(new p(15, true).x).toBe(30); + }); - test("trapping Reflect.construct", () => { - function f(value) { - this.x = value; - } + test("trapping Reflect.construct", () => { + function f(value) { + this.x = value; + } - let p; - function theNewTarget() {}; - const handler = { - construct(target, arguments, newTarget) { - expect(target).toBe(f); - expect(newTarget).toBe(theNewTarget); - if (arguments[1]) - return Reflect.construct(target, [arguments[0] * 2], newTarget); - return Reflect.construct(target, arguments, newTarget); - }, - }; - p = new Proxy(f, handler); + let p; + function theNewTarget() {} + const handler = { + construct(target, arguments, newTarget) { + expect(target).toBe(f); + expect(newTarget).toBe(theNewTarget); + if (arguments[1]) return Reflect.construct(target, [arguments[0] * 2], newTarget); + return Reflect.construct(target, arguments, newTarget); + }, + }; + p = new Proxy(f, handler); - Reflect.construct(p, [15], theNewTarget); - }); + Reflect.construct(p, [15], theNewTarget); + }); }); describe("[[Construct]] invariants", () => { - test("target must have a [[Construct]] slot", () => { - [{}, [], new Proxy({}, {})].forEach(item => { - expect(() => { - new (new Proxy(item, {})); - }).toThrowWithMessage(TypeError, "[object ProxyObject] is not a constructor"); - }); + test("target must have a [[Construct]] slot", () => { + [{}, [], new Proxy({}, {})].forEach(item => { + expect(() => { + new new Proxy(item, {})(); + }).toThrowWithMessage(TypeError, "[object ProxyObject] is not a constructor"); }); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js index c09338c457..c5fffa3239 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js @@ -1,110 +1,133 @@ describe("[[DefineProperty]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - let p = new Proxy({}, { defineProperty: null }); - expect(Object.defineProperty(p, "foo", {})).toBe(p); - p = new Proxy({}, { defineProperty: undefined }); - expect(Object.defineProperty(p, "foo", {})).toBe(p); - p = new Proxy({}, {}); - expect(Object.defineProperty(p, "foo", {})).toBe(p); + test("forwarding when not defined in handler", () => { + let p = new Proxy({}, { defineProperty: null }); + expect(Object.defineProperty(p, "foo", {})).toBe(p); + p = new Proxy({}, { defineProperty: undefined }); + expect(Object.defineProperty(p, "foo", {})).toBe(p); + p = new Proxy({}, {}); + expect(Object.defineProperty(p, "foo", {})).toBe(p); + }); + + test("correct arguments passed to trap", () => { + let o = {}; + p = new Proxy(o, { + defineProperty(target, name, descriptor) { + expect(target).toBe(o); + expect(name).toBe("foo"); + expect(descriptor.configurable).toBeTrue(); + expect(descriptor.enumerable).toBeUndefined(); + expect(descriptor.writable).toBeTrue(); + expect(descriptor.value).toBe(10); + expect(descriptor.get).toBeUndefined(); + expect(descriptor.set).toBeUndefined(); + return true; + }, }); - test("correct arguments passed to trap", () => { - let o = {}; - p = new Proxy(o, { - defineProperty(target, name, descriptor) { - expect(target).toBe(o); - expect(name).toBe("foo"); - expect(descriptor.configurable).toBeTrue(); - expect(descriptor.enumerable).toBeUndefined(); - expect(descriptor.writable).toBeTrue(); - expect(descriptor.value).toBe(10); - expect(descriptor.get).toBeUndefined(); - expect(descriptor.set).toBeUndefined(); - return true; - }, - }); + Object.defineProperty(p, "foo", { configurable: true, writable: true, value: 10 }); + }); - Object.defineProperty(p, "foo", { configurable: true, writable: true, value: 10 }); + test("optionally ignoring the define call", () => { + let o = {}; + let p = new Proxy(o, { + defineProperty(target, name, descriptor) { + if (target[name] === undefined) Object.defineProperty(target, name, descriptor); + return true; + }, }); - test("optionally ignoring the define call", () => { - let o = {}; - let p = new Proxy(o, { - defineProperty(target, name, descriptor) { - if (target[name] === undefined) - Object.defineProperty(target, name, descriptor); - return true; - }, - }); - - Object.defineProperty(p, "foo", { value: 10, enumerable: true, configurable: false, writable: true }); - expect(p).toHaveEnumerableProperty("foo"); - expect(p).not.toHaveConfigurableProperty("foo"); - expect(p).toHaveWritableProperty("foo"); - expect(p).toHaveValueProperty("foo", 10); - expect(p).not.toHaveGetterProperty("foo"); - expect(p).not.toHaveSetterProperty("foo"); - - Object.defineProperty(p, "foo", { value: 20, enumerable: true, configurable: false, writable: true }); - expect(p).toHaveEnumerableProperty("foo"); - expect(p).not.toHaveConfigurableProperty("foo"); - expect(p).toHaveWritableProperty("foo"); - expect(p).toHaveValueProperty("foo", 10); - expect(p).not.toHaveGetterProperty("foo"); - expect(p).not.toHaveSetterProperty("foo"); + Object.defineProperty(p, "foo", { + value: 10, + enumerable: true, + configurable: false, + writable: true, }); + expect(p).toHaveEnumerableProperty("foo"); + expect(p).not.toHaveConfigurableProperty("foo"); + expect(p).toHaveWritableProperty("foo"); + expect(p).toHaveValueProperty("foo", 10); + expect(p).not.toHaveGetterProperty("foo"); + expect(p).not.toHaveSetterProperty("foo"); + + Object.defineProperty(p, "foo", { + value: 20, + enumerable: true, + configurable: false, + writable: true, + }); + expect(p).toHaveEnumerableProperty("foo"); + expect(p).not.toHaveConfigurableProperty("foo"); + expect(p).toHaveWritableProperty("foo"); + expect(p).toHaveValueProperty("foo", 10); + expect(p).not.toHaveGetterProperty("foo"); + expect(p).not.toHaveSetterProperty("foo"); + }); }); describe("[[DefineProperty]] invariants", () => { - test("trap can't return false", () => { - let p = new Proxy({}, { - defineProperty() { return false; } - }); + test("trap can't return false", () => { + let p = new Proxy( + {}, + { + defineProperty() { + return false; + }, + } + ); - expect(() => { - Object.defineProperty(p, "foo", {}); - }).toThrowWithMessage(TypeError, "Object's [[DefineProperty]] method returned false"); + expect(() => { + Object.defineProperty(p, "foo", {}); + }).toThrowWithMessage(TypeError, "Object's [[DefineProperty]] method returned false"); + }); + + test("trap cannot return true for a non-extensible target if the property does not exist", () => { + let o = {}; + Object.preventExtensions(o); + let p = new Proxy(o, { + defineProperty() { + return true; + }, }); - test("trap cannot return true for a non-extensible target if the property does not exist", () => { - let o = {}; - Object.preventExtensions(o); - let p = new Proxy(o, { - defineProperty() { - return true; - } - }); + expect(() => { + Object.defineProperty(p, "foo", {}); + }).toThrowWithMessage( + TypeError, + "Proxy handler's defineProperty trap violates invariant: a property cannot be reported as being defined if the property does not exist on the target and the target is non-extensible" + ); + }); - expect(() => { - Object.defineProperty(p, "foo", {}); - }).toThrowWithMessage(TypeError, "Proxy handler's defineProperty trap violates invariant: a property cannot be reported as being defined if the property does not exist on the target and the target is non-extensible"); + test("trap cannot return true for a non-configurable property if it doesn't already exist on the target", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: 10, configurable: true }); + let p = new Proxy(o, { + defineProperty() { + return true; + }, }); - test("trap cannot return true for a non-configurable property if it doesn't already exist on the target", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 10, configurable: true }); - let p = new Proxy(o, { - defineProperty() { - return true; - }, - }); + expect(() => { + Object.defineProperty(p, "bar", { value: 6, configurable: false }); + }).toThrowWithMessage( + TypeError, + "Proxy handler's defineProperty trap violates invariant: a property cannot be defined as non-configurable if it does not already exist on the target object" + ); + }); - expect(() => { - Object.defineProperty(p, "bar", { value: 6, configurable: false }); - }).toThrowWithMessage(TypeError, "Proxy handler's defineProperty trap violates invariant: a property cannot be defined as non-configurable if it does not already exist on the target object"); + test("trap cannot return true for a non-configurable property if it already exists as a configurable property", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: 10, configurable: true }); + let p = new Proxy(o, { + defineProperty() { + return true; + }, }); - test("trap cannot return true for a non-configurable property if it already exists as a configurable property", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 10, configurable: true }); - let p = new Proxy(o, { - defineProperty() { - return true; - }, - }); - - expect(() => { - Object.defineProperty(p, "foo", { value: 6, configurable: false }); - }).toThrowWithMessage(TypeError, "Proxy handler's defineProperty trap violates invariant: a property cannot be defined as non-configurable if it already exists on the target object as a configurable property"); - }) + expect(() => { + Object.defineProperty(p, "foo", { value: 6, configurable: false }); + }).toThrowWithMessage( + TypeError, + "Proxy handler's defineProperty trap violates invariant: a property cannot be defined as non-configurable if it already exists on the target object as a configurable property" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js index 8e8f445059..2ec4ae4a28 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js @@ -1,56 +1,58 @@ describe("[[Delete]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - expect(delete (new Proxy({}, { deleteProperty: undefined })).foo).toBeTrue(); - expect(delete (new Proxy({}, { deleteProperty: null })).foo).toBeTrue(); - expect(delete (new Proxy({}, {})).foo).toBeTrue(); + test("forwarding when not defined in handler", () => { + expect(delete new Proxy({}, { deleteProperty: undefined }).foo).toBeTrue(); + expect(delete new Proxy({}, { deleteProperty: null }).foo).toBeTrue(); + expect(delete new Proxy({}, {}).foo).toBeTrue(); + }); + + test("correct arguments supplied to trap", () => { + let o = {}; + let p = new Proxy(o, { + deleteProperty(target, property) { + expect(target).toBe(o); + expect(property).toBe("foo"); + return true; + }, }); - test("correct arguments supplied to trap", () => { - let o = {}; - let p = new Proxy(o, { - deleteProperty(target, property) { - expect(target).toBe(o); - expect(property).toBe("foo"); - return true; - } - }); + delete p.foo; + }); - delete p.foo; + test("conditional deletion", () => { + o = { foo: 1, bar: 2 }; + p = new Proxy(o, { + deleteProperty(target, property) { + if (property === "foo") { + delete target[property]; + return true; + } + return false; + }, }); - test("conditional deletion", () => { - o = { foo: 1, bar: 2 }; - p = new Proxy(o, { - deleteProperty(target, property) { - if (property === "foo") { - delete target[property]; - return true; - } - return false; - } - }); + expect(delete p.foo).toBeTrue(); + expect(delete p.bar).toBeFalse(); - expect(delete p.foo).toBeTrue(); - expect(delete p.bar).toBeFalse(); - - expect(o.foo).toBe(undefined); - expect(o.bar).toBe(2); - }); + expect(o.foo).toBeUndefined(); + expect(o.bar).toBe(2); + }); }); - describe("[[Delete]] invariants", () => { - test("cannot report a non-configurable own property as deleted", () => { - let o = {}; - Object.defineProperty(o, "foo", { configurable: false }); - let p = new Proxy(o, { - deleteProperty() { - return true; - }, - }); - - expect(() => { - delete p.foo; - }).toThrowWithMessage(TypeError, "Proxy handler's deleteProperty trap violates invariant: cannot report a non-configurable own property of the target as deleted"); + test("cannot report a non-configurable own property as deleted", () => { + let o = {}; + Object.defineProperty(o, "foo", { configurable: false }); + let p = new Proxy(o, { + deleteProperty() { + return true; + }, }); + + expect(() => { + delete p.foo; + }).toThrowWithMessage( + TypeError, + "Proxy handler's deleteProperty trap violates invariant: cannot report a non-configurable own property of the target as deleted" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-get.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-get.js index b2d6e94ec1..02505c9d49 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-get.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-get.js @@ -1,76 +1,82 @@ describe("[[Get]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - expect((new Proxy({}, { get: undefined })).foo).toBeUndefined(); - expect((new Proxy({}, { get: null })).foo).toBeUndefined(); - expect((new Proxy({}, {})).foo).toBeUndefined(); + test("forwarding when not defined in handler", () => { + expect(new Proxy({}, { get: undefined }).foo).toBeUndefined(); + expect(new Proxy({}, { get: null }).foo).toBeUndefined(); + expect(new Proxy({}, {}).foo).toBeUndefined(); + }); + + test("correct arguments supplied to trap", () => { + let o = {}; + let p = new Proxy(o, { + get(target, property, receiver) { + expect(target).toBe(o); + expect(property).toBe("foo"); + expect(receiver).toBe(p); + }, }); - test("correct arguments supplied to trap", () => { - let o = {}; - let p = new Proxy(o, { - get(target, property, receiver) { - expect(target).toBe(o); - expect(property).toBe("foo"); - expect(receiver).toBe(p); - }, - }); + p.foo; + }); - p.foo; + test("conditional return", () => { + let o = { foo: 1 }; + let p = new Proxy(o, { + get(target, property, receiver) { + if (property === "bar") { + return 2; + } else if (property === "baz") { + return receiver.qux; + } else if (property === "qux") { + return 3; + } + return target[property]; + }, }); - test("conditional return", () => { - let o = { foo: 1 }; - let p = new Proxy(o, { - get(target, property, receiver) { - if (property === "bar") { - return 2; - } else if (property === "baz") { - return receiver.qux; - } else if (property === "qux") { - return 3; - } - return target[property]; - } - }); - - expect(p.foo).toBe(1); - expect(p.bar).toBe(2); - expect(p.baz).toBe(3); - expect(p.qux).toBe(3); - expect(p.test).toBeUndefined(); - }); + expect(p.foo).toBe(1); + expect(p.bar).toBe(2); + expect(p.baz).toBe(3); + expect(p.qux).toBe(3); + expect(p.test).toBeUndefined(); + }); }); describe("[[Get]] invariants", () => { - test("returned value must match the target property value if the property is non-configurable and non-writable", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 5, configurable: false, writable: true }); - Object.defineProperty(o, "bar", { value: 10, configurable: false, writable: false }); + test("returned value must match the target property value if the property is non-configurable and non-writable", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: 5, configurable: false, writable: true }); + Object.defineProperty(o, "bar", { value: 10, configurable: false, writable: false }); - let p = new Proxy(o, { - get() { - return 8; - }, - }); - - expect(p.foo).toBe(8); - expect(() => { - p.bar; - }).toThrowWithMessage(TypeError, "Proxy handler's get trap violates invariant: the returned value must match the value on the target if the property exists on the target as a non-writable, non-configurable own data property"); + let p = new Proxy(o, { + get() { + return 8; + }, }); - test("returned value must be undefined if the property is a non-configurable accessor with no getter", () => { - let o = {}; - Object.defineProperty(o, "foo", { configurable: false, set(_) {} }); + expect(p.foo).toBe(8); + expect(() => { + p.bar; + }).toThrowWithMessage( + TypeError, + "Proxy handler's get trap violates invariant: the returned value must match the value on the target if the property exists on the target as a non-writable, non-configurable own data property" + ); + }); - let p = new Proxy(o, { - get() { - return 8; - }, - }); + test("returned value must be undefined if the property is a non-configurable accessor with no getter", () => { + let o = {}; + Object.defineProperty(o, "foo", { configurable: false, set(_) {} }); - expect(() => { - p.foo; - }).toThrowWithMessage(TypeError, "Proxy handler's get trap violates invariant: the returned value must be undefined if the property exists on the target as a non-configurable accessor property with an undefined get attribute"); - }) + let p = new Proxy(o, { + get() { + return 8; + }, + }); + + expect(() => { + p.foo; + }).toThrowWithMessage( + TypeError, + "Proxy handler's get trap violates invariant: the returned value must be undefined if the property exists on the target as a non-configurable accessor property with an undefined get attribute" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js index c32042fd26..78f7061daa 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js @@ -1,145 +1,212 @@ describe("[Call][GetOwnProperty]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - expect(Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: null }), "a")).toBeUndefined(); - expect(Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: undefined }), "a")).toBeUndefined(); - expect(Object.getOwnPropertyDescriptor(new Proxy({}, {}), "a")).toBeUndefined(); + test("forwarding when not defined in handler", () => { + expect( + Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: null }), "a") + ).toBeUndefined(); + expect( + Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: undefined }), "a") + ).toBeUndefined(); + expect(Object.getOwnPropertyDescriptor(new Proxy({}, {}), "a")).toBeUndefined(); + }); + + test("correct arguments supplied to trap", () => { + let o = {}; + let p = new Proxy(o, { + getOwnPropertyDescriptor(target, property) { + expect(target).toBe(o); + expect(property).toBe("foo"); + }, }); - test("correct arguments supplied to trap", () => { - let o = {}; - let p = new Proxy(o, { - getOwnPropertyDescriptor(target, property) { - expect(target).toBe(o); - expect(property).toBe("foo"); - } - }); + Object.getOwnPropertyDescriptor(p, "foo"); + }); - Object.getOwnPropertyDescriptor(p, "foo"); + test("conditional returned descriptor", () => { + let o = { foo: "bar" }; + Object.defineProperty(o, "baz", { + value: "qux", + enumerable: false, + configurable: true, + writable: false, }); - test("conditional returned descriptor", () => { - let o = { foo: "bar" }; - Object.defineProperty(o, "baz", { value: "qux", enumerable: false, configurable: true, writable: false }); - - let p = new Proxy(o, { - getOwnPropertyDescriptor(target, property) { - if (property === "baz") - return Object.getOwnPropertyDescriptor(target, "baz"); - return { value: target[property], enumerable: false, configurable: true, writable: true }; - } - }); - - expect(p).toHaveConfigurableProperty("baz"); - expect(p).not.toHaveEnumerableProperty("baz"); - expect(p).not.toHaveWritableProperty("baz"); - expect(p).toHaveValueProperty("baz", "qux"); - expect(p).not.toHaveGetterProperty("baz"); - expect(p).not.toHaveSetterProperty("baz"); - - d = Object.getOwnPropertyDescriptor(p, "foo"); - - expect(p).toHaveConfigurableProperty("foo"); - expect(p).not.toHaveEnumerableProperty("foo"); - expect(p).toHaveWritableProperty("foo"); - expect(p).toHaveValueProperty("foo", "bar"); - expect(p).not.toHaveGetterProperty("foo"); - expect(p).not.toHaveSetterProperty("foo"); + let p = new Proxy(o, { + getOwnPropertyDescriptor(target, property) { + if (property === "baz") return Object.getOwnPropertyDescriptor(target, "baz"); + return { value: target[property], enumerable: false, configurable: true, writable: true }; + }, }); + + expect(p).toHaveConfigurableProperty("baz"); + expect(p).not.toHaveEnumerableProperty("baz"); + expect(p).not.toHaveWritableProperty("baz"); + expect(p).toHaveValueProperty("baz", "qux"); + expect(p).not.toHaveGetterProperty("baz"); + expect(p).not.toHaveSetterProperty("baz"); + + d = Object.getOwnPropertyDescriptor(p, "foo"); + + expect(p).toHaveConfigurableProperty("foo"); + expect(p).not.toHaveEnumerableProperty("foo"); + expect(p).toHaveWritableProperty("foo"); + expect(p).toHaveValueProperty("foo", "bar"); + expect(p).not.toHaveGetterProperty("foo"); + expect(p).not.toHaveSetterProperty("foo"); + }); }); describe("[[GetOwnProperty]] invariants", () => { - test("must return an object or undefined", () => { - expect(() => { - Object.getOwnPropertyDescriptor(new Proxy({}, { - getOwnPropertyDescriptor() { - return 1; - }, - })); - }).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: must return an object or undefined"); - }); - - test("cannot return undefined for a non-configurable property", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 10, configurable: false }); - - let p = new Proxy(o, { + test("must return an object or undefined", () => { + expect(() => { + Object.getOwnPropertyDescriptor( + new Proxy( + {}, + { getOwnPropertyDescriptor() { - return undefined; + return 1; }, - }); + } + ) + ); + }).toThrowWithMessage( + TypeError, + "Proxy handler's getOwnPropertyDescriptor trap violates invariant: must return an object or undefined" + ); + }); - expect(Object.getOwnPropertyDescriptor(p, "bar")).toBeUndefined(); + test("cannot return undefined for a non-configurable property", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: 10, configurable: false }); - expect(() => { - Object.getOwnPropertyDescriptor(p, "foo"); - }).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot return undefined for a property on the target which is a non-configurable property"); + let p = new Proxy(o, { + getOwnPropertyDescriptor() { + return undefined; + }, }); - test("cannot return undefined for an existing property if the target is non-extensible", () => { - let o = {}; - Object.defineProperty(o, "baz", { value: 20, configurable: true, writable: true, enumerable: true }); - Object.preventExtensions(o); + expect(Object.getOwnPropertyDescriptor(p, "bar")).toBeUndefined(); - let p = new Proxy(o, { - getOwnPropertyDescriptor() { - return undefined; - }, - }); + expect(() => { + Object.getOwnPropertyDescriptor(p, "foo"); + }).toThrowWithMessage( + TypeError, + "Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot return undefined for a property on the target which is a non-configurable property" + ); + }); - expect(() => { - Object.getOwnPropertyDescriptor(p, "baz"); - }).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot report a property as being undefined if it exists as an own property of the target and the target is non-extensible"); + test("cannot return undefined for an existing property if the target is non-extensible", () => { + let o = {}; + Object.defineProperty(o, "baz", { + value: 20, + configurable: true, + writable: true, + enumerable: true, + }); + Object.preventExtensions(o); + + let p = new Proxy(o, { + getOwnPropertyDescriptor() { + return undefined; + }, }); - test("invalid property descriptors", () => { - let o = {}; - Object.defineProperty(o, "v1", { value: 10, configurable: false }); - Object.defineProperty(o, "v2", { value: 10, configurable: false, enumerable: true }); - Object.defineProperty(o, "v3", { configurable: false, get() { return 1; } }); - Object.defineProperty(o, "v4", { value: 10, configurable: false, writable: false, enumerable: true }); + expect(() => { + Object.getOwnPropertyDescriptor(p, "baz"); + }).toThrowWithMessage( + TypeError, + "Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot report a property as being undefined if it exists as an own property of the target and the target is non-extensible" + ); + }); - expect(() => { - Object.getOwnPropertyDescriptor(new Proxy(o, { - getOwnPropertyDescriptor() { - return { configurable: true }; - }, - }), "v1"); - }).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"); - - expect(() => { - Object.getOwnPropertyDescriptor(new Proxy(o, { - getOwnPropertyDescriptor() { - return { enumerable: false }; - }, - }), "v2"); - }).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"); - - expect(() => { - Object.getOwnPropertyDescriptor(new Proxy(o, { - getOwnPropertyDescriptor() { - return { value: 10 }; - }, - }), "v3"); - }).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"); - - expect(() => { - Object.getOwnPropertyDescriptor(new Proxy(o, { - getOwnPropertyDescriptor() { - return { value: 10, writable: true }; - }, - }), "v4"); - }).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"); + test("invalid property descriptors", () => { + let o = {}; + Object.defineProperty(o, "v1", { value: 10, configurable: false }); + Object.defineProperty(o, "v2", { value: 10, configurable: false, enumerable: true }); + Object.defineProperty(o, "v3", { + configurable: false, + get() { + return 1; + }, + }); + Object.defineProperty(o, "v4", { + value: 10, + configurable: false, + writable: false, + enumerable: true, }); - test("cannot report a property as non-configurable if it does not exist or is non-configurable", () => { - let o = {}; - Object.defineProperty(o, "v", { configurable: true }); - expect(() => { - Object.getOwnPropertyDescriptor(new Proxy(o, { - getOwnPropertyDescriptor() { - return { configurable: false }; - }, - }), "v"); - }).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot report target's property as non-configurable if the property does not exist, or if it is configurable"); - }); + expect(() => { + Object.getOwnPropertyDescriptor( + new Proxy(o, { + getOwnPropertyDescriptor() { + return { configurable: true }; + }, + }), + "v1" + ); + }).toThrowWithMessage( + TypeError, + "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target" + ); + + expect(() => { + Object.getOwnPropertyDescriptor( + new Proxy(o, { + getOwnPropertyDescriptor() { + return { enumerable: false }; + }, + }), + "v2" + ); + }).toThrowWithMessage( + TypeError, + "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target" + ); + + expect(() => { + Object.getOwnPropertyDescriptor( + new Proxy(o, { + getOwnPropertyDescriptor() { + return { value: 10 }; + }, + }), + "v3" + ); + }).toThrowWithMessage( + TypeError, + "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target" + ); + + expect(() => { + Object.getOwnPropertyDescriptor( + new Proxy(o, { + getOwnPropertyDescriptor() { + return { value: 10, writable: true }; + }, + }), + "v4" + ); + }).toThrowWithMessage( + TypeError, + "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target" + ); + }); + + test("cannot report a property as non-configurable if it does not exist or is non-configurable", () => { + let o = {}; + Object.defineProperty(o, "v", { configurable: true }); + expect(() => { + Object.getOwnPropertyDescriptor( + new Proxy(o, { + getOwnPropertyDescriptor() { + return { configurable: false }; + }, + }), + "v" + ); + }).toThrowWithMessage( + TypeError, + "Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot report target's property as non-configurable if the property does not exist, or if it is configurable" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getPrototypeOf.js index 7690a2beb6..5cce8c6c48 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getPrototypeOf.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getPrototypeOf.js @@ -1,81 +1,95 @@ describe("[[GetPrototypeOf]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - let proto = {}; - let o = {}; - Object.setPrototypeOf(o, proto); + test("forwarding when not defined in handler", () => { + let proto = {}; + let o = {}; + Object.setPrototypeOf(o, proto); - let p = new Proxy(o, { prototype: null }); - expect(Object.getPrototypeOf(p)).toBe(proto); - p = new Proxy(o, { apply: undefined }); - expect(Object.getPrototypeOf(p)).toBe(proto); - p = new Proxy(o, {}); - expect(Object.getPrototypeOf(p)).toBe(proto); + let p = new Proxy(o, { prototype: null }); + expect(Object.getPrototypeOf(p)).toBe(proto); + p = new Proxy(o, { apply: undefined }); + expect(Object.getPrototypeOf(p)).toBe(proto); + p = new Proxy(o, {}); + expect(Object.getPrototypeOf(p)).toBe(proto); + }); + + test("correct arguments supplied to trap", () => { + let o = {}; + let p = new Proxy(o, { + getPrototypeOf(target) { + expect(target).toBe(o); + return null; + }, }); - test("correct arguments supplied to trap", () => { - let o = {}; - let p = new Proxy(o, { - getPrototypeOf(target) { - expect(target).toBe(o); - return null; - } - }); + Object.getPrototypeOf(p); + }); - Object.getPrototypeOf(p); + test("conditional return", () => { + let o = {}; + let p = new Proxy(o, { + getPrototypeOf(target) { + if (target.foo) return { bar: 1 }; + return { bar: 2 }; + }, }); - test("conditional return", () => { - let o = {}; - let p = new Proxy(o, { - getPrototypeOf(target) { - if (target.foo) - return { bar: 1 }; - return { bar: 2 }; - }, - }); + expect(Object.getPrototypeOf(p).bar).toBe(2); + o.foo = 20; + expect(Object.getPrototypeOf(p).bar).toBe(1); + }); - expect(Object.getPrototypeOf(p).bar).toBe(2); - o.foo = 20 - expect(Object.getPrototypeOf(p).bar).toBe(1); + test("non-extensible target", () => { + let o = {}; + let proto = { foo: "bar" }; + Object.setPrototypeOf(o, proto); + Object.preventExtensions(o); + + p = new Proxy(o, { + getPrototypeOf() { + return proto; + }, }); - test("non-extensible target", () => { - let o = {}; - let proto = { foo: "bar" }; - Object.setPrototypeOf(o, proto); - Object.preventExtensions(o); - - p = new Proxy(o, { - getPrototypeOf() { - return proto; - } - }); - - expect(Object.getPrototypeOf(p).foo).toBe("bar"); - }); + expect(Object.getPrototypeOf(p).foo).toBe("bar"); + }); }); describe("[[GetPrototypeOf]] invariants", () => { - test("must return an object or null", () => { - expect(() => { - Object.getPrototypeOf(new Proxy({}, { getPrototypeOf() { return 1; } })); - }).toThrowWithMessage(TypeError, "Proxy handler's getPrototypeOf trap violates invariant: must return an object or null"); + test("must return an object or null", () => { + expect(() => { + Object.getPrototypeOf( + new Proxy( + {}, + { + getPrototypeOf() { + return 1; + }, + } + ) + ); + }).toThrowWithMessage( + TypeError, + "Proxy handler's getPrototypeOf trap violates invariant: must return an object or null" + ); + }); + + test("different return object for non-extensible target", () => { + let o = {}; + let proto = {}; + Object.setPrototypeOf(o, proto); + Object.preventExtensions(o); + + let p = new Proxy(o, { + getPrototypeOf(target) { + return { baz: "qux" }; + }, }); - test("different return object for non-extensible target", () => { - let o = {}; - let proto = {}; - Object.setPrototypeOf(o, proto); - Object.preventExtensions(o); - - let p = new Proxy(o, { - getPrototypeOf(target) { - return { baz: "qux" }; - } - }); - - expect(() => { - Object.getPrototypeOf(p); - }).toThrowWithMessage(TypeError, "Proxy handler's getPrototypeOf trap violates invariant: cannot return a different prototype object for a non-extensible target"); - }); + expect(() => { + Object.getPrototypeOf(p); + }).toThrowWithMessage( + TypeError, + "Proxy handler's getPrototypeOf trap violates invariant: cannot return a different prototype object for a non-extensible target" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js index 0d231f7436..d43ceba970 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js @@ -1,70 +1,74 @@ describe("[[Has]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - expect("foo" in new Proxy({}, { has: null })).toBeFalse(); - expect("foo" in new Proxy({}, { has: undefined})).toBeFalse(); - expect("foo" in new Proxy({}, {})).toBeFalse(); + test("forwarding when not defined in handler", () => { + expect("foo" in new Proxy({}, { has: null })).toBeFalse(); + expect("foo" in new Proxy({}, { has: undefined })).toBeFalse(); + expect("foo" in new Proxy({}, {})).toBeFalse(); + }); + + test("correct arguments supplied to trap", () => { + let o = {}; + let p = new Proxy(o, { + has(target, prop) { + expect(target).toBe(o); + expect(prop).toBe("foo"); + return true; + }, }); - test("correct arguments supplied to trap", () => { - let o = {}; - let p = new Proxy(o, { - has(target, prop) { - expect(target).toBe(o); - expect(prop).toBe("foo"); - return true; - } - }); + "foo" in p; + }); - "foo" in p; + test("conditional return", () => { + let o = {}; + let p = new Proxy(o, { + has(target, prop) { + if (target.checkedFoo) return true; + if (prop === "foo") target.checkedFoo = true; + return false; + }, }); - test("conditional return", () => { - let o = {}; - let p = new Proxy(o, { - has(target, prop) { - if (target.checkedFoo) - return true; - if (prop === "foo") - target.checkedFoo = true; - return false; - } - }); - - expect("foo" in p).toBeFalse(); - expect("foo" in p).toBeTrue(); - }); + expect("foo" in p).toBeFalse(); + expect("foo" in p).toBeTrue(); + }); }); describe("[[Has]] invariants", () => { - test("cannot return false if the property exists and is non-configurable", () => { - let o = {}; - Object.defineProperty(o, "foo", { configurable: false }); + test("cannot return false if the property exists and is non-configurable", () => { + let o = {}; + Object.defineProperty(o, "foo", { configurable: false }); - p = new Proxy(o, { - has() { - return false; - } - }); - - expect(() => { - "foo" in p; - }).toThrowWithMessage(TypeError, "Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target as a non-configurable property"); + p = new Proxy(o, { + has() { + return false; + }, }); - test("cannot return false if the property exists and the target is non-extensible", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 10, configurable: true }); + expect(() => { + "foo" in p; + }).toThrowWithMessage( + TypeError, + "Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target as a non-configurable property" + ); + }); - let p = new Proxy(o, { - has() { - return false; - } - }); + test("cannot return false if the property exists and the target is non-extensible", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: 10, configurable: true }); - Object.preventExtensions(o); - - expect(() => { - "foo" in p; - }).toThrowWithMessage(TypeError, "Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target and the target is non-extensible"); + let p = new Proxy(o, { + has() { + return false; + }, }); + + Object.preventExtensions(o); + + expect(() => { + "foo" in p; + }).toThrowWithMessage( + TypeError, + "Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target and the target is non-extensible" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js index 89f15a3b1a..510eb296da 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js @@ -1,36 +1,39 @@ describe("[[IsExtensible]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - expect(Object.isExtensible(new Proxy({}, { isExtensible: null }))).toBeTrue(); - expect(Object.isExtensible(new Proxy({}, { isExtensible: undefined }))).toBeTrue(); - expect(Object.isExtensible(new Proxy({}, {}))).toBeTrue(); + test("forwarding when not defined in handler", () => { + expect(Object.isExtensible(new Proxy({}, { isExtensible: null }))).toBeTrue(); + expect(Object.isExtensible(new Proxy({}, { isExtensible: undefined }))).toBeTrue(); + expect(Object.isExtensible(new Proxy({}, {}))).toBeTrue(); + }); + + test("correct arguments supplied to trap", () => { + let o = {}; + let p = new Proxy(o, { + isExtensible(target) { + expect(target).toBe(o); + return true; + }, }); - test("correct arguments supplied to trap", () => { - let o = {}; - let p = new Proxy(o, { - isExtensible(target) { - expect(target).toBe(o); - return true; - } - }); - - expect(Object.isExtensible(p)).toBeTrue(); - }); + expect(Object.isExtensible(p)).toBeTrue(); + }); }); describe("[[Call]] invariants", () => { - test("return value must match the target's extensibility", () => { - let o = {}; - Object.preventExtensions(o); + test("return value must match the target's extensibility", () => { + let o = {}; + Object.preventExtensions(o); - let p = new Proxy(o, { - isExtensible() { - return true; - }, - }); - - expect(() => { - Object.isExtensible(p); - }).toThrowWithMessage(TypeError, "Proxy handler's isExtensible trap violates invariant: return value must match the target's extensibility"); + let p = new Proxy(o, { + isExtensible() { + return true; + }, }); + + expect(() => { + Object.isExtensible(p); + }).toThrowWithMessage( + TypeError, + "Proxy handler's isExtensible trap violates invariant: return value must match the target's extensibility" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-preventExtensions.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-preventExtensions.js index ca92a8d489..43cb6ef0c6 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-preventExtensions.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-preventExtensions.js @@ -1,53 +1,59 @@ describe("[[PreventExtension]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - let p = new Proxy({}, { preventExtensions: null }); - expect(Object.preventExtensions(p)).toBe(p); - p = new Proxy({}, { preventExtensions: undefined }); - expect(Object.preventExtensions(p)).toBe(p); - p = new Proxy({}, {}); - expect(Object.preventExtensions(p)).toBe(p); + test("forwarding when not defined in handler", () => { + let p = new Proxy({}, { preventExtensions: null }); + expect(Object.preventExtensions(p)).toBe(p); + p = new Proxy({}, { preventExtensions: undefined }); + expect(Object.preventExtensions(p)).toBe(p); + p = new Proxy({}, {}); + expect(Object.preventExtensions(p)).toBe(p); + }); + + test("correct arguments supplied to trap", () => { + let o = {}; + p = new Proxy(o, { + preventExtensions(target) { + expect(target).toBe(o); + return true; + }, }); - test("correct arguments supplied to trap", () => { - let o = {}; - p = new Proxy(o, { - preventExtensions(target) { - expect(target).toBe(o); - return true; - } - }); - - Object.preventExtensions(o); - Object.preventExtensions(p); - }); + Object.preventExtensions(o); + Object.preventExtensions(p); + }); }); describe("[[PreventExtensions]] invariants", () => { - test("cannot return false", () => { - let p = new Proxy({}, { - preventExtensions() { - return false; - }, - }); + test("cannot return false", () => { + let p = new Proxy( + {}, + { + preventExtensions() { + return false; + }, + } + ); - expect(() => { - Object.preventExtensions(p); - }).toThrowWithMessage(TypeError, "Object's [[PreventExtensions]] method returned false"); + expect(() => { + Object.preventExtensions(p); + }).toThrowWithMessage(TypeError, "Object's [[PreventExtensions]] method returned false"); + }); + + test("cannot return true if the target is extensible", () => { + let o = {}; + let p = new Proxy(o, { + preventExtensions() { + return true; + }, }); - test("cannot return true if the target is extensible", () => { - let o = {}; - let p = new Proxy(o, { - preventExtensions() { - return true; - }, - }); + expect(() => { + Object.preventExtensions(p); + }).toThrowWithMessage( + TypeError, + "Proxy handler's preventExtensions trap violates invariant: cannot return true if the target object is extensible" + ); - expect(() => { - Object.preventExtensions(p); - }).toThrowWithMessage(TypeError, "Proxy handler's preventExtensions trap violates invariant: cannot return true if the target object is extensible"); - - Object.preventExtensions(o); - expect(Object.preventExtensions(p)).toBe(p); - }); + Object.preventExtensions(o); + expect(Object.preventExtensions(p)).toBe(p); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-set.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-set.js index 6f3d83939d..f3cc7a665f 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-set.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-set.js @@ -1,73 +1,82 @@ describe("[[Set]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - expect((new Proxy({}, { set: undefined }).foo = 1)).toBe(1); - expect((new Proxy({}, { set: null }).foo = 1)).toBe(1); - expect((new Proxy({}, {}).foo = 1)).toBe(1); + test("forwarding when not defined in handler", () => { + expect((new Proxy({}, { set: undefined }).foo = 1)).toBe(1); + expect((new Proxy({}, { set: null }).foo = 1)).toBe(1); + expect((new Proxy({}, {}).foo = 1)).toBe(1); + }); + + test("correct arguments supplied to trap", () => { + let o = {}; + let p = new Proxy(o, { + set(target, prop, value, receiver) { + expect(target).toBe(o); + expect(prop).toBe("foo"); + expect(value).toBe(10); + expect(receiver).toBe(p); + return true; + }, }); - test("correct arguments supplied to trap", () => { - let o = {}; - let p = new Proxy(o, { - set(target, prop, value, receiver) { - expect(target).toBe(o); - expect(prop).toBe("foo"); - expect(value).toBe(10); - expect(receiver).toBe(p); - return true; - }, - }); + p.foo = 10; + }); - p.foo = 10; - }); + test("conditional return value", () => { + let p = new Proxy( + {}, + { + set(target, prop, value) { + if (target[prop] === value) { + target[prop] *= 2; + } else { + target[prop] = value; + } + }, + } + ); - test("conditional return value", () => { - let p = new Proxy({}, { - set(target, prop, value) { - if (target[prop] === value) { - target[prop] *= 2; - } else { - target[prop] = value; - } - }, - }); - - p.foo = 10; - expect(p.foo).toBe(10); - p.foo = 10; - expect(p.foo).toBe(20); - p.foo = 10; - expect(p.foo).toBe(10); - }); + p.foo = 10; + expect(p.foo).toBe(10); + p.foo = 10; + expect(p.foo).toBe(20); + p.foo = 10; + expect(p.foo).toBe(10); + }); }); describe("[[Set]] invariants", () => { - test("cannot return true for a non-configurable, non-writable property", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 10 }); + test("cannot return true for a non-configurable, non-writable property", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: 10 }); - let p = new Proxy(o, { - set() { - return true; - }, - }); - - expect(() => { - p.foo = 12; - }).toThrowWithMessage(TypeError, "Proxy handler's set trap violates invariant: cannot return true for a property on the target which is a non-configurable, non-writable own data property"); + let p = new Proxy(o, { + set() { + return true; + }, }); - test("cannot return true for a non-configurable accessor property with no setter", () => { - let o = {}; - Object.defineProperty(o, "foo", { get() {} }); + expect(() => { + p.foo = 12; + }).toThrowWithMessage( + TypeError, + "Proxy handler's set trap violates invariant: cannot return true for a property on the target which is a non-configurable, non-writable own data property" + ); + }); - let p = new Proxy(o, { - set() { - return true; - }, - }); + test("cannot return true for a non-configurable accessor property with no setter", () => { + let o = {}; + Object.defineProperty(o, "foo", { get() {} }); - expect(() => { - p.foo = 12; - }).toThrowWithMessage(TypeError, "Proxy handler's set trap violates invariant: cannot return true for a property on the target which is a non-configurable own accessor property with an undefined set attribute"); + let p = new Proxy(o, { + set() { + return true; + }, }); + + expect(() => { + p.foo = 12; + }).toThrowWithMessage( + TypeError, + "Proxy handler's set trap violates invariant: cannot return true for a property on the target which is a non-configurable own accessor property with an undefined set attribute" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js index 91d4d83075..14e90d0dd9 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js @@ -1,94 +1,96 @@ describe("[[SetPrototypeOf]] trap normal behavior", () => { - test("forwarding when not defined in handler", () => { - const o = {}; - const proto = { foo: "bar" }; - Object.setPrototypeOf(o, proto); + test("forwarding when not defined in handler", () => { + const o = {}; + const proto = { foo: "bar" }; + Object.setPrototypeOf(o, proto); - let p = new Proxy(o, { setPrototypeOf: null }); - expect(Object.setPrototypeOf(p, proto)).toBe(p); - let p = new Proxy(o, { setPrototypeOf: undefined }); - expect(Object.setPrototypeOf(p, proto)).toBe(p); - let p = new Proxy(o, {}); - expect(Object.setPrototypeOf(p, proto)).toBe(p); + let p = new Proxy(o, { setPrototypeOf: null }); + expect(Object.setPrototypeOf(p, proto)).toBe(p); + let p = new Proxy(o, { setPrototypeOf: undefined }); + expect(Object.setPrototypeOf(p, proto)).toBe(p); + let p = new Proxy(o, {}); + expect(Object.setPrototypeOf(p, proto)).toBe(p); + }); + + test("correct arguments supplied to trap", () => { + let o = {}; + let theNewProto = { foo: "bar" }; + + let p = new Proxy(o, { + setPrototypeOf(target, newProto) { + expect(target).toBe(o); + expect(newProto).toBe(theNewProto); + return true; + }, }); - test("correct arguments supplied to trap", () => { - let o = {}; - let theNewProto = { foo: "bar" }; + Object.setPrototypeOf(p, theNewProto); + }); - let p = new Proxy(o, { - setPrototypeOf(target, newProto) { - expect(target).toBe(o); - expect(newProto).toBe(theNewProto); - return true; - } - }); + test("conditional setting", () => { + let o = {}; - Object.setPrototypeOf(p, theNewProto); + let p = new Proxy(o, { + setPrototypeOf(target, newProto) { + if (target.shouldSet) Object.setPrototypeOf(target, newProto); + return true; + }, }); - test("conditional setting", () => { - let o = {}; + Object.setPrototypeOf(p, { foo: 1 }); + expect(Object.getPrototypeOf(p).foo).toBeUndefined(); + p.shouldSet = true; + expect(o.shouldSet).toBeTrue(); + Object.setPrototypeOf(p, { foo: 1 }); + expect(Object.getPrototypeOf(p).foo).toBe(1); + }); - let p = new Proxy(o, { - setPrototypeOf(target, newProto) { - if (target.shouldSet) - Object.setPrototypeOf(target, newProto); - return true; - }, - }); + test("non-extensible targets", () => { + let o = {}; + let proto = {}; + Object.setPrototypeOf(o, proto); + Object.preventExtensions(o); - Object.setPrototypeOf(p, { foo: 1 }); - expect(Object.getPrototypeOf(p).foo).toBeUndefined(); - p.shouldSet = true; - expect(o.shouldSet).toBeTrue(); - Object.setPrototypeOf(p, { foo: 1 }); - expect(Object.getPrototypeOf(p).foo).toBe(1); + p = new Proxy(o, { + setPrototypeOf() { + return true; + }, }); - test("non-extensible targets", () => { - let o = {}; - let proto = {}; - Object.setPrototypeOf(o, proto); - Object.preventExtensions(o); - - p = new Proxy(o, { - setPrototypeOf() { - return true; - }, - }); - - expect(Object.setPrototypeOf(p, proto)).toBe(p); - expect(Object.getPrototypeOf(p)).toBe(proto); - }); + expect(Object.setPrototypeOf(p, proto)).toBe(p); + expect(Object.getPrototypeOf(p)).toBe(proto); + }); }); describe("[[SetPrototypeOf]] invariants", () => { - test("cannot return false", () => { - let o = {}; - p = new Proxy(o, { - setPrototypeOf() { - return false; - }, - }); - - expect(() => { - Object.setPrototypeOf(p, {}); - }).toThrowWithMessage(TypeError, "Object's [[SetPrototypeOf]] method returned false"); + test("cannot return false", () => { + let o = {}; + p = new Proxy(o, { + setPrototypeOf() { + return false; + }, }); - test("the argument must match the target's prototype if the target is non-extensible", () => { - let o = {}; - Object.preventExtensions(o); + expect(() => { + Object.setPrototypeOf(p, {}); + }).toThrowWithMessage(TypeError, "Object's [[SetPrototypeOf]] method returned false"); + }); - let p = new Proxy(o, { - setPrototypeOf() { - return true; - } - }); + test("the argument must match the target's prototype if the target is non-extensible", () => { + let o = {}; + Object.preventExtensions(o); - expect(() => { - Object.setPrototypeOf(p, {}); - }).toThrowWithMessage(TypeError, "Proxy handler's setPrototypeOf trap violates invariant: the argument must match the prototype of the target if the target is non-extensible"); + let p = new Proxy(o, { + setPrototypeOf() { + return true; + }, }); + + expect(() => { + Object.setPrototypeOf(p, {}); + }).toThrowWithMessage( + TypeError, + "Proxy handler's setPrototypeOf trap violates invariant: the argument must match the prototype of the target if the target is non-extensible" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js index f3ed65886d..3f25cdb96b 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js @@ -1,31 +1,37 @@ test("constructs properly", () => { - expect(() => { - new Proxy({}, {}); - }).not.toThrow(); + expect(() => { + new Proxy({}, {}); + }).not.toThrow(); }); test("constructor argument count", () => { - expect(() => { - new Proxy(); - }).toThrowWithMessage(TypeError, "Proxy constructor requires at least two arguments"); + expect(() => { + new Proxy(); + }).toThrowWithMessage(TypeError, "Proxy constructor requires at least two arguments"); - expect(() => { - new Proxy({}); - }).toThrowWithMessage(TypeError, "Proxy constructor requires at least two arguments"); + expect(() => { + new Proxy({}); + }).toThrowWithMessage(TypeError, "Proxy constructor requires at least two arguments"); }); test("constructor requires objects", () => { - expect(() => { - new Proxy(1, {}); - }).toThrowWithMessage(TypeError, "Expected target argument of Proxy constructor to be object, got 1"); + expect(() => { + new Proxy(1, {}); + }).toThrowWithMessage( + TypeError, + "Expected target argument of Proxy constructor to be object, got 1" + ); - expect(() => { - new Proxy({}, 1); - }).toThrowWithMessage(TypeError, "Expected handler argument of Proxy constructor to be object, got 1"); + expect(() => { + new Proxy({}, 1); + }).toThrowWithMessage( + TypeError, + "Expected handler argument of Proxy constructor to be object, got 1" + ); }); test("constructor must be invoked with 'new'", () => { - expect(() => { - Proxy({}, {}); - }).toThrowWithMessage(TypeError, "Proxy must be called with the 'new' operator"); + expect(() => { + Proxy({}, {}); + }).toThrowWithMessage(TypeError, "Proxy must be called with the 'new' operator"); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js index e85fe258f8..06cde6eb5e 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js @@ -1,39 +1,39 @@ test("length is 3", () => { - expect(Reflect.apply).toHaveLength(3); + expect(Reflect.apply).toHaveLength(3); }); describe("errors", () => { - test("target must be a function", () => { - [null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => { - expect(() => { - Reflect.apply(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.apply() must be a function"); - }); + test("target must be a function", () => { + [null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => { + expect(() => { + Reflect.apply(value); + }).toThrowWithMessage(TypeError, "First argument of Reflect.apply() must be a function"); }); + }); - test("arguments list must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.apply(() => {}, undefined, value); - }).toThrowWithMessage(TypeError, "Arguments list must be an object"); - }); + test("arguments list must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.apply(() => {}, undefined, value); + }).toThrowWithMessage(TypeError, "Arguments list must be an object"); }); + }); }); describe("normal behavior", () => { - test("calling built-in functions", () => { - expect(Reflect.apply(String.prototype.charAt, "foo", [0])).toBe("f"); - expect(Reflect.apply(Array.prototype.indexOf, ["hello", 123, "foo", "bar"], ["foo"])).toBe(2); - }); + test("calling built-in functions", () => { + expect(Reflect.apply(String.prototype.charAt, "foo", [0])).toBe("f"); + expect(Reflect.apply(Array.prototype.indexOf, ["hello", 123, "foo", "bar"], ["foo"])).toBe(2); + }); - test("|this| argument is forwarded to called function", () => { - function Foo(foo) { - this.foo = foo; - } + test("|this| argument is forwarded to called function", () => { + function Foo(foo) { + this.foo = foo; + } - var o = {}; - expect(o.foo).toBeUndefined(); - Reflect.apply(Foo, o, ["bar"]); - expect(o.foo).toBe("bar"); - }); + var o = {}; + expect(o.foo).toBeUndefined(); + Reflect.apply(Foo, o, ["bar"]); + expect(o.foo).toBe("bar"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js index 2ad89b63e7..412f76f4c2 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js @@ -1,69 +1,72 @@ test("length is 2", () => { - expect(Reflect.construct).toHaveLength(2); + expect(Reflect.construct).toHaveLength(2); }); describe("errors", () => { - test("target must be a function", () => { - [null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => { - expect(() => { - Reflect.construct(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.construct() must be a function"); - }); + test("target must be a function", () => { + [null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => { + expect(() => { + Reflect.construct(value); + }).toThrowWithMessage(TypeError, "First argument of Reflect.construct() must be a function"); }); + }); - test("arguments list must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.construct(() => {}, value); - }).toThrowWithMessage(TypeError, "Arguments list must be an object"); - }); + test("arguments list must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.construct(() => {}, value); + }).toThrowWithMessage(TypeError, "Arguments list must be an object"); }); + }); - test("new target must be a function", () => { - [null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => { - expect(() => { - Reflect.construct(() => {}, [], value); - }).toThrowWithMessage(TypeError, "Optional third argument of Reflect.construct() must be a constructor"); - }); + test("new target must be a function", () => { + [null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => { + expect(() => { + Reflect.construct(() => {}, [], value); + }).toThrowWithMessage( + TypeError, + "Optional third argument of Reflect.construct() must be a constructor" + ); }); + }); }); describe("normal behavior", () => { - test("built-in Array function", () => { - var a = Reflect.construct(Array, [5]); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(5); - }); + test("built-in Array function", () => { + var a = Reflect.construct(Array, [5]); + expect(a instanceof Array).toBeTrue(); + expect(a).toHaveLength(5); + }); - test("built-in String function", () => { - var s = Reflect.construct(String, [123]); - expect(s instanceof String).toBeTrue(); - expect(s).toHaveLength(3); - expect(s.toString()).toBe("123"); - }); + test("built-in String function", () => { + var s = Reflect.construct(String, [123]); + expect(s instanceof String).toBeTrue(); + expect(s).toHaveLength(3); + expect(s.toString()).toBe("123"); + }); - test("user-defined function", () => { - function Foo() { - this.name = "foo"; - } + test("user-defined function", () => { + function Foo() { + this.name = "foo"; + } - var o = Reflect.construct(Foo, []); - expect(o.name).toBe("foo"); - expect(o instanceof Foo).toBeTrue(); - }); + var o = Reflect.construct(Foo, []); + expect(o.name).toBe("foo"); + expect(o instanceof Foo).toBeTrue(); + }); - test("user-defined function with different new target", () => { - function Foo() { - this.name = "foo"; - } - - function Bar() { - this.name = "bar"; - } + test("user-defined function with different new target", () => { + function Foo() { + this.name = "foo"; + } - var o = Reflect.construct(Foo, [], Bar); - expect(o.name).toBe("foo"); - expect(o instanceof Foo).toBeFalse(); - expect(o instanceof Bar).toBeTrue(); - }); + function Bar() { + this.name = "bar"; + } + + var o = Reflect.construct(Foo, [], Bar); + expect(o.name).toBe("foo"); + expect(o instanceof Foo).toBeFalse(); + expect(o instanceof Bar).toBeTrue(); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.defineProperty.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.defineProperty.js index ebb2e638ce..69d8ffc4e2 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.defineProperty.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.defineProperty.js @@ -1,74 +1,82 @@ test("length is 3", () => { - expect(Reflect.defineProperty).toHaveLength(3); + expect(Reflect.defineProperty).toHaveLength(3); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.defineProperty(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.defineProperty() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.defineProperty(value); + }).toThrowWithMessage( + TypeError, + "First argument of Reflect.defineProperty() must be an object" + ); }); + }); - test("descriptor must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.defineProperty({}, "foo", value); - }).toThrowWithMessage(TypeError, "Descriptor argument is not an object"); - }); + test("descriptor must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.defineProperty({}, "foo", value); + }).toThrowWithMessage(TypeError, "Descriptor argument is not an object"); }); + }); }); - describe("normal behavior", () => { - test("initial value and non-writable", () => { - var o = {}; + test("initial value and non-writable", () => { + var o = {}; - expect(o.foo).toBeUndefined(); - expect(Reflect.defineProperty(o, "foo", { value: 1, writable: false })).toBeTrue(); - expect(o.foo).toBe(1); - o.foo = 2; - expect(o.foo).toBe(1); - }); + expect(o.foo).toBeUndefined(); + expect(Reflect.defineProperty(o, "foo", { value: 1, writable: false })).toBeTrue(); + expect(o.foo).toBe(1); + o.foo = 2; + expect(o.foo).toBe(1); + }); - test("initial value and writable", () => { - var o = {}; + test("initial value and writable", () => { + var o = {}; - expect(o.foo).toBeUndefined(); - expect(Reflect.defineProperty(o, "foo", { value: 1, writable: true })).toBeTrue(); - expect(o.foo).toBe(1); - o.foo = 2; - expect(o.foo).toBe(2); - }); + expect(o.foo).toBeUndefined(); + expect(Reflect.defineProperty(o, "foo", { value: 1, writable: true })).toBeTrue(); + expect(o.foo).toBe(1); + o.foo = 2; + expect(o.foo).toBe(2); + }); - test("can redefine value of configurable, writable property", () => { - var o = {}; + test("can redefine value of configurable, writable property", () => { + var o = {}; - expect(o.foo).toBeUndefined(); - expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: true })).toBeTrue(); - expect(o.foo).toBe(1); - expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue(); - expect(o.foo).toBe(2); - }); + expect(o.foo).toBeUndefined(); + expect( + Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: true }) + ).toBeTrue(); + expect(o.foo).toBe(1); + expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue(); + expect(o.foo).toBe(2); + }); - test("can redefine value of configurable, non-writable property", () => { - var o = {}; + test("can redefine value of configurable, non-writable property", () => { + var o = {}; - expect(o.foo).toBeUndefined(); - expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: false })).toBeTrue(); - expect(o.foo).toBe(1); - expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue(); - expect(o.foo).toBe(2); - }); + expect(o.foo).toBeUndefined(); + expect( + Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: false }) + ).toBeTrue(); + expect(o.foo).toBe(1); + expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue(); + expect(o.foo).toBe(2); + }); - test("cannot redefine value of non-configurable, non-writable property", () => { - var o = {}; + test("cannot redefine value of non-configurable, non-writable property", () => { + var o = {}; - expect(o.foo).toBeUndefined(); - expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: false, writable: false })).toBeTrue(); - expect(o.foo).toBe(1); - expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeFalse(); - expect(o.foo).toBe(1); - }); + expect(o.foo).toBeUndefined(); + expect( + Reflect.defineProperty(o, "foo", { value: 1, configurable: false, writable: false }) + ).toBeTrue(); + expect(o.foo).toBe(1); + expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeFalse(); + expect(o.foo).toBe(1); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.deleteProperty.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.deleteProperty.js index 769095955c..b5df4bfc93 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.deleteProperty.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.deleteProperty.js @@ -1,63 +1,66 @@ test("length is 2", () => { - expect(Reflect.deleteProperty).toHaveLength(2); + expect(Reflect.deleteProperty).toHaveLength(2); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.deleteProperty(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.deleteProperty() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.deleteProperty(value); + }).toThrowWithMessage( + TypeError, + "First argument of Reflect.deleteProperty() must be an object" + ); }); + }); }); describe("normal behavior", () => { - test("deleting non-existent property", () => { - expect(Reflect.deleteProperty({})).toBeTrue(); - expect(Reflect.deleteProperty({}, "foo")).toBeTrue(); - }); + test("deleting non-existent property", () => { + expect(Reflect.deleteProperty({})).toBeTrue(); + expect(Reflect.deleteProperty({}, "foo")).toBeTrue(); + }); - test("deleting existent property", () => { - var o = { foo: 1 }; - expect(o.foo).toBe(1); - expect(Reflect.deleteProperty(o, "foo")).toBeTrue(); - expect(o.foo).toBeUndefined(); - expect(Reflect.deleteProperty(o, "foo")).toBeTrue(); - expect(o.foo).toBeUndefined(); - }); + test("deleting existent property", () => { + var o = { foo: 1 }; + expect(o.foo).toBe(1); + expect(Reflect.deleteProperty(o, "foo")).toBeTrue(); + expect(o.foo).toBeUndefined(); + expect(Reflect.deleteProperty(o, "foo")).toBeTrue(); + expect(o.foo).toBeUndefined(); + }); - test("deleting existent, configurable, non-writable property", () => { - var o = {}; - Object.defineProperty(o, "foo", { value: 1, configurable: true, writable: false }); - expect(Reflect.deleteProperty(o, "foo")).toBeTrue(); - expect(o.foo).toBeUndefined(); - }); + test("deleting existent, configurable, non-writable property", () => { + var o = {}; + Object.defineProperty(o, "foo", { value: 1, configurable: true, writable: false }); + expect(Reflect.deleteProperty(o, "foo")).toBeTrue(); + expect(o.foo).toBeUndefined(); + }); - test("deleting existent, non-configurable, writable property", () => { - var o = {}; - Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: true }); - expect(Reflect.deleteProperty(o, "foo")).toBeFalse(); - expect(o.foo).toBe(1); - }); + test("deleting existent, non-configurable, writable property", () => { + var o = {}; + Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: true }); + expect(Reflect.deleteProperty(o, "foo")).toBeFalse(); + expect(o.foo).toBe(1); + }); - test("deleting existent, non-configurable, non-writable property", () => { - var o = {}; - Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: false }); - expect(Reflect.deleteProperty(o, "foo")).toBeFalse(); - expect(o.foo).toBe(1); - }); + test("deleting existent, non-configurable, non-writable property", () => { + var o = {}; + Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: false }); + expect(Reflect.deleteProperty(o, "foo")).toBeFalse(); + expect(o.foo).toBe(1); + }); - test("deleting array index", () => { - var a = [1, 2, 3]; - expect(a).toHaveLength(3); - expect(a[0]).toBe(1); - expect(a[1]).toBe(2); - expect(a[2]).toBe(3); - expect(Reflect.deleteProperty(a, 1)).toBeTrue(); - expect(a).toHaveLength(3); - expect(a[0]).toBe(1); - expect(a[1]).toBeUndefined(); - expect(a[2]).toBe(3); - }); + test("deleting array index", () => { + var a = [1, 2, 3]; + expect(a).toHaveLength(3); + expect(a[0]).toBe(1); + expect(a[1]).toBe(2); + expect(a[2]).toBe(3); + expect(Reflect.deleteProperty(a, 1)).toBeTrue(); + expect(a).toHaveLength(3); + expect(a[0]).toBe(1); + expect(a[1]).toBeUndefined(); + expect(a[2]).toBe(3); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.get.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.get.js index 9dc1e2e392..d22322450b 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.get.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.get.js @@ -1,63 +1,63 @@ test("length is 2", () => { - expect(Reflect.get).toHaveLength(2); + expect(Reflect.get).toHaveLength(2); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.get(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.get() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.get(value); + }).toThrowWithMessage(TypeError, "First argument of Reflect.get() must be an object"); }); + }); }); describe("normal behavior", () => { - test("regular object", () => { - expect(Reflect.get({})).toBeUndefined(); - expect(Reflect.get({ undefined: 1 })).toBe(1); - expect(Reflect.get({ foo: 1 })).toBeUndefined(); - expect(Reflect.get({ foo: 1 }, "foo")).toBe(1); - }); + test("regular object", () => { + expect(Reflect.get({})).toBeUndefined(); + expect(Reflect.get({ undefined: 1 })).toBe(1); + expect(Reflect.get({ foo: 1 })).toBeUndefined(); + expect(Reflect.get({ foo: 1 }, "foo")).toBe(1); + }); - test("array", () => { - expect(Reflect.get([])).toBeUndefined(); - expect(Reflect.get([1, 2, 3])).toBeUndefined(); - expect(Reflect.get([1, 2, 3], "0")).toBe(1); - expect(Reflect.get([1, 2, 3], 0)).toBe(1); - expect(Reflect.get([1, 2, 3], 1)).toBe(2); - expect(Reflect.get([1, 2, 3], 2)).toBe(3); - expect(Reflect.get([1, 2, 3], 4)).toBeUndefined(); - }); + test("array", () => { + expect(Reflect.get([])).toBeUndefined(); + expect(Reflect.get([1, 2, 3])).toBeUndefined(); + expect(Reflect.get([1, 2, 3], "0")).toBe(1); + expect(Reflect.get([1, 2, 3], 0)).toBe(1); + expect(Reflect.get([1, 2, 3], 1)).toBe(2); + expect(Reflect.get([1, 2, 3], 2)).toBe(3); + expect(Reflect.get([1, 2, 3], 4)).toBeUndefined(); + }); - test("string object", () => { - expect(Reflect.get(new String())).toBeUndefined(); - expect(Reflect.get(new String(), 0)).toBeUndefined(); - expect(Reflect.get(new String("foo"), "0")).toBe("f"); - expect(Reflect.get(new String("foo"), 0)).toBe("f"); - expect(Reflect.get(new String("foo"), 1)).toBe("o"); - expect(Reflect.get(new String("foo"), 2)).toBe("o"); - expect(Reflect.get(new String("foo"), 3)).toBeUndefined(); - }); + test("string object", () => { + expect(Reflect.get(new String())).toBeUndefined(); + expect(Reflect.get(new String(), 0)).toBeUndefined(); + expect(Reflect.get(new String("foo"), "0")).toBe("f"); + expect(Reflect.get(new String("foo"), 0)).toBe("f"); + expect(Reflect.get(new String("foo"), 1)).toBe("o"); + expect(Reflect.get(new String("foo"), 2)).toBe("o"); + expect(Reflect.get(new String("foo"), 3)).toBeUndefined(); + }); - test("getter function", () => { - const foo = { - get prop() { - this.getPropCalled = true; - } - }; - const bar = {}; - Object.setPrototypeOf(bar, foo); + test("getter function", () => { + const foo = { + get prop() { + this.getPropCalled = true; + }, + }; + const bar = {}; + Object.setPrototypeOf(bar, foo); - expect(foo.getPropCalled).toBeUndefined(); - expect(bar.getPropCalled).toBeUndefined(); + expect(foo.getPropCalled).toBeUndefined(); + expect(bar.getPropCalled).toBeUndefined(); - Reflect.get(bar, "prop"); - expect(foo.getPropCalled).toBeUndefined(); - expect(bar.getPropCalled).toBeTrue(); + Reflect.get(bar, "prop"); + expect(foo.getPropCalled).toBeUndefined(); + expect(bar.getPropCalled).toBeTrue(); - Reflect.get(bar, "prop", foo); - expect(foo.getPropCalled).toBeTrue(); - expect(bar.getPropCalled).toBeTrue(); - }); + Reflect.get(bar, "prop", foo); + expect(foo.getPropCalled).toBeTrue(); + expect(bar.getPropCalled).toBeTrue(); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getOwnPropertyDescriptor.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getOwnPropertyDescriptor.js index cb4d53f8b9..7f00ad8e9d 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getOwnPropertyDescriptor.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getOwnPropertyDescriptor.js @@ -1,38 +1,41 @@ test("length is 2", () => { - expect(Reflect.getOwnPropertyDescriptor).toHaveLength(2); + expect(Reflect.getOwnPropertyDescriptor).toHaveLength(2); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.getOwnPropertyDescriptor(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.getOwnPropertyDescriptor() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.getOwnPropertyDescriptor(value); + }).toThrowWithMessage( + TypeError, + "First argument of Reflect.getOwnPropertyDescriptor() must be an object" + ); }); + }); }); describe("normal behavior", () => { - test("get descriptor of undefined object property", () => { - expect(Reflect.getOwnPropertyDescriptor({})).toBeUndefined(); - expect(Reflect.getOwnPropertyDescriptor({}, "foo")).toBeUndefined(); - }); + test("get descriptor of undefined object property", () => { + expect(Reflect.getOwnPropertyDescriptor({})).toBeUndefined(); + expect(Reflect.getOwnPropertyDescriptor({}, "foo")).toBeUndefined(); + }); - test("get descriptor of defined object property", () => { - var o = { foo: "bar" }; - var d = Reflect.getOwnPropertyDescriptor(o, "foo"); - expect(d.value).toBe("bar"); - expect(d.writable).toBeTrue(); - expect(d.enumerable).toBeTrue(); - expect(d.configurable).toBeTrue(); - }); + test("get descriptor of defined object property", () => { + var o = { foo: "bar" }; + var d = Reflect.getOwnPropertyDescriptor(o, "foo"); + expect(d.value).toBe("bar"); + expect(d.writable).toBeTrue(); + expect(d.enumerable).toBeTrue(); + expect(d.configurable).toBeTrue(); + }); - test("get descriptor of array length property", () => { - var a = []; - d = Reflect.getOwnPropertyDescriptor(a, "length"); - expect(d.value).toBe(0); - expect(d.writable).toBeTrue(); - expect(d.enumerable).toBeFalse(); - expect(d.configurable).toBeFalse(); - }); + test("get descriptor of array length property", () => { + var a = []; + d = Reflect.getOwnPropertyDescriptor(a, "length"); + expect(d.value).toBe(0); + expect(d.writable).toBeTrue(); + expect(d.enumerable).toBeFalse(); + expect(d.configurable).toBeFalse(); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getPrototypeOf.js index 74b09ad5d7..19f8b833d2 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getPrototypeOf.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getPrototypeOf.js @@ -1,34 +1,37 @@ test("length is 1", () => { - expect(Reflect.getPrototypeOf).toHaveLength(1); + expect(Reflect.getPrototypeOf).toHaveLength(1); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.getPrototypeOf(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.getPrototypeOf() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.getPrototypeOf(value); + }).toThrowWithMessage( + TypeError, + "First argument of Reflect.getPrototypeOf() must be an object" + ); }); + }); }); describe("normal behavior", () => { - test("get prototype of regular object", () => { - expect(Reflect.getPrototypeOf({})).toBe(Object.prototype); - }); + test("get prototype of regular object", () => { + expect(Reflect.getPrototypeOf({})).toBe(Object.prototype); + }); - test("get prototype of array", () => { - expect(Reflect.getPrototypeOf([])).toBe(Array.prototype); - }); + test("get prototype of array", () => { + expect(Reflect.getPrototypeOf([])).toBe(Array.prototype); + }); - test("get prototype of string object", () => { - expect(Reflect.getPrototypeOf(new String())).toBe(String.prototype); - }); + test("get prototype of string object", () => { + expect(Reflect.getPrototypeOf(new String())).toBe(String.prototype); + }); - test("get user-defined prototype of regular object", () => { - var o = {}; - var p = { foo: "bar" }; - Reflect.setPrototypeOf(o, p); - expect(Reflect.getPrototypeOf(o)).toBe(p); - }); + test("get user-defined prototype of regular object", () => { + var o = {}; + var p = { foo: "bar" }; + Reflect.setPrototypeOf(o, p); + expect(Reflect.getPrototypeOf(o)).toBe(p); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.has.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.has.js index f343daeafa..c374ac6f13 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.has.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.has.js @@ -1,45 +1,45 @@ test("length is 2", () => { - expect(Reflect.has).toHaveLength(2); + expect(Reflect.has).toHaveLength(2); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.has(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.has() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.has(value); + }).toThrowWithMessage(TypeError, "First argument of Reflect.has() must be an object"); }); + }); }); describe("normal behavior", () => { - test("regular object has property", () => { - expect(Reflect.has({})).toBeFalse(); - expect(Reflect.has({ undefined })).toBeTrue(); - expect(Reflect.has({ 0: "1" }, "0")).toBeTrue(); - expect(Reflect.has({ foo: "bar" }, "foo")).toBeTrue(); - expect(Reflect.has({ bar: "baz" }, "foo")).toBeFalse(); - expect(Reflect.has({}, "toString")).toBeTrue(); - }); + test("regular object has property", () => { + expect(Reflect.has({})).toBeFalse(); + expect(Reflect.has({ undefined })).toBeTrue(); + expect(Reflect.has({ 0: "1" }, "0")).toBeTrue(); + expect(Reflect.has({ foo: "bar" }, "foo")).toBeTrue(); + expect(Reflect.has({ bar: "baz" }, "foo")).toBeFalse(); + expect(Reflect.has({}, "toString")).toBeTrue(); + }); - test("array has property", () => { - expect(Reflect.has([])).toBeFalse(); - expect(Reflect.has([], 0)).toBeFalse(); - expect(Reflect.has([1, 2, 3], "0")).toBeTrue(); - expect(Reflect.has([1, 2, 3], 0)).toBeTrue(); - expect(Reflect.has([1, 2, 3], 1)).toBeTrue(); - expect(Reflect.has([1, 2, 3], 2)).toBeTrue(); - expect(Reflect.has([1, 2, 3], 3)).toBeFalse(); - expect(Reflect.has([], "pop")).toBeTrue(); - }); + test("array has property", () => { + expect(Reflect.has([])).toBeFalse(); + expect(Reflect.has([], 0)).toBeFalse(); + expect(Reflect.has([1, 2, 3], "0")).toBeTrue(); + expect(Reflect.has([1, 2, 3], 0)).toBeTrue(); + expect(Reflect.has([1, 2, 3], 1)).toBeTrue(); + expect(Reflect.has([1, 2, 3], 2)).toBeTrue(); + expect(Reflect.has([1, 2, 3], 3)).toBeFalse(); + expect(Reflect.has([], "pop")).toBeTrue(); + }); - test("string object has property", () => { - expect(Reflect.has(new String())).toBeFalse(); - expect(Reflect.has(new String("foo"), "0")).toBeTrue(); - expect(Reflect.has(new String("foo"), 0)).toBeTrue(); - expect(Reflect.has(new String("foo"), 1)).toBeTrue(); - expect(Reflect.has(new String("foo"), 2)).toBeTrue(); - expect(Reflect.has(new String("foo"), 3)).toBeFalse(); - expect(Reflect.has(new String("foo"), "charAt")).toBeTrue(); - }); + test("string object has property", () => { + expect(Reflect.has(new String())).toBeFalse(); + expect(Reflect.has(new String("foo"), "0")).toBeTrue(); + expect(Reflect.has(new String("foo"), 0)).toBeTrue(); + expect(Reflect.has(new String("foo"), 1)).toBeTrue(); + expect(Reflect.has(new String("foo"), 2)).toBeTrue(); + expect(Reflect.has(new String("foo"), 3)).toBeFalse(); + expect(Reflect.has(new String("foo"), "charAt")).toBeTrue(); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.isExtensible.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.isExtensible.js index a2b8d8c34f..39f31c001f 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.isExtensible.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.isExtensible.js @@ -1,30 +1,33 @@ test("length is 1", () => { - expect(Reflect.isExtensible).toHaveLength(1); + expect(Reflect.isExtensible).toHaveLength(1); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.isExtensible(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.isExtensible() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.isExtensible(value); + }).toThrowWithMessage( + TypeError, + "First argument of Reflect.isExtensible() must be an object" + ); }); + }); }); describe("normal behavior", () => { - test("regular object is extensible", () => { - expect(Reflect.isExtensible({})).toBeTrue(); - }); + test("regular object is extensible", () => { + expect(Reflect.isExtensible({})).toBeTrue(); + }); - test("global object is extensible", () => { - expect(Reflect.isExtensible(globalThis)).toBeTrue(); - }); + test("global object is extensible", () => { + expect(Reflect.isExtensible(globalThis)).toBeTrue(); + }); - test("regular object is not extensible after preventExtensions()", () => { - var o = {}; - expect(Reflect.isExtensible(o)).toBeTrue(); - Reflect.preventExtensions(o); - expect(Reflect.isExtensible(o)).toBeFalse(); - }); + test("regular object is not extensible after preventExtensions()", () => { + var o = {}; + expect(Reflect.isExtensible(o)).toBeTrue(); + Reflect.preventExtensions(o); + expect(Reflect.isExtensible(o)).toBeFalse(); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.ownKeys.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.ownKeys.js index b7df6c3493..e5707fa66e 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.ownKeys.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.ownKeys.js @@ -1,48 +1,48 @@ test("length is 1", () => { - expect(Reflect.ownKeys).toHaveLength(1); + expect(Reflect.ownKeys).toHaveLength(1); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.ownKeys(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.ownKeys() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.ownKeys(value); + }).toThrowWithMessage(TypeError, "First argument of Reflect.ownKeys() must be an object"); }); + }); }); describe("normal behavior", () => { - test("regular empty object has no own keys", () => { - var objectOwnKeys = Reflect.ownKeys({}); - expect(objectOwnKeys instanceof Array).toBeTrue(); - expect(objectOwnKeys).toHaveLength(0); - }); + test("regular empty object has no own keys", () => { + var objectOwnKeys = Reflect.ownKeys({}); + expect(objectOwnKeys instanceof Array).toBeTrue(); + expect(objectOwnKeys).toHaveLength(0); + }); - test("regular object with some properties has own keys", () => { - var objectOwnKeys = Reflect.ownKeys({ foo: "bar", bar: "baz", 0: 42 }); - expect(objectOwnKeys instanceof Array).toBeTrue(); - expect(objectOwnKeys).toHaveLength(3); - expect(objectOwnKeys[0]).toBe("0"); - expect(objectOwnKeys[1]).toBe("foo"); - expect(objectOwnKeys[2]).toBe("bar"); - }); + test("regular object with some properties has own keys", () => { + var objectOwnKeys = Reflect.ownKeys({ foo: "bar", bar: "baz", 0: 42 }); + expect(objectOwnKeys instanceof Array).toBeTrue(); + expect(objectOwnKeys).toHaveLength(3); + expect(objectOwnKeys[0]).toBe("0"); + expect(objectOwnKeys[1]).toBe("foo"); + expect(objectOwnKeys[2]).toBe("bar"); + }); - test("empty array has only 'length' own key", () => { - var arrayOwnKeys = Reflect.ownKeys([]); - expect(arrayOwnKeys instanceof Array).toBeTrue(); - expect(arrayOwnKeys).toHaveLength(1); - expect(arrayOwnKeys[0]).toBe("length"); - }); + test("empty array has only 'length' own key", () => { + var arrayOwnKeys = Reflect.ownKeys([]); + expect(arrayOwnKeys instanceof Array).toBeTrue(); + expect(arrayOwnKeys).toHaveLength(1); + expect(arrayOwnKeys[0]).toBe("length"); + }); - test("array with some values has 'lenght' and indices own keys", () => { - var arrayOwnKeys = Reflect.ownKeys(["foo", [], 123, undefined]); - expect(arrayOwnKeys instanceof Array).toBeTrue(); - expect(arrayOwnKeys).toHaveLength(5); - expect(arrayOwnKeys[0]).toBe("0"); - expect(arrayOwnKeys[1]).toBe("1"); - expect(arrayOwnKeys[2]).toBe("2"); - expect(arrayOwnKeys[3]).toBe("3"); - expect(arrayOwnKeys[4]).toBe("length"); - }); + test("array with some values has 'lenght' and indices own keys", () => { + var arrayOwnKeys = Reflect.ownKeys(["foo", [], 123, undefined]); + expect(arrayOwnKeys instanceof Array).toBeTrue(); + expect(arrayOwnKeys).toHaveLength(5); + expect(arrayOwnKeys[0]).toBe("0"); + expect(arrayOwnKeys[1]).toBe("1"); + expect(arrayOwnKeys[2]).toBe("2"); + expect(arrayOwnKeys[3]).toBe("3"); + expect(arrayOwnKeys[4]).toBe("length"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.preventExtensions.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.preventExtensions.js index c4d8335ab3..f37ab52739 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.preventExtensions.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.preventExtensions.js @@ -1,33 +1,36 @@ test("length is 1", () => { - expect(Reflect.preventExtensions).toHaveLength(1); + expect(Reflect.preventExtensions).toHaveLength(1); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.preventExtensions(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.preventExtensions() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.preventExtensions(value); + }).toThrowWithMessage( + TypeError, + "First argument of Reflect.preventExtensions() must be an object" + ); }); + }); }); describe("normal behavior", () => { - test("properties cannot be added", () => { - var o = {}; - o.foo = "foo"; - expect(Reflect.preventExtensions(o)).toBeTrue(); - o.bar = "bar"; - expect(o.foo).toBe("foo"); - expect(o.bar).toBeUndefined(); - }); + test("properties cannot be added", () => { + var o = {}; + o.foo = "foo"; + expect(Reflect.preventExtensions(o)).toBeTrue(); + o.bar = "bar"; + expect(o.foo).toBe("foo"); + expect(o.bar).toBeUndefined(); + }); - test("property values can still be changed", () => { - // FIXME: This doesn't work even though it should (the value remains unchanged) - // var o = {}; - // o.foo = "foo"; - // expect(Reflect.preventExtensions(o)).toBeTrue(); - // o.foo = "bar"; - // expect(o.foo).toBe("bar"); - }); + test("property values can still be changed", () => { + // FIXME: This doesn't work even though it should (the value remains unchanged) + // var o = {}; + // o.foo = "foo"; + // expect(Reflect.preventExtensions(o)).toBeTrue(); + // o.foo = "bar"; + // expect(o.foo).toBe("bar"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.set.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.set.js index 8d291d1dbe..2bb3da68a4 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.set.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.set.js @@ -1,96 +1,96 @@ test("length is 3", () => { - expect(Reflect.set).toHaveLength(3); + expect(Reflect.set).toHaveLength(3); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.set(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.set() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.set(value); + }).toThrowWithMessage(TypeError, "First argument of Reflect.set() must be an object"); }); + }); }); describe("normal behavior", () => { - test("setting properties of regular object", () => { - var o = {}; + test("setting properties of regular object", () => { + var o = {}; - expect(Reflect.set(o)).toBeTrue(); - expect(o.undefined).toBeUndefined(); + expect(Reflect.set(o)).toBeTrue(); + expect(o.undefined).toBeUndefined(); - expect(Reflect.set(o, "foo")).toBeTrue(); - expect(o.foo).toBeUndefined(); + expect(Reflect.set(o, "foo")).toBeTrue(); + expect(o.foo).toBeUndefined(); - expect(Reflect.set(o, "foo", "bar")).toBeTrue(); - expect(o.foo).toBe("bar"); + expect(Reflect.set(o, "foo", "bar")).toBeTrue(); + expect(o.foo).toBe("bar"); - expect(Reflect.set(o, "foo", 42)).toBeTrue(); - expect(o.foo).toBe(42); - }); + expect(Reflect.set(o, "foo", 42)).toBeTrue(); + expect(o.foo).toBe(42); + }); - test("setting configurable, non-writable property of regular object", () => { - var o = {}; - Object.defineProperty(o, "foo", { value: 1, configurable: true, writable: false }); - expect(Reflect.set(o, "foo", 2)).toBeFalse(); - expect(o.foo).toBe(1); - }); + test("setting configurable, non-writable property of regular object", () => { + var o = {}; + Object.defineProperty(o, "foo", { value: 1, configurable: true, writable: false }); + expect(Reflect.set(o, "foo", 2)).toBeFalse(); + expect(o.foo).toBe(1); + }); - test("setting non-configurable, writable property of regular object", () => { - var o = {}; - Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: true }); - expect(Reflect.set(o, "foo", 2)).toBeTrue(); - expect(o.foo).toBe(2); - }); + test("setting non-configurable, writable property of regular object", () => { + var o = {}; + Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: true }); + expect(Reflect.set(o, "foo", 2)).toBeTrue(); + expect(o.foo).toBe(2); + }); - test("", () => { - var a = []; - expect(a.length === 0); - expect(Reflect.set(a, "0")).toBeTrue(); - expect(a.length === 1); - expect(a[0]).toBeUndefined(); - expect(Reflect.set(a, 1, "foo")).toBeTrue(); - expect(a.length === 2); - expect(a[0]).toBeUndefined(); - expect(a[1] === "foo"); - expect(Reflect.set(a, 4, "bar")).toBeTrue(); - expect(a.length === 5); - expect(a[0]).toBeUndefined(); - expect(a[1] === "foo"); - expect(a[2]).toBeUndefined(); - expect(a[3]).toBeUndefined(); - expect(a[4] === "bar"); - }); + test("", () => { + var a = []; + expect(a.length === 0); + expect(Reflect.set(a, "0")).toBeTrue(); + expect(a.length === 1); + expect(a[0]).toBeUndefined(); + expect(Reflect.set(a, 1, "foo")).toBeTrue(); + expect(a.length === 2); + expect(a[0]).toBeUndefined(); + expect(a[1] === "foo"); + expect(Reflect.set(a, 4, "bar")).toBeTrue(); + expect(a.length === 5); + expect(a[0]).toBeUndefined(); + expect(a[1] === "foo"); + expect(a[2]).toBeUndefined(); + expect(a[3]).toBeUndefined(); + expect(a[4] === "bar"); + }); - test("setting setter property of regular object", () => { - const foo = { - set prop(value) { - this.setPropCalled = true; - } - }; - expect(foo.setPropCalled).toBeUndefined(); - Reflect.set(foo, "prop", 42); - expect(foo.setPropCalled).toBeTrue(); - }); + test("setting setter property of regular object", () => { + const foo = { + set prop(value) { + this.setPropCalled = true; + }, + }; + expect(foo.setPropCalled).toBeUndefined(); + Reflect.set(foo, "prop", 42); + expect(foo.setPropCalled).toBeTrue(); + }); - test("setting setter property of regular object with different receiver", () => { - const foo = { - set prop(value) { - this.setPropCalled = true; - } - }; - const bar = {}; - Object.setPrototypeOf(bar, foo); - - expect(foo.setPropCalled).toBeUndefined(); - expect(bar.setPropCalled).toBeUndefined(); + test("setting setter property of regular object with different receiver", () => { + const foo = { + set prop(value) { + this.setPropCalled = true; + }, + }; + const bar = {}; + Object.setPrototypeOf(bar, foo); - Reflect.set(bar, "prop", 42); - expect(foo.setPropCalled).toBeUndefined(); - expect(bar.setPropCalled).toBeTrue(); + expect(foo.setPropCalled).toBeUndefined(); + expect(bar.setPropCalled).toBeUndefined(); - Reflect.set(bar, "prop", 42, foo); - expect(foo.setPropCalled).toBeTrue(); - expect(bar.setPropCalled).toBeTrue(); - }); + Reflect.set(bar, "prop", 42); + expect(foo.setPropCalled).toBeUndefined(); + expect(bar.setPropCalled).toBeTrue(); + + Reflect.set(bar, "prop", 42, foo); + expect(foo.setPropCalled).toBeTrue(); + expect(bar.setPropCalled).toBeTrue(); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.setPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.setPrototypeOf.js index 9938957f6a..86bf927f63 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.setPrototypeOf.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.setPrototypeOf.js @@ -1,54 +1,57 @@ test("length is 2", () => { - expect(Reflect.setPrototypeOf).toHaveLength(2); + expect(Reflect.setPrototypeOf).toHaveLength(2); }); describe("errors", () => { - test("target must be an object", () => { - [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.setPrototypeOf(value); - }).toThrowWithMessage(TypeError, "First argument of Reflect.setPrototypeOf() must be an object"); - }); + test("target must be an object", () => { + [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.setPrototypeOf(value); + }).toThrowWithMessage( + TypeError, + "First argument of Reflect.setPrototypeOf() must be an object" + ); }); + }); - test("prototype must be an object or null", () => { - [undefined, "foo", 123, NaN, Infinity].forEach(value => { - expect(() => { - Reflect.setPrototypeOf({}, value); - }).toThrowWithMessage(TypeError, "Prototype must be an object or null"); - }); + test("prototype must be an object or null", () => { + [undefined, "foo", 123, NaN, Infinity].forEach(value => { + expect(() => { + Reflect.setPrototypeOf({}, value); + }).toThrowWithMessage(TypeError, "Prototype must be an object or null"); }); + }); }); describe("normal behavior", () => { - test("setting prototype of regular object", () => { - expect(Reflect.setPrototypeOf({}, null)).toBeTrue(); - expect(Reflect.setPrototypeOf({}, {})).toBeTrue(); - expect(Reflect.setPrototypeOf({}, Object.prototype)).toBeTrue(); - expect(Reflect.setPrototypeOf({}, Array.prototype)).toBeTrue(); - expect(Reflect.setPrototypeOf({}, String.prototype)).toBeTrue(); - expect(Reflect.setPrototypeOf({}, Reflect.getPrototypeOf({}))).toBeTrue(); - }); + test("setting prototype of regular object", () => { + expect(Reflect.setPrototypeOf({}, null)).toBeTrue(); + expect(Reflect.setPrototypeOf({}, {})).toBeTrue(); + expect(Reflect.setPrototypeOf({}, Object.prototype)).toBeTrue(); + expect(Reflect.setPrototypeOf({}, Array.prototype)).toBeTrue(); + expect(Reflect.setPrototypeOf({}, String.prototype)).toBeTrue(); + expect(Reflect.setPrototypeOf({}, Reflect.getPrototypeOf({}))).toBeTrue(); + }); - test("setting user-defined prototype of regular object", () => { - var o = {}; - var p = { foo: "bar" }; - expect(o.foo).toBeUndefined(); - expect(Reflect.setPrototypeOf(o, p)).toBeTrue(); - expect(o.foo).toBe("bar"); - }); + test("setting user-defined prototype of regular object", () => { + var o = {}; + var p = { foo: "bar" }; + expect(o.foo).toBeUndefined(); + expect(Reflect.setPrototypeOf(o, p)).toBeTrue(); + expect(o.foo).toBe("bar"); + }); - test("setting prototype of non-extensible object", () => { - var o = {}; - Reflect.preventExtensions(o); - expect(Reflect.setPrototypeOf(o, {})).toBeFalse(); - }); + test("setting prototype of non-extensible object", () => { + var o = {}; + Reflect.preventExtensions(o); + expect(Reflect.setPrototypeOf(o, {})).toBeFalse(); + }); - test("setting same prototype of non-extensible object", () => { - var o = {}; - var p = { foo: "bar" }; - expect(Reflect.setPrototypeOf(o, p)).toBeTrue(); - Reflect.preventExtensions(o); - expect(Reflect.setPrototypeOf(o, p)).toBeTrue(); - }); + test("setting same prototype of non-extensible object", () => { + var o = {}; + var p = { foo: "bar" }; + expect(Reflect.setPrototypeOf(o, p)).toBeTrue(); + Reflect.preventExtensions(o); + expect(Reflect.setPrototypeOf(o, p)).toBeTrue(); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js b/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js index c6b52fd2e1..2a76ee29c9 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js +++ b/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js @@ -1,17 +1,17 @@ test("basic functionality", () => { - expect(String.fromCharCode).toHaveLength(1); + expect(String.fromCharCode).toHaveLength(1); - expect(String.fromCharCode()).toBe(""); - expect(String.fromCharCode(0)).toBe("\u0000"); - expect(String.fromCharCode(false)).toBe("\u0000"); - expect(String.fromCharCode(null)).toBe("\u0000"); - expect(String.fromCharCode(undefined)).toBe("\u0000"); - expect(String.fromCharCode(1)).toBe("\u0001"); - expect(String.fromCharCode(true)).toBe("\u0001"); - expect(String.fromCharCode(-1)).toBe("\uffff"); - expect(String.fromCharCode(0xffff)).toBe("\uffff"); - expect(String.fromCharCode(0x123ffff)).toBe("\uffff"); - expect(String.fromCharCode(65)).toBe("A"); - expect(String.fromCharCode(65, 66, 67)).toBe("ABC"); - expect(String.fromCharCode(228, 246, 252)).toBe("äöü"); + expect(String.fromCharCode()).toBe(""); + expect(String.fromCharCode(0)).toBe("\u0000"); + expect(String.fromCharCode(false)).toBe("\u0000"); + expect(String.fromCharCode(null)).toBe("\u0000"); + expect(String.fromCharCode(undefined)).toBe("\u0000"); + expect(String.fromCharCode(1)).toBe("\u0001"); + expect(String.fromCharCode(true)).toBe("\u0001"); + expect(String.fromCharCode(-1)).toBe("\uffff"); + expect(String.fromCharCode(0xffff)).toBe("\uffff"); + expect(String.fromCharCode(0x123ffff)).toBe("\uffff"); + expect(String.fromCharCode(65)).toBe("A"); + expect(String.fromCharCode(65, 66, 67)).toBe("ABC"); + expect(String.fromCharCode(228, 246, 252)).toBe("äöü"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.js b/Libraries/LibJS/Tests/builtins/String/String.js index 687e0929d4..9457209d5c 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.js +++ b/Libraries/LibJS/Tests/builtins/String/String.js @@ -1,9 +1,9 @@ test("constructor properties", () => { - expect(String).toHaveLength(1); - expect(String.name).toBe("String"); + expect(String).toHaveLength(1); + expect(String.name).toBe("String"); }); test("typeof", () => { - expect(typeof String()).toBe("string"); - expect(typeof new String()).toBe("object"); + expect(typeof String()).toBe("string"); + expect(typeof new String()).toBe("object"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js b/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js index 3d7d7468b6..367b9affed 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js @@ -1,37 +1,37 @@ test("basic functionality", () => { - const genericStringPrototypeFunctions = [ - "charAt", - "repeat", - "startsWith", - "indexOf", - "toLowerCase", - "toUpperCase", - "padStart", - "padEnd", - "trim", - "trimStart", - "trimEnd", - "concat", - "substring", - "includes", - "slice", - ]; + const genericStringPrototypeFunctions = [ + "charAt", + "repeat", + "startsWith", + "indexOf", + "toLowerCase", + "toUpperCase", + "padStart", + "padEnd", + "trim", + "trimStart", + "trimEnd", + "concat", + "substring", + "includes", + "slice", + ]; - genericStringPrototypeFunctions.forEach(name => { - String.prototype[name].call({ toString: () => "hello friends" }); - String.prototype[name].call({ toString: () => 123 }); - String.prototype[name].call({ toString: () => undefined }); + genericStringPrototypeFunctions.forEach(name => { + String.prototype[name].call({ toString: () => "hello friends" }); + String.prototype[name].call({ toString: () => 123 }); + String.prototype[name].call({ toString: () => undefined }); - expect(() => { - String.prototype[name].call({ toString: () => new String() }); - }).toThrowWithMessage(TypeError, "Cannot convert object to string"); + expect(() => { + String.prototype[name].call({ toString: () => new String() }); + }).toThrowWithMessage(TypeError, "Cannot convert object to string"); - expect(() => { - String.prototype[name].call({ toString: () => [] }); - }).toThrowWithMessage(TypeError, "Cannot convert object to string"); + expect(() => { + String.prototype[name].call({ toString: () => [] }); + }).toThrowWithMessage(TypeError, "Cannot convert object to string"); - expect(() => { - String.prototype[name].call({ toString: () => ({}) }); - }).toThrowWithMessage(TypeError, "Cannot convert object to string"); - }); + expect(() => { + String.prototype[name].call({ toString: () => ({}) }); + }).toThrowWithMessage(TypeError, "Cannot convert object to string"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js index 7f5ec19e83..f3cc6506fa 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js @@ -1,20 +1,20 @@ test("basic functionality", () => { - expect(String.prototype.charAt).toHaveLength(1); + expect(String.prototype.charAt).toHaveLength(1); - var s = "foobar" - expect(typeof s).toBe("string"); - expect(s).toHaveLength(6); + var s = "foobar"; + expect(typeof s).toBe("string"); + expect(s).toHaveLength(6); - expect(s.charAt(0)).toBe("f"); - expect(s.charAt(1)).toBe("o"); - expect(s.charAt(2)).toBe("o"); - expect(s.charAt(3)).toBe("b"); - expect(s.charAt(4)).toBe("a"); - expect(s.charAt(5)).toBe("r"); - expect(s.charAt(6)).toBe(""); + expect(s.charAt(0)).toBe("f"); + expect(s.charAt(1)).toBe("o"); + expect(s.charAt(2)).toBe("o"); + expect(s.charAt(3)).toBe("b"); + expect(s.charAt(4)).toBe("a"); + expect(s.charAt(5)).toBe("r"); + expect(s.charAt(6)).toBe(""); - expect(s.charAt()).toBe("f"); - expect(s.charAt(NaN)).toBe("f"); - expect(s.charAt("foo")).toBe("f"); - expect(s.charAt(undefined)).toBe("f"); + expect(s.charAt()).toBe("f"); + expect(s.charAt(NaN)).toBe("f"); + expect(s.charAt("foo")).toBe("f"); + expect(s.charAt(undefined)).toBe("f"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js index 4faab2a44f..d082e91981 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js @@ -1,17 +1,17 @@ test("basic functionality", () => { - expect(String.prototype.concat).toHaveLength(1); + expect(String.prototype.concat).toHaveLength(1); - expect("".concat(1)).toBe("1"); - expect("".concat(3,2,1)).toBe("321"); - expect("hello".concat(" ", "friends")).toBe("hello friends"); - expect("".concat(null)).toBe("null"); - expect("".concat(false)).toBe("false"); - expect("".concat(true)).toBe("true"); - expect("".concat([])).toBe(""); - expect("".concat([1, 2, 3, 'hello'])).toBe("1,2,3,hello"); - expect("".concat(true, [])).toBe("true"); - expect("".concat(true, false)).toBe("truefalse"); - expect("".concat({})).toBe("[object Object]"); - expect("".concat(1, {})).toBe("1[object Object]"); - expect("".concat(1, {}, false)).toBe("1[object Object]false"); + expect("".concat(1)).toBe("1"); + expect("".concat(3, 2, 1)).toBe("321"); + expect("hello".concat(" ", "friends")).toBe("hello friends"); + expect("".concat(null)).toBe("null"); + expect("".concat(false)).toBe("false"); + expect("".concat(true)).toBe("true"); + expect("".concat([])).toBe(""); + expect("".concat([1, 2, 3, "hello"])).toBe("1,2,3,hello"); + expect("".concat(true, [])).toBe("true"); + expect("".concat(true, false)).toBe("truefalse"); + expect("".concat({})).toBe("[object Object]"); + expect("".concat(1, {})).toBe("1[object Object]"); + expect("".concat(1, {}, false)).toBe("1[object Object]false"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js index e871e29ac7..ec83a56efc 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js @@ -1,12 +1,12 @@ test("basic functionality", () => { - expect(String.prototype.includes).toHaveLength(1); + expect(String.prototype.includes).toHaveLength(1); - expect("hello friends".includes("hello")).toBe(true); - expect("hello friends".includes("hello", 100)).toBe(false); - expect("hello friends".includes("hello", -10)).toBe(true); - expect("hello friends".includes("friends", 6)).toBe(true); - expect("hello friends".includes("hello", 6)).toBe(false); - expect("hello friends false".includes(false)).toBe(true); - expect("hello 10 friends".includes(10)).toBe(true); - expect("hello friends undefined".includes()).toBe(true); + expect("hello friends".includes("hello")).toBeTrue(); + expect("hello friends".includes("hello", 100)).toBeFalse(); + expect("hello friends".includes("hello", -10)).toBeTrue(); + expect("hello friends".includes("friends", 6)).toBeTrue(); + expect("hello friends".includes("hello", 6)).toBeFalse(); + expect("hello friends false".includes(false)).toBeTrue(); + expect("hello 10 friends".includes(10)).toBeTrue(); + expect("hello friends undefined".includes()).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js index 289267b4a8..bea486323a 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js @@ -1,8 +1,8 @@ test("basic functionality", () => { - expect(String.prototype.indexOf).toHaveLength(1); + expect(String.prototype.indexOf).toHaveLength(1); - var s = "hello friends" + var s = "hello friends"; - expect(s.indexOf("friends")).toBe(6); - expect(s.indexOf("enemies")).toBe(-1); + expect(s.indexOf("friends")).toBe(6); + expect(s.indexOf("enemies")).toBe(-1); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.js index c9d41e4982..fe44a81ce0 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.js @@ -1,9 +1,9 @@ test("basic functionality", () => { - expect(String.prototype).toHaveLength(0); - - expect(typeof Object.getPrototypeOf("")).toBe("object"); - expect(Object.getPrototypeOf("").valueOf()).toBe(""); + expect(String.prototype).toHaveLength(0); - expect(typeof String.prototype).toBe("object"); - expect(String.prototype.valueOf()).toBe(""); + expect(typeof Object.getPrototypeOf("")).toBe("object"); + expect(Object.getPrototypeOf("").valueOf()).toBe(""); + + expect(typeof String.prototype).toBe("object"); + expect(String.prototype.valueOf()).toBe(""); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js index ce69fc3214..40bb9cb233 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js @@ -1,22 +1,22 @@ test("basic functionality", () => { - expect(String.prototype.lastIndexOf).toHaveLength(1); + expect(String.prototype.lastIndexOf).toHaveLength(1); - expect("hello friends".lastIndexOf()).toBe(-1); - expect("hello friends".lastIndexOf("e")).toBe(9); - expect("hello friends".lastIndexOf("e", -7)).toBe(-1); - expect("hello friends".lastIndexOf("e", 100)).toBe(9); - expect("hello friends".lastIndexOf("")).toBe(13); - expect("hello friends".lastIndexOf("Z")).toBe(-1); - expect("hello friends".lastIndexOf("serenity")).toBe(-1); - expect("hello friends".lastIndexOf("", 4)).toBe(4); - expect("hello serenity friends".lastIndexOf("serenity")).toBe(6); - expect("hello serenity friends serenity".lastIndexOf("serenity")).toBe(23); - expect("hello serenity friends serenity".lastIndexOf("serenity", 14)).toBe(6); - expect("".lastIndexOf("")).toBe(0); - expect("".lastIndexOf("", 1)).toBe(0); - expect("".lastIndexOf("", -1)).toBe(0); - expect("hello friends serenity".lastIndexOf("h", 10)).toBe(0); - expect("hello friends serenity".lastIndexOf("l", 4)).toBe(3); - expect("hello friends serenity".lastIndexOf("s", 13)).toBe(12); - expect("hello".lastIndexOf("serenity")).toBe(-1); + expect("hello friends".lastIndexOf()).toBe(-1); + expect("hello friends".lastIndexOf("e")).toBe(9); + expect("hello friends".lastIndexOf("e", -7)).toBe(-1); + expect("hello friends".lastIndexOf("e", 100)).toBe(9); + expect("hello friends".lastIndexOf("")).toBe(13); + expect("hello friends".lastIndexOf("Z")).toBe(-1); + expect("hello friends".lastIndexOf("serenity")).toBe(-1); + expect("hello friends".lastIndexOf("", 4)).toBe(4); + expect("hello serenity friends".lastIndexOf("serenity")).toBe(6); + expect("hello serenity friends serenity".lastIndexOf("serenity")).toBe(23); + expect("hello serenity friends serenity".lastIndexOf("serenity", 14)).toBe(6); + expect("".lastIndexOf("")).toBe(0); + expect("".lastIndexOf("", 1)).toBe(0); + expect("".lastIndexOf("", -1)).toBe(0); + expect("hello friends serenity".lastIndexOf("h", 10)).toBe(0); + expect("hello friends serenity".lastIndexOf("l", 4)).toBe(3); + expect("hello friends serenity".lastIndexOf("s", 13)).toBe(12); + expect("hello".lastIndexOf("serenity")).toBe(-1); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js index a103084c3a..cecd5a241f 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js @@ -1,18 +1,18 @@ test("basic functionality", () => { - expect(String.prototype.padEnd).toHaveLength(1); + expect(String.prototype.padEnd).toHaveLength(1); - var s = "foo"; - expect(s.padEnd(-1)).toBe("foo"); - expect(s.padEnd(0)).toBe("foo"); - expect(s.padEnd(3)).toBe("foo"); - expect(s.padEnd(5)).toBe("foo "); - expect(s.padEnd(10)).toBe("foo "); - expect(s.padEnd("5")).toBe("foo "); - expect(s.padEnd([[["5"]]])).toBe("foo "); - expect(s.padEnd(2, "+")).toBe("foo"); - expect(s.padEnd(5, "+")).toBe("foo++"); - expect(s.padEnd(5, 1)).toBe("foo11"); - expect(s.padEnd(10, null)).toBe("foonullnul"); - expect(s.padEnd(10, "bar")).toBe("foobarbarb"); - expect(s.padEnd(10, "123456789")).toBe("foo1234567"); + var s = "foo"; + expect(s.padEnd(-1)).toBe("foo"); + expect(s.padEnd(0)).toBe("foo"); + expect(s.padEnd(3)).toBe("foo"); + expect(s.padEnd(5)).toBe("foo "); + expect(s.padEnd(10)).toBe("foo "); + expect(s.padEnd("5")).toBe("foo "); + expect(s.padEnd([[["5"]]])).toBe("foo "); + expect(s.padEnd(2, "+")).toBe("foo"); + expect(s.padEnd(5, "+")).toBe("foo++"); + expect(s.padEnd(5, 1)).toBe("foo11"); + expect(s.padEnd(10, null)).toBe("foonullnul"); + expect(s.padEnd(10, "bar")).toBe("foobarbarb"); + expect(s.padEnd(10, "123456789")).toBe("foo1234567"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js index a2f0f0b710..2c588bdbbb 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js @@ -1,18 +1,18 @@ test("basic functionality", () => { - expect(String.prototype.padStart).toHaveLength(1); + expect(String.prototype.padStart).toHaveLength(1); - var s = "foo"; - expect(s.padStart(-1)).toBe("foo"); - expect(s.padStart(0)).toBe("foo"); - expect(s.padStart(3)).toBe("foo"); - expect(s.padStart(5)).toBe(" foo"); - expect(s.padStart(10)).toBe(" foo"); - expect(s.padStart("5")).toBe(" foo"); - expect(s.padStart([[["5"]]])).toBe(" foo"); - expect(s.padStart(2, "+")).toBe("foo"); - expect(s.padStart(5, "+")).toBe("++foo"); - expect(s.padStart(5, 1)).toBe("11foo"); - expect(s.padStart(10, null)).toBe("nullnulfoo"); - expect(s.padStart(10, "bar")).toBe("barbarbfoo"); - expect(s.padStart(10, "123456789")).toBe("1234567foo"); + var s = "foo"; + expect(s.padStart(-1)).toBe("foo"); + expect(s.padStart(0)).toBe("foo"); + expect(s.padStart(3)).toBe("foo"); + expect(s.padStart(5)).toBe(" foo"); + expect(s.padStart(10)).toBe(" foo"); + expect(s.padStart("5")).toBe(" foo"); + expect(s.padStart([[["5"]]])).toBe(" foo"); + expect(s.padStart(2, "+")).toBe("foo"); + expect(s.padStart(5, "+")).toBe("++foo"); + expect(s.padStart(5, 1)).toBe("11foo"); + expect(s.padStart(10, null)).toBe("nullnulfoo"); + expect(s.padStart(10, "bar")).toBe("barbarbfoo"); + expect(s.padStart(10, "123456789")).toBe("1234567foo"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js index 8427698509..9ffd4edc31 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js @@ -1,25 +1,25 @@ test("basic functionality", () => { - expect(String.prototype.repeat).toHaveLength(1); + expect(String.prototype.repeat).toHaveLength(1); - expect("foo".repeat(0)).toBe(""); - expect("foo".repeat(1)).toBe("foo"); - expect("foo".repeat(2)).toBe("foofoo"); - expect("foo".repeat(3)).toBe("foofoofoo"); - expect("foo".repeat(3.1)).toBe("foofoofoo"); - expect("foo".repeat(3.5)).toBe("foofoofoo"); - expect("foo".repeat(3.9)).toBe("foofoofoo"); - expect("foo".repeat(null)).toBe(""); - expect("foo".repeat(undefined)).toBe(""); - expect("foo".repeat([])).toBe(""); - expect("foo".repeat("")).toBe(""); + expect("foo".repeat(0)).toBe(""); + expect("foo".repeat(1)).toBe("foo"); + expect("foo".repeat(2)).toBe("foofoo"); + expect("foo".repeat(3)).toBe("foofoofoo"); + expect("foo".repeat(3.1)).toBe("foofoofoo"); + expect("foo".repeat(3.5)).toBe("foofoofoo"); + expect("foo".repeat(3.9)).toBe("foofoofoo"); + expect("foo".repeat(null)).toBe(""); + expect("foo".repeat(undefined)).toBe(""); + expect("foo".repeat([])).toBe(""); + expect("foo".repeat("")).toBe(""); }); test("throws correct range errors", () => { - expect(() => { - "foo".repeat(-1); - }).toThrowWithMessage(RangeError, "repeat count must be a positive number"); + expect(() => { + "foo".repeat(-1); + }).toThrowWithMessage(RangeError, "repeat count must be a positive number"); - expect(() => { - "foo".repeat(Infinity); - }).toThrowWithMessage(RangeError, "repeat count must be a finite number"); + expect(() => { + "foo".repeat(Infinity); + }).toThrowWithMessage(RangeError, "repeat count must be a finite number"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js index 33bb1e374f..6d54170eb4 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js @@ -1,18 +1,17 @@ test("basic functionality", () => { - expect(String.prototype.slice).toHaveLength(2); + expect(String.prototype.slice).toHaveLength(2); - expect("hello friends".slice()).toBe("hello friends"); - expect("hello friends".slice(1)).toBe("ello friends"); - expect("hello friends".slice(0, 5)).toBe("hello"); - expect("hello friends".slice(13, 6)).toBe(""); - expect("hello friends".slice("", 5)).toBe("hello"); - expect("hello friends".slice(3, 3)).toBe(""); - expect("hello friends".slice(-1, 13)).toBe("s"); - expect("hello friends".slice(0, 50)).toBe("hello friends"); - expect("hello friends".slice(0, "5")).toBe("hello"); - expect("hello friends".slice("6", "13")).toBe("friends"); - expect("hello friends".slice(-7)).toBe("friends"); - expect("hello friends".slice(1000)).toBe(""); - expect("hello friends".slice(-1000)).toBe("hello friends"); + expect("hello friends".slice()).toBe("hello friends"); + expect("hello friends".slice(1)).toBe("ello friends"); + expect("hello friends".slice(0, 5)).toBe("hello"); + expect("hello friends".slice(13, 6)).toBe(""); + expect("hello friends".slice("", 5)).toBe("hello"); + expect("hello friends".slice(3, 3)).toBe(""); + expect("hello friends".slice(-1, 13)).toBe("s"); + expect("hello friends".slice(0, 50)).toBe("hello friends"); + expect("hello friends".slice(0, "5")).toBe("hello"); + expect("hello friends".slice("6", "13")).toBe("friends"); + expect("hello friends".slice(-7)).toBe("friends"); + expect("hello friends".slice(1000)).toBe(""); + expect("hello friends".slice(-1000)).toBe("hello friends"); }); - diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js index 5114da78f9..6687bb4df2 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js @@ -1,36 +1,36 @@ test("basic functionality", () => { - expect(String.prototype.startsWith).toHaveLength(1); + expect(String.prototype.startsWith).toHaveLength(1); - var s = "foobar"; - expect(s.startsWith("f")).toBeTrue(); - expect(s.startsWith("fo")).toBeTrue(); - expect(s.startsWith("foo")).toBeTrue(); - expect(s.startsWith("foob")).toBeTrue(); - expect(s.startsWith("fooba")).toBeTrue(); - expect(s.startsWith("foobar")).toBeTrue(); - expect(s.startsWith("foobar1")).toBeFalse(); - expect(s.startsWith("f", 0)).toBeTrue(); - expect(s.startsWith("fo", 0)).toBeTrue(); - expect(s.startsWith("foo", 0)).toBeTrue(); - expect(s.startsWith("foob", 0)).toBeTrue(); - expect(s.startsWith("fooba", 0)).toBeTrue(); - expect(s.startsWith("foobar", 0)).toBeTrue(); - expect(s.startsWith("foobar1", 0)).toBeFalse(); - expect(s.startsWith("foo", [])).toBeTrue(); - expect(s.startsWith("foo", null)).toBeTrue(); - expect(s.startsWith("foo", undefined)).toBeTrue(); - expect(s.startsWith("foo", false)).toBeTrue(); - expect(s.startsWith("foo", true)).toBeFalse(); - expect(s.startsWith("foo", "foo")).toBeTrue(); - expect(s.startsWith("foo", -1)).toBeTrue(); - expect(s.startsWith("foo", 42)).toBeFalse(); - expect(s.startsWith("bar", 3)).toBeTrue(); - expect(s.startsWith("bar", "3")).toBeTrue(); - expect(s.startsWith("bar1", 3)).toBeFalse(); - expect(s.startsWith()).toBeFalse(); - expect(s.startsWith("")).toBeTrue(); - expect(s.startsWith("", 0)).toBeTrue(); - expect(s.startsWith("", 1)).toBeTrue(); - expect(s.startsWith("", -1)).toBeTrue(); - expect(s.startsWith("", 42)).toBeTrue(); + var s = "foobar"; + expect(s.startsWith("f")).toBeTrue(); + expect(s.startsWith("fo")).toBeTrue(); + expect(s.startsWith("foo")).toBeTrue(); + expect(s.startsWith("foob")).toBeTrue(); + expect(s.startsWith("fooba")).toBeTrue(); + expect(s.startsWith("foobar")).toBeTrue(); + expect(s.startsWith("foobar1")).toBeFalse(); + expect(s.startsWith("f", 0)).toBeTrue(); + expect(s.startsWith("fo", 0)).toBeTrue(); + expect(s.startsWith("foo", 0)).toBeTrue(); + expect(s.startsWith("foob", 0)).toBeTrue(); + expect(s.startsWith("fooba", 0)).toBeTrue(); + expect(s.startsWith("foobar", 0)).toBeTrue(); + expect(s.startsWith("foobar1", 0)).toBeFalse(); + expect(s.startsWith("foo", [])).toBeTrue(); + expect(s.startsWith("foo", null)).toBeTrue(); + expect(s.startsWith("foo", undefined)).toBeTrue(); + expect(s.startsWith("foo", false)).toBeTrue(); + expect(s.startsWith("foo", true)).toBeFalse(); + expect(s.startsWith("foo", "foo")).toBeTrue(); + expect(s.startsWith("foo", -1)).toBeTrue(); + expect(s.startsWith("foo", 42)).toBeFalse(); + expect(s.startsWith("bar", 3)).toBeTrue(); + expect(s.startsWith("bar", "3")).toBeTrue(); + expect(s.startsWith("bar1", 3)).toBeFalse(); + expect(s.startsWith()).toBeFalse(); + expect(s.startsWith("")).toBeTrue(); + expect(s.startsWith("", 0)).toBeTrue(); + expect(s.startsWith("", 1)).toBeTrue(); + expect(s.startsWith("", -1)).toBeTrue(); + expect(s.startsWith("", 42)).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js index 294d756898..f2b06bcb62 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js @@ -1,14 +1,14 @@ test("basic functionality", () => { - expect(String.prototype.substring).toHaveLength(2); + expect(String.prototype.substring).toHaveLength(2); - expect("hello friends".substring()).toBe("hello friends"); - expect("hello friends".substring(1)).toBe("ello friends"); - expect("hello friends".substring(0, 5)).toBe("hello"); - expect("hello friends".substring(13, 6)).toBe("friends"); - expect("hello friends".substring('', 5)).toBe("hello"); - expect("hello friends".substring(3, 3)).toBe(""); - expect("hello friends".substring(-1, 13)).toBe("hello friends"); - expect("hello friends".substring(0, 50)).toBe("hello friends"); - expect("hello friends".substring(0, "5")).toBe("hello"); - expect("hello friends".substring("6", "13")).toBe("friends"); + expect("hello friends".substring()).toBe("hello friends"); + expect("hello friends".substring(1)).toBe("ello friends"); + expect("hello friends".substring(0, 5)).toBe("hello"); + expect("hello friends".substring(13, 6)).toBe("friends"); + expect("hello friends".substring("", 5)).toBe("hello"); + expect("hello friends".substring(3, 3)).toBe(""); + expect("hello friends".substring(-1, 13)).toBe("hello friends"); + expect("hello friends".substring(0, 50)).toBe("hello friends"); + expect("hello friends".substring(0, "5")).toBe("hello"); + expect("hello friends".substring("6", "13")).toBe("friends"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js index 8823cfda45..0be8bfb68b 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js @@ -1,9 +1,9 @@ test("basic functionality", () => { - expect(String.prototype.toLowerCase).toHaveLength(0); + expect(String.prototype.toLowerCase).toHaveLength(0); - expect("foo".toLowerCase()).toBe("foo"); - expect("Foo".toLowerCase()).toBe("foo"); - expect("FOO".toLowerCase()).toBe("foo"); + expect("foo".toLowerCase()).toBe("foo"); + expect("Foo".toLowerCase()).toBe("foo"); + expect("FOO".toLowerCase()).toBe("foo"); - expect(('b' + 'a' + + 'a' + 'a').toLowerCase()).toBe("banana"); + expect(("b" + "a" + +"a" + "a").toLowerCase()).toBe("banana"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js index 59a6885772..726d33b8e2 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js @@ -1,6 +1,6 @@ test("basic functionality", () => { - expect(String.prototype.toString).toHaveLength(0) + expect(String.prototype.toString).toHaveLength(0); - expect("".toString()).toBe(""); - expect("hello friends".toString()).toBe("hello friends"); + expect("".toString()).toBe(""); + expect("hello friends".toString()).toBe("hello friends"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.toUpperCase.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.toUpperCase.js index 1c4877d071..419b68abac 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.toUpperCase.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.toUpperCase.js @@ -1,9 +1,9 @@ test("basic functionality", () => { - expect(String.prototype.toUpperCase).toHaveLength(0); + expect(String.prototype.toUpperCase).toHaveLength(0); - expect("foo".toUpperCase()).toBe("FOO"); - expect("Foo".toUpperCase()).toBe("FOO"); - expect("FOO".toUpperCase()).toBe("FOO"); + expect("foo".toUpperCase()).toBe("FOO"); + expect("Foo".toUpperCase()).toBe("FOO"); + expect("FOO".toUpperCase()).toBe("FOO"); - expect(('b' + 'a' + + 'n' + 'a').toUpperCase()).toBe("BANANA"); + expect(("b" + "a" + +"n" + "a").toUpperCase()).toBe("BANANA"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js index d60522cad4..0ccfd207d4 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js @@ -1,58 +1,58 @@ test("trim", () => { - expect(String.prototype.trim).toHaveLength(0); + expect(String.prototype.trim).toHaveLength(0); - expect(" hello friends ".trim()).toBe("hello friends"); - expect("hello friends ".trim()).toBe("hello friends"); - expect(" hello friends".trim()).toBe("hello friends"); + expect(" hello friends ".trim()).toBe("hello friends"); + expect("hello friends ".trim()).toBe("hello friends"); + expect(" hello friends".trim()).toBe("hello friends"); - expect("\thello friends\t".trim()).toBe("hello friends"); - expect("\thello friends".trim()).toBe("hello friends"); - expect("hello friends\t".trim()).toBe("hello friends"); + expect("\thello friends\t".trim()).toBe("hello friends"); + expect("\thello friends".trim()).toBe("hello friends"); + expect("hello friends\t".trim()).toBe("hello friends"); - expect("\rhello friends\r".trim()).toBe("hello friends"); - expect("\rhello friends".trim()).toBe("hello friends"); - expect("hello friends\r".trim()).toBe("hello friends"); + expect("\rhello friends\r".trim()).toBe("hello friends"); + expect("\rhello friends".trim()).toBe("hello friends"); + expect("hello friends\r".trim()).toBe("hello friends"); - expect("\rhello friends\n".trim()).toBe("hello friends"); - expect("\r\thello friends".trim()).toBe("hello friends"); - expect("hello friends\r\n".trim()).toBe("hello friends"); - expect(" \thello friends\r\n".trim()).toBe("hello friends"); - expect("\n\t\thello friends\r\n".trim()).toBe("hello friends"); - expect("\n\t\thello friends\t\t".trim()).toBe("hello friends"); + expect("\rhello friends\n".trim()).toBe("hello friends"); + expect("\r\thello friends".trim()).toBe("hello friends"); + expect("hello friends\r\n".trim()).toBe("hello friends"); + expect(" \thello friends\r\n".trim()).toBe("hello friends"); + expect("\n\t\thello friends\r\n".trim()).toBe("hello friends"); + expect("\n\t\thello friends\t\t".trim()).toBe("hello friends"); }); test("trimStart", () => { - expect(String.prototype.trimStart).toHaveLength(0); + expect(String.prototype.trimStart).toHaveLength(0); - expect(" hello friends".trimStart()).toBe("hello friends"); - expect("hello friends ".trimStart()).toBe("hello friends "); - expect(" hello friends ".trimStart()).toBe("hello friends "); + expect(" hello friends".trimStart()).toBe("hello friends"); + expect("hello friends ".trimStart()).toBe("hello friends "); + expect(" hello friends ".trimStart()).toBe("hello friends "); - expect("\thello friends".trimStart()).toBe("hello friends"); - expect("hello friends\t".trimStart()).toBe("hello friends\t"); - expect("\thello friends\t".trimStart()).toBe("hello friends\t"); + expect("\thello friends".trimStart()).toBe("hello friends"); + expect("hello friends\t".trimStart()).toBe("hello friends\t"); + expect("\thello friends\t".trimStart()).toBe("hello friends\t"); - expect("\rhello friends".trimStart()).toBe("hello friends"); - expect("hello friends\r".trimStart()).toBe("hello friends\r"); - expect("\rhello friends\r".trimStart()).toBe("hello friends\r"); + expect("\rhello friends".trimStart()).toBe("hello friends"); + expect("hello friends\r".trimStart()).toBe("hello friends\r"); + expect("\rhello friends\r".trimStart()).toBe("hello friends\r"); }); test("trimEnd", () => { - expect(String.prototype.trimEnd).toHaveLength(0); + expect(String.prototype.trimEnd).toHaveLength(0); - expect("hello friends ".trimEnd()).toBe("hello friends"); - expect(" hello friends".trimEnd()).toBe(" hello friends"); - expect(" hello friends ".trimEnd()).toBe(" hello friends"); + expect("hello friends ".trimEnd()).toBe("hello friends"); + expect(" hello friends".trimEnd()).toBe(" hello friends"); + expect(" hello friends ".trimEnd()).toBe(" hello friends"); - expect("hello friends\t".trimEnd()).toBe("hello friends"); - expect("\thello friends".trimEnd()).toBe("\thello friends"); - expect("\thello friends\t".trimEnd()).toBe("\thello friends"); + expect("hello friends\t".trimEnd()).toBe("hello friends"); + expect("\thello friends".trimEnd()).toBe("\thello friends"); + expect("\thello friends\t".trimEnd()).toBe("\thello friends"); - expect("hello friends\r".trimEnd()).toBe("hello friends"); - expect("\rhello friends".trimEnd()).toBe("\rhello friends"); - expect("\rhello friends\r".trimEnd()).toBe("\rhello friends"); + expect("hello friends\r".trimEnd()).toBe("hello friends"); + expect("\rhello friends".trimEnd()).toBe("\rhello friends"); + expect("\rhello friends\r".trimEnd()).toBe("\rhello friends"); - expect("hello friends\n".trimEnd()).toBe("hello friends"); - expect("\r\nhello friends".trimEnd()).toBe("\r\nhello friends"); - expect("\rhello friends\r\n".trimEnd()).toBe("\rhello friends"); + expect("hello friends\n".trimEnd()).toBe("hello friends"); + expect("\r\nhello friends".trimEnd()).toBe("\r\nhello friends"); + expect("\rhello friends\r\n".trimEnd()).toBe("\rhello friends"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js index 9831064a0b..6d21cbc501 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js @@ -1,12 +1,12 @@ test("basic functionality", () => { - expect(String.prototype.valueOf).toHaveLength(0); - - expect(String()).toBe(""); - expect(new String().valueOf()).toBe(""); - expect(String("foo")).toBe("foo"); - expect(new String("foo").valueOf()).toBe("foo"); - expect(String(123)).toBe("123"); - expect(new String(123).valueOf()).toBe("123"); - expect(String(123)).toBe("123"); - expect(new String(123).valueOf()).toBe("123"); + expect(String.prototype.valueOf).toHaveLength(0); + + expect(String()).toBe(""); + expect(new String().valueOf()).toBe(""); + expect(String("foo")).toBe("foo"); + expect(new String("foo").valueOf()).toBe("foo"); + expect(String(123)).toBe("123"); + expect(new String(123).valueOf()).toBe("123"); + expect(String(123)).toBe("123"); + expect(new String(123).valueOf()).toBe("123"); }); diff --git a/Libraries/LibJS/Tests/builtins/String/String.raw.js b/Libraries/LibJS/Tests/builtins/String/String.raw.js index a866276034..603d88e974 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.raw.js +++ b/Libraries/LibJS/Tests/builtins/String/String.raw.js @@ -1,31 +1,31 @@ test("basic functionality", () => { - expect(String.raw).toHaveLength(1); + expect(String.raw).toHaveLength(1); - let str = String.raw`foo\nbar`; - expect(str).toHaveLength(8); - expect(str).toBe("foo\\nbar"); + let str = String.raw`foo\nbar`; + expect(str).toHaveLength(8); + expect(str).toBe("foo\\nbar"); - str = String.raw`foo ${1 + 9}\nbar${"hf!"}`; - expect(str).toBe("foo 10\\nbarhf!"); + str = String.raw`foo ${1 + 9}\nbar${"hf!"}`; + expect(str).toBe("foo 10\\nbarhf!"); - str = String.raw`${10}${20}${30}`; - expect(str).toBe("102030"); + str = String.raw`${10}${20}${30}`; + expect(str).toBe("102030"); - str = String.raw({ raw: ["foo ", "\\nbar"] }, 10, "hf!"); - expect(str).toBe("foo 10\\nbar"); + str = String.raw({ raw: ["foo ", "\\nbar"] }, 10, "hf!"); + expect(str).toBe("foo 10\\nbar"); - str = String.raw({ raw: ["foo ", "\\nbar"] }); - expect(str).toBe("foo \\nbar"); + str = String.raw({ raw: ["foo ", "\\nbar"] }); + expect(str).toBe("foo \\nbar"); - str = String.raw({ raw: [] }, 10, "hf!"); - expect(str).toBe(""); + str = String.raw({ raw: [] }, 10, "hf!"); + expect(str).toBe(""); - str = String.raw({ raw: 1 }); - expect(str).toBe(""); + str = String.raw({ raw: 1 }); + expect(str).toBe(""); }); test("passing object with no 'raw' property", () => { - expect(() => { - String.raw({}); - }).toThrowWithMessage(TypeError, "Cannot convert property 'raw' to object from undefined"); + expect(() => { + String.raw({}); + }).toThrowWithMessage(TypeError, "Cannot convert property 'raw' to object from undefined"); }); diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.for.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.for.js index 11b586ffcb..0d581d98b6 100644 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.for.js +++ b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.for.js @@ -1,30 +1,33 @@ -load("test-common.js") +load("test-common.js"); try { - const localSym = Symbol("foo"); - const globalSym = Symbol.for("foo"); + const localSym = Symbol("foo"); + const globalSym = Symbol.for("foo"); - assert(localSym !== globalSym); - assert(localSym !== Symbol("foo")); - assert(globalSym !== Symbol("foo")); - assert(globalSym === Symbol.for("foo")); - assert(localSym.toString() === "Symbol(foo)"); - assert(globalSym.toString() === "Symbol(foo)"); + assert(localSym !== globalSym); + assert(localSym !== Symbol("foo")); + assert(globalSym !== Symbol("foo")); + assert(globalSym === Symbol.for("foo")); + assert(localSym.toString() === "Symbol(foo)"); + assert(globalSym.toString() === "Symbol(foo)"); - assert(Symbol.for(1).description === "1"); - assert(Symbol.for(true).description === "true"); - assert(Symbol.for({}).description === "[object Object]"); - assert(Symbol.for().description === "undefined"); - assert(Symbol.for(null).description === "null"); + assert(Symbol.for(1).description === "1"); + assert(Symbol.for(true).description === "true"); + assert(Symbol.for({}).description === "[object Object]"); + assert(Symbol.for().description === "undefined"); + assert(Symbol.for(null).description === "null"); - assertThrowsError(() => { - Symbol.for(Symbol()); - }, { - error: TypeError, - message: "Cannot convert symbol to string", - }); + assertThrowsError( + () => { + Symbol.for(Symbol()); + }, + { + error: TypeError, + message: "Cannot convert symbol to string", + } + ); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js index a982391921..f6cf02fa66 100644 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js +++ b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js @@ -1,26 +1,29 @@ -load("test-common.js") +load("test-common.js"); try { - const s1 = Symbol("foo"); - const s2 = Symbol("foo"); + const s1 = Symbol("foo"); + const s2 = Symbol("foo"); - assert(s1 !== s2); - assert(s1.description === "foo"); - assert(s2.description === "foo"); + assert(s1 !== s2); + assert(s1.description === "foo"); + assert(s2.description === "foo"); - s1.description = "bar"; - assert(s1.description === "foo"); + s1.description = "bar"; + assert(s1.description === "foo"); - assert(typeof s1 === "symbol"); + assert(typeof s1 === "symbol"); - assertThrowsError(() => { - Symbol(Symbol('foo')); - }, { - error: TypeError, - message: "Cannot convert symbol to string" - }) - - console.log("PASS"); + assertThrowsError( + () => { + Symbol(Symbol("foo")); + }, + { + error: TypeError, + message: "Cannot convert symbol to string", + } + ); + + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.keyFor.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.keyFor.js index 56e3ed9d81..93311673b3 100644 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.keyFor.js +++ b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.keyFor.js @@ -1,31 +1,34 @@ -load("test-common.js") +load("test-common.js"); try { - const localSym = Symbol("foo"); - const globalSym = Symbol.for("foo"); + const localSym = Symbol("foo"); + const globalSym = Symbol.for("foo"); - assert(Symbol.keyFor(localSym) === undefined); - assert(Symbol.keyFor(globalSym) === "foo"); + assert(Symbol.keyFor(localSym) === undefined); + assert(Symbol.keyFor(globalSym) === "foo"); - const testThrows = (value, str) => { - assertThrowsError(() => { - Symbol.keyFor(value); - }, { - error: TypeError, - message: str + " is not a symbol", - }); - }; + const testThrows = (value, str) => { + assertThrowsError( + () => { + Symbol.keyFor(value); + }, + { + error: TypeError, + message: str + " is not a symbol", + } + ); + }; - testThrows(1, "1"); - testThrows(null, "null"); - testThrows(undefined, "undefined"); - testThrows([], "[object Array]"); - testThrows({}, "[object Object]"); - testThrows(true, "true"); - testThrows("foobar", "foobar"); - testThrows(function(){}, "[object ScriptFunction]"); // FIXME: Better function stringification + testThrows(1, "1"); + testThrows(null, "null"); + testThrows(undefined, "undefined"); + testThrows([], "[object Array]"); + testThrows({}, "[object Object]"); + testThrows(true, "true"); + testThrows("foobar", "foobar"); + testThrows(function () {}, "[object ScriptFunction]"); // FIXME: Better function stringification - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js index d4c620d8d7..f4dbc0bcb7 100644 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js @@ -1,27 +1,33 @@ -load("test-common.js") +load("test-common.js"); try { - const s1 = Symbol("foo"); - const s2 = Symbol.for("bar"); + const s1 = Symbol("foo"); + const s2 = Symbol.for("bar"); - assert(s1.toString() === "Symbol(foo)"); - assert(s2.toString() === "Symbol(bar)"); - - assertThrowsError(() => { - s1 + ""; - }, { - error: TypeError, - message: "Cannot convert symbol to string", - }); - - assertThrowsError(() => { - s1 + 1; - }, { - error: TypeError, - message: "Cannot convert symbol to number", - }); - - console.log("PASS"); + assert(s1.toString() === "Symbol(foo)"); + assert(s2.toString() === "Symbol(bar)"); + + assertThrowsError( + () => { + s1 + ""; + }, + { + error: TypeError, + message: "Cannot convert symbol to string", + } + ); + + assertThrowsError( + () => { + s1 + 1; + }, + { + error: TypeError, + message: "Cannot convert symbol to number", + } + ); + + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); -} + console.log("FAIL: " + e); +} diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.valueOf.js index 0af3600ad2..c242268c52 100644 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.valueOf.js +++ b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.valueOf.js @@ -1,22 +1,25 @@ load("test-common.js"); try { - let local = Symbol('foo'); - let global = Symbol.for('foo'); - assert(local.valueOf() === local); - assert(global.valueOf() === global); + let local = Symbol("foo"); + let global = Symbol.for("foo"); + assert(local.valueOf() === local); + assert(global.valueOf() === global); - assert(Symbol.prototype.valueOf.call(local) === local); - assert(Symbol.prototype.valueOf.call(global) === global); + assert(Symbol.prototype.valueOf.call(local) === local); + assert(Symbol.prototype.valueOf.call(global) === global); - assertThrowsError(() => { - Symbol.prototype.valueOf.call("foo"); - }, { - error: TypeError, - message: "Not a Symbol object", - }); + assertThrowsError( + () => { + Symbol.prototype.valueOf.call("foo"); + }, + { + error: TypeError, + message: "Not a Symbol object", + } + ); - console.log("PASS"); + console.log("PASS"); } catch (err) { - console.log("FAIL: " + err); + console.log("FAIL: " + err); } diff --git a/Libraries/LibJS/Tests/builtins/functions/isFinite.js b/Libraries/LibJS/Tests/builtins/functions/isFinite.js index 71f4f70655..fc4ef12092 100644 --- a/Libraries/LibJS/Tests/builtins/functions/isFinite.js +++ b/Libraries/LibJS/Tests/builtins/functions/isFinite.js @@ -1,23 +1,23 @@ test("basic functionality", () => { - expect(isFinite).toHaveLength(1); + expect(isFinite).toHaveLength(1); - expect(isFinite(0)).toBeTrue(); - expect(isFinite(1.23)).toBeTrue(); - expect(isFinite(42)).toBeTrue(); - expect(isFinite("")).toBeTrue(); - expect(isFinite("0")).toBeTrue(); - expect(isFinite("42")).toBeTrue(); - expect(isFinite(true)).toBeTrue(); - expect(isFinite(false)).toBeTrue(); - expect(isFinite(null)).toBeTrue(); - expect(isFinite([])).toBeTrue(); + expect(isFinite(0)).toBeTrue(); + expect(isFinite(1.23)).toBeTrue(); + expect(isFinite(42)).toBeTrue(); + expect(isFinite("")).toBeTrue(); + expect(isFinite("0")).toBeTrue(); + expect(isFinite("42")).toBeTrue(); + expect(isFinite(true)).toBeTrue(); + expect(isFinite(false)).toBeTrue(); + expect(isFinite(null)).toBeTrue(); + expect(isFinite([])).toBeTrue(); - expect(isFinite()).toBeFalse(); - expect(isFinite(NaN)).toBeFalse(); - expect(isFinite(undefined)).toBeFalse(); - expect(isFinite(Infinity)).toBeFalse(); - expect(isFinite(-Infinity)).toBeFalse(); - expect(isFinite("foo")).toBeFalse(); - expect(isFinite({})).toBeFalse(); - expect(isFinite([1, 2, 3])).toBeFalse(); + expect(isFinite()).toBeFalse(); + expect(isFinite(NaN)).toBeFalse(); + expect(isFinite(undefined)).toBeFalse(); + expect(isFinite(Infinity)).toBeFalse(); + expect(isFinite(-Infinity)).toBeFalse(); + expect(isFinite("foo")).toBeFalse(); + expect(isFinite({})).toBeFalse(); + expect(isFinite([1, 2, 3])).toBeFalse(); }); diff --git a/Libraries/LibJS/Tests/builtins/functions/isNaN.js b/Libraries/LibJS/Tests/builtins/functions/isNaN.js index 188050ef6e..3ad781a649 100644 --- a/Libraries/LibJS/Tests/builtins/functions/isNaN.js +++ b/Libraries/LibJS/Tests/builtins/functions/isNaN.js @@ -1,22 +1,22 @@ test("basic functionality", () => { - expect(isNaN).toHaveLength(1); + expect(isNaN).toHaveLength(1); - expect(isNaN(0)).toBeFalse(); - expect(isNaN(42)).toBeFalse(); - expect(isNaN("")).toBeFalse(); - expect(isNaN("0")).toBeFalse(); - expect(isNaN("42")).toBeFalse(); - expect(isNaN(true)).toBeFalse(); - expect(isNaN(false)).toBeFalse(); - expect(isNaN(null)).toBeFalse(); - expect(isNaN([])).toBeFalse(); - expect(isNaN(Infinity)).toBeFalse(); - expect(isNaN(-Infinity)).toBeFalse(); + expect(isNaN(0)).toBeFalse(); + expect(isNaN(42)).toBeFalse(); + expect(isNaN("")).toBeFalse(); + expect(isNaN("0")).toBeFalse(); + expect(isNaN("42")).toBeFalse(); + expect(isNaN(true)).toBeFalse(); + expect(isNaN(false)).toBeFalse(); + expect(isNaN(null)).toBeFalse(); + expect(isNaN([])).toBeFalse(); + expect(isNaN(Infinity)).toBeFalse(); + expect(isNaN(-Infinity)).toBeFalse(); - expect(isNaN()).toBeTrue(); - expect(isNaN(NaN)).toBeTrue(); - expect(isNaN(undefined)).toBeTrue(); - expect(isNaN("foo")).toBeTrue(); - expect(isNaN({})).toBeTrue(); - expect(isNaN([1, 2, 3])).toBeTrue(); + expect(isNaN()).toBeTrue(); + expect(isNaN(NaN)).toBeTrue(); + expect(isNaN(undefined)).toBeTrue(); + expect(isNaN("foo")).toBeTrue(); + expect(isNaN({})).toBeTrue(); + expect(isNaN([1, 2, 3])).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/builtins/functions/parseFloat.js b/Libraries/LibJS/Tests/builtins/functions/parseFloat.js index 20ca28e445..63c016535b 100644 --- a/Libraries/LibJS/Tests/builtins/functions/parseFloat.js +++ b/Libraries/LibJS/Tests/builtins/functions/parseFloat.js @@ -1,59 +1,59 @@ test("parsing numbers", () => { - [ - [0, 0], - [1, 1], - [.23, 0.23], - [1.23, 1.23], - [0.0123E+2, 1.23], - [1.23e4, 12300], - [Infinity, Infinity] - ].forEach(test => { - expect(parseFloat(test[0])).toBe(test[1]); - expect(parseFloat(+test[0])).toBe(test[1]); - expect(parseFloat(-test[0])).toBe(-test[1]); - }); + [ + [0, 0], + [1, 1], + [0.23, 0.23], + [1.23, 1.23], + [0.0123e2, 1.23], + [1.23e4, 12300], + [Infinity, Infinity], + ].forEach(test => { + expect(parseFloat(test[0])).toBe(test[1]); + expect(parseFloat(+test[0])).toBe(test[1]); + expect(parseFloat(-test[0])).toBe(-test[1]); + }); }); test("parsing strings", () => { - [ - ["0", 0], - ["1", 1], - [".23", 0.23], - ["1.23", 1.23], - ["0.0123E+2", 1.23], - ["1.23e4", 12300], - ["Infinity", Infinity] - ].forEach(test => { - expect(parseFloat(test[0])).toBe(test[1]); - expect(parseFloat(`+${test[0]}`)).toBe(test[1]); - expect(parseFloat(`-${test[0]}`)).toBe(-test[1]); - expect(parseFloat(`${test[0]}foo`)).toBe(test[1]); - expect(parseFloat(`+${test[0]}foo`)).toBe(test[1]); - expect(parseFloat(`-${test[0]}foo`)).toBe(-test[1]); - expect(parseFloat(` \n \t ${test[0]} \v foo `)).toBe(test[1]); - expect(parseFloat(` \r -${test[0]} \f \n\n foo `)).toBe(-test[1]); - expect(parseFloat({ toString: () => test[0] })).toBe(test[1]); - }); + [ + ["0", 0], + ["1", 1], + [".23", 0.23], + ["1.23", 1.23], + ["0.0123E+2", 1.23], + ["1.23e4", 12300], + ["Infinity", Infinity], + ].forEach(test => { + expect(parseFloat(test[0])).toBe(test[1]); + expect(parseFloat(`+${test[0]}`)).toBe(test[1]); + expect(parseFloat(`-${test[0]}`)).toBe(-test[1]); + expect(parseFloat(`${test[0]}foo`)).toBe(test[1]); + expect(parseFloat(`+${test[0]}foo`)).toBe(test[1]); + expect(parseFloat(`-${test[0]}foo`)).toBe(-test[1]); + expect(parseFloat(` \n \t ${test[0]} \v foo `)).toBe(test[1]); + expect(parseFloat(` \r -${test[0]} \f \n\n foo `)).toBe(-test[1]); + expect(parseFloat({ toString: () => test[0] })).toBe(test[1]); + }); }); test("parsing NaN", () => { - [ - "", - [], - [], - true, - false, - null, - undefined, - NaN, - "foo123", - "foo+123", - "fooInfinity", - "foo+Infinity" - ].forEach(value => { - expect(parseFloat(value)).toBeNaN(); - }); + [ + "", + [], + [], + true, + false, + null, + undefined, + NaN, + "foo123", + "foo+123", + "fooInfinity", + "foo+Infinity", + ].forEach(value => { + expect(parseFloat(value)).toBeNaN(); + }); - expect(parseFloat()).toBeNaN(); - expect(parseFloat("", 123, Infinity)).toBeNaN(); + expect(parseFloat()).toBeNaN(); + expect(parseFloat("", 123, Infinity)).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/classes/class-basic.js b/Libraries/LibJS/Tests/classes/class-basic.js index 842efd472b..2fd856ac36 100644 --- a/Libraries/LibJS/Tests/classes/class-basic.js +++ b/Libraries/LibJS/Tests/classes/class-basic.js @@ -1,158 +1,166 @@ load("test-common.js"); try { - class X { - constructor() { - this.x = 3; - } - getX() { - return 3; - } - - init() { - this.y = 3; - } + class X { + constructor() { + this.x = 3; + } + getX() { + return 3; } - assert(X.name === "X"); - assert(X.length === 0); + init() { + this.y = 3; + } + } - class Y extends X { - init() { - super.init(); - this.y += 3; - } + assert(X.name === "X"); + assert(X.length === 0); + + class Y extends X { + init() { + super.init(); + this.y += 3; + } + } + + assert(new Y().getX() === 3); + assert(new Y().x === 3); + + let x = new X(); + assert(x.x === 3); + assert(x.getX() === 3); + + let y = new Y(); + assert(y.x === 3); + assert(y.y === undefined); + y.init(); + assert(y.y === 6); + assert(y.hasOwnProperty("y")); + + class Foo { + constructor(x) { + this.x = x; + } + } + assert(Foo.length === 1); + + class Bar extends Foo { + constructor() { + super(5); + } + } + + class Baz { + constructor() { + this.foo = 55; + this._bar = 33; } - assert(new Y().getX() === 3); - assert(new Y().x === 3); - - let x = new X(); - assert(x.x === 3); - assert(x.getX() === 3); - - let y = new Y(); - assert(y.x === 3); - assert(y.y === undefined); - y.init(); - assert(y.y === 6); - assert(y.hasOwnProperty("y")); - - class Foo { - constructor(x) { - this.x = x; - } - } - assert(Foo.length === 1); - - class Bar extends Foo { - constructor() { - super(5); - } + get bar() { + return this._bar; } - class Baz { - "constructor"() { - this.foo = 55; - this._bar = 33; - } - - get bar() { - return this._bar; - } - - set bar(value) { - this._bar = value; - } - - ["get" + "Foo"]() { - return this.foo; - } - - static get staticFoo() { - assert(this === Baz); - return 11; - } + set bar(value) { + this._bar = value; } - - let barPropertyDescriptor = Object.getOwnPropertyDescriptor(Baz.prototype, "bar"); - assert(barPropertyDescriptor.get.name === "get bar"); - assert(barPropertyDescriptor.set.name === "set bar"); - - let baz = new Baz(); - assert(baz.foo === 55); - assert(baz.bar === 33); - baz.bar = 22; - assert(baz.bar === 22); - - assert(baz.getFoo() === 55); - assert(Baz.staticFoo === 11); - - assert(new Bar().x === 5); - - class ExtendsFunction extends function () { this.foo = 22; } { } - assert(new ExtendsFunction().foo === 22); - - class ExtendsString extends String { } - assert(new ExtendsString() instanceof String); - assert(new ExtendsString() instanceof ExtendsString); - assert(new ExtendsString("abc").charAt(1) === "b"); - - class MyWeirdString extends ExtendsString { - charAt(i) { - return "#" + super.charAt(i); - } - } - assert(new MyWeirdString("abc").charAt(1) === "#b") - - class ExtendsNull extends null { } - - assertThrowsError(() => { - new ExtendsNull(); - }, { - error: ReferenceError - }); - assert(Object.getPrototypeOf(ExtendsNull.prototype) === null); - - class ExtendsClassExpression extends class { constructor(x) { this.x = x; } } { - constructor(y) { - super(5); - this.y = 6; - } - } - let extendsClassExpression = new ExtendsClassExpression(); - assert(extendsClassExpression.x === 5); - assert(extendsClassExpression.y === 6); - - class InStrictMode { - constructor() { - assert(isStrictMode()); - } - - method() { - assert(isStrictMode()); - } + ["get" + "Foo"]() { + return this.foo; } - let resultOfAnExpression = new (class { - constructor(x) { - this.x = x; - } - getX() { - return this.x + 10; - } - })(55); - assert(resultOfAnExpression.x === 55); - assert(resultOfAnExpression.getX() === 65); + static get staticFoo() { + assert(this === Baz); + return 11; + } + } - let ClassExpression = class Foo { }; - assert(ClassExpression.name === "Foo"); + let barPropertyDescriptor = Object.getOwnPropertyDescriptor(Baz.prototype, "bar"); + assert(barPropertyDescriptor.get.name === "get bar"); + assert(barPropertyDescriptor.set.name === "set bar"); - new InStrictMode().method(); - assert(!isStrictMode()); + let baz = new Baz(); + assert(baz.foo === 55); + assert(baz.bar === 33); + baz.bar = 22; + assert(baz.bar === 22); - assertIsSyntaxError(` + assert(baz.getFoo() === 55); + assert(Baz.staticFoo === 11); + + assert(new Bar().x === 5); + + class ExtendsFunction extends function () { + this.foo = 22; + } {} + assert(new ExtendsFunction().foo === 22); + + class ExtendsString extends String {} + assert(new ExtendsString() instanceof String); + assert(new ExtendsString() instanceof ExtendsString); + assert(new ExtendsString("abc").charAt(1) === "b"); + + class MyWeirdString extends ExtendsString { + charAt(i) { + return "#" + super.charAt(i); + } + } + assert(new MyWeirdString("abc").charAt(1) === "#b"); + + class ExtendsNull extends null {} + + assertThrowsError( + () => { + new ExtendsNull(); + }, + { + error: ReferenceError, + } + ); + assert(Object.getPrototypeOf(ExtendsNull.prototype) === null); + + class ExtendsClassExpression extends class { + constructor(x) { + this.x = x; + } + } { + constructor(y) { + super(5); + this.y = 6; + } + } + let extendsClassExpression = new ExtendsClassExpression(); + assert(extendsClassExpression.x === 5); + assert(extendsClassExpression.y === 6); + + class InStrictMode { + constructor() { + assert(isStrictMode()); + } + + method() { + assert(isStrictMode()); + } + } + + let resultOfAnExpression = new (class { + constructor(x) { + this.x = x; + } + getX() { + return this.x + 10; + } + })(55); + assert(resultOfAnExpression.x === 55); + assert(resultOfAnExpression.getX() === 65); + + let ClassExpression = class Foo {}; + assert(ClassExpression.name === "Foo"); + + new InStrictMode().method(); + assert(!isStrictMode()); + + assertIsSyntaxError(` class GetterWithArgument { get foo(bar) { return 0; @@ -160,21 +168,21 @@ try { } `); - assertIsSyntaxError(` + assertIsSyntaxError(` class SetterWithNoArgumetns { set foo() { } } `); - assertIsSyntaxError(` + assertIsSyntaxError(` class SetterWithMoreThanOneArgument { set foo(bar, baz) { } } `); - assertIsSyntaxError(` + assertIsSyntaxError(` class FooBase {} class IsASyntaxError extends FooBase { bar() { @@ -183,7 +191,7 @@ try { } `); - assertIsSyntaxError(` + assertIsSyntaxError(` class NoBaseSuper { constructor() { super(); @@ -191,58 +199,71 @@ try { } `); - assertThrowsError(() => { - class BadExtends extends 3 { } - - }, { - error: TypeError - }); - - assertThrowsError(() => { - class BadExtends extends undefined { } - }, { - error: TypeError - }); - - class SuperNotASyntaxError { - bar() { - () => { super.baz }; - } + assertThrowsError( + () => { + class BadExtends extends 3 {} + }, + { + error: TypeError, } + ); - class SuperNoBasePropertyLookup { + assertThrowsError( + () => { + class BadExtends extends undefined {} + }, + { + error: TypeError, + } + ); + + class SuperNotASyntaxError { + bar() { + () => { + super.baz; + }; + } + } + + class SuperNoBasePropertyLookup { + constructor() { + super.foo; + } + } + + assertThrowsError( + () => { + class Base {} + class DerivedDoesntCallSuper extends Base { constructor() { - super.foo; + this; } + } + + new DerivedDoesntCallSuper(); + }, + { + error: ReferenceError, } - - assertThrowsError(() => { - class Base { } - class DerivedDoesntCallSuper extends Base { - constructor() { - this; - } + ); + assertThrowsError( + () => { + class Base {} + class CallsSuperTwice extends Base { + constructor() { + super(); + super(); } + } - new DerivedDoesntCallSuper(); - }, { - error: ReferenceError, - }); - assertThrowsError(() => { - class Base { } - class CallsSuperTwice extends Base { - constructor() { - super(); - super(); - } - } + new CallsSuperTwice(); + }, + { + error: ReferenceError, + } + ); - new CallsSuperTwice(); - }, { - error: ReferenceError, - }); - - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/comments-basic.js b/Libraries/LibJS/Tests/comments-basic.js index 48f7c27c79..460525d28b 100644 --- a/Libraries/LibJS/Tests/comments-basic.js +++ b/Libraries/LibJS/Tests/comments-basic.js @@ -1,6 +1,5 @@ test("regular comments", () => { - const source = -`var i = 0; + const source = `var i = 0; // i++; /* i++; */ @@ -9,17 +8,16 @@ i++; */ return i;`; - expect(source).toEvalTo(0); + expect(source).toEvalTo(0); }); test("html comments", () => { - const source = -`var i = 0; + const source = `var i = 0; i++; i++; -return i;` +return i;`; - expect(source).toEvalTo(1); + expect(source).toEvalTo(1); }); diff --git a/Libraries/LibJS/Tests/debugger-statement.js b/Libraries/LibJS/Tests/debugger-statement.js index e5b0b14761..f97fcc212a 100644 --- a/Libraries/LibJS/Tests/debugger-statement.js +++ b/Libraries/LibJS/Tests/debugger-statement.js @@ -1,3 +1,3 @@ test("debugger keyword", () => { - expect("debugger").toEval(); + expect("debugger").toEval(); }); diff --git a/Libraries/LibJS/Tests/empty-statements.js b/Libraries/LibJS/Tests/empty-statements.js index 1c8fe467b8..982c831c72 100644 --- a/Libraries/LibJS/Tests/empty-statements.js +++ b/Libraries/LibJS/Tests/empty-statements.js @@ -1,19 +1,19 @@ test("empty semicolon statements", () => { - expect(";;;").toEval(); + expect(";;;").toEval(); }); test("if with no body", () => { - expect("if (true);").toEval(); + expect("if (true);").toEval(); }); test("chained ifs with no bodies", () => { - expect("if (false); else if (false); else;").toEval(); + expect("if (false); else if (false); else;").toEval(); }); test("while with no body", () => { - expect("while (false);").toEval(); + expect("while (false);").toEval(); }); test("do while with no body", () => { - expect("do; while (false);").toEval(); + expect("do; while (false);").toEval(); }); diff --git a/Libraries/LibJS/Tests/exception-ReferenceError.js b/Libraries/LibJS/Tests/exception-ReferenceError.js index 5cd436d0bf..3713340717 100644 --- a/Libraries/LibJS/Tests/exception-ReferenceError.js +++ b/Libraries/LibJS/Tests/exception-ReferenceError.js @@ -1,3 +1,3 @@ test("unknown variable produces ReferenceError", () => { - expect(new Function("i < 3")).toThrow(ReferenceError); + expect(new Function("i < 3")).toThrow(ReferenceError); }); diff --git a/Libraries/LibJS/Tests/exponentiation-basic.js b/Libraries/LibJS/Tests/exponentiation-basic.js index a49781ce04..5796b644b9 100644 --- a/Libraries/LibJS/Tests/exponentiation-basic.js +++ b/Libraries/LibJS/Tests/exponentiation-basic.js @@ -1,37 +1,37 @@ test("regular exponentiation", () => { - expect(2 ** 0).toBe(1); - expect(2 ** 1).toBe(2); - expect(2 ** 2).toBe(4); - expect(2 ** 3).toBe(8); - expect(3 ** 2).toBe(9); - expect(0 ** 0).toBe(1); - expect(2 ** 3 ** 2).toBe(512); - expect(2 ** (3 ** 2)).toBe(512); - expect((2 ** 3) ** 2).toBe(64); + expect(2 ** 0).toBe(1); + expect(2 ** 1).toBe(2); + expect(2 ** 2).toBe(4); + expect(2 ** 3).toBe(8); + expect(3 ** 2).toBe(9); + expect(0 ** 0).toBe(1); + expect(2 ** (3 ** 2)).toBe(512); + expect(2 ** (3 ** 2)).toBe(512); + expect((2 ** 3) ** 2).toBe(64); }); test("exponentation with negatives", () => { - expect(2 ** -3).toBe(0.125); - expect((-2) ** 3).toBe(-8); - - // FIXME: This should fail :) - // expect("-2 ** 3").not.toEval(); + expect(2 ** -3).toBe(0.125); + expect((-2) ** 3).toBe(-8); + + // FIXME: This should fail :) + // expect("-2 ** 3").not.toEval(); }); test("exponentation with non-numeric primitives", () => { - expect("2" ** "3").toBe(8); - expect("" ** []).toBe(1); - expect([] ** null).toBe(1); - expect(null ** null).toBe(1); - expect(undefined ** null).toBe(1); -}) + expect("2" ** "3").toBe(8); + expect("" ** []).toBe(1); + expect([] ** null).toBe(1); + expect(null ** null).toBe(1); + expect(undefined ** null).toBe(1); +}); test("exponentation that produces NaN", () => { - expect(NaN ** 2).toBeNaN(); - expect(2 ** NaN).toBeNaN(); - expect(undefined ** 2).toBeNaN(); - expect(2 ** undefined).toBeNaN(); - expect(null ** undefined).toBeNaN(); - expect(2 ** "foo").toBeNaN(); - expect("foo" ** 2).toBeNaN(); + expect(NaN ** 2).toBeNaN(); + expect(2 ** NaN).toBeNaN(); + expect(undefined ** 2).toBeNaN(); + expect(2 ** undefined).toBeNaN(); + expect(null ** undefined).toBeNaN(); + expect(2 ** "foo").toBeNaN(); + expect("foo" ** 2).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/functions/arrow-functions.js b/Libraries/LibJS/Tests/functions/arrow-functions.js index add2c0a6fc..6f9afc632d 100644 --- a/Libraries/LibJS/Tests/functions/arrow-functions.js +++ b/Libraries/LibJS/Tests/functions/arrow-functions.js @@ -1,119 +1,122 @@ load("test-common.js"); try { - let getNumber = () => 42; - assert(getNumber() === 42); + let getNumber = () => 42; + assert(getNumber() === 42); - getNumber = () => 99; - assert(getNumber() === 99); + getNumber = () => 99; + assert(getNumber() === 99); - let add = (a, b) => a + b; - assert(add(2, 3) === 5); + let add = (a, b) => a + b; + assert(add(2, 3) === 5); - const addBlock = (a, b) => { - let res = a + b; - return res; + const addBlock = (a, b) => { + let res = a + b; + return res; + }; + assert(addBlock(5, 4) === 9); + + let chompy = [x => x, 2]; + assert(chompy.length === 2); + assert(chompy[0](1) === 1); + + const makeObject = (a, b) => ({ a, b }); + const obj = makeObject(33, 44); + assert(typeof obj === "object"); + assert(obj.a === 33); + assert(obj.b === 44); + + let returnUndefined = () => {}; + assert(typeof returnUndefined() === "undefined"); + + const makeArray = (a, b) => [a, b]; + const array = makeArray("3", { foo: 4 }); + assert(array[0] === "3"); + assert(array[1].foo === 4); + + let square = x => x * x; + assert(square(3) === 9); + + let squareBlock = x => { + return x * x; + }; + assert(squareBlock(4) === 16); + + const message = (who => "Hello " + who)("friends!"); + assert(message === "Hello friends!"); + + const sum = ((x, y, z) => x + y + z)(1, 2, 3); + assert(sum === 6); + + const product = ((x, y, z) => { + let res = x * y * z; + return res; + })(5, 4, 2); + assert(product === 40); + + const half = (x => { + return x / 2; + })(10); + assert(half === 5); + + var foo, bar; + (foo = bar), baz => {}; + assert(foo === undefined); + assert(bar === undefined); + + function FooBar() { + this.x = { + y: () => this, + z: function () { + return (() => this)(); + }, }; - assert(addBlock(5, 4) === 9); + } - let chompy = [(x) => x, 2]; - assert(chompy.length === 2); - assert(chompy[0](1) === 1); + var foobar = new FooBar(); + assert(foobar.x.y() === foobar); + assert(foobar.x.z() === foobar.x); - const makeObject = (a, b) => ({ a, b }); - const obj = makeObject(33, 44); - assert(typeof obj === "object"); - assert(obj.a === 33); - assert(obj.b === 44); + var Baz = () => {}; - let returnUndefined = () => { }; - assert(typeof returnUndefined() === "undefined"); + assert(Baz.prototype === undefined); - const makeArray = (a, b) => [a, b]; - const array = makeArray("3", { foo: 4 }); - assert(array[0] === "3"); - assert(array[1].foo === 4); - - let square = x => x * x; - assert(square(3) === 9); - - let squareBlock = x => { - return x * x; - }; - assert(squareBlock(4) === 16); - - const message = (who => "Hello " + who)("friends!"); - assert(message === "Hello friends!"); - - const sum = ((x, y, z) => x + y + z)(1, 2, 3); - assert(sum === 6); - - const product = ((x, y, z) => { - let res = x * y * z; - return res; - })(5, 4, 2); - assert(product === 40); - - const half = (x => { - return x / 2; - })(10); - assert(half === 5); - - var foo, bar; - foo = bar, baz => {}; - assert(foo === undefined); - assert(bar === undefined); - - function FooBar() { - this.x = { - y: () => this, - z: function () { - return (() => this)(); - } - }; + assertThrowsError( + () => { + new Baz(); + }, + { + error: TypeError, + message: "Baz is not a constructor", } + ); - var foobar = new FooBar(); - assert(foobar.x.y() === foobar); - assert(foobar.x.z() === foobar.x); - - var Baz = () => {}; - - assert(Baz.prototype === undefined); - - assertThrowsError(() => { - new Baz(); - }, { - error: TypeError, - message: "Baz is not a constructor" - }); + (() => { + "use strict"; + assert(isStrictMode()); (() => { - "use strict"; - assert(isStrictMode()); - - (() => { - assert(isStrictMode()); - })(); + assert(isStrictMode()); })(); + })(); + + (() => { + "use strict"; + assert(isStrictMode()); + })(); + + (() => { + assert(!isStrictMode()); (() => { - 'use strict'; - assert(isStrictMode()); + "use strict"; + assert(isStrictMode()); })(); - (() => { - assert(!isStrictMode()); + assert(!isStrictMode()); + })(); - (() => { - "use strict"; - assert(isStrictMode()); - })(); - - assert(!isStrictMode()); - })(); - - console.log("PASS"); + console.log("PASS"); } catch { - console.log("FAIL"); + console.log("FAIL"); } diff --git a/Libraries/LibJS/Tests/functions/constructor-basic.js b/Libraries/LibJS/Tests/functions/constructor-basic.js index 08eb97739d..669bc77d96 100644 --- a/Libraries/LibJS/Tests/functions/constructor-basic.js +++ b/Libraries/LibJS/Tests/functions/constructor-basic.js @@ -2,7 +2,7 @@ load("test-common.js"); try { function Foo() { - this.x = 123; + this.x = 123; } assert(Foo.prototype.constructor === Foo); diff --git a/Libraries/LibJS/Tests/functions/function-TypeError.js b/Libraries/LibJS/Tests/functions/function-TypeError.js index 21d67699d4..6a59534d96 100644 --- a/Libraries/LibJS/Tests/functions/function-TypeError.js +++ b/Libraries/LibJS/Tests/functions/function-TypeError.js @@ -1,52 +1,70 @@ load("test-common.js"); try { - assertThrowsError(() => { - var b = true; - b(); - }, { - error: TypeError, - message: "true is not a function (evaluated from 'b')" - }); + assertThrowsError( + () => { + var b = true; + b(); + }, + { + error: TypeError, + message: "true is not a function (evaluated from 'b')", + } + ); - assertThrowsError(() => { - var n = 100 + 20 + 3; - n(); - }, { - error: TypeError, - message: "123 is not a function (evaluated from 'n')" - }); + assertThrowsError( + () => { + var n = 100 + 20 + 3; + n(); + }, + { + error: TypeError, + message: "123 is not a function (evaluated from 'n')", + } + ); - assertThrowsError(() => { - var o = {}; - o.a(); - }, { - error: TypeError, - message: "undefined is not a function (evaluated from 'o.a')" - }); + assertThrowsError( + () => { + var o = {}; + o.a(); + }, + { + error: TypeError, + message: "undefined is not a function (evaluated from 'o.a')", + } + ); - assertThrowsError(() => { - Math(); - }, { - error: TypeError, - message: "[object MathObject] is not a function (evaluated from 'Math')" - }); + assertThrowsError( + () => { + Math(); + }, + { + error: TypeError, + message: "[object MathObject] is not a function (evaluated from 'Math')", + } + ); - assertThrowsError(() => { - new Math(); - }, { - error: TypeError, - message: "[object MathObject] is not a constructor (evaluated from 'Math')" - }); + assertThrowsError( + () => { + new Math(); + }, + { + error: TypeError, + message: "[object MathObject] is not a constructor (evaluated from 'Math')", + } + ); - assertThrowsError(() => { - new isNaN(); - }, { - error: TypeError, - message: "[object NativeFunction] is not a constructor (evaluated from 'isNaN')" - }); + assertThrowsError( + () => { + new isNaN(); + }, + { + error: TypeError, + message: "[object NativeFunction] is not a constructor (evaluated from 'isNaN')", + } + ); - console.log("PASS"); -} catch(e) { - console.log("FAIL: " + e); + console.log("PASS"); +} catch (e) { + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/functions/function-default-parameters.js b/Libraries/LibJS/Tests/functions/function-default-parameters.js index ab537928b0..4e0064dacc 100644 --- a/Libraries/LibJS/Tests/functions/function-default-parameters.js +++ b/Libraries/LibJS/Tests/functions/function-default-parameters.js @@ -1,112 +1,136 @@ load("test-common.js"); try { - function func1(a, b = 1) { - return a + b; + function func1(a, b = 1) { + return a + b; + } + + const arrowFunc1 = (a, b = 1) => a + b; + + assert(func1(4, 5) === 9); + assert(func1(4) === 5); + assert(func1(4, undefined) === 5); + assert(Number.isNaN(func1())); + + assert(arrowFunc1(4, 5) === 9); + assert(arrowFunc1(4) === 5); + assert(arrowFunc1(4, undefined) === 5); + assert(Number.isNaN(arrowFunc1())); + + function func2(a = 6) { + return typeof a; + } + + const arrowFunc2 = (a = 6) => typeof a; + + assert(func2() === "number"); + assert(func2(5) === "number"); + assert(func2(undefined) === "number"); + assert(func2(false) === "boolean"); + assert(func2(null) === "object"); + assert(func2({}) === "object"); + + assert(arrowFunc2() === "number"); + assert(arrowFunc2(5) === "number"); + assert(arrowFunc2(undefined) === "number"); + assert(arrowFunc2(false) === "boolean"); + assert(arrowFunc2(null) === "object"); + assert(arrowFunc2({}) === "object"); + + function func3(a = 5, b) { + return a + b; + } + + const arrowFunc3 = (a = 5, b) => a + b; + + assert(func3(4, 5) === 9); + assert(func3(undefined, 4) === 9); + assert(Number.isNaN(func3())); + + assert(arrowFunc3(4, 5) === 9); + assert(arrowFunc3(undefined, 4) === 9); + assert(Number.isNaN(arrowFunc3())); + + function func4(a, b = a) { + return a + b; + } + + const arrowFunc4 = (a, b = a) => a + b; + + assert(func4(4, 5) === 9); + assert(func4(4) === 8); + assert(func4("hf") === "hfhf"); + assert(func4(true) === 2); + assert(Number.isNaN(func4())); + + assert(arrowFunc4(4, 5) === 9); + assert(arrowFunc4(4) === 8); + assert(arrowFunc4("hf") === "hfhf"); + assert(arrowFunc4(true) === 2); + assert(Number.isNaN(arrowFunc4())); + + function func5( + a = function () { + return 5; } + ) { + return a(); + } - const arrowFunc1 = (a, b = 1) => a + b; - - assert(func1(4, 5) === 9); - assert(func1(4) === 5); - assert(func1(4, undefined) === 5); - assert(Number.isNaN(func1())); - - assert(arrowFunc1(4, 5) === 9); - assert(arrowFunc1(4) === 5); - assert(arrowFunc1(4, undefined) === 5); - assert(Number.isNaN(arrowFunc1())); - - function func2(a = 6) { - return typeof a; + const arrowFunc5 = ( + a = function () { + return 5; } + ) => a(); - const arrowFunc2 = (a = 6) => typeof a; + assert(func5() === 5); + assert( + func5(function () { + return 10; + }) === 10 + ); + assert(func5(() => 10) === 10); + assert(arrowFunc5() === 5); + assert( + arrowFunc5(function () { + return 10; + }) === 10 + ); + assert(arrowFunc5(() => 10) === 10); - assert(func2() === "number"); - assert(func2(5) === "number"); - assert(func2(undefined) === "number"); - assert(func2(false) === "boolean"); - assert(func2(null) === "object"); - assert(func2({}) === "object"); + function func6(a = () => 5) { + return a(); + } - assert(arrowFunc2() === "number"); - assert(arrowFunc2(5) === "number"); - assert(arrowFunc2(undefined) === "number"); - assert(arrowFunc2(false) === "boolean"); - assert(arrowFunc2(null) === "object"); - assert(arrowFunc2({}) === "object"); + const arrowFunc6 = (a = () => 5) => a(); - function func3(a = 5, b) { - return a + b; - } + assert(func6() === 5); + assert( + func6(function () { + return 10; + }) === 10 + ); + assert(func6(() => 10) === 10); + assert(arrowFunc6() === 5); + assert( + arrowFunc6(function () { + return 10; + }) === 10 + ); + assert(arrowFunc6(() => 10) === 10); - const arrowFunc3 = (a = 5, b) => a + b; + function func7(a = { foo: "bar" }) { + return a.foo; + } - assert(func3(4, 5) === 9); - assert(func3(undefined, 4) === 9); - assert(Number.isNaN(func3())); + const arrowFunc7 = (a = { foo: "bar" }) => a.foo; - assert(arrowFunc3(4, 5) === 9); - assert(arrowFunc3(undefined, 4) === 9); - assert(Number.isNaN(arrowFunc3())); + assert(func7() === "bar"); + assert(func7({ foo: "baz" }) === "baz"); + assert(arrowFunc7() === "bar"); + assert(arrowFunc7({ foo: "baz" }) === "baz"); - function func4(a, b = a) { - return a + b; - } - - const arrowFunc4 = (a, b = a) => a + b; - - assert(func4(4, 5) === 9); - assert(func4(4) === 8); - assert(func4("hf") === "hfhf"); - assert(func4(true) === 2); - assert(Number.isNaN(func4())); - - assert(arrowFunc4(4, 5) === 9); - assert(arrowFunc4(4) === 8); - assert(arrowFunc4("hf") === "hfhf"); - assert(arrowFunc4(true) === 2); - assert(Number.isNaN(arrowFunc4())); - - function func5(a = function() { return 5; }) { - return a(); - } - - const arrowFunc5 = (a = function() { return 5; }) => a(); - - assert(func5() === 5); - assert(func5(function() { return 10; }) === 10); - assert(func5(() => 10) === 10); - assert(arrowFunc5() === 5); - assert(arrowFunc5(function() { return 10; }) === 10); - assert(arrowFunc5(() => 10) === 10); - - function func6(a = () => 5) { - return a(); - } - - const arrowFunc6 = (a = () => 5) => a(); - - assert(func6() === 5); - assert(func6(function() { return 10; }) === 10); - assert(func6(() => 10) === 10); - assert(arrowFunc6() === 5); - assert(arrowFunc6(function() { return 10; }) === 10); - assert(arrowFunc6(() => 10) === 10); - - function func7(a = { foo: "bar" }) { - return a.foo; - } - - const arrowFunc7 = (a = { foo: "bar" }) => a.foo - - assert(func7() === "bar"); - assert(func7({ foo: "baz" }) === "baz"); - assert(arrowFunc7() === "bar"); - assert(arrowFunc7({ foo: "baz" }) === "baz"); - - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/functions/function-hoisting.js b/Libraries/LibJS/Tests/functions/function-hoisting.js index 6cd155567b..0df5f3ddd0 100644 --- a/Libraries/LibJS/Tests/functions/function-hoisting.js +++ b/Libraries/LibJS/Tests/functions/function-hoisting.js @@ -1,37 +1,37 @@ load("test-common.js"); try { - var callHoisted = hoisted(); - function hoisted() { - return true; - } - assert(hoisted() === true); - assert(callHoisted === true); + var callHoisted = hoisted(); + function hoisted() { + return true; + } + assert(hoisted() === true); + assert(callHoisted === true); - { - var callScopedHoisted = scopedHoisted(); - function scopedHoisted() { - return "foo"; - } - assert(scopedHoisted() === "foo"); - assert(callScopedHoisted === "foo"); + { + var callScopedHoisted = scopedHoisted(); + function scopedHoisted() { + return "foo"; } assert(scopedHoisted() === "foo"); assert(callScopedHoisted === "foo"); + } + assert(scopedHoisted() === "foo"); + assert(callScopedHoisted === "foo"); - const test = () => { - var iife = (function () { - return declaredLater(); - })(); - function declaredLater() { - return "yay"; - } - return iife; - }; - assert(typeof declaredLater === "undefined"); - assert(test() === "yay"); + const test = () => { + var iife = (function () { + return declaredLater(); + })(); + function declaredLater() { + return "yay"; + } + return iife; + }; + assert(typeof declaredLater === "undefined"); + assert(test() === "yay"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/functions/function-length.js b/Libraries/LibJS/Tests/functions/function-length.js index c6b85d8f3f..481e436f10 100644 --- a/Libraries/LibJS/Tests/functions/function-length.js +++ b/Libraries/LibJS/Tests/functions/function-length.js @@ -1,27 +1,27 @@ load("test-common.js"); try { - function foo() { } - assert(foo.length === 0); - assert((foo.length = 5) === 5); - assert(foo.length === 0); + function foo() {} + assert(foo.length === 0); + assert((foo.length = 5) === 5); + assert(foo.length === 0); - function bar(a, b, c) {} - assert(bar.length === 3); - assert((bar.length = 5) === 5); - assert(bar.length === 3); + function bar(a, b, c) {} + assert(bar.length === 3); + assert((bar.length = 5) === 5); + assert(bar.length === 3); - function baz(a, b = 1, c) {} - assert(baz.length === 1); - assert((baz.length = 5) === 5); - assert(baz.length === 1); + function baz(a, b = 1, c) {} + assert(baz.length === 1); + assert((baz.length = 5) === 5); + assert(baz.length === 1); - function qux(a, b, ...c) {} - assert(qux.length === 2); - assert((qux.length = 5) === 5); - assert(qux.length === 2); + function qux(a, b, ...c) {} + assert(qux.length === 2); + assert((qux.length = 5) === 5); + assert(qux.length === 2); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/functions/function-missing-arg.js b/Libraries/LibJS/Tests/functions/function-missing-arg.js index 39c10b6649..a9d77e7514 100644 --- a/Libraries/LibJS/Tests/functions/function-missing-arg.js +++ b/Libraries/LibJS/Tests/functions/function-missing-arg.js @@ -1,13 +1,15 @@ load("test-common.js"); -function foo(a, b) { return a + b; } +function foo(a, b) { + return a + b; +} try { - assert(isNaN(foo()) === true); - assert(isNaN(foo(1)) === true); - assert(foo(2, 3) === 5); - assert(foo(2, 3, 4) === 5); - console.log("PASS"); + assert(isNaN(foo()) === true); + assert(isNaN(foo(1)) === true); + assert(foo(2, 3) === 5); + assert(foo(2, 3, 4) === 5); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/functions/function-name.js b/Libraries/LibJS/Tests/functions/function-name.js index 9a934c01fb..3a8fbe7e3a 100644 --- a/Libraries/LibJS/Tests/functions/function-name.js +++ b/Libraries/LibJS/Tests/functions/function-name.js @@ -1,49 +1,45 @@ load("test-common.js"); try { - assert((function () { }).name === ""); + assert(function () {}.name === ""); - var foo = function () { } - assert(foo.name === "foo"); - assert((foo.name = "bar") === "bar"); - assert(foo.name === "foo"); + var foo = function () {}; + assert(foo.name === "foo"); + assert((foo.name = "bar") === "bar"); + assert(foo.name === "foo"); - var a, b; - a = b = function () { } - assert(a.name === "b"); - assert(b.name === "b"); + var a, b; + a = b = function () {}; + assert(a.name === "b"); + assert(b.name === "b"); - var arr = [ - function () { }, - function () { }, - function () { } - ]; - assert(arr[0].name === "arr"); - assert(arr[1].name === "arr"); - assert(arr[2].name === "arr"); + var arr = [function () {}, function () {}, function () {}]; + assert(arr[0].name === "arr"); + assert(arr[1].name === "arr"); + assert(arr[2].name === "arr"); - var f; - var o = { a: function () { } }; - assert(o.a.name === "a"); - f = o.a; - assert(f.name === "a"); - assert(o.a.name === "a"); - o = { ...o, b: f }; - assert(o.a.name === "a"); - assert(o.b.name === "a"); - o.c = function () { }; - assert(o.c.name === "c"); + var f; + var o = { a: function () {} }; + assert(o.a.name === "a"); + f = o.a; + assert(f.name === "a"); + assert(o.a.name === "a"); + o = { ...o, b: f }; + assert(o.a.name === "a"); + assert(o.b.name === "a"); + o.c = function () {}; + assert(o.c.name === "c"); - function bar() { } - assert(bar.name === "bar"); - assert((bar.name = "baz") === "baz"); - assert(bar.name === "bar"); + function bar() {} + assert(bar.name === "bar"); + assert((bar.name = "baz") === "baz"); + assert(bar.name === "bar"); - assert(console.log.name === "log"); - assert((console.log.name = "warn") === "warn"); - assert(console.log.name === "log"); + assert(console.log.name === "log"); + assert((console.log.name = "warn") === "warn"); + assert(console.log.name === "log"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/functions/function-rest-params.js b/Libraries/LibJS/Tests/functions/function-rest-params.js index efcd66cddf..a4a7597d68 100644 --- a/Libraries/LibJS/Tests/functions/function-rest-params.js +++ b/Libraries/LibJS/Tests/functions/function-rest-params.js @@ -1,57 +1,57 @@ load("test-common.js"); try { - function foo(...a) { - assert(a instanceof Array); - assert(a.length === 0); - } - foo(); + function foo(...a) { + assert(a instanceof Array); + assert(a.length === 0); + } + foo(); - function foo1(...a) { - assert(a instanceof Array); - assert(a.length === 4); - assert(a[0] === "foo"); - assert(a[1] === 123); - assert(a[2] === undefined); - assert(a[3].foo === "bar"); - } - foo1("foo", 123, undefined, { foo: "bar" }); + function foo1(...a) { + assert(a instanceof Array); + assert(a.length === 4); + assert(a[0] === "foo"); + assert(a[1] === 123); + assert(a[2] === undefined); + assert(a[3].foo === "bar"); + } + foo1("foo", 123, undefined, { foo: "bar" }); - function foo2(a, b, ...c) { - assert(a === "foo"); - assert(b === 123); - assert(c instanceof Array); - assert(c.length === 0); - } - foo2("foo", 123); + function foo2(a, b, ...c) { + assert(a === "foo"); + assert(b === 123); + assert(c instanceof Array); + assert(c.length === 0); + } + foo2("foo", 123); - function foo3(a, b, ...c) { - assert(a === "foo"); - assert(b === 123); - assert(c instanceof Array); - assert(c.length === 2); - assert(c[0] === undefined); - assert(c[1].foo === "bar"); - } - foo3("foo", 123, undefined, { foo: "bar" }); + function foo3(a, b, ...c) { + assert(a === "foo"); + assert(b === 123); + assert(c instanceof Array); + assert(c.length === 2); + assert(c[0] === undefined); + assert(c[1].foo === "bar"); + } + foo3("foo", 123, undefined, { foo: "bar" }); - var foo = (...a) => { - assert(a instanceof Array); - assert(a.length === 0); - }; - foo(); + var foo = (...a) => { + assert(a instanceof Array); + assert(a.length === 0); + }; + foo(); - var foo = (a, b, ...c) => { - assert(a === "foo"); - assert(b === 123); - assert(c instanceof Array); - assert(c.length === 2); - assert(c[0] === undefined); - assert(c[1].foo === "bar"); - }; - foo("foo", 123, undefined, { foo: "bar" }); + var foo = (a, b, ...c) => { + assert(a === "foo"); + assert(b === 123); + assert(c instanceof Array); + assert(c.length === 2); + assert(c[0] === undefined); + assert(c[1].foo === "bar"); + }; + foo("foo", 123, undefined, { foo: "bar" }); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/functions/function-spread.js b/Libraries/LibJS/Tests/functions/function-spread.js index f7d7d2ea2f..e3fe7c520f 100644 --- a/Libraries/LibJS/Tests/functions/function-spread.js +++ b/Libraries/LibJS/Tests/functions/function-spread.js @@ -1,27 +1,30 @@ load("test-common.js"); try { - const sum = (a, b, c) => a + b + c; - const a = [1, 2, 3]; + const sum = (a, b, c) => a + b + c; + const a = [1, 2, 3]; - assert(sum(...a) === 6); - assert(sum(1, ...a) === 4); - assert(sum(...a, 10) === 6); + assert(sum(...a) === 6); + assert(sum(1, ...a) === 4); + assert(sum(...a, 10) === 6); - const foo = (a, b, c) => c; + const foo = (a, b, c) => c; - const o = { bar: [1, 2, 3] }; - assert(foo(...o.bar) === 3); - assert(foo(..."abc") === "c"); + const o = { bar: [1, 2, 3] }; + assert(foo(...o.bar) === 3); + assert(foo(..."abc") === "c"); - assertThrowsError(() => { - [...1]; - }, { - error: TypeError, - message: "1 is not iterable", - }); + assertThrowsError( + () => { + [...1]; + }, + { + error: TypeError, + message: "1 is not iterable", + } + ); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/functions/function-strict-mode.js b/Libraries/LibJS/Tests/functions/function-strict-mode.js index 382327d9bb..44385ec32d 100644 --- a/Libraries/LibJS/Tests/functions/function-strict-mode.js +++ b/Libraries/LibJS/Tests/functions/function-strict-mode.js @@ -1,52 +1,52 @@ load("test-common.js"); try { - (function() { - assert(!isStrictMode()); - })(); + (function () { + assert(!isStrictMode()); + })(); - (function() { - 'use strict'; - assert(isStrictMode()); - })(); + (function () { + "use strict"; + assert(isStrictMode()); + })(); - (function() { - "use strict"; - assert(isStrictMode()); - })(); + (function () { + "use strict"; + assert(isStrictMode()); + })(); - (function() { - `use strict`; - assert(!isStrictMode()); - })(); + (function () { + `use strict`; + assert(!isStrictMode()); + })(); - (function() { - ;'use strict'; - assert(!isStrictMode()); - })(); + (function () { + ("use strict"); + assert(!isStrictMode()); + })(); - (function() { - ;"use strict"; - assert(!isStrictMode()); - })(); + (function () { + ("use strict"); + assert(!isStrictMode()); + })(); - (function() { - "use strict"; - (function() { - assert(isStrictMode()); - })(); + (function () { + "use strict"; + (function () { + assert(isStrictMode()); })(); + })(); - (function() { - assert(!isStrictMode()); - (function(){ - "use strict"; - assert(isStrictMode()); - })(); - assert(!isStrictMode()); + (function () { + assert(!isStrictMode()); + (function () { + "use strict"; + assert(isStrictMode()); })(); + assert(!isStrictMode()); + })(); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/indexed-access-string-object.js b/Libraries/LibJS/Tests/indexed-access-string-object.js index 7946cbfbf4..362f112748 100644 --- a/Libraries/LibJS/Tests/indexed-access-string-object.js +++ b/Libraries/LibJS/Tests/indexed-access-string-object.js @@ -1,15 +1,15 @@ test("string literal indexing", () => { - var s = "foo"; - expect(s[0]).toBe("f"); - expect(s[1]).toBe("o"); - expect(s[2]).toBe("o"); - expect(s[3]).toBeUndefined(); + var s = "foo"; + expect(s[0]).toBe("f"); + expect(s[1]).toBe("o"); + expect(s[2]).toBe("o"); + expect(s[3]).toBeUndefined(); }); test("string object indexing", () => { - var s = new String("bar"); - expect(s[0]).toBe("b"); - expect(s[1]).toBe("a"); - expect(s[2]).toBe("r"); - expect(s[3]).toBeUndefined(); + var s = new String("bar"); + expect(s[0]).toBe("b"); + expect(s[1]).toBe("a"); + expect(s[2]).toBe("r"); + expect(s[3]).toBeUndefined(); }); diff --git a/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js b/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js index 4b402c3fc7..a2cff0af23 100644 --- a/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js +++ b/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js @@ -1,13 +1,12 @@ - test("assignment to function call", () => { - expect(() => { - function foo() {}; - foo() = "foo"; - }).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment"); + expect(() => { + function foo() {} + foo() = "foo"; + }).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment"); }); test("assignment to inline function call", () => { - expect(() => { - (function () { })() = "foo"; - }).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment"); + expect(() => { + (function () {})() = "foo"; + }).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment"); }); diff --git a/Libraries/LibJS/Tests/labels.js b/Libraries/LibJS/Tests/labels.js index 5ae9e4ee38..315f9f7343 100644 --- a/Libraries/LibJS/Tests/labels.js +++ b/Libraries/LibJS/Tests/labels.js @@ -1,43 +1,39 @@ test("labeled plain scope", () => { - test: { - let o = 1; - expect(o).toBe(1); - break test; - expect().fail(); - } + test: { + let o = 1; + expect(o).toBe(1); + break test; + expect().fail(); + } }); test("break on plain scope from inner scope", () => { - outer: { - { - break outer; - } - expect().fail(); + outer: { + { + break outer; } + expect().fail(); + } }); test("labeled for loop with break", () => { - let counter = 0; - outer: - for (a of [1, 2, 3]) { - for (b of [4, 5, 6]) { - if (a === 2 && b === 5) - break outer; - counter++; - } + let counter = 0; + outer: for (a of [1, 2, 3]) { + for (b of [4, 5, 6]) { + if (a === 2 && b === 5) break outer; + counter++; } - expect(counter).toBe(4); + } + expect(counter).toBe(4); }); test("labeled for loop with continue", () => { - let counter = 0; - outer: - for (a of [1, 2, 3]) { - for (b of [4, 5, 6]) { - if (b === 6) - continue outer; - counter++; - } + let counter = 0; + outer: for (a of [1, 2, 3]) { + for (b of [4, 5, 6]) { + if (b === 6) continue outer; + counter++; } - expect(counter).toBe(6); + } + expect(counter).toBe(6); }); diff --git a/Libraries/LibJS/Tests/let-scoping.js b/Libraries/LibJS/Tests/let-scoping.js index 27c92e23f9..ff2eaddeb5 100644 --- a/Libraries/LibJS/Tests/let-scoping.js +++ b/Libraries/LibJS/Tests/let-scoping.js @@ -1,14 +1,14 @@ test("let scoping", () => { - let i = 1; - { - let i = 3; - expect(i).toBe(3); - } - expect(i).toBe(1); + let i = 1; + { + let i = 3; + expect(i).toBe(3); + } + expect(i).toBe(1); - { - const i = 2; - expect(i).toBe(2); - } - expect(i).toBe(1); + { + const i = 2; + expect(i).toBe(2); + } + expect(i).toBe(1); }); diff --git a/Libraries/LibJS/Tests/loops/continue-basic.js b/Libraries/LibJS/Tests/loops/continue-basic.js index 28d2cfa588..4a9ad656cf 100644 --- a/Libraries/LibJS/Tests/loops/continue-basic.js +++ b/Libraries/LibJS/Tests/loops/continue-basic.js @@ -1,14 +1,11 @@ load("test-common.js"); try { - var j = 0; - for (var i = 0; i < 9; ++i) { - if (i == 3) - continue; - ++j; - } - assert(j == 8); - console.log("PASS"); -} catch { -} - + var j = 0; + for (var i = 0; i < 9; ++i) { + if (i == 3) continue; + ++j; + } + assert(j == 8); + console.log("PASS"); +} catch {} diff --git a/Libraries/LibJS/Tests/loops/do-while-basic.js b/Libraries/LibJS/Tests/loops/do-while-basic.js index 9472ec4808..b701cceb9a 100644 --- a/Libraries/LibJS/Tests/loops/do-while-basic.js +++ b/Libraries/LibJS/Tests/loops/do-while-basic.js @@ -1,17 +1,18 @@ load("test-common.js"); try { - var number = 0; - do { - number++; - } while (number < 9); - assert(number === 9); + var number = 0; + do { + number++; + } while (number < 9); + assert(number === 9); - number = 0; - do number++; while(number < 3); - assert(number === 3); + number = 0; + do number++; + while (number < 3); + assert(number === 3); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/loops/for-basic.js b/Libraries/LibJS/Tests/loops/for-basic.js index 747a574cb1..d0041040d2 100644 --- a/Libraries/LibJS/Tests/loops/for-basic.js +++ b/Libraries/LibJS/Tests/loops/for-basic.js @@ -1,24 +1,24 @@ load("test-common.js"); try { - var a = []; - for (var i = 0; i < 3; ++i) { - a.push(i); - } - assert(a.length === 3); - assert(a[0] === 0); - assert(a[1] === 1); - assert(a[2] === 2); + var a = []; + for (var i = 0; i < 3; ++i) { + a.push(i); + } + assert(a.length === 3); + assert(a[0] === 0); + assert(a[1] === 1); + assert(a[2] === 2); - for (; a.length < 6;) { - a.push('x'); - } - assert(a.length === 6); - assert(a[3] === 'x'); - assert(a[4] === 'x'); - assert(a[5] === 'x'); + for (; a.length < 6; ) { + a.push("x"); + } + assert(a.length === 6); + assert(a[3] === "x"); + assert(a[4] === "x"); + assert(a[5] === "x"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/loops/for-head-errors.js b/Libraries/LibJS/Tests/loops/for-head-errors.js index 195869887b..a2ddecc989 100644 --- a/Libraries/LibJS/Tests/loops/for-head-errors.js +++ b/Libraries/LibJS/Tests/loops/for-head-errors.js @@ -1,36 +1,45 @@ load("test-common.js"); try { - assertThrowsError(() => { - for (var i = foo; i < 100; ++i) { - assertNotReached(); - } - }, { - error: ReferenceError, - message: "'foo' is not defined" - }); + assertThrowsError( + () => { + for (var i = foo; i < 100; ++i) { + assertNotReached(); + } + }, + { + error: ReferenceError, + message: "'foo' is not defined", + } + ); - assertThrowsError(() => { - for (var i = 0; i < foo; ++i) { - assertNotReached(); - } - }, { - error: ReferenceError, - message: "'foo' is not defined" - }); + assertThrowsError( + () => { + for (var i = 0; i < foo; ++i) { + assertNotReached(); + } + }, + { + error: ReferenceError, + message: "'foo' is not defined", + } + ); - var loopCount = 0; - assertThrowsError(() => { - for (var i = 0; i < 100; ++foo) { - loopCount++; - } - }, { - error: ReferenceError, - message: "'foo' is not defined" - }); - assert(loopCount === 1); + var loopCount = 0; + assertThrowsError( + () => { + for (var i = 0; i < 100; ++foo) { + loopCount++; + } + }, + { + error: ReferenceError, + message: "'foo' is not defined", + } + ); + assert(loopCount === 1); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/loops/for-in-basic.js b/Libraries/LibJS/Tests/loops/for-in-basic.js index 1d6189c301..f74382c21f 100644 --- a/Libraries/LibJS/Tests/loops/for-in-basic.js +++ b/Libraries/LibJS/Tests/loops/for-in-basic.js @@ -1,41 +1,47 @@ load("test-common.js"); try { - assertVisitsAll(visit => { - for (const property in "") { - visit(property); - } - }, []); + assertVisitsAll(visit => { + for (const property in "") { + visit(property); + } + }, []); - assertVisitsAll(visit => { - for (const property in 123) { - visit(property); - } - }, []); + assertVisitsAll(visit => { + for (const property in 123) { + visit(property); + } + }, []); - assertVisitsAll(visit => { - for (const property in {}) { - visit(property); - } - }, []); + assertVisitsAll(visit => { + for (const property in {}) { + visit(property); + } + }, []); - assertVisitsAll(visit => { - for (const property in "hello") { - visit(property); - } - }, ["0", "1", "2", "3", "4"]); + assertVisitsAll( + visit => { + for (const property in "hello") { + visit(property); + } + }, + ["0", "1", "2", "3", "4"] + ); - assertVisitsAll(visit => { - for (const property in {a: 1, b: 2, c: 2}) { - visit(property); - } - }, ["a", "b", "c"]); + assertVisitsAll( + visit => { + for (const property in { a: 1, b: 2, c: 2 }) { + visit(property); + } + }, + ["a", "b", "c"] + ); - var property; - for (property in "abc"); - assert(property === "2"); + var property; + for (property in "abc"); + assert(property === "2"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/loops/for-no-curlies.js b/Libraries/LibJS/Tests/loops/for-no-curlies.js index 6b808dad91..4cae046294 100644 --- a/Libraries/LibJS/Tests/loops/for-no-curlies.js +++ b/Libraries/LibJS/Tests/loops/for-no-curlies.js @@ -1,14 +1,12 @@ load("test-common.js"); try { - var number = 0; + var number = 0; - for (var i = 0; i < 3; ++i) - for (var j = 0; j < 3; ++j) - number++; + for (var i = 0; i < 3; ++i) for (var j = 0; j < 3; ++j) number++; - assert(number === 9); - console.log("PASS"); + assert(number === 9); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/loops/for-of-basic.js b/Libraries/LibJS/Tests/loops/for-of-basic.js index f01fb80750..4669a6c9b6 100644 --- a/Libraries/LibJS/Tests/loops/for-of-basic.js +++ b/Libraries/LibJS/Tests/loops/for-of-basic.js @@ -1,43 +1,60 @@ load("test-common.js"); try { - assertThrowsError(() => { - for (const _ of 123) {} - }, { - error: TypeError, - message: "for..of right-hand side must be iterable" - }); + assertThrowsError( + () => { + for (const _ of 123) { + } + }, + { + error: TypeError, + message: "for..of right-hand side must be iterable", + } + ); - assertThrowsError(() => { - for (const _ of {foo: 1, bar: 2}) {} - }, { - error: TypeError, - message: "for..of right-hand side must be iterable" - }); + assertThrowsError( + () => { + for (const _ of { foo: 1, bar: 2 }) { + } + }, + { + error: TypeError, + message: "for..of right-hand side must be iterable", + } + ); - assertVisitsAll(visit => { - for (const num of [1, 2, 3]) { - visit(num); - } - }, [1, 2, 3]); + assertVisitsAll( + visit => { + for (const num of [1, 2, 3]) { + visit(num); + } + }, + [1, 2, 3] + ); - assertVisitsAll(visit => { - for (const char of "hello") { - visit(char); - } - }, ["h", "e", "l", "l", "o"]); + assertVisitsAll( + visit => { + for (const char of "hello") { + visit(char); + } + }, + ["h", "e", "l", "l", "o"] + ); - assertVisitsAll(visit => { - for (const char of new String("hello")) { - visit(char); - } - }, ["h", "e", "l", "l", "o"]); + assertVisitsAll( + visit => { + for (const char of new String("hello")) { + visit(char); + } + }, + ["h", "e", "l", "l", "o"] + ); - var char; - for (char of "abc"); - assert(char === "c"); + var char; + for (char of "abc"); + assert(char === "c"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/loops/for-scopes.js b/Libraries/LibJS/Tests/loops/for-scopes.js index 00c6a96c88..182edde831 100644 --- a/Libraries/LibJS/Tests/loops/for-scopes.js +++ b/Libraries/LibJS/Tests/loops/for-scopes.js @@ -1,22 +1,22 @@ load("test-common.js"); try { - for (var v = 5; false; ); - assert(v == 5); + for (var v = 5; false; ); + assert(v == 5); - const options = {error: ReferenceError}; + const options = { error: ReferenceError }; - assertThrowsError(() => { - for (let l = 5; false; ); - l; - }, options); + assertThrowsError(() => { + for (let l = 5; false; ); + l; + }, options); - assertThrowsError(() => { - for (const c = 5; false; ); - c; - }, options) + assertThrowsError(() => { + for (const c = 5; false; ); + c; + }, options); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/loops/while-basic.js b/Libraries/LibJS/Tests/loops/while-basic.js index 5868ec7170..4932bb830f 100644 --- a/Libraries/LibJS/Tests/loops/while-basic.js +++ b/Libraries/LibJS/Tests/loops/while-basic.js @@ -1,21 +1,21 @@ load("test-common.js"); try { - var number = 0; - while (number < 9) { - number++; - } - assert(number === 9); + var number = 0; + while (number < 9) { + number++; + } + assert(number === 9); - number = 0; - while(number < 3) number++; - assert(number === 3); + number = 0; + while (number < 3) number++; + assert(number === 3); - while (false) { - assertNotReached(); - } + while (false) { + assertNotReached(); + } - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/new-expression.js b/Libraries/LibJS/Tests/new-expression.js index d4ee3c0b0c..7bc892ae68 100644 --- a/Libraries/LibJS/Tests/new-expression.js +++ b/Libraries/LibJS/Tests/new-expression.js @@ -1,49 +1,48 @@ test("new-expression parsing", () => { - function Foo() { this.x = 1; } - - let foo = new Foo(); - expect(foo.x).toBe(1); - - foo = new Foo - expect(foo.x).toBe(1); - - foo = new - Foo - () - expect(foo.x).toBe(1); - - foo = new Foo + 2 - expect(foo).toBe("[object Object]2"); + function Foo() { + this.x = 1; + } + + let foo = new Foo(); + expect(foo.x).toBe(1); + + foo = new Foo(); + expect(foo.x).toBe(1); + + foo = new Foo(); + expect(foo.x).toBe(1); + + foo = new Foo() + 2; + expect(foo).toBe("[object Object]2"); }); test("new-expressions with object keys", () => { - let a = { - b: function() { - this.x = 2; - }, - }; - - foo = new a.b(); - expect(foo.x).toBe(2); - - foo = new a.b; - expect(foo.x).toBe(2); - - foo = new - a.b(); - expect(foo.x).toBe(2); + let a = { + b: function () { + this.x = 2; + }, + }; + + foo = new a.b(); + expect(foo.x).toBe(2); + + foo = new a.b(); + expect(foo.x).toBe(2); + + foo = new a.b(); + expect(foo.x).toBe(2); }); test("new-expressions with function calls", () => { - function funcGetter() { - return function(a, b) { - this.x = a + b; - }; + function funcGetter() { + return function (a, b) { + this.x = a + b; }; - - foo = new funcGetter()(1, 5); - expect(foo).toBeUndefined(); - - foo = new (funcGetter())(1, 5); - expect(foo.x).toBe(6); + } + + foo = new funcGetter()(1, 5); + expect(foo).toBeUndefined(); + + foo = new (funcGetter())(1, 5); + expect(foo.x).toBe(6); }); diff --git a/Libraries/LibJS/Tests/numeric-literals-basic.js b/Libraries/LibJS/Tests/numeric-literals-basic.js index 8209431953..be3841fd92 100644 --- a/Libraries/LibJS/Tests/numeric-literals-basic.js +++ b/Libraries/LibJS/Tests/numeric-literals-basic.js @@ -1,37 +1,37 @@ test("hex literals", () => { - expect(0xff).toBe(255); - expect(0xFF).toBe(255); + expect(0xff).toBe(255); + expect(0xff).toBe(255); }); test("octal literals", () => { - expect(0o10).toBe(8); - expect(0O10).toBe(8); + expect(0o10).toBe(8); + expect(0o10).toBe(8); }); test("binary literals", () => { - expect(0b10).toBe(2); - expect(0B10).toBe(2); + expect(0b10).toBe(2); + expect(0b10).toBe(2); }); test("exponential literals", () => { - expect(1e3).toBe(1000); - expect(1e+3).toBe(1000); - expect(1e-3).toBe(0.001); - expect(1.e1).toBe(10); - expect(.1e1).toBe(1); - expect(0.1e1).toBe(1); - expect(.1e+1).toBe(1); - expect(0.1e+1).toBe(1); + expect(1e3).toBe(1000); + expect(1e3).toBe(1000); + expect(1e-3).toBe(0.001); + expect(1e1).toBe(10); + expect(0.1e1).toBe(1); + expect(0.1e1).toBe(1); + expect(0.1e1).toBe(1); + expect(0.1e1).toBe(1); }); test("decimal numbers", () => { - expect(1.).toBe(1); - expect(.1).toBe(0.1); + expect(1).toBe(1); + expect(0.1).toBe(0.1); }); test("accessing properties of decimal numbers", () => { - Number.prototype.foo = "foo"; - expect(1..foo).toBe("foo"); - expect(1.1.foo).toBe("foo"); - expect(.1.foo).toBe("foo"); + Number.prototype.foo = "foo"; + expect((1).foo).toBe("foo"); + expect((1.1).foo).toBe("foo"); + expect((0.1).foo).toBe("foo"); }); diff --git a/Libraries/LibJS/Tests/object-basic.js b/Libraries/LibJS/Tests/object-basic.js index 5e61525e40..d4d0b83e79 100644 --- a/Libraries/LibJS/Tests/object-basic.js +++ b/Libraries/LibJS/Tests/object-basic.js @@ -1,103 +1,104 @@ load("test-common.js"); try { - var foo = "bar"; - var computed = "computed" - var o = { - 1: 23, - foo, - bar: "baz", - qux: true ? 10 : 20, - "hello": "friends", - [1 + 2]: 42, - ["I am a " + computed + " key"]: foo, - duplicate: "hello", - duplicate: "world" - }; - assert(o[1] === 23); - assert(o[1n] === 23); - assert(o["1"] === 23); - assert(o.foo === "bar"); - assert(o["foo"] === "bar"); - assert(o.qux === 10), - assert(o.hello === "friends"); - assert(o["hello"] === "friends"); - assert(o[3] === 42); - assert(o["I am a computed key"] === "bar"); - assert(o.duplicate === "world"); - o.baz = "test"; - assert(o.baz === "test"); - assert(o["baz"] === "test"); - o[10] = "123"; - assert(o[10] === "123"); - assert(o["10"] === "123"); - o[10n] = "123"; - assert(o[10] === "123"); - assert(o["10"] === "123"); - o[-1] = "hello friends"; - assert(o[-1] === "hello friends"); - assert(o["-1"] === "hello friends"); + var foo = "bar"; + var computed = "computed"; + var o = { + 1: 23, + foo, + bar: "baz", + qux: true ? 10 : 20, + hello: "friends", + [1 + 2]: 42, + ["I am a " + computed + " key"]: foo, + duplicate: "hello", + duplicate: "world", + }; + assert(o[1] === 23); + assert(o[1n] === 23); + assert(o["1"] === 23); + assert(o.foo === "bar"); + assert(o["foo"] === "bar"); + assert(o.qux === 10), assert(o.hello === "friends"); + assert(o["hello"] === "friends"); + assert(o[3] === 42); + assert(o["I am a computed key"] === "bar"); + assert(o.duplicate === "world"); + o.baz = "test"; + assert(o.baz === "test"); + assert(o["baz"] === "test"); + o[10] = "123"; + assert(o[10] === "123"); + assert(o["10"] === "123"); + o[10n] = "123"; + assert(o[10] === "123"); + assert(o["10"] === "123"); + o[-1] = "hello friends"; + assert(o[-1] === "hello friends"); + assert(o["-1"] === "hello friends"); - var math = { 3.14: "pi" }; - assert(math["3.14"] === "pi"); - // Note : this test doesn't pass yet due to floating-point literals being coerced to i32 on access - // assert(math[3.14] === "pi"); + var math = { 3.14: "pi" }; + assert(math["3.14"] === "pi"); + // Note : this test doesn't pass yet due to floating-point literals being coerced to i32 on access + // assert(math[3.14] === "pi"); - // This is also allowed! Watch out for syntax errors. - var o2 = { return: 1, yield: 1, for: 1, catch: 1, break: 1 }; - assert(o2.return === 1); - assert(o2.yield === 1); - assert(o2.for === 1); - assert(o2.catch === 1); - assert(o2.break === 1); + // This is also allowed! Watch out for syntax errors. + var o2 = { return: 1, yield: 1, for: 1, catch: 1, break: 1 }; + assert(o2.return === 1); + assert(o2.yield === 1); + assert(o2.for === 1); + assert(o2.catch === 1); + assert(o2.break === 1); - var a; - var append = x => { a.push(x); }; + var a; + var append = x => { + a.push(x); + }; - a = []; - var o3 = {[append(1)]: 1, [append(2)]: 2, [append(3)]: 3} - assert(a.length === 3); - assert(a[0] === 1); - assert(a[1] === 2); - assert(a[2] === 3); - assert(o3.undefined === 3); + a = []; + var o3 = { [append(1)]: 1, [append(2)]: 2, [append(3)]: 3 }; + assert(a.length === 3); + assert(a[0] === 1); + assert(a[1] === 2); + assert(a[2] === 3); + assert(o3.undefined === 3); - a = []; - var o4 = {"test": append(1), "test": append(2), "test": append(3)} - assert(a.length === 3); - assert(a[0] === 1); - assert(a[1] === 2); - assert(a[2] === 3); - assert(o4.test === undefined); + a = []; + var o4 = { test: append(1), test: append(2), test: append(3) }; + assert(a.length === 3); + assert(a[0] === 1); + assert(a[1] === 2); + assert(a[2] === 3); + assert(o4.test === undefined); - var base = { - getNumber() { - return 10; - } - }; + var base = { + getNumber() { + return 10; + }, + }; - var derived = { - getNumber() { - return 20 + super.getNumber(); - } - }; + var derived = { + getNumber() { + return 20 + super.getNumber(); + }, + }; - Object.setPrototypeOf(derived, base) - assert(derived.getNumber() === 30); + Object.setPrototypeOf(derived, base); + assert(derived.getNumber() === 30); - assertIsSyntaxError("({ foo: function() { super.bar; } })") - assertIsSyntaxError("({ get ...foo })"); - assertIsSyntaxError("({ get... foo })"); - assertIsSyntaxError("({ get foo })"); - assertIsSyntaxError("({ get foo: bar })"); - assertIsSyntaxError("({ get [foo]: bar })"); - assertIsSyntaxError("({ get ...[foo] })"); - assertIsSyntaxError("({ get foo(bar) {} })"); - assertIsSyntaxError("({ set foo() {} })"); - assertIsSyntaxError("({ set foo(bar, baz) {} })"); - assertIsSyntaxError("({ ...foo: bar })"); + assertIsSyntaxError("({ foo: function() { super.bar; } })"); + assertIsSyntaxError("({ get ...foo })"); + assertIsSyntaxError("({ get... foo })"); + assertIsSyntaxError("({ get foo })"); + assertIsSyntaxError("({ get foo: bar })"); + assertIsSyntaxError("({ get [foo]: bar })"); + assertIsSyntaxError("({ get ...[foo] })"); + assertIsSyntaxError("({ get foo(bar) {} })"); + assertIsSyntaxError("({ set foo() {} })"); + assertIsSyntaxError("({ set foo(bar, baz) {} })"); + assertIsSyntaxError("({ ...foo: bar })"); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/object-getter-setter-shorthand.js b/Libraries/LibJS/Tests/object-getter-setter-shorthand.js index 3849bc5343..ced18d827e 100644 --- a/Libraries/LibJS/Tests/object-getter-setter-shorthand.js +++ b/Libraries/LibJS/Tests/object-getter-setter-shorthand.js @@ -1,50 +1,62 @@ test("normal methods named get and set", () => { - let o = { - get() { return 5; }, - set() { return 10; }, - }; - expect(o.get()).toBe(5); - expect(o.set()).toBe(10); + let o = { + get() { + return 5; + }, + set() { + return 10; + }, + }; + expect(o.get()).toBe(5); + expect(o.set()).toBe(10); }); test("basic get and set", () => { - let o = { - get x() { return 5; }, - set x(_) { }, - }; - expect(o.x).toBe(5); - o.x = 10; - expect(o.x).toBe(5); + let o = { + get x() { + return 5; + }, + set x(_) {}, + }; + expect(o.x).toBe(5); + o.x = 10; + expect(o.x).toBe(5); }); test("get and set with 'this'", () => { - let o = { - get x() { - return this._x + 1; - }, - set x(value) { - this._x = value + 1; - }, - }; + let o = { + get x() { + return this._x + 1; + }, + set x(value) { + this._x = value + 1; + }, + }; - expect(o.x).toBeNaN(); - o.x = 10; - expect(o.x).toBe(12); - o.x = 20; - expect(o.x).toBe(22); + expect(o.x).toBeNaN(); + o.x = 10; + expect(o.x).toBe(12); + o.x = 20; + expect(o.x).toBe(22); }); test("multiple getters", () => { - let o = { - get x() { return 5; }, - get x() { return 10; }, - }; - expect(o.x).toBe(10); + let o = { + get x() { + return 5; + }, + get x() { + return 10; + }, + }; + expect(o.x).toBe(10); }); test("setter return value", () => { - o = { - set x(value) { return 10; }, - }; - expect(o.x = 20).toBe(20); + o = { + set x(value) { + return 10; + }, + }; + expect((o.x = 20)).toBe(20); }); diff --git a/Libraries/LibJS/Tests/object-method-shorthand.js b/Libraries/LibJS/Tests/object-method-shorthand.js index 66b659d054..1e7bd9bf11 100644 --- a/Libraries/LibJS/Tests/object-method-shorthand.js +++ b/Libraries/LibJS/Tests/object-method-shorthand.js @@ -1,39 +1,39 @@ test("basic method shorthand", () => { - const o = { - foo: "bar", - getFoo() { - return this.foo; - }, - }; - expect(o.getFoo()).toBe("bar"); + const o = { + foo: "bar", + getFoo() { + return this.foo; + }, + }; + expect(o.getFoo()).toBe("bar"); }); test("numeric literal method shorthand", () => { - const o = { - foo: "bar", - 12() { - return this.foo; - }, - }; - expect(o[12]()).toBe("bar"); + const o = { + foo: "bar", + 12() { + return this.foo; + }, + }; + expect(o[12]()).toBe("bar"); }); test("string literal method shorthand", () => { - const o = { - foo: "bar", - "hello friends"() { - return this.foo; - }, - }; - expect(o["hello friends"]()).toBe("bar"); + const o = { + foo: "bar", + "hello friends"() { + return this.foo; + }, + }; + expect(o["hello friends"]()).toBe("bar"); }); test("computed property method shorthand", () => { - const o = { - foo: "bar", - [4 + 10]() { - return this.foo; - }, - }; - expect(o[14]()).toBe("bar"); + const o = { + foo: "bar", + [4 + 10]() { + return this.foo; + }, + }; + expect(o[14]()).toBe("bar"); }); diff --git a/Libraries/LibJS/Tests/object-spread.js b/Libraries/LibJS/Tests/object-spread.js index 1c3e5b3134..70c2cd09b1 100644 --- a/Libraries/LibJS/Tests/object-spread.js +++ b/Libraries/LibJS/Tests/object-spread.js @@ -1,82 +1,82 @@ const testObjSpread = obj => { - expect(obj).toEqual({ - foo: 0, - bar: 1, - baz: 2, - qux: 3 - }); + expect(obj).toEqual({ + foo: 0, + bar: 1, + baz: 2, + qux: 3, + }); }; const testObjStrSpread = obj => { - expect(obj).toEqual(["a", "b", "c", "d"]); + expect(obj).toEqual(["a", "b", "c", "d"]); }; test("spread object literal inside object literal", () => { - let obj = { - foo: 0, - ...{ bar: 1, baz: 2 }, - qux: 3, - }; - testObjSpread(obj); + let obj = { + foo: 0, + ...{ bar: 1, baz: 2 }, + qux: 3, + }; + testObjSpread(obj); }); test("spread object with assigned property inside object literal", () => { - obj = { foo: 0, bar: 1, baz: 2 }; - obj.qux = 3; - testObjSpread({ ...obj }); + obj = { foo: 0, bar: 1, baz: 2 }; + obj.qux = 3; + testObjSpread({ ...obj }); }); test("spread object inside object literal", () => { - let a = { bar: 1, baz: 2 }; - obj = { foo: 0, ...a, qux: 3 }; - testObjSpread(obj); + let a = { bar: 1, baz: 2 }; + obj = { foo: 0, ...a, qux: 3 }; + testObjSpread(obj); }); test("complex nested object spreading", () => { - obj = { - ...{}, - ...{ - ...{ foo: 0, bar: 1, baz: 2 }, - }, - qux: 3, - }; - testObjSpread(obj); + obj = { + ...{}, + ...{ + ...{ foo: 0, bar: 1, baz: 2 }, + }, + qux: 3, + }; + testObjSpread(obj); }); test("spread string in object literal", () => { - obj = { ..."abcd" }; - testObjStrSpread(obj); + obj = { ..."abcd" }; + testObjStrSpread(obj); }); test("spread array in object literal", () => { - obj = { ...["a", "b", "c", "d"] }; - testObjStrSpread(obj); + obj = { ...["a", "b", "c", "d"] }; + testObjStrSpread(obj); }); test("spread string object in object literal", () => { - obj = { ...String("abcd") }; - testObjStrSpread(obj); + obj = { ...String("abcd") }; + testObjStrSpread(obj); }); test("spread object with non-enumerable property", () => { - a = { foo: 0 }; - Object.defineProperty(a, "bar", { - value: 1, - enumerable: false, - }); - obj = { ...a }; - expect(obj.foo).toBe(0); - expect(obj).not.toHaveProperty("bar"); + a = { foo: 0 }; + Object.defineProperty(a, "bar", { + value: 1, + enumerable: false, + }); + obj = { ...a }; + expect(obj.foo).toBe(0); + expect(obj).not.toHaveProperty("bar"); }); test("spreading non-spreadable values", () => { - let empty = ({ - ...undefined, - ...null, - ...1, - ...true, - ...function(){}, - ...Date, - }); - expect(Object.getOwnPropertyNames(empty)).toHaveLength(0); + let empty = { + ...undefined, + ...null, + ...1, + ...true, + ...function () {}, + ...Date, + }; + expect(Object.getOwnPropertyNames(empty)).toHaveLength(0); }); diff --git a/Libraries/LibJS/Tests/operators/assignment-operators.js b/Libraries/LibJS/Tests/operators/assignment-operators.js index fd1d82ca74..ef39d3a3ac 100644 --- a/Libraries/LibJS/Tests/operators/assignment-operators.js +++ b/Libraries/LibJS/Tests/operators/assignment-operators.js @@ -1,61 +1,61 @@ load("test-common.js"); try { - var x; + var x; - x = 1; - assert((x = 2) === 2); - assert(x === 2); + x = 1; + assert((x = 2) === 2); + assert(x === 2); - x = 1; - assert((x += 2) === 3); - assert(x === 3); + x = 1; + assert((x += 2) === 3); + assert(x === 3); - x = 3; - assert((x -= 2) === 1); - assert(x === 1); + x = 3; + assert((x -= 2) === 1); + assert(x === 1); - x = 3; - assert((x *= 2) === 6); - assert(x === 6); + x = 3; + assert((x *= 2) === 6); + assert(x === 6); - x = 6; - assert((x /= 2) === 3); - assert(x === 3); + x = 6; + assert((x /= 2) === 3); + assert(x === 3); - x = 6; - assert((x %= 4) === 2); - assert(x === 2); + x = 6; + assert((x %= 4) === 2); + assert(x === 2); - x = 2; - assert((x **= 3) === 8); - assert(x === 8); + x = 2; + assert((x **= 3) === 8); + assert(x === 8); - x = 3; - assert((x &= 2) === 2); - assert(x === 2); + x = 3; + assert((x &= 2) === 2); + assert(x === 2); - x = 3; - assert((x |= 4) === 7); - assert(x === 7); + x = 3; + assert((x |= 4) === 7); + assert(x === 7); - x = 6; - assert((x ^= 2) === 4); - assert(x === 4); + x = 6; + assert((x ^= 2) === 4); + assert(x === 4); - x = 2; - assert((x <<= 2) === 8); - assert(x === 8); + x = 2; + assert((x <<= 2) === 8); + assert(x === 8); - x = 8; - assert((x >>= 2) === 2); - assert(x === 2); + x = 8; + assert((x >>= 2) === 2); + assert(x === 2); - x = -(2 ** 32 - 10); - assert((x >>>= 2) === 2); - assert(x === 2); + x = -(2 ** 32 - 10); + assert((x >>>= 2) === 2); + assert(x === 2); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js b/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js index 7eca53f10f..713c156670 100644 --- a/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js +++ b/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js @@ -1,63 +1,63 @@ load("test-common.js"); try { - assert((0 << 0) === 0); - assert((0 << 1) === 0); - assert((0 << 2) === 0); - assert((0 << 3) === 0); - assert((0 << 4) === 0); - assert((0 << 5) === 0); + assert(0 << 0 === 0); + assert(0 << 1 === 0); + assert(0 << 2 === 0); + assert(0 << 3 === 0); + assert(0 << 4 === 0); + assert(0 << 5 === 0); - assert((1 << 0) === 1); - assert((1 << 1) === 2); - assert((1 << 2) === 4); - assert((1 << 3) === 8); - assert((1 << 4) === 16); - assert((1 << 5) === 32); + assert(1 << 0 === 1); + assert(1 << 1 === 2); + assert(1 << 2 === 4); + assert(1 << 3 === 8); + assert(1 << 4 === 16); + assert(1 << 5 === 32); - assert((2 << 0) === 2); - assert((2 << 1) === 4); - assert((2 << 2) === 8); - assert((2 << 3) === 16); - assert((2 << 4) === 32); - assert((2 << 5) === 64); + assert(2 << 0 === 2); + assert(2 << 1 === 4); + assert(2 << 2 === 8); + assert(2 << 3 === 16); + assert(2 << 4 === 32); + assert(2 << 5 === 64); - assert((3 << 0) === 3); - assert((3 << 1) === 6); - assert((3 << 2) === 12); - assert((3 << 3) === 24); - assert((3 << 4) === 48); - assert((3 << 5) === 96); + assert(3 << 0 === 3); + assert(3 << 1 === 6); + assert(3 << 2 === 12); + assert(3 << 3 === 24); + assert(3 << 4 === 48); + assert(3 << 5 === 96); - assert((4 << 0) === 4); - assert((4 << 1) === 8); - assert((4 << 2) === 16); - assert((4 << 3) === 32); - assert((4 << 4) === 64); - assert((4 << 5) === 128); + assert(4 << 0 === 4); + assert(4 << 1 === 8); + assert(4 << 2 === 16); + assert(4 << 3 === 32); + assert(4 << 4 === 64); + assert(4 << 5 === 128); - assert((5 << 0) === 5); - assert((5 << 1) === 10); - assert((5 << 2) === 20); - assert((5 << 3) === 40); - assert((5 << 4) === 80); - assert((5 << 5) === 160); + assert(5 << 0 === 5); + assert(5 << 1 === 10); + assert(5 << 2 === 20); + assert(5 << 3 === 40); + assert(5 << 4 === 80); + assert(5 << 5 === 160); - var x = 3; - var y = 7; - assert(("42" << 6) === 2688); - assert((x << y) === 384); - assert((x << [[[[12]]]]) === 12288); - assert((undefined << y) === 0); - assert(("a" << "b") === 0); - assert((null << null) === 0); - assert((undefined << undefined) === 0); - assert((NaN << NaN) === 0); - assert((NaN << 6) === 0); - assert((Infinity << Infinity) === 0); - assert((-Infinity << Infinity) === 0); + var x = 3; + var y = 7; + assert("42" << 6 === 2688); + assert(x << y === 384); + assert(x << [[[[12]]]] === 12288); + assert(undefined << y === 0); + assert("a" << "b" === 0); + assert(null << null === 0); + assert(undefined << undefined === 0); + assert(NaN << NaN === 0); + assert(NaN << 6 === 0); + assert(Infinity << Infinity === 0); + assert(-Infinity << Infinity === 0); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/binary-bitwise-or.js b/Libraries/LibJS/Tests/operators/binary-bitwise-or.js index 09eb1ae036..2274d02217 100644 --- a/Libraries/LibJS/Tests/operators/binary-bitwise-or.js +++ b/Libraries/LibJS/Tests/operators/binary-bitwise-or.js @@ -1,63 +1,63 @@ load("test-common.js"); try { - assert((0 | 0) === 0); - assert((0 | 1) === 1); - assert((0 | 2) === 2); - assert((0 | 3) === 3); - assert((0 | 4) === 4); - assert((0 | 5) === 5); + assert((0 | 0) === 0); + assert((0 | 1) === 1); + assert((0 | 2) === 2); + assert((0 | 3) === 3); + assert((0 | 4) === 4); + assert((0 | 5) === 5); - assert((1 | 0) === 1); - assert((1 | 1) === 1); - assert((1 | 2) === 3); - assert((1 | 3) === 3); - assert((1 | 4) === 5); - assert((1 | 5) === 5); + assert((1 | 0) === 1); + assert((1 | 1) === 1); + assert((1 | 2) === 3); + assert((1 | 3) === 3); + assert((1 | 4) === 5); + assert((1 | 5) === 5); - assert((2 | 0) === 2); - assert((2 | 1) === 3); - assert((2 | 2) === 2); - assert((2 | 3) === 3); - assert((2 | 4) === 6); - assert((2 | 5) === 7); + assert((2 | 0) === 2); + assert((2 | 1) === 3); + assert((2 | 2) === 2); + assert((2 | 3) === 3); + assert((2 | 4) === 6); + assert((2 | 5) === 7); - assert((3 | 0) === 3); - assert((3 | 1) === 3); - assert((3 | 2) === 3); - assert((3 | 3) === 3); - assert((3 | 4) === 7); - assert((3 | 5) === 7); + assert((3 | 0) === 3); + assert((3 | 1) === 3); + assert((3 | 2) === 3); + assert((3 | 3) === 3); + assert((3 | 4) === 7); + assert((3 | 5) === 7); - assert((4 | 0) === 4); - assert((4 | 1) === 5); - assert((4 | 2) === 6); - assert((4 | 3) === 7); - assert((4 | 4) === 4); - assert((4 | 5) === 5); + assert((4 | 0) === 4); + assert((4 | 1) === 5); + assert((4 | 2) === 6); + assert((4 | 3) === 7); + assert((4 | 4) === 4); + assert((4 | 5) === 5); - assert((5 | 0) === 5); - assert((5 | 1) === 5); - assert((5 | 2) === 7); - assert((5 | 3) === 7); - assert((5 | 4) === 5); - assert((5 | 5) === 5); + assert((5 | 0) === 5); + assert((5 | 1) === 5); + assert((5 | 2) === 7); + assert((5 | 3) === 7); + assert((5 | 4) === 5); + assert((5 | 5) === 5); - var x = 3; - var y = 7; - assert(("42" | 6) === 46); - assert((x | y) === 7); - assert((x | [[[[12]]]]) === 15); - assert((undefined | y) === 7); - assert(("a" | "b") === 0); - assert((null | null) === 0); - assert((undefined | undefined) === 0); - assert((NaN | NaN) === 0); - assert((NaN | 6) === 6); - assert((Infinity | Infinity) === 0); - assert((-Infinity | Infinity) === 0); + var x = 3; + var y = 7; + assert(("42" | 6) === 46); + assert((x | y) === 7); + assert((x | [[[[12]]]]) === 15); + assert((undefined | y) === 7); + assert(("a" | "b") === 0); + assert((null | null) === 0); + assert((undefined | undefined) === 0); + assert((NaN | NaN) === 0); + assert((NaN | 6) === 6); + assert((Infinity | Infinity) === 0); + assert((-Infinity | Infinity) === 0); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js b/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js index 4338d09652..96e5cfb31d 100644 --- a/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js +++ b/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js @@ -1,63 +1,63 @@ load("test-common.js"); try { - assert((0 >> 0) === 0); - assert((0 >> 1) === 0); - assert((0 >> 2) === 0); - assert((0 >> 3) === 0); - assert((0 >> 4) === 0); - assert((0 >> 5) === 0); + assert(0 >> 0 === 0); + assert(0 >> 1 === 0); + assert(0 >> 2 === 0); + assert(0 >> 3 === 0); + assert(0 >> 4 === 0); + assert(0 >> 5 === 0); - assert((1 >> 0) === 1); - assert((1 >> 1) === 0); - assert((1 >> 2) === 0); - assert((1 >> 3) === 0); - assert((1 >> 4) === 0); - assert((1 >> 5) === 0); + assert(1 >> 0 === 1); + assert(1 >> 1 === 0); + assert(1 >> 2 === 0); + assert(1 >> 3 === 0); + assert(1 >> 4 === 0); + assert(1 >> 5 === 0); - assert((5 >> 0) === 5); - assert((5 >> 1) === 2); - assert((5 >> 2) === 1); - assert((5 >> 3) === 0); - assert((5 >> 4) === 0); - assert((5 >> 5) === 0); + assert(5 >> 0 === 5); + assert(5 >> 1 === 2); + assert(5 >> 2 === 1); + assert(5 >> 3 === 0); + assert(5 >> 4 === 0); + assert(5 >> 5 === 0); - assert((42 >> 0) === 42); - assert((42 >> 1) === 21); - assert((42 >> 2) === 10); - assert((42 >> 3) === 5); - assert((42 >> 4) === 2); - assert((42 >> 5) === 1); + assert(42 >> 0 === 42); + assert(42 >> 1 === 21); + assert(42 >> 2 === 10); + assert(42 >> 3 === 5); + assert(42 >> 4 === 2); + assert(42 >> 5 === 1); - assert((-1 >> 0) === -1); - assert((-1 >> 1) === -1); - assert((-1 >> 2) === -1); - assert((-1 >> 3) === -1); - assert((-1 >> 4) === -1); - assert((-1 >> 5) === -1); + assert(-1 >> 0 === -1); + assert(-1 >> 1 === -1); + assert(-1 >> 2 === -1); + assert(-1 >> 3 === -1); + assert(-1 >> 4 === -1); + assert(-1 >> 5 === -1); - assert((-5 >> 0) === -5); - assert((-5 >> 1) === -3); - assert((-5 >> 2) === -2); - assert((-5 >> 3) === -1); - assert((-5 >> 4) === -1); - assert((-5 >> 5) === -1); + assert(-5 >> 0 === -5); + assert(-5 >> 1 === -3); + assert(-5 >> 2 === -2); + assert(-5 >> 3 === -1); + assert(-5 >> 4 === -1); + assert(-5 >> 5 === -1); - var x = 67; - var y = 4; - assert(("42" >> 3) === 5); - assert((x >> y) === 4); - assert((x >> [[[[5]]]]) === 2); - assert((undefined >> y) === 0); - assert(("a" >> "b") === 0); - assert((null >> null) === 0); - assert((undefined >> undefined) === 0); - assert((NaN >> NaN) === 0); - assert((6 >> NaN) === 6); - assert((Infinity >> Infinity) === 0); - assert((-Infinity >> Infinity) === 0); + var x = 67; + var y = 4; + assert("42" >> 3 === 5); + assert(x >> y === 4); + assert(x >> [[[[5]]]] === 2); + assert(undefined >> y === 0); + assert("a" >> "b" === 0); + assert(null >> null === 0); + assert(undefined >> undefined === 0); + assert(NaN >> NaN === 0); + assert(6 >> NaN === 6); + assert(Infinity >> Infinity === 0); + assert(-Infinity >> Infinity === 0); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/binary-bitwise-unsigned-right-shift.js b/Libraries/LibJS/Tests/operators/binary-bitwise-unsigned-right-shift.js index 0f69b6b63a..30303672e9 100644 --- a/Libraries/LibJS/Tests/operators/binary-bitwise-unsigned-right-shift.js +++ b/Libraries/LibJS/Tests/operators/binary-bitwise-unsigned-right-shift.js @@ -1,63 +1,63 @@ load("test-common.js"); try { - assert((0 >>> 0) === 0); - assert((0 >>> 1) === 0); - assert((0 >>> 2) === 0); - assert((0 >>> 3) === 0); - assert((0 >>> 4) === 0); - assert((0 >>> 5) === 0); + assert(0 >>> 0 === 0); + assert(0 >>> 1 === 0); + assert(0 >>> 2 === 0); + assert(0 >>> 3 === 0); + assert(0 >>> 4 === 0); + assert(0 >>> 5 === 0); - assert((1 >>> 0) === 1); - assert((1 >>> 1) === 0); - assert((1 >>> 2) === 0); - assert((1 >>> 3) === 0); - assert((1 >>> 4) === 0); - assert((1 >>> 5) === 0); + assert(1 >>> 0 === 1); + assert(1 >>> 1 === 0); + assert(1 >>> 2 === 0); + assert(1 >>> 3 === 0); + assert(1 >>> 4 === 0); + assert(1 >>> 5 === 0); - assert((5 >>> 0) === 5); - assert((5 >>> 1) === 2); - assert((5 >>> 2) === 1); - assert((5 >>> 3) === 0); - assert((5 >>> 4) === 0); - assert((5 >>> 5) === 0); + assert(5 >>> 0 === 5); + assert(5 >>> 1 === 2); + assert(5 >>> 2 === 1); + assert(5 >>> 3 === 0); + assert(5 >>> 4 === 0); + assert(5 >>> 5 === 0); - assert((42 >>> 0) === 42); - assert((42 >>> 1) === 21); - assert((42 >>> 2) === 10); - assert((42 >>> 3) === 5); - assert((42 >>> 4) === 2); - assert((42 >>> 5) === 1); + assert(42 >>> 0 === 42); + assert(42 >>> 1 === 21); + assert(42 >>> 2 === 10); + assert(42 >>> 3 === 5); + assert(42 >>> 4 === 2); + assert(42 >>> 5 === 1); - assert((-1 >>> 0) === 4294967295); - assert((-1 >>> 1) === 2147483647); - assert((-1 >>> 2) === 1073741823); - assert((-1 >>> 3) === 536870911); - assert((-1 >>> 4) === 268435455); - assert((-1 >>> 5) === 134217727); + assert(-1 >>> 0 === 4294967295); + assert(-1 >>> 1 === 2147483647); + assert(-1 >>> 2 === 1073741823); + assert(-1 >>> 3 === 536870911); + assert(-1 >>> 4 === 268435455); + assert(-1 >>> 5 === 134217727); - assert((-5 >>> 0) === 4294967291); - assert((-5 >>> 1) === 2147483645); - assert((-5 >>> 2) === 1073741822); - assert((-5 >>> 3) === 536870911); - assert((-5 >>> 4) === 268435455); - assert((-5 >>> 5) === 134217727); + assert(-5 >>> 0 === 4294967291); + assert(-5 >>> 1 === 2147483645); + assert(-5 >>> 2 === 1073741822); + assert(-5 >>> 3 === 536870911); + assert(-5 >>> 4 === 268435455); + assert(-5 >>> 5 === 134217727); - var x = -67; - var y = 4; - assert(("-42" >>> 3) === 536870906); - assert((x >>> y) === 268435451); - assert((x >>> [[[[5]]]]) === 134217725); - assert((undefined >>> y) === 0); - assert(("a" >>> "b") === 0); - assert((null >>> null) === 0); - assert((undefined >>> undefined) === 0); - assert((NaN >>> NaN) === 0); - assert((6 >>> NaN) === 6); - assert((Infinity >>> Infinity) === 0); - assert((-Infinity >>> Infinity) === 0); + var x = -67; + var y = 4; + assert("-42" >>> 3 === 536870906); + assert(x >>> y === 268435451); + assert(x >>> [[[[5]]]] === 134217725); + assert(undefined >>> y === 0); + assert("a" >>> "b" === 0); + assert(null >>> null === 0); + assert(undefined >>> undefined === 0); + assert(NaN >>> NaN === 0); + assert(6 >>> NaN === 6); + assert(Infinity >>> Infinity === 0); + assert(-Infinity >>> Infinity === 0); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/binary-relational.js b/Libraries/LibJS/Tests/operators/binary-relational.js index 01397d5147..719927c7a0 100644 --- a/Libraries/LibJS/Tests/operators/binary-relational.js +++ b/Libraries/LibJS/Tests/operators/binary-relational.js @@ -1,735 +1,735 @@ load("test-common.js"); try { - const vals = [ - 1, - 2, - 1.23, - 2.34567, - 1n, - 2n, - [], - [1], - [2], - [1, 2], - "foo", - "fooo", - "🔥", - "❤️", - "bar", - {}, - { a: 1 }, - { a: 2 }, - { b: 1 }, - true, - false, - undefined, - null, - NaN, - +Infinity, - -Infinity, - ]; + const vals = [ + 1, + 2, + 1.23, + 2.34567, + 1n, + 2n, + [], + [1], + [2], + [1, 2], + "foo", + "fooo", + "🔥", + "❤️", + "bar", + {}, + { a: 1 }, + { a: 2 }, + { b: 1 }, + true, + false, + undefined, + null, + NaN, + +Infinity, + -Infinity, + ]; - // Each row contains: xIndex, yIndex, (x < y), (x > y), (x <= y), (x >= y) - // where x = vals[xIndex], y = vals[yIndex] - // Table can be generated using a mature engine and the following code: - // for (var xIndex = 0; xIndex < vals.length; ++xIndex) { - // for (var yIndex = 0; yIndex < vals.length; ++yIndex) { - // var x = vals[xIndex]; - // var y = vals[yIndex]; - // console.log(`[${xIndex}, ${yIndex}, ${x < y}, ${x > y}, ${x <= y}, ${x >= y}]`); - // } - // } - const table = [ - [0, 0, false, false, true, true], - [0, 1, true, false, true, false], - [0, 2, true, false, true, false], - [0, 3, true, false, true, false], - [0, 4, false, false, true, true], - [0, 5, true, false, true, false], - [0, 6, false, true, false, true], - [0, 7, false, false, true, true], - [0, 8, true, false, true, false], - [0, 9, false, false, false, false], - [0, 10, false, false, false, false], - [0, 11, false, false, false, false], - [0, 12, false, false, false, false], - [0, 13, false, false, false, false], - [0, 14, false, false, false, false], - [0, 15, false, false, false, false], - [0, 16, false, false, false, false], - [0, 17, false, false, false, false], - [0, 18, false, false, false, false], - [0, 19, false, false, true, true], - [0, 20, false, true, false, true], - [0, 21, false, false, false, false], - [0, 22, false, true, false, true], - [0, 23, false, false, false, false], - [0, 24, true, false, true, false], - [0, 25, false, true, false, true], - [1, 0, false, true, false, true], - [1, 1, false, false, true, true], - [1, 2, false, true, false, true], - [1, 3, true, false, true, false], - [1, 4, false, true, false, true], - [1, 5, false, false, true, true], - [1, 6, false, true, false, true], - [1, 7, false, true, false, true], - [1, 8, false, false, true, true], - [1, 9, false, false, false, false], - [1, 10, false, false, false, false], - [1, 11, false, false, false, false], - [1, 12, false, false, false, false], - [1, 13, false, false, false, false], - [1, 14, false, false, false, false], - [1, 15, false, false, false, false], - [1, 16, false, false, false, false], - [1, 17, false, false, false, false], - [1, 18, false, false, false, false], - [1, 19, false, true, false, true], - [1, 20, false, true, false, true], - [1, 21, false, false, false, false], - [1, 22, false, true, false, true], - [1, 23, false, false, false, false], - [1, 24, true, false, true, false], - [1, 25, false, true, false, true], - [2, 0, false, true, false, true], - [2, 1, true, false, true, false], - [2, 2, false, false, true, true], - [2, 3, true, false, true, false], - [2, 4, false, true, false, true], - [2, 5, true, false, true, false], - [2, 6, false, true, false, true], - [2, 7, false, true, false, true], - [2, 8, true, false, true, false], - [2, 9, false, false, false, false], - [2, 10, false, false, false, false], - [2, 11, false, false, false, false], - [2, 12, false, false, false, false], - [2, 13, false, false, false, false], - [2, 14, false, false, false, false], - [2, 15, false, false, false, false], - [2, 16, false, false, false, false], - [2, 17, false, false, false, false], - [2, 18, false, false, false, false], - [2, 19, false, true, false, true], - [2, 20, false, true, false, true], - [2, 21, false, false, false, false], - [2, 22, false, true, false, true], - [2, 23, false, false, false, false], - [2, 24, true, false, true, false], - [2, 25, false, true, false, true], - [3, 0, false, true, false, true], - [3, 1, false, true, false, true], - [3, 2, false, true, false, true], - [3, 3, false, false, true, true], - [3, 4, false, true, false, true], - [3, 5, false, true, false, true], - [3, 6, false, true, false, true], - [3, 7, false, true, false, true], - [3, 8, false, true, false, true], - [3, 9, false, false, false, false], - [3, 10, false, false, false, false], - [3, 11, false, false, false, false], - [3, 12, false, false, false, false], - [3, 13, false, false, false, false], - [3, 14, false, false, false, false], - [3, 15, false, false, false, false], - [3, 16, false, false, false, false], - [3, 17, false, false, false, false], - [3, 18, false, false, false, false], - [3, 19, false, true, false, true], - [3, 20, false, true, false, true], - [3, 21, false, false, false, false], - [3, 22, false, true, false, true], - [3, 23, false, false, false, false], - [3, 24, true, false, true, false], - [3, 25, false, true, false, true], - [4, 0, false, false, true, true], - [4, 1, true, false, true, false], - [4, 2, true, false, true, false], - [4, 3, true, false, true, false], - [4, 4, false, false, true, true], - [4, 5, true, false, true, false], - [4, 6, false, true, false, true], - [4, 7, false, false, true, true], - [4, 8, true, false, true, false], - [4, 9, false, false, false, false], - [4, 10, false, false, false, false], - [4, 11, false, false, false, false], - [4, 12, false, false, false, false], - [4, 13, false, false, false, false], - [4, 14, false, false, false, false], - [4, 15, false, false, false, false], - [4, 16, false, false, false, false], - [4, 17, false, false, false, false], - [4, 18, false, false, false, false], - [4, 19, false, false, true, true], - [4, 20, false, true, false, true], - [4, 21, false, false, false, false], - [4, 22, false, true, false, true], - [4, 23, false, false, false, false], - [4, 24, true, false, true, false], - [4, 25, false, true, false, true], - [5, 0, false, true, false, true], - [5, 1, false, false, true, true], - [5, 2, false, true, false, true], - [5, 3, true, false, true, false], - [5, 4, false, true, false, true], - [5, 5, false, false, true, true], - [5, 6, false, true, false, true], - [5, 7, false, true, false, true], - [5, 8, false, false, true, true], - [5, 9, false, false, false, false], - [5, 10, false, false, false, false], - [5, 11, false, false, false, false], - [5, 12, false, false, false, false], - [5, 13, false, false, false, false], - [5, 14, false, false, false, false], - [5, 15, false, false, false, false], - [5, 16, false, false, false, false], - [5, 17, false, false, false, false], - [5, 18, false, false, false, false], - [5, 19, false, true, false, true], - [5, 20, false, true, false, true], - [5, 21, false, false, false, false], - [5, 22, false, true, false, true], - [5, 23, false, false, false, false], - [5, 24, true, false, true, false], - [5, 25, false, true, false, true], - [6, 0, true, false, true, false], - [6, 1, true, false, true, false], - [6, 2, true, false, true, false], - [6, 3, true, false, true, false], - [6, 4, true, false, true, false], - [6, 5, true, false, true, false], - [6, 6, false, false, true, true], - [6, 7, true, false, true, false], - [6, 8, true, false, true, false], - [6, 9, true, false, true, false], - [6, 10, true, false, true, false], - [6, 11, true, false, true, false], - [6, 12, true, false, true, false], - [6, 13, true, false, true, false], - [6, 14, true, false, true, false], - [6, 15, true, false, true, false], - [6, 16, true, false, true, false], - [6, 17, true, false, true, false], - [6, 18, true, false, true, false], - [6, 19, true, false, true, false], - [6, 20, false, false, true, true], - [6, 21, false, false, false, false], - [6, 22, false, false, true, true], - [6, 23, false, false, false, false], - [6, 24, true, false, true, false], - [6, 25, false, true, false, true], - [7, 0, false, false, true, true], - [7, 1, true, false, true, false], - [7, 2, true, false, true, false], - [7, 3, true, false, true, false], - [7, 4, false, false, true, true], - [7, 5, true, false, true, false], - [7, 6, false, true, false, true], - [7, 7, false, false, true, true], - [7, 8, true, false, true, false], - [7, 9, true, false, true, false], - [7, 10, true, false, true, false], - [7, 11, true, false, true, false], - [7, 12, true, false, true, false], - [7, 13, true, false, true, false], - [7, 14, true, false, true, false], - [7, 15, true, false, true, false], - [7, 16, true, false, true, false], - [7, 17, true, false, true, false], - [7, 18, true, false, true, false], - [7, 19, false, false, true, true], - [7, 20, false, true, false, true], - [7, 21, false, false, false, false], - [7, 22, false, true, false, true], - [7, 23, false, false, false, false], - [7, 24, true, false, true, false], - [7, 25, false, true, false, true], - [8, 0, false, true, false, true], - [8, 1, false, false, true, true], - [8, 2, false, true, false, true], - [8, 3, true, false, true, false], - [8, 4, false, true, false, true], - [8, 5, false, false, true, true], - [8, 6, false, true, false, true], - [8, 7, false, true, false, true], - [8, 8, false, false, true, true], - [8, 9, false, true, false, true], - [8, 10, true, false, true, false], - [8, 11, true, false, true, false], - [8, 12, true, false, true, false], - [8, 13, true, false, true, false], - [8, 14, true, false, true, false], - [8, 15, true, false, true, false], - [8, 16, true, false, true, false], - [8, 17, true, false, true, false], - [8, 18, true, false, true, false], - [8, 19, false, true, false, true], - [8, 20, false, true, false, true], - [8, 21, false, false, false, false], - [8, 22, false, true, false, true], - [8, 23, false, false, false, false], - [8, 24, true, false, true, false], - [8, 25, false, true, false, true], - [9, 0, false, false, false, false], - [9, 1, false, false, false, false], - [9, 2, false, false, false, false], - [9, 3, false, false, false, false], - [9, 4, false, false, false, false], - [9, 5, false, false, false, false], - [9, 6, false, true, false, true], - [9, 7, false, true, false, true], - [9, 8, true, false, true, false], - [9, 9, false, false, true, true], - [9, 10, true, false, true, false], - [9, 11, true, false, true, false], - [9, 12, true, false, true, false], - [9, 13, true, false, true, false], - [9, 14, true, false, true, false], - [9, 15, true, false, true, false], - [9, 16, true, false, true, false], - [9, 17, true, false, true, false], - [9, 18, true, false, true, false], - [9, 19, false, false, false, false], - [9, 20, false, false, false, false], - [9, 21, false, false, false, false], - [9, 22, false, false, false, false], - [9, 23, false, false, false, false], - [9, 24, false, false, false, false], - [9, 25, false, false, false, false], - [10, 0, false, false, false, false], - [10, 1, false, false, false, false], - [10, 2, false, false, false, false], - [10, 3, false, false, false, false], - [10, 4, false, false, false, false], - [10, 5, false, false, false, false], - [10, 6, false, true, false, true], - [10, 7, false, true, false, true], - [10, 8, false, true, false, true], - [10, 9, false, true, false, true], - [10, 10, false, false, true, true], - [10, 11, true, false, true, false], - [10, 12, true, false, true, false], - [10, 13, true, false, true, false], - [10, 14, false, true, false, true], - [10, 15, false, true, false, true], - [10, 16, false, true, false, true], - [10, 17, false, true, false, true], - [10, 18, false, true, false, true], - [10, 19, false, false, false, false], - [10, 20, false, false, false, false], - [10, 21, false, false, false, false], - [10, 22, false, false, false, false], - [10, 23, false, false, false, false], - [10, 24, false, false, false, false], - [10, 25, false, false, false, false], - [11, 0, false, false, false, false], - [11, 1, false, false, false, false], - [11, 2, false, false, false, false], - [11, 3, false, false, false, false], - [11, 4, false, false, false, false], - [11, 5, false, false, false, false], - [11, 6, false, true, false, true], - [11, 7, false, true, false, true], - [11, 8, false, true, false, true], - [11, 9, false, true, false, true], - [11, 10, false, true, false, true], - [11, 11, false, false, true, true], - [11, 12, true, false, true, false], - [11, 13, true, false, true, false], - [11, 14, false, true, false, true], - [11, 15, false, true, false, true], - [11, 16, false, true, false, true], - [11, 17, false, true, false, true], - [11, 18, false, true, false, true], - [11, 19, false, false, false, false], - [11, 20, false, false, false, false], - [11, 21, false, false, false, false], - [11, 22, false, false, false, false], - [11, 23, false, false, false, false], - [11, 24, false, false, false, false], - [11, 25, false, false, false, false], - [12, 0, false, false, false, false], - [12, 1, false, false, false, false], - [12, 2, false, false, false, false], - [12, 3, false, false, false, false], - [12, 4, false, false, false, false], - [12, 5, false, false, false, false], - [12, 6, false, true, false, true], - [12, 7, false, true, false, true], - [12, 8, false, true, false, true], - [12, 9, false, true, false, true], - [12, 10, false, true, false, true], - [12, 11, false, true, false, true], - [12, 12, false, false, true, true], - [12, 13, false, true, false, true], - [12, 14, false, true, false, true], - [12, 15, false, true, false, true], - [12, 16, false, true, false, true], - [12, 17, false, true, false, true], - [12, 18, false, true, false, true], - [12, 19, false, false, false, false], - [12, 20, false, false, false, false], - [12, 21, false, false, false, false], - [12, 22, false, false, false, false], - [12, 23, false, false, false, false], - [12, 24, false, false, false, false], - [12, 25, false, false, false, false], - [13, 0, false, false, false, false], - [13, 1, false, false, false, false], - [13, 2, false, false, false, false], - [13, 3, false, false, false, false], - [13, 4, false, false, false, false], - [13, 5, false, false, false, false], - [13, 6, false, true, false, true], - [13, 7, false, true, false, true], - [13, 8, false, true, false, true], - [13, 9, false, true, false, true], - [13, 10, false, true, false, true], - [13, 11, false, true, false, true], - [13, 12, true, false, true, false], - [13, 13, false, false, true, true], - [13, 14, false, true, false, true], - [13, 15, false, true, false, true], - [13, 16, false, true, false, true], - [13, 17, false, true, false, true], - [13, 18, false, true, false, true], - [13, 19, false, false, false, false], - [13, 20, false, false, false, false], - [13, 21, false, false, false, false], - [13, 22, false, false, false, false], - [13, 23, false, false, false, false], - [13, 24, false, false, false, false], - [13, 25, false, false, false, false], - [14, 0, false, false, false, false], - [14, 1, false, false, false, false], - [14, 2, false, false, false, false], - [14, 3, false, false, false, false], - [14, 4, false, false, false, false], - [14, 5, false, false, false, false], - [14, 6, false, true, false, true], - [14, 7, false, true, false, true], - [14, 8, false, true, false, true], - [14, 9, false, true, false, true], - [14, 10, true, false, true, false], - [14, 11, true, false, true, false], - [14, 12, true, false, true, false], - [14, 13, true, false, true, false], - [14, 14, false, false, true, true], - [14, 15, false, true, false, true], - [14, 16, false, true, false, true], - [14, 17, false, true, false, true], - [14, 18, false, true, false, true], - [14, 19, false, false, false, false], - [14, 20, false, false, false, false], - [14, 21, false, false, false, false], - [14, 22, false, false, false, false], - [14, 23, false, false, false, false], - [14, 24, false, false, false, false], - [14, 25, false, false, false, false], - [15, 0, false, false, false, false], - [15, 1, false, false, false, false], - [15, 2, false, false, false, false], - [15, 3, false, false, false, false], - [15, 4, false, false, false, false], - [15, 5, false, false, false, false], - [15, 6, false, true, false, true], - [15, 7, false, true, false, true], - [15, 8, false, true, false, true], - [15, 9, false, true, false, true], - [15, 10, true, false, true, false], - [15, 11, true, false, true, false], - [15, 12, true, false, true, false], - [15, 13, true, false, true, false], - [15, 14, true, false, true, false], - [15, 15, false, false, true, true], - [15, 16, false, false, true, true], - [15, 17, false, false, true, true], - [15, 18, false, false, true, true], - [15, 19, false, false, false, false], - [15, 20, false, false, false, false], - [15, 21, false, false, false, false], - [15, 22, false, false, false, false], - [15, 23, false, false, false, false], - [15, 24, false, false, false, false], - [15, 25, false, false, false, false], - [16, 0, false, false, false, false], - [16, 1, false, false, false, false], - [16, 2, false, false, false, false], - [16, 3, false, false, false, false], - [16, 4, false, false, false, false], - [16, 5, false, false, false, false], - [16, 6, false, true, false, true], - [16, 7, false, true, false, true], - [16, 8, false, true, false, true], - [16, 9, false, true, false, true], - [16, 10, true, false, true, false], - [16, 11, true, false, true, false], - [16, 12, true, false, true, false], - [16, 13, true, false, true, false], - [16, 14, true, false, true, false], - [16, 15, false, false, true, true], - [16, 16, false, false, true, true], - [16, 17, false, false, true, true], - [16, 18, false, false, true, true], - [16, 19, false, false, false, false], - [16, 20, false, false, false, false], - [16, 21, false, false, false, false], - [16, 22, false, false, false, false], - [16, 23, false, false, false, false], - [16, 24, false, false, false, false], - [16, 25, false, false, false, false], - [17, 0, false, false, false, false], - [17, 1, false, false, false, false], - [17, 2, false, false, false, false], - [17, 3, false, false, false, false], - [17, 4, false, false, false, false], - [17, 5, false, false, false, false], - [17, 6, false, true, false, true], - [17, 7, false, true, false, true], - [17, 8, false, true, false, true], - [17, 9, false, true, false, true], - [17, 10, true, false, true, false], - [17, 11, true, false, true, false], - [17, 12, true, false, true, false], - [17, 13, true, false, true, false], - [17, 14, true, false, true, false], - [17, 15, false, false, true, true], - [17, 16, false, false, true, true], - [17, 17, false, false, true, true], - [17, 18, false, false, true, true], - [17, 19, false, false, false, false], - [17, 20, false, false, false, false], - [17, 21, false, false, false, false], - [17, 22, false, false, false, false], - [17, 23, false, false, false, false], - [17, 24, false, false, false, false], - [17, 25, false, false, false, false], - [18, 0, false, false, false, false], - [18, 1, false, false, false, false], - [18, 2, false, false, false, false], - [18, 3, false, false, false, false], - [18, 4, false, false, false, false], - [18, 5, false, false, false, false], - [18, 6, false, true, false, true], - [18, 7, false, true, false, true], - [18, 8, false, true, false, true], - [18, 9, false, true, false, true], - [18, 10, true, false, true, false], - [18, 11, true, false, true, false], - [18, 12, true, false, true, false], - [18, 13, true, false, true, false], - [18, 14, true, false, true, false], - [18, 15, false, false, true, true], - [18, 16, false, false, true, true], - [18, 17, false, false, true, true], - [18, 18, false, false, true, true], - [18, 19, false, false, false, false], - [18, 20, false, false, false, false], - [18, 21, false, false, false, false], - [18, 22, false, false, false, false], - [18, 23, false, false, false, false], - [18, 24, false, false, false, false], - [18, 25, false, false, false, false], - [19, 0, false, false, true, true], - [19, 1, true, false, true, false], - [19, 2, true, false, true, false], - [19, 3, true, false, true, false], - [19, 4, false, false, true, true], - [19, 5, true, false, true, false], - [19, 6, false, true, false, true], - [19, 7, false, false, true, true], - [19, 8, true, false, true, false], - [19, 9, false, false, false, false], - [19, 10, false, false, false, false], - [19, 11, false, false, false, false], - [19, 12, false, false, false, false], - [19, 13, false, false, false, false], - [19, 14, false, false, false, false], - [19, 15, false, false, false, false], - [19, 16, false, false, false, false], - [19, 17, false, false, false, false], - [19, 18, false, false, false, false], - [19, 19, false, false, true, true], - [19, 20, false, true, false, true], - [19, 21, false, false, false, false], - [19, 22, false, true, false, true], - [19, 23, false, false, false, false], - [19, 24, true, false, true, false], - [19, 25, false, true, false, true], - [20, 0, true, false, true, false], - [20, 1, true, false, true, false], - [20, 2, true, false, true, false], - [20, 3, true, false, true, false], - [20, 4, true, false, true, false], - [20, 5, true, false, true, false], - [20, 6, false, false, true, true], - [20, 7, true, false, true, false], - [20, 8, true, false, true, false], - [20, 9, false, false, false, false], - [20, 10, false, false, false, false], - [20, 11, false, false, false, false], - [20, 12, false, false, false, false], - [20, 13, false, false, false, false], - [20, 14, false, false, false, false], - [20, 15, false, false, false, false], - [20, 16, false, false, false, false], - [20, 17, false, false, false, false], - [20, 18, false, false, false, false], - [20, 19, true, false, true, false], - [20, 20, false, false, true, true], - [20, 21, false, false, false, false], - [20, 22, false, false, true, true], - [20, 23, false, false, false, false], - [20, 24, true, false, true, false], - [20, 25, false, true, false, true], - [21, 0, false, false, false, false], - [21, 1, false, false, false, false], - [21, 2, false, false, false, false], - [21, 3, false, false, false, false], - [21, 4, false, false, false, false], - [21, 5, false, false, false, false], - [21, 6, false, false, false, false], - [21, 7, false, false, false, false], - [21, 8, false, false, false, false], - [21, 9, false, false, false, false], - [21, 10, false, false, false, false], - [21, 11, false, false, false, false], - [21, 12, false, false, false, false], - [21, 13, false, false, false, false], - [21, 14, false, false, false, false], - [21, 15, false, false, false, false], - [21, 16, false, false, false, false], - [21, 17, false, false, false, false], - [21, 18, false, false, false, false], - [21, 19, false, false, false, false], - [21, 20, false, false, false, false], - [21, 21, false, false, false, false], - [21, 22, false, false, false, false], - [21, 23, false, false, false, false], - [21, 24, false, false, false, false], - [21, 25, false, false, false, false], - [22, 0, true, false, true, false], - [22, 1, true, false, true, false], - [22, 2, true, false, true, false], - [22, 3, true, false, true, false], - [22, 4, true, false, true, false], - [22, 5, true, false, true, false], - [22, 6, false, false, true, true], - [22, 7, true, false, true, false], - [22, 8, true, false, true, false], - [22, 9, false, false, false, false], - [22, 10, false, false, false, false], - [22, 11, false, false, false, false], - [22, 12, false, false, false, false], - [22, 13, false, false, false, false], - [22, 14, false, false, false, false], - [22, 15, false, false, false, false], - [22, 16, false, false, false, false], - [22, 17, false, false, false, false], - [22, 18, false, false, false, false], - [22, 19, true, false, true, false], - [22, 20, false, false, true, true], - [22, 21, false, false, false, false], - [22, 22, false, false, true, true], - [22, 23, false, false, false, false], - [22, 24, true, false, true, false], - [22, 25, false, true, false, true], - [23, 0, false, false, false, false], - [23, 1, false, false, false, false], - [23, 2, false, false, false, false], - [23, 3, false, false, false, false], - [23, 4, false, false, false, false], - [23, 5, false, false, false, false], - [23, 6, false, false, false, false], - [23, 7, false, false, false, false], - [23, 8, false, false, false, false], - [23, 9, false, false, false, false], - [23, 10, false, false, false, false], - [23, 11, false, false, false, false], - [23, 12, false, false, false, false], - [23, 13, false, false, false, false], - [23, 14, false, false, false, false], - [23, 15, false, false, false, false], - [23, 16, false, false, false, false], - [23, 17, false, false, false, false], - [23, 18, false, false, false, false], - [23, 19, false, false, false, false], - [23, 20, false, false, false, false], - [23, 21, false, false, false, false], - [23, 22, false, false, false, false], - [23, 23, false, false, false, false], - [23, 24, false, false, false, false], - [23, 25, false, false, false, false], - [24, 0, false, true, false, true], - [24, 1, false, true, false, true], - [24, 2, false, true, false, true], - [24, 3, false, true, false, true], - [24, 4, false, true, false, true], - [24, 5, false, true, false, true], - [24, 6, false, true, false, true], - [24, 7, false, true, false, true], - [24, 8, false, true, false, true], - [24, 9, false, false, false, false], - [24, 10, false, false, false, false], - [24, 11, false, false, false, false], - [24, 12, false, false, false, false], - [24, 13, false, false, false, false], - [24, 14, false, false, false, false], - [24, 15, false, false, false, false], - [24, 16, false, false, false, false], - [24, 17, false, false, false, false], - [24, 18, false, false, false, false], - [24, 19, false, true, false, true], - [24, 20, false, true, false, true], - [24, 21, false, false, false, false], - [24, 22, false, true, false, true], - [24, 23, false, false, false, false], - [24, 24, false, false, true, true], - [24, 25, false, true, false, true], - [25, 0, true, false, true, false], - [25, 1, true, false, true, false], - [25, 2, true, false, true, false], - [25, 3, true, false, true, false], - [25, 4, true, false, true, false], - [25, 5, true, false, true, false], - [25, 6, true, false, true, false], - [25, 7, true, false, true, false], - [25, 8, true, false, true, false], - [25, 9, false, false, false, false], - [25, 10, false, false, false, false], - [25, 11, false, false, false, false], - [25, 12, false, false, false, false], - [25, 13, false, false, false, false], - [25, 14, false, false, false, false], - [25, 15, false, false, false, false], - [25, 16, false, false, false, false], - [25, 17, false, false, false, false], - [25, 18, false, false, false, false], - [25, 19, true, false, true, false], - [25, 20, true, false, true, false], - [25, 21, false, false, false, false], - [25, 22, true, false, true, false], - [25, 23, false, false, false, false], - [25, 24, true, false, true, false], - [25, 25, false, false, true, true], - ]; + // Each row contains: xIndex, yIndex, (x < y), (x > y), (x <= y), (x >= y) + // where x = vals[xIndex], y = vals[yIndex] + // Table can be generated using a mature engine and the following code: + // for (var xIndex = 0; xIndex < vals.length; ++xIndex) { + // for (var yIndex = 0; yIndex < vals.length; ++yIndex) { + // var x = vals[xIndex]; + // var y = vals[yIndex]; + // console.log(`[${xIndex}, ${yIndex}, ${x < y}, ${x > y}, ${x <= y}, ${x >= y}]`); + // } + // } + const table = [ + [0, 0, false, false, true, true], + [0, 1, true, false, true, false], + [0, 2, true, false, true, false], + [0, 3, true, false, true, false], + [0, 4, false, false, true, true], + [0, 5, true, false, true, false], + [0, 6, false, true, false, true], + [0, 7, false, false, true, true], + [0, 8, true, false, true, false], + [0, 9, false, false, false, false], + [0, 10, false, false, false, false], + [0, 11, false, false, false, false], + [0, 12, false, false, false, false], + [0, 13, false, false, false, false], + [0, 14, false, false, false, false], + [0, 15, false, false, false, false], + [0, 16, false, false, false, false], + [0, 17, false, false, false, false], + [0, 18, false, false, false, false], + [0, 19, false, false, true, true], + [0, 20, false, true, false, true], + [0, 21, false, false, false, false], + [0, 22, false, true, false, true], + [0, 23, false, false, false, false], + [0, 24, true, false, true, false], + [0, 25, false, true, false, true], + [1, 0, false, true, false, true], + [1, 1, false, false, true, true], + [1, 2, false, true, false, true], + [1, 3, true, false, true, false], + [1, 4, false, true, false, true], + [1, 5, false, false, true, true], + [1, 6, false, true, false, true], + [1, 7, false, true, false, true], + [1, 8, false, false, true, true], + [1, 9, false, false, false, false], + [1, 10, false, false, false, false], + [1, 11, false, false, false, false], + [1, 12, false, false, false, false], + [1, 13, false, false, false, false], + [1, 14, false, false, false, false], + [1, 15, false, false, false, false], + [1, 16, false, false, false, false], + [1, 17, false, false, false, false], + [1, 18, false, false, false, false], + [1, 19, false, true, false, true], + [1, 20, false, true, false, true], + [1, 21, false, false, false, false], + [1, 22, false, true, false, true], + [1, 23, false, false, false, false], + [1, 24, true, false, true, false], + [1, 25, false, true, false, true], + [2, 0, false, true, false, true], + [2, 1, true, false, true, false], + [2, 2, false, false, true, true], + [2, 3, true, false, true, false], + [2, 4, false, true, false, true], + [2, 5, true, false, true, false], + [2, 6, false, true, false, true], + [2, 7, false, true, false, true], + [2, 8, true, false, true, false], + [2, 9, false, false, false, false], + [2, 10, false, false, false, false], + [2, 11, false, false, false, false], + [2, 12, false, false, false, false], + [2, 13, false, false, false, false], + [2, 14, false, false, false, false], + [2, 15, false, false, false, false], + [2, 16, false, false, false, false], + [2, 17, false, false, false, false], + [2, 18, false, false, false, false], + [2, 19, false, true, false, true], + [2, 20, false, true, false, true], + [2, 21, false, false, false, false], + [2, 22, false, true, false, true], + [2, 23, false, false, false, false], + [2, 24, true, false, true, false], + [2, 25, false, true, false, true], + [3, 0, false, true, false, true], + [3, 1, false, true, false, true], + [3, 2, false, true, false, true], + [3, 3, false, false, true, true], + [3, 4, false, true, false, true], + [3, 5, false, true, false, true], + [3, 6, false, true, false, true], + [3, 7, false, true, false, true], + [3, 8, false, true, false, true], + [3, 9, false, false, false, false], + [3, 10, false, false, false, false], + [3, 11, false, false, false, false], + [3, 12, false, false, false, false], + [3, 13, false, false, false, false], + [3, 14, false, false, false, false], + [3, 15, false, false, false, false], + [3, 16, false, false, false, false], + [3, 17, false, false, false, false], + [3, 18, false, false, false, false], + [3, 19, false, true, false, true], + [3, 20, false, true, false, true], + [3, 21, false, false, false, false], + [3, 22, false, true, false, true], + [3, 23, false, false, false, false], + [3, 24, true, false, true, false], + [3, 25, false, true, false, true], + [4, 0, false, false, true, true], + [4, 1, true, false, true, false], + [4, 2, true, false, true, false], + [4, 3, true, false, true, false], + [4, 4, false, false, true, true], + [4, 5, true, false, true, false], + [4, 6, false, true, false, true], + [4, 7, false, false, true, true], + [4, 8, true, false, true, false], + [4, 9, false, false, false, false], + [4, 10, false, false, false, false], + [4, 11, false, false, false, false], + [4, 12, false, false, false, false], + [4, 13, false, false, false, false], + [4, 14, false, false, false, false], + [4, 15, false, false, false, false], + [4, 16, false, false, false, false], + [4, 17, false, false, false, false], + [4, 18, false, false, false, false], + [4, 19, false, false, true, true], + [4, 20, false, true, false, true], + [4, 21, false, false, false, false], + [4, 22, false, true, false, true], + [4, 23, false, false, false, false], + [4, 24, true, false, true, false], + [4, 25, false, true, false, true], + [5, 0, false, true, false, true], + [5, 1, false, false, true, true], + [5, 2, false, true, false, true], + [5, 3, true, false, true, false], + [5, 4, false, true, false, true], + [5, 5, false, false, true, true], + [5, 6, false, true, false, true], + [5, 7, false, true, false, true], + [5, 8, false, false, true, true], + [5, 9, false, false, false, false], + [5, 10, false, false, false, false], + [5, 11, false, false, false, false], + [5, 12, false, false, false, false], + [5, 13, false, false, false, false], + [5, 14, false, false, false, false], + [5, 15, false, false, false, false], + [5, 16, false, false, false, false], + [5, 17, false, false, false, false], + [5, 18, false, false, false, false], + [5, 19, false, true, false, true], + [5, 20, false, true, false, true], + [5, 21, false, false, false, false], + [5, 22, false, true, false, true], + [5, 23, false, false, false, false], + [5, 24, true, false, true, false], + [5, 25, false, true, false, true], + [6, 0, true, false, true, false], + [6, 1, true, false, true, false], + [6, 2, true, false, true, false], + [6, 3, true, false, true, false], + [6, 4, true, false, true, false], + [6, 5, true, false, true, false], + [6, 6, false, false, true, true], + [6, 7, true, false, true, false], + [6, 8, true, false, true, false], + [6, 9, true, false, true, false], + [6, 10, true, false, true, false], + [6, 11, true, false, true, false], + [6, 12, true, false, true, false], + [6, 13, true, false, true, false], + [6, 14, true, false, true, false], + [6, 15, true, false, true, false], + [6, 16, true, false, true, false], + [6, 17, true, false, true, false], + [6, 18, true, false, true, false], + [6, 19, true, false, true, false], + [6, 20, false, false, true, true], + [6, 21, false, false, false, false], + [6, 22, false, false, true, true], + [6, 23, false, false, false, false], + [6, 24, true, false, true, false], + [6, 25, false, true, false, true], + [7, 0, false, false, true, true], + [7, 1, true, false, true, false], + [7, 2, true, false, true, false], + [7, 3, true, false, true, false], + [7, 4, false, false, true, true], + [7, 5, true, false, true, false], + [7, 6, false, true, false, true], + [7, 7, false, false, true, true], + [7, 8, true, false, true, false], + [7, 9, true, false, true, false], + [7, 10, true, false, true, false], + [7, 11, true, false, true, false], + [7, 12, true, false, true, false], + [7, 13, true, false, true, false], + [7, 14, true, false, true, false], + [7, 15, true, false, true, false], + [7, 16, true, false, true, false], + [7, 17, true, false, true, false], + [7, 18, true, false, true, false], + [7, 19, false, false, true, true], + [7, 20, false, true, false, true], + [7, 21, false, false, false, false], + [7, 22, false, true, false, true], + [7, 23, false, false, false, false], + [7, 24, true, false, true, false], + [7, 25, false, true, false, true], + [8, 0, false, true, false, true], + [8, 1, false, false, true, true], + [8, 2, false, true, false, true], + [8, 3, true, false, true, false], + [8, 4, false, true, false, true], + [8, 5, false, false, true, true], + [8, 6, false, true, false, true], + [8, 7, false, true, false, true], + [8, 8, false, false, true, true], + [8, 9, false, true, false, true], + [8, 10, true, false, true, false], + [8, 11, true, false, true, false], + [8, 12, true, false, true, false], + [8, 13, true, false, true, false], + [8, 14, true, false, true, false], + [8, 15, true, false, true, false], + [8, 16, true, false, true, false], + [8, 17, true, false, true, false], + [8, 18, true, false, true, false], + [8, 19, false, true, false, true], + [8, 20, false, true, false, true], + [8, 21, false, false, false, false], + [8, 22, false, true, false, true], + [8, 23, false, false, false, false], + [8, 24, true, false, true, false], + [8, 25, false, true, false, true], + [9, 0, false, false, false, false], + [9, 1, false, false, false, false], + [9, 2, false, false, false, false], + [9, 3, false, false, false, false], + [9, 4, false, false, false, false], + [9, 5, false, false, false, false], + [9, 6, false, true, false, true], + [9, 7, false, true, false, true], + [9, 8, true, false, true, false], + [9, 9, false, false, true, true], + [9, 10, true, false, true, false], + [9, 11, true, false, true, false], + [9, 12, true, false, true, false], + [9, 13, true, false, true, false], + [9, 14, true, false, true, false], + [9, 15, true, false, true, false], + [9, 16, true, false, true, false], + [9, 17, true, false, true, false], + [9, 18, true, false, true, false], + [9, 19, false, false, false, false], + [9, 20, false, false, false, false], + [9, 21, false, false, false, false], + [9, 22, false, false, false, false], + [9, 23, false, false, false, false], + [9, 24, false, false, false, false], + [9, 25, false, false, false, false], + [10, 0, false, false, false, false], + [10, 1, false, false, false, false], + [10, 2, false, false, false, false], + [10, 3, false, false, false, false], + [10, 4, false, false, false, false], + [10, 5, false, false, false, false], + [10, 6, false, true, false, true], + [10, 7, false, true, false, true], + [10, 8, false, true, false, true], + [10, 9, false, true, false, true], + [10, 10, false, false, true, true], + [10, 11, true, false, true, false], + [10, 12, true, false, true, false], + [10, 13, true, false, true, false], + [10, 14, false, true, false, true], + [10, 15, false, true, false, true], + [10, 16, false, true, false, true], + [10, 17, false, true, false, true], + [10, 18, false, true, false, true], + [10, 19, false, false, false, false], + [10, 20, false, false, false, false], + [10, 21, false, false, false, false], + [10, 22, false, false, false, false], + [10, 23, false, false, false, false], + [10, 24, false, false, false, false], + [10, 25, false, false, false, false], + [11, 0, false, false, false, false], + [11, 1, false, false, false, false], + [11, 2, false, false, false, false], + [11, 3, false, false, false, false], + [11, 4, false, false, false, false], + [11, 5, false, false, false, false], + [11, 6, false, true, false, true], + [11, 7, false, true, false, true], + [11, 8, false, true, false, true], + [11, 9, false, true, false, true], + [11, 10, false, true, false, true], + [11, 11, false, false, true, true], + [11, 12, true, false, true, false], + [11, 13, true, false, true, false], + [11, 14, false, true, false, true], + [11, 15, false, true, false, true], + [11, 16, false, true, false, true], + [11, 17, false, true, false, true], + [11, 18, false, true, false, true], + [11, 19, false, false, false, false], + [11, 20, false, false, false, false], + [11, 21, false, false, false, false], + [11, 22, false, false, false, false], + [11, 23, false, false, false, false], + [11, 24, false, false, false, false], + [11, 25, false, false, false, false], + [12, 0, false, false, false, false], + [12, 1, false, false, false, false], + [12, 2, false, false, false, false], + [12, 3, false, false, false, false], + [12, 4, false, false, false, false], + [12, 5, false, false, false, false], + [12, 6, false, true, false, true], + [12, 7, false, true, false, true], + [12, 8, false, true, false, true], + [12, 9, false, true, false, true], + [12, 10, false, true, false, true], + [12, 11, false, true, false, true], + [12, 12, false, false, true, true], + [12, 13, false, true, false, true], + [12, 14, false, true, false, true], + [12, 15, false, true, false, true], + [12, 16, false, true, false, true], + [12, 17, false, true, false, true], + [12, 18, false, true, false, true], + [12, 19, false, false, false, false], + [12, 20, false, false, false, false], + [12, 21, false, false, false, false], + [12, 22, false, false, false, false], + [12, 23, false, false, false, false], + [12, 24, false, false, false, false], + [12, 25, false, false, false, false], + [13, 0, false, false, false, false], + [13, 1, false, false, false, false], + [13, 2, false, false, false, false], + [13, 3, false, false, false, false], + [13, 4, false, false, false, false], + [13, 5, false, false, false, false], + [13, 6, false, true, false, true], + [13, 7, false, true, false, true], + [13, 8, false, true, false, true], + [13, 9, false, true, false, true], + [13, 10, false, true, false, true], + [13, 11, false, true, false, true], + [13, 12, true, false, true, false], + [13, 13, false, false, true, true], + [13, 14, false, true, false, true], + [13, 15, false, true, false, true], + [13, 16, false, true, false, true], + [13, 17, false, true, false, true], + [13, 18, false, true, false, true], + [13, 19, false, false, false, false], + [13, 20, false, false, false, false], + [13, 21, false, false, false, false], + [13, 22, false, false, false, false], + [13, 23, false, false, false, false], + [13, 24, false, false, false, false], + [13, 25, false, false, false, false], + [14, 0, false, false, false, false], + [14, 1, false, false, false, false], + [14, 2, false, false, false, false], + [14, 3, false, false, false, false], + [14, 4, false, false, false, false], + [14, 5, false, false, false, false], + [14, 6, false, true, false, true], + [14, 7, false, true, false, true], + [14, 8, false, true, false, true], + [14, 9, false, true, false, true], + [14, 10, true, false, true, false], + [14, 11, true, false, true, false], + [14, 12, true, false, true, false], + [14, 13, true, false, true, false], + [14, 14, false, false, true, true], + [14, 15, false, true, false, true], + [14, 16, false, true, false, true], + [14, 17, false, true, false, true], + [14, 18, false, true, false, true], + [14, 19, false, false, false, false], + [14, 20, false, false, false, false], + [14, 21, false, false, false, false], + [14, 22, false, false, false, false], + [14, 23, false, false, false, false], + [14, 24, false, false, false, false], + [14, 25, false, false, false, false], + [15, 0, false, false, false, false], + [15, 1, false, false, false, false], + [15, 2, false, false, false, false], + [15, 3, false, false, false, false], + [15, 4, false, false, false, false], + [15, 5, false, false, false, false], + [15, 6, false, true, false, true], + [15, 7, false, true, false, true], + [15, 8, false, true, false, true], + [15, 9, false, true, false, true], + [15, 10, true, false, true, false], + [15, 11, true, false, true, false], + [15, 12, true, false, true, false], + [15, 13, true, false, true, false], + [15, 14, true, false, true, false], + [15, 15, false, false, true, true], + [15, 16, false, false, true, true], + [15, 17, false, false, true, true], + [15, 18, false, false, true, true], + [15, 19, false, false, false, false], + [15, 20, false, false, false, false], + [15, 21, false, false, false, false], + [15, 22, false, false, false, false], + [15, 23, false, false, false, false], + [15, 24, false, false, false, false], + [15, 25, false, false, false, false], + [16, 0, false, false, false, false], + [16, 1, false, false, false, false], + [16, 2, false, false, false, false], + [16, 3, false, false, false, false], + [16, 4, false, false, false, false], + [16, 5, false, false, false, false], + [16, 6, false, true, false, true], + [16, 7, false, true, false, true], + [16, 8, false, true, false, true], + [16, 9, false, true, false, true], + [16, 10, true, false, true, false], + [16, 11, true, false, true, false], + [16, 12, true, false, true, false], + [16, 13, true, false, true, false], + [16, 14, true, false, true, false], + [16, 15, false, false, true, true], + [16, 16, false, false, true, true], + [16, 17, false, false, true, true], + [16, 18, false, false, true, true], + [16, 19, false, false, false, false], + [16, 20, false, false, false, false], + [16, 21, false, false, false, false], + [16, 22, false, false, false, false], + [16, 23, false, false, false, false], + [16, 24, false, false, false, false], + [16, 25, false, false, false, false], + [17, 0, false, false, false, false], + [17, 1, false, false, false, false], + [17, 2, false, false, false, false], + [17, 3, false, false, false, false], + [17, 4, false, false, false, false], + [17, 5, false, false, false, false], + [17, 6, false, true, false, true], + [17, 7, false, true, false, true], + [17, 8, false, true, false, true], + [17, 9, false, true, false, true], + [17, 10, true, false, true, false], + [17, 11, true, false, true, false], + [17, 12, true, false, true, false], + [17, 13, true, false, true, false], + [17, 14, true, false, true, false], + [17, 15, false, false, true, true], + [17, 16, false, false, true, true], + [17, 17, false, false, true, true], + [17, 18, false, false, true, true], + [17, 19, false, false, false, false], + [17, 20, false, false, false, false], + [17, 21, false, false, false, false], + [17, 22, false, false, false, false], + [17, 23, false, false, false, false], + [17, 24, false, false, false, false], + [17, 25, false, false, false, false], + [18, 0, false, false, false, false], + [18, 1, false, false, false, false], + [18, 2, false, false, false, false], + [18, 3, false, false, false, false], + [18, 4, false, false, false, false], + [18, 5, false, false, false, false], + [18, 6, false, true, false, true], + [18, 7, false, true, false, true], + [18, 8, false, true, false, true], + [18, 9, false, true, false, true], + [18, 10, true, false, true, false], + [18, 11, true, false, true, false], + [18, 12, true, false, true, false], + [18, 13, true, false, true, false], + [18, 14, true, false, true, false], + [18, 15, false, false, true, true], + [18, 16, false, false, true, true], + [18, 17, false, false, true, true], + [18, 18, false, false, true, true], + [18, 19, false, false, false, false], + [18, 20, false, false, false, false], + [18, 21, false, false, false, false], + [18, 22, false, false, false, false], + [18, 23, false, false, false, false], + [18, 24, false, false, false, false], + [18, 25, false, false, false, false], + [19, 0, false, false, true, true], + [19, 1, true, false, true, false], + [19, 2, true, false, true, false], + [19, 3, true, false, true, false], + [19, 4, false, false, true, true], + [19, 5, true, false, true, false], + [19, 6, false, true, false, true], + [19, 7, false, false, true, true], + [19, 8, true, false, true, false], + [19, 9, false, false, false, false], + [19, 10, false, false, false, false], + [19, 11, false, false, false, false], + [19, 12, false, false, false, false], + [19, 13, false, false, false, false], + [19, 14, false, false, false, false], + [19, 15, false, false, false, false], + [19, 16, false, false, false, false], + [19, 17, false, false, false, false], + [19, 18, false, false, false, false], + [19, 19, false, false, true, true], + [19, 20, false, true, false, true], + [19, 21, false, false, false, false], + [19, 22, false, true, false, true], + [19, 23, false, false, false, false], + [19, 24, true, false, true, false], + [19, 25, false, true, false, true], + [20, 0, true, false, true, false], + [20, 1, true, false, true, false], + [20, 2, true, false, true, false], + [20, 3, true, false, true, false], + [20, 4, true, false, true, false], + [20, 5, true, false, true, false], + [20, 6, false, false, true, true], + [20, 7, true, false, true, false], + [20, 8, true, false, true, false], + [20, 9, false, false, false, false], + [20, 10, false, false, false, false], + [20, 11, false, false, false, false], + [20, 12, false, false, false, false], + [20, 13, false, false, false, false], + [20, 14, false, false, false, false], + [20, 15, false, false, false, false], + [20, 16, false, false, false, false], + [20, 17, false, false, false, false], + [20, 18, false, false, false, false], + [20, 19, true, false, true, false], + [20, 20, false, false, true, true], + [20, 21, false, false, false, false], + [20, 22, false, false, true, true], + [20, 23, false, false, false, false], + [20, 24, true, false, true, false], + [20, 25, false, true, false, true], + [21, 0, false, false, false, false], + [21, 1, false, false, false, false], + [21, 2, false, false, false, false], + [21, 3, false, false, false, false], + [21, 4, false, false, false, false], + [21, 5, false, false, false, false], + [21, 6, false, false, false, false], + [21, 7, false, false, false, false], + [21, 8, false, false, false, false], + [21, 9, false, false, false, false], + [21, 10, false, false, false, false], + [21, 11, false, false, false, false], + [21, 12, false, false, false, false], + [21, 13, false, false, false, false], + [21, 14, false, false, false, false], + [21, 15, false, false, false, false], + [21, 16, false, false, false, false], + [21, 17, false, false, false, false], + [21, 18, false, false, false, false], + [21, 19, false, false, false, false], + [21, 20, false, false, false, false], + [21, 21, false, false, false, false], + [21, 22, false, false, false, false], + [21, 23, false, false, false, false], + [21, 24, false, false, false, false], + [21, 25, false, false, false, false], + [22, 0, true, false, true, false], + [22, 1, true, false, true, false], + [22, 2, true, false, true, false], + [22, 3, true, false, true, false], + [22, 4, true, false, true, false], + [22, 5, true, false, true, false], + [22, 6, false, false, true, true], + [22, 7, true, false, true, false], + [22, 8, true, false, true, false], + [22, 9, false, false, false, false], + [22, 10, false, false, false, false], + [22, 11, false, false, false, false], + [22, 12, false, false, false, false], + [22, 13, false, false, false, false], + [22, 14, false, false, false, false], + [22, 15, false, false, false, false], + [22, 16, false, false, false, false], + [22, 17, false, false, false, false], + [22, 18, false, false, false, false], + [22, 19, true, false, true, false], + [22, 20, false, false, true, true], + [22, 21, false, false, false, false], + [22, 22, false, false, true, true], + [22, 23, false, false, false, false], + [22, 24, true, false, true, false], + [22, 25, false, true, false, true], + [23, 0, false, false, false, false], + [23, 1, false, false, false, false], + [23, 2, false, false, false, false], + [23, 3, false, false, false, false], + [23, 4, false, false, false, false], + [23, 5, false, false, false, false], + [23, 6, false, false, false, false], + [23, 7, false, false, false, false], + [23, 8, false, false, false, false], + [23, 9, false, false, false, false], + [23, 10, false, false, false, false], + [23, 11, false, false, false, false], + [23, 12, false, false, false, false], + [23, 13, false, false, false, false], + [23, 14, false, false, false, false], + [23, 15, false, false, false, false], + [23, 16, false, false, false, false], + [23, 17, false, false, false, false], + [23, 18, false, false, false, false], + [23, 19, false, false, false, false], + [23, 20, false, false, false, false], + [23, 21, false, false, false, false], + [23, 22, false, false, false, false], + [23, 23, false, false, false, false], + [23, 24, false, false, false, false], + [23, 25, false, false, false, false], + [24, 0, false, true, false, true], + [24, 1, false, true, false, true], + [24, 2, false, true, false, true], + [24, 3, false, true, false, true], + [24, 4, false, true, false, true], + [24, 5, false, true, false, true], + [24, 6, false, true, false, true], + [24, 7, false, true, false, true], + [24, 8, false, true, false, true], + [24, 9, false, false, false, false], + [24, 10, false, false, false, false], + [24, 11, false, false, false, false], + [24, 12, false, false, false, false], + [24, 13, false, false, false, false], + [24, 14, false, false, false, false], + [24, 15, false, false, false, false], + [24, 16, false, false, false, false], + [24, 17, false, false, false, false], + [24, 18, false, false, false, false], + [24, 19, false, true, false, true], + [24, 20, false, true, false, true], + [24, 21, false, false, false, false], + [24, 22, false, true, false, true], + [24, 23, false, false, false, false], + [24, 24, false, false, true, true], + [24, 25, false, true, false, true], + [25, 0, true, false, true, false], + [25, 1, true, false, true, false], + [25, 2, true, false, true, false], + [25, 3, true, false, true, false], + [25, 4, true, false, true, false], + [25, 5, true, false, true, false], + [25, 6, true, false, true, false], + [25, 7, true, false, true, false], + [25, 8, true, false, true, false], + [25, 9, false, false, false, false], + [25, 10, false, false, false, false], + [25, 11, false, false, false, false], + [25, 12, false, false, false, false], + [25, 13, false, false, false, false], + [25, 14, false, false, false, false], + [25, 15, false, false, false, false], + [25, 16, false, false, false, false], + [25, 17, false, false, false, false], + [25, 18, false, false, false, false], + [25, 19, true, false, true, false], + [25, 20, true, false, true, false], + [25, 21, false, false, false, false], + [25, 22, true, false, true, false], + [25, 23, false, false, false, false], + [25, 24, true, false, true, false], + [25, 25, false, false, true, true], + ]; - for (let test of table) { - let x = vals[test[0]]; - let y = vals[test[1]]; + for (let test of table) { + let x = vals[test[0]]; + let y = vals[test[1]]; - assert(x < y === test[2]); - assert(x > y === test[3]); - assert(x <= y === test[4]); - assert(x >= y === test[5]); - } + assert(x < y === test[2]); + assert(x > y === test[3]); + assert(x <= y === test[4]); + assert(x >= y === test[5]); + } - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/comma-operator.js b/Libraries/LibJS/Tests/operators/comma-operator.js index 8f8c65a532..549610dbe6 100644 --- a/Libraries/LibJS/Tests/operators/comma-operator.js +++ b/Libraries/LibJS/Tests/operators/comma-operator.js @@ -1,26 +1,26 @@ load("test-common.js"); try { - assert((1, 2, 3) === 3); - assert((1, 2 + 3, 4) === 4); + assert((1, 2, 3) === 3); + assert((1, 2 + 3, 4) === 4); - var foo = 0; - foo = (foo++, foo); - assert(foo === 1); + var foo = 0; + foo = (foo++, foo); + assert(foo === 1); - var a, b, c; - assert((a = b = 3, c = 4) === 4); - assert(a === 3); - assert(b === 3); - assert(c === 4); + var a, b, c; + assert(((a = b = 3), (c = 4)) === 4); + assert(a === 3); + assert(b === 3); + assert(c === 4); - var x, y, z; - assert((x = (y = 5, z = 6)) === 6); - assert(x === 6) - assert(y === 5) - assert(z === 6) + var x, y, z; + assert((x = ((y = 5), (z = 6))) === 6); + assert(x === 6); + assert(y === 5); + assert(z === 6); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/delete-basic.js b/Libraries/LibJS/Tests/operators/delete-basic.js index eda9741b6b..cb763c9895 100644 --- a/Libraries/LibJS/Tests/operators/delete-basic.js +++ b/Libraries/LibJS/Tests/operators/delete-basic.js @@ -1,60 +1,60 @@ load("test-common.js"); try { - o = {}; - o.x = 1; - o.y = 2; - o.z = 3; - assert(Object.getOwnPropertyNames(o).length === 3); + o = {}; + o.x = 1; + o.y = 2; + o.z = 3; + assert(Object.getOwnPropertyNames(o).length === 3); - assert(delete o.x === true); - assert(o.hasOwnProperty('x') === false); - assert(o.hasOwnProperty('y') === true); - assert(o.hasOwnProperty('z') === true); - assert(Object.getOwnPropertyNames(o).length === 2); + assert(delete o.x === true); + assert(o.hasOwnProperty("x") === false); + assert(o.hasOwnProperty("y") === true); + assert(o.hasOwnProperty("z") === true); + assert(Object.getOwnPropertyNames(o).length === 2); - assert(delete o.y === true); - assert(o.hasOwnProperty('x') === false); - assert(o.hasOwnProperty('y') === false); - assert(o.hasOwnProperty('z') === true); - assert(Object.getOwnPropertyNames(o).length === 1); + assert(delete o.y === true); + assert(o.hasOwnProperty("x") === false); + assert(o.hasOwnProperty("y") === false); + assert(o.hasOwnProperty("z") === true); + assert(Object.getOwnPropertyNames(o).length === 1); - assert(delete o.z === true); - assert(o.hasOwnProperty('x') === false); - assert(o.hasOwnProperty('y') === false); - assert(o.hasOwnProperty('z') === false); - assert(Object.getOwnPropertyNames(o).length === 0); + assert(delete o.z === true); + assert(o.hasOwnProperty("x") === false); + assert(o.hasOwnProperty("y") === false); + assert(o.hasOwnProperty("z") === false); + assert(Object.getOwnPropertyNames(o).length === 0); - a = [ 3, 5, 7 ]; + a = [3, 5, 7]; - assert(Object.getOwnPropertyNames(a).length === 4); + assert(Object.getOwnPropertyNames(a).length === 4); - assert(delete a[0] === true); - assert(a.hasOwnProperty(0) === false); - assert(a.hasOwnProperty(1) === true); - assert(a.hasOwnProperty(2) === true); - assert(Object.getOwnPropertyNames(a).length === 3); + assert(delete a[0] === true); + assert(a.hasOwnProperty(0) === false); + assert(a.hasOwnProperty(1) === true); + assert(a.hasOwnProperty(2) === true); + assert(Object.getOwnPropertyNames(a).length === 3); - assert(delete a[1] === true); - assert(a.hasOwnProperty(0) === false); - assert(a.hasOwnProperty(1) === false); - assert(a.hasOwnProperty(2) === true); - assert(Object.getOwnPropertyNames(a).length === 2); + assert(delete a[1] === true); + assert(a.hasOwnProperty(0) === false); + assert(a.hasOwnProperty(1) === false); + assert(a.hasOwnProperty(2) === true); + assert(Object.getOwnPropertyNames(a).length === 2); - assert(delete a[2] === true); - assert(a.hasOwnProperty(0) === false); - assert(a.hasOwnProperty(1) === false); - assert(a.hasOwnProperty(2) === false); - assert(Object.getOwnPropertyNames(a).length === 1); + assert(delete a[2] === true); + assert(a.hasOwnProperty(0) === false); + assert(a.hasOwnProperty(1) === false); + assert(a.hasOwnProperty(2) === false); + assert(Object.getOwnPropertyNames(a).length === 1); - q = {}; - Object.defineProperty(q, "foo", { value: 1, writable: false, enumerable: false }); - assert(q.foo === 1); + q = {}; + Object.defineProperty(q, "foo", { value: 1, writable: false, enumerable: false }); + assert(q.foo === 1); - assert(delete q.foo === false); - assert(q.hasOwnProperty('foo') === true); + assert(delete q.foo === false); + assert(q.hasOwnProperty("foo") === true); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/delete-global-variable.js b/Libraries/LibJS/Tests/operators/delete-global-variable.js index 99143772fb..a96afbe464 100644 --- a/Libraries/LibJS/Tests/operators/delete-global-variable.js +++ b/Libraries/LibJS/Tests/operators/delete-global-variable.js @@ -1,16 +1,19 @@ load("test-common.js"); try { - a = 1; - assert(delete a === true); + a = 1; + assert(delete a === true); - assertThrowsError(() => { - a; - }, { - error: ReferenceError - }); + assertThrowsError( + () => { + a; + }, + { + error: ReferenceError, + } + ); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/delete-globalThis-property-crash.js b/Libraries/LibJS/Tests/operators/delete-globalThis-property-crash.js index 246d9debff..4738197327 100644 --- a/Libraries/LibJS/Tests/operators/delete-globalThis-property-crash.js +++ b/Libraries/LibJS/Tests/operators/delete-globalThis-property-crash.js @@ -1,10 +1,10 @@ load("test-common.js"); try { - a = 1; - assert(delete globalThis.a === true); - a = 2; - console.log("PASS"); + a = 1; + assert(delete globalThis.a === true); + a = 2; + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/in-operator-basic.js b/Libraries/LibJS/Tests/operators/in-operator-basic.js index f6c90a823a..0a495cd2a5 100644 --- a/Libraries/LibJS/Tests/operators/in-operator-basic.js +++ b/Libraries/LibJS/Tests/operators/in-operator-basic.js @@ -1,35 +1,38 @@ load("test-common.js"); try { - ["foo", 123, null, undefined].forEach(value => { - assertThrowsError(() => { - "prop" in value; - }, { - error: TypeError, - message: "'in' operator must be used on an object" - }); - }); + ["foo", 123, null, undefined].forEach(value => { + assertThrowsError( + () => { + "prop" in value; + }, + { + error: TypeError, + message: "'in' operator must be used on an object", + } + ); + }); - var o = {foo: "bar", bar: undefined}; - assert("" in o === false); - assert("foo" in o === true); - assert("bar" in o === true); - assert("baz" in o === false); - assert("toString" in o === true); + var o = { foo: "bar", bar: undefined }; + assert("" in o === false); + assert("foo" in o === true); + assert("bar" in o === true); + assert("baz" in o === false); + assert("toString" in o === true); - var a = ["hello", "friends"]; - assert(0 in a === true); - assert(1 in a === true); - assert(2 in a === false); - assert("0" in a === true); - assert("hello" in a === false); - assert("friends" in a === false); - assert("length" in a === true); + var a = ["hello", "friends"]; + assert(0 in a === true); + assert(1 in a === true); + assert(2 in a === false); + assert("0" in a === true); + assert("hello" in a === false); + assert("friends" in a === false); + assert("length" in a === true); - var s = new String("foo"); - assert("length" in s); + var s = new String("foo"); + assert("length" in s); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/instanceof-basic.js b/Libraries/LibJS/Tests/operators/instanceof-basic.js index 29d22e7e60..23a1ead60c 100644 --- a/Libraries/LibJS/Tests/operators/instanceof-basic.js +++ b/Libraries/LibJS/Tests/operators/instanceof-basic.js @@ -1,28 +1,28 @@ load("test-common.js"); try { - function Foo() { - this.x = 123; - } + function Foo() { + this.x = 123; + } - var foo = new Foo(); - assert(foo instanceof Foo); + var foo = new Foo(); + assert(foo instanceof Foo); - function Base() { - this.is_base = true; - } + function Base() { + this.is_base = true; + } - function Derived() { - this.is_derived = true; - } + function Derived() { + this.is_derived = true; + } - Object.setPrototypeOf(Derived.prototype, Base.prototype); + Object.setPrototypeOf(Derived.prototype, Base.prototype); - var d = new Derived(); - assert(d instanceof Derived); - assert(d instanceof Base); + var d = new Derived(); + assert(d instanceof Derived); + assert(d instanceof Base); - console.log("PASS"); -} catch(e) { - console.log("FAIL: " + e); + console.log("PASS"); +} catch (e) { + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/logical-expressions-basic.js b/Libraries/LibJS/Tests/operators/logical-expressions-basic.js index ebd2b7c865..63f27efb9e 100644 --- a/Libraries/LibJS/Tests/operators/logical-expressions-basic.js +++ b/Libraries/LibJS/Tests/operators/logical-expressions-basic.js @@ -1,118 +1,118 @@ load("test-common.js"); try { - assert((true && true) === true); - assert((false && false) === false); - assert((true && false) === false); - assert((false && true) === false); - assert((false && (1 === 2)) === false); - assert((true && (1 === 2)) === false); - assert(("" && "") === ""); - assert(("" && false) === ""); - assert(("" && true) === ""); - assert((false && "") === false); - assert((true && "") === ""); - assert(("foo" && "bar") === "bar"); - assert(("foo" && false) === false); - assert(("foo" && true) === true); - assert((false && "bar") === false); - assert((true && "bar") === "bar"); - assert((0 && false) === 0); - assert((0 && true) === 0); - assert((42 && false) === false); - assert((42 && true) === true); - assert((false && 0) === false); - assert((true && 0) === 0); - assert((false && 42) === false); - assert((true && 42) === 42); - assert(([] && false) === false); - assert(([] && true) === true); - assert((false && []) === false); - assert((true && []).length === 0); - assert((null && false) === null); - assert((null && true) === null); - assert((false && null) === false); - assert((true && null) === null); - assert((undefined && false) === undefined); - assert((undefined && true) === undefined); - assert((false && undefined) === false); - assert((true && undefined) === undefined); + assert((true && true) === true); + assert((false && false) === false); + assert((true && false) === false); + assert((false && true) === false); + assert((false && 1 === 2) === false); + assert((true && 1 === 2) === false); + assert(("" && "") === ""); + assert(("" && false) === ""); + assert(("" && true) === ""); + assert((false && "") === false); + assert((true && "") === ""); + assert(("foo" && "bar") === "bar"); + assert(("foo" && false) === false); + assert(("foo" && true) === true); + assert((false && "bar") === false); + assert((true && "bar") === "bar"); + assert((0 && false) === 0); + assert((0 && true) === 0); + assert((42 && false) === false); + assert((42 && true) === true); + assert((false && 0) === false); + assert((true && 0) === 0); + assert((false && 42) === false); + assert((true && 42) === 42); + assert(([] && false) === false); + assert(([] && true) === true); + assert((false && []) === false); + assert((true && []).length === 0); + assert((null && false) === null); + assert((null && true) === null); + assert((false && null) === false); + assert((true && null) === null); + assert((undefined && false) === undefined); + assert((undefined && true) === undefined); + assert((false && undefined) === false); + assert((true && undefined) === undefined); - assert((true || true) === true); - assert((false || false) === false); - assert((true || false) === true); - assert((false || true) === true); - assert((false || (1 === 2)) === false); - assert((true || (1 === 2)) === true); - assert(("" || "") === ""); - assert(("" || false) === false); - assert(("" || true) === true); - assert((false || "") === ""); - assert((true || "") === true); - assert(("foo" || "bar") === "foo"); - assert(("foo" || false) === "foo"); - assert(("foo" || true) === "foo"); - assert((false || "bar") === "bar"); - assert((true || "bar") === true); - assert((0 || false) === false); - assert((0 || true) === true); - assert((42 || false) === 42); - assert((42 || true) === 42); - assert((false || 0) === 0); - assert((true || 0) === true); - assert((false || 42) === 42); - assert((true || 42) === true); - assert(([] || false).length === 0); - assert(([] || true).length === 0); - assert((false || []).length === 0); - assert((true || []) === true); - assert((null || false) === false); - assert((null || true) === true); - assert((false || null) === null); - assert((true || null) === true); - assert((undefined || false) === false); - assert((undefined || true) === true); - assert((false || undefined) === undefined); - assert((true || undefined) === true); + assert((true || true) === true); + assert((false || false) === false); + assert((true || false) === true); + assert((false || true) === true); + assert((false || 1 === 2) === false); + assert((true || 1 === 2) === true); + assert(("" || "") === ""); + assert(("" || false) === false); + assert(("" || true) === true); + assert((false || "") === ""); + assert((true || "") === true); + assert(("foo" || "bar") === "foo"); + assert(("foo" || false) === "foo"); + assert(("foo" || true) === "foo"); + assert((false || "bar") === "bar"); + assert((true || "bar") === true); + assert((0 || false) === false); + assert((0 || true) === true); + assert((42 || false) === 42); + assert((42 || true) === 42); + assert((false || 0) === 0); + assert((true || 0) === true); + assert((false || 42) === 42); + assert((true || 42) === true); + assert(([] || false).length === 0); + assert(([] || true).length === 0); + assert((false || []).length === 0); + assert((true || []) === true); + assert((null || false) === false); + assert((null || true) === true); + assert((false || null) === null); + assert((true || null) === true); + assert((undefined || false) === false); + assert((undefined || true) === true); + assert((false || undefined) === undefined); + assert((true || undefined) === true); - assert((true ?? true) === true); - assert((false ?? false) === false); - assert((true ?? false) === true); - assert((false ?? true) === false); - assert((false ?? (1 === 2)) === false); - assert((true ?? (1 === 2)) === true); - assert(("" ?? "") === ""); - assert(("" ?? false) === ""); - assert(("" ?? true) === ""); - assert((false ?? "") === false); - assert((true ?? "") === true); - assert(("foo" ?? "bar") === "foo"); - assert(("foo" ?? false) === "foo"); - assert(("foo" ?? true) === "foo"); - assert((false ?? "bar") === false); - assert((true ?? "bar") === true); - assert((0 ?? false) === 0); - assert((0 ?? true) === 0); - assert((42 ?? false) === 42); - assert((42 ?? true) === 42); - assert((false ?? 0) === false); - assert((true ?? 0) === true); - assert((false ?? 42) === false); - assert((true ?? 42) === true); - assert(([] ?? false).length === 0); - assert(([] ?? true).length === 0); - assert((false ?? []) === false); - assert((true ?? []) === true); - assert((null ?? false) === false); - assert((null ?? true) === true); - assert((false ?? null) === false); - assert((true ?? null) === true); - assert((undefined ?? false) === false); - assert((undefined ?? true) === true); - assert((false ?? undefined) === false); - assert((true ?? undefined) === true); + assert((true ?? true) === true); + assert((false ?? false) === false); + assert((true ?? false) === true); + assert((false ?? true) === false); + assert((false ?? 1 === 2) === false); + assert((true ?? 1 === 2) === true); + assert(("" ?? "") === ""); + assert(("" ?? false) === ""); + assert(("" ?? true) === ""); + assert((false ?? "") === false); + assert((true ?? "") === true); + assert(("foo" ?? "bar") === "foo"); + assert(("foo" ?? false) === "foo"); + assert(("foo" ?? true) === "foo"); + assert((false ?? "bar") === false); + assert((true ?? "bar") === true); + assert((0 ?? false) === 0); + assert((0 ?? true) === 0); + assert((42 ?? false) === 42); + assert((42 ?? true) === 42); + assert((false ?? 0) === false); + assert((true ?? 0) === true); + assert((false ?? 42) === false); + assert((true ?? 42) === true); + assert(([] ?? false).length === 0); + assert(([] ?? true).length === 0); + assert((false ?? []) === false); + assert((true ?? []) === true); + assert((null ?? false) === false); + assert((null ?? true) === true); + assert((false ?? null) === false); + assert((true ?? null) === true); + assert((undefined ?? false) === false); + assert((undefined ?? true) === true); + assert((false ?? undefined) === false); + assert((true ?? undefined) === true); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/logical-expressions-short-circuit.js b/Libraries/LibJS/Tests/operators/logical-expressions-short-circuit.js index 77edd59b80..9e6a29dae4 100644 --- a/Libraries/LibJS/Tests/operators/logical-expressions-short-circuit.js +++ b/Libraries/LibJS/Tests/operators/logical-expressions-short-circuit.js @@ -1,15 +1,15 @@ load("test-common.js"); try { - let foo = 1; - false && (foo = 2); - assert(foo === 1); + let foo = 1; + false && (foo = 2); + assert(foo === 1); - foo = 1; - true || (foo = 2); - assert(foo === 1); + foo = 1; + true || (foo = 2); + assert(foo === 1); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/modulo-basic.js b/Libraries/LibJS/Tests/operators/modulo-basic.js index c8e9a22fb0..21fbbeed68 100644 --- a/Libraries/LibJS/Tests/operators/modulo-basic.js +++ b/Libraries/LibJS/Tests/operators/modulo-basic.js @@ -1,22 +1,22 @@ load("test-common.js"); try { - assert(10 % 3 === 1); - assert(10.5 % 2.5 === 0.5); - assert(-0.99 % 0.99 === -0); + assert(10 % 3 === 1); + assert(10.5 % 2.5 === 0.5); + assert(-0.99 % 0.99 === -0); - // Examples from MDN: - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - assert(12 % 5 === 2); - assert(-1 % 2 === -1); - assert(1 % -2 === 1); - assert(isNaN(NaN % 2)); - assert(1 % 2 === 1); - assert(2 % 3 === 2); - assert(-4 % 2 === -0); - assert(5.5 % 2 === 1.5); + // Examples from MDN: + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators + assert(12 % 5 === 2); + assert(-1 % 2 === -1); + assert(1 % -2 === 1); + assert(isNaN(NaN % 2)); + assert(1 % 2 === 1); + assert(2 % 3 === 2); + assert(-4 % 2 === -0); + assert(5.5 % 2 === 1.5); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/ternary-basic.js b/Libraries/LibJS/Tests/operators/ternary-basic.js index c01f611902..d760ef1dec 100644 --- a/Libraries/LibJS/Tests/operators/ternary-basic.js +++ b/Libraries/LibJS/Tests/operators/ternary-basic.js @@ -1,21 +1,21 @@ load("test-common.js"); try { - var x = 1; + var x = 1; - assert(x === 1 ? true : false); - assert((x ? x : 0) === x); - assert(1 < 2 ? (true) : (false)); - assert((0 ? 1 : 1 ? 10 : 20) === 10); - assert((0 ? 1 ? 1 : 10 : 20) === 20); + assert(x === 1 ? true : false); + assert((x ? x : 0) === x); + assert(1 < 2 ? true : false); + assert((0 ? 1 : 1 ? 10 : 20) === 10); + assert((0 ? (1 ? 1 : 10) : 20) === 20); - var o = {}; - o.f = true; - assert(o.f ? true : false); + var o = {}; + o.f = true; + assert(o.f ? true : false); - assert(1 ? o.f : null); + assert(1 ? o.f : null); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/typeof-basic.js b/Libraries/LibJS/Tests/operators/typeof-basic.js index e07c68ae13..29372ac606 100644 --- a/Libraries/LibJS/Tests/operators/typeof-basic.js +++ b/Libraries/LibJS/Tests/operators/typeof-basic.js @@ -1,27 +1,27 @@ load("test-common.js"); try { - assert(typeof "foo" === "string"); - assert(!(typeof "foo" !== "string")); - assert(typeof (1 + 2) === "number"); - assert(typeof {} === "object"); - assert(typeof null === "object"); - assert(typeof undefined === "undefined"); + assert(typeof "foo" === "string"); + assert(!(typeof "foo" !== "string")); + assert(typeof (1 + 2) === "number"); + assert(typeof {} === "object"); + assert(typeof null === "object"); + assert(typeof undefined === "undefined"); - var iExist = 1; - assert(typeof iExist === "number"); - assert(typeof iDontExist === "undefined"); + var iExist = 1; + assert(typeof iExist === "number"); + assert(typeof iDontExist === "undefined"); - var calls = 0; - Object.defineProperty(globalThis, "foo", { - get() { - calls++; - }, - }); - assert(typeof foo === "undefined"); - assert(calls === 1); + var calls = 0; + Object.defineProperty(globalThis, "foo", { + get() { + calls++; + }, + }); + assert(typeof foo === "undefined"); + assert(calls === 1); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/operators/void-basic.js b/Libraries/LibJS/Tests/operators/void-basic.js index d96ee0239f..a4648600d5 100644 --- a/Libraries/LibJS/Tests/operators/void-basic.js +++ b/Libraries/LibJS/Tests/operators/void-basic.js @@ -1,20 +1,20 @@ load("test-common.js"); try { - assert(void "" === undefined); - assert(void "foo" === undefined); - assert(void 1 === undefined); - assert(void 42 === undefined); - assert(void true === undefined); - assert(void false === undefined); - assert(void null === undefined); - assert(void undefined === undefined); - assert(void function () {} === undefined); - assert(void (() => {}) === undefined); - assert(void (() => "hello friends")() === undefined); - assert((() => void "hello friends")() === undefined); + assert(void "" === undefined); + assert(void "foo" === undefined); + assert(void 1 === undefined); + assert(void 42 === undefined); + assert(void true === undefined); + assert(void false === undefined); + assert(void null === undefined); + assert(void undefined === undefined); + assert(void function () {} === undefined); + assert(void (() => {}) === undefined); + assert(void (() => "hello friends")() === undefined); + assert((() => void "hello friends")() === undefined); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/parser-unary-associativity.js b/Libraries/LibJS/Tests/parser-unary-associativity.js index 6ed427110a..4ed4b015ff 100644 --- a/Libraries/LibJS/Tests/parser-unary-associativity.js +++ b/Libraries/LibJS/Tests/parser-unary-associativity.js @@ -1,20 +1,20 @@ load("test-common.js"); try { - var o = {}; - o.a = 1; + var o = {}; + o.a = 1; - assert(o.a === 1); - assert(!o.a === false); - assert(!o.a === !(o.a)); - assert(~o.a === ~(o.a)); - assert(+o.a === +(o.a)); - assert(-o.a === -(o.a)); + assert(o.a === 1); + assert(!o.a === false); + assert(!o.a === !o.a); + assert(~o.a === ~o.a); + assert(+o.a === +o.a); + assert(-o.a === -o.a); - assert((typeof "x" === "string") === true); - assert(!(typeof "x" === "string") === false); + assert((typeof "x" === "string") === true); + assert(!(typeof "x" === "string") === false); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/program-strict-mode.js b/Libraries/LibJS/Tests/program-strict-mode.js index 3bc3859915..6d896750b0 100644 --- a/Libraries/LibJS/Tests/program-strict-mode.js +++ b/Libraries/LibJS/Tests/program-strict-mode.js @@ -3,28 +3,27 @@ load("test-common.js"); try { + assert(isStrictMode()); + + (function () { assert(isStrictMode()); + })(); - (function() { - assert(isStrictMode()); - })(); + (function () { + "use strict"; + assert(isStrictMode()); + })(); - (function() { - "use strict"; - assert(isStrictMode()); - })(); + (() => { + assert(isStrictMode()); + })(); + (() => { + "use strict"; + assert(isStrictMode()); + })(); - (() => { - assert(isStrictMode()); - })(); - - (() => { - "use strict"; - assert(isStrictMode()); - })(); - - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/strict-mode-errors.js b/Libraries/LibJS/Tests/strict-mode-errors.js index 430596ca9c..6557650652 100644 --- a/Libraries/LibJS/Tests/strict-mode-errors.js +++ b/Libraries/LibJS/Tests/strict-mode-errors.js @@ -1,18 +1,21 @@ "use strict"; -load("test-common.js") +load("test-common.js"); try { - [true, false, "foo", 123].forEach(primitive => { - assertThrowsError(() => { - primitive.foo = "bar"; - }, { - error: TypeError, - message: "Cannot assign property foo to primitive value" - }); - }); + [true, false, "foo", 123].forEach(primitive => { + assertThrowsError( + () => { + primitive.foo = "bar"; + }, + { + error: TypeError, + message: "Cannot assign property foo to primitive value", + } + ); + }); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/string-escapes.js b/Libraries/LibJS/Tests/string-escapes.js index ad9f47ea12..c3242c7924 100644 --- a/Libraries/LibJS/Tests/string-escapes.js +++ b/Libraries/LibJS/Tests/string-escapes.js @@ -1,17 +1,17 @@ -load("test-common.js") +load("test-common.js"); try { - assert("\x55" === "U"); - assert("\X55" === "X55"); - assert(`\x55` === "U"); - assert(`\X55` === "X55"); + assert("\x55" === "U"); + assert("X55" === "X55"); + assert(`\x55` === "U"); + assert(`\X55` === "X55"); - assert("\u26a0" === "⚠"); - assert(`\u26a0` === "⚠"); - assert("\u{1f41e}" === "🐞"); - assert(`\u{1f41e}` === "🐞"); - - console.log("PASS"); + assert("\u26a0" === "⚠"); + assert(`\u26a0` === "⚠"); + assert("\u{1f41e}" === "🐞"); + assert(`\u{1f41e}` === "🐞"); + + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/string-spread.js b/Libraries/LibJS/Tests/string-spread.js index 433aa3b066..cca1ab60bf 100644 --- a/Libraries/LibJS/Tests/string-spread.js +++ b/Libraries/LibJS/Tests/string-spread.js @@ -1,31 +1,27 @@ load("test-common.js"); function testArray(arr) { - return arr.length === 4 && - arr[0] === "a" && - arr[1] === "b" && - arr[2] === "c" && - arr[3] === "d"; + return arr.length === 4 && arr[0] === "a" && arr[1] === "b" && arr[2] === "c" && arr[3] === "d"; } try { - var arr; + var arr; - arr = ["a", ..."bc", "d"]; - assert(testArray(arr)); + arr = ["a", ..."bc", "d"]; + assert(testArray(arr)); - let s = "bc"; - arr = ["a", ...s, "d"]; - assert(testArray(arr)); + let s = "bc"; + arr = ["a", ...s, "d"]; + assert(testArray(arr)); - let obj = { a: "bc" }; - arr = ["a", ...obj.a, "d"]; - assert(testArray(arr)); + let obj = { a: "bc" }; + arr = ["a", ...obj.a, "d"]; + assert(testArray(arr)); - arr = [..."", ...[...new String("abc")], "d"]; - assert(testArray(arr)); + arr = [..."", ...[...new String("abc")], "d"]; + assert(testArray(arr)); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/switch-basic.js b/Libraries/LibJS/Tests/switch-basic.js index c848293ac5..37c6f2ce33 100644 --- a/Libraries/LibJS/Tests/switch-basic.js +++ b/Libraries/LibJS/Tests/switch-basic.js @@ -1,39 +1,39 @@ describe("basic switch tests", () => { - test("string case does not match number target", () => { - switch (1 + 2) { - case '3': - expect().fail(); - case 3: - return; - case 5: - case 1: - break; - default: - break; - } - + test("string case does not match number target", () => { + switch (1 + 2) { + case "3": expect().fail(); - }); + case 3: + return; + case 5: + case 1: + break; + default: + break; + } - test("string concatenation in target", () => { - var a = "foo"; - - switch (a + "bar") { - case 1: - expect().fail(); - case "foobar": - case 2: - return; - } + expect().fail(); + }); + + test("string concatenation in target", () => { + var a = "foo"; + + switch (a + "bar") { + case 1: expect().fail(); - }); + case "foobar": + case 2: + return; + } + expect().fail(); + }); - test("default", () => { - switch (100) { - default: - return; - } + test("default", () => { + switch (100) { + default: + return; + } - expect().fail(); - }); + expect().fail(); + }); }); diff --git a/Libraries/LibJS/Tests/switch-break.js b/Libraries/LibJS/Tests/switch-break.js index 0fe5fe1aab..ea0ceaef97 100644 --- a/Libraries/LibJS/Tests/switch-break.js +++ b/Libraries/LibJS/Tests/switch-break.js @@ -1,25 +1,23 @@ load("test-common.js"); try { - var i = 0; - var three; - var five; + var i = 0; + var three; + var five; - for (; i < 9; ) { - switch (i) { - case 3: - three = i; - break; - case 5: - five = i; - break; - } - ++i; + for (; i < 9; ) { + switch (i) { + case 3: + three = i; + break; + case 5: + five = i; + break; } - assert(three === 3); - assert(five === 5); - - console.log("PASS"); -} catch { -} + ++i; + } + assert(three === 3); + assert(five === 5); + console.log("PASS"); +} catch {} diff --git a/Libraries/LibJS/Tests/tagged-template-literals.js b/Libraries/LibJS/Tests/tagged-template-literals.js index 31e7c1629d..6f491b261e 100644 --- a/Libraries/LibJS/Tests/tagged-template-literals.js +++ b/Libraries/LibJS/Tests/tagged-template-literals.js @@ -1,106 +1,106 @@ describe("tagged template literal errors", () => { - test("undefined variables in template expression throw a ReferenceError", () => { - expect(() => { - foo`bar${baz}`; - }).toThrowWithMessage(ReferenceError, "'foo' is not defined"); + test("undefined variables in template expression throw a ReferenceError", () => { + expect(() => { + foo`bar${baz}`; + }).toThrowWithMessage(ReferenceError, "'foo' is not defined"); - expect(() => { - function foo() {}; - foo`bar${baz}`; - }).toThrowWithMessage(ReferenceError, "'baz' is not defined"); - }); + expect(() => { + function foo() {} + foo`bar${baz}`; + }).toThrowWithMessage(ReferenceError, "'baz' is not defined"); + }); - test("cannot tag a non-function", () => { - expect(() => { - undefined``; - }).toThrowWithMessage(TypeError, "undefined is not a function"); - }); + test("cannot tag a non-function", () => { + expect(() => { + undefined``; + }).toThrowWithMessage(TypeError, "undefined is not a function"); + }); }); describe("tagged template literal functionality", () => { - test("empty template tag", () => { - function test1(strings) { - expect(strings).toBeInstanceOf(Array); - expect(strings).toHaveLength(1); - expect(strings[0]).toBe(""); - return 42; - } - expect(test1``).toBe(42); - }); + test("empty template tag", () => { + function test1(strings) { + expect(strings).toBeInstanceOf(Array); + expect(strings).toHaveLength(1); + expect(strings[0]).toBe(""); + return 42; + } + expect(test1``).toBe(42); + }); - test("tagging a template literal", () => { - function test2(s) { - return function (strings) { - expect(strings).toBeInstanceOf(Array); - expect(strings).toHaveLength(1); - expect(strings[0]).toBe("bar"); - return s + strings[0]; - } - } - expect(test2("foo")`bar`).toBe("foobar"); - }); + test("tagging a template literal", () => { + function test2(s) { + return function (strings) { + expect(strings).toBeInstanceOf(Array); + expect(strings).toHaveLength(1); + expect(strings[0]).toBe("bar"); + return s + strings[0]; + }; + } + expect(test2("foo")`bar`).toBe("foobar"); + }); - test("tagging an object function key", () => { - var test3 = { - foo(strings, p1) { - expect(strings).toBeInstanceOf(Array); - expect(strings).toHaveLength(2); - expect(strings[0]).toBe(""); - expect(strings[1]).toBe(""); - expect(p1).toBe("bar"); - } - }; - test3.foo`${"bar"}`; - }); + test("tagging an object function key", () => { + var test3 = { + foo(strings, p1) { + expect(strings).toBeInstanceOf(Array); + expect(strings).toHaveLength(2); + expect(strings[0]).toBe(""); + expect(strings[1]).toBe(""); + expect(p1).toBe("bar"); + }, + }; + test3.foo`${"bar"}`; + }); - test("tagging with a variable in a template expression", () => { - function test4(strings, p1) { - expect(strings).toBeInstanceOf(Array); - expect(strings).toHaveLength(2); - expect(strings[0]).toBe("foo"); - expect(strings[1]).toBe(""); - expect(p1).toBe(42); - } - var bar = 42; - test4`foo${bar}`; - }); + test("tagging with a variable in a template expression", () => { + function test4(strings, p1) { + expect(strings).toBeInstanceOf(Array); + expect(strings).toHaveLength(2); + expect(strings[0]).toBe("foo"); + expect(strings[1]).toBe(""); + expect(p1).toBe(42); + } + var bar = 42; + test4`foo${bar}`; + }); - test("template tag result of another template tag", () => { - function test5(strings, p1, p2) { - expect(strings).toBeInstanceOf(Array); - expect(strings).toHaveLength(3); - expect(strings[0]).toBe("foo"); - expect(strings[1]).toBe("baz"); - expect(strings[2]).toBe(""); - expect(p1).toBe(42); - expect(p2).toBe("qux"); - return (strings, value) => `${value}${strings[0]}`; - } - var bar = 42; - expect(test5`foo${bar}baz${"qux"}``test${123}`).toBe("123test"); - }); + test("template tag result of another template tag", () => { + function test5(strings, p1, p2) { + expect(strings).toBeInstanceOf(Array); + expect(strings).toHaveLength(3); + expect(strings[0]).toBe("foo"); + expect(strings[1]).toBe("baz"); + expect(strings[2]).toBe(""); + expect(p1).toBe(42); + expect(p2).toBe("qux"); + return (strings, value) => `${value}${strings[0]}`; + } + var bar = 42; + expect(test5`foo${bar}baz${"qux"}``test${123}`).toBe("123test"); + }); - test("general test", () => { - function review(strings, name, rating) { - return `${strings[0]}**${name}**${strings[1]}_${rating}_${strings[2]}`; - } - var name = "SerenityOS"; - var rating = "great"; - expect(review`${name} is a ${rating} project!`).toBe("**SerenityOS** is a _great_ project!"); - }); + test("general test", () => { + function review(strings, name, rating) { + return `${strings[0]}**${name}**${strings[1]}_${rating}_${strings[2]}`; + } + var name = "SerenityOS"; + var rating = "great"; + expect(review`${name} is a ${rating} project!`).toBe("**SerenityOS** is a _great_ project!"); + }); - test("template object structure", () => { - const getTemplateObject = (...rest) => rest; - const getRawTemplateStrings = arr => arr.raw; - - let o = getTemplateObject`foo\nbar`; - expect(Object.getOwnPropertyNames(o[0])).toContain("raw"); - - let raw = getRawTemplateStrings`foo${1 + 3}\nbar`; - expect(Object.getOwnPropertyNames(raw)).not.toContain("raw"); - expect(raw).toHaveLength(2); - expect(raw[0]).toBe("foo"); - expect(raw[1]).toHaveLength(5); - expect(raw[1]).toBe("\\nbar"); - }); + test("template object structure", () => { + const getTemplateObject = (...rest) => rest; + const getRawTemplateStrings = arr => arr.raw; + + let o = getTemplateObject`foo\nbar`; + expect(Object.getOwnPropertyNames(o[0])).toContain("raw"); + + let raw = getRawTemplateStrings`foo${1 + 3}\nbar`; + expect(Object.getOwnPropertyNames(raw)).not.toContain("raw"); + expect(raw).toHaveLength(2); + expect(raw[0]).toBe("foo"); + expect(raw[1]).toHaveLength(5); + expect(raw[1]).toBe("\\nbar"); + }); }); diff --git a/Libraries/LibJS/Tests/template-literals.js b/Libraries/LibJS/Tests/template-literals.js index d3f07e86b5..aac01b5025 100644 --- a/Libraries/LibJS/Tests/template-literals.js +++ b/Libraries/LibJS/Tests/template-literals.js @@ -1,45 +1,50 @@ load("test-common.js"); try { - assert(`foo` === "foo"); - assert(`foo{` === "foo{"); - assert(`foo}` === "foo}"); - assert(`foo$` === "foo$"); - assert(`foo\`` === "foo`") - assert(`foo\$` === "foo$"); - - assert(`foo ${undefined}` === "foo undefined"); - assert(`foo ${null}` === "foo null"); - assert(`foo ${5}` === "foo 5"); - assert(`foo ${true}` === "foo true"); - assert(`foo ${"bar"}` === "foo bar"); - assert(`foo \${"bar"}` === 'foo ${"bar"}'); + assert(`foo` === "foo"); + assert(`foo{` === "foo{"); + assert(`foo}` === "foo}"); + assert(`foo$` === "foo$"); + assert(`foo\`` === "foo`"); + assert(`foo\$` === "foo$"); - assert(`foo ${{}}` === "foo [object Object]"); - assert(`foo ${{ bar: { baz: "qux" }}}` === "foo [object Object]"); - assert(`foo ${"bar"} ${"baz"}` === "foo bar baz"); - assert(`${"foo"} bar baz` === "foo bar baz"); - assert(`${"foo bar baz"}` === "foo bar baz"); + assert(`foo ${undefined}` === "foo undefined"); + assert(`foo ${null}` === "foo null"); + assert(`foo ${5}` === "foo 5"); + assert(`foo ${true}` === "foo true"); + assert(`foo ${"bar"}` === "foo bar"); + assert(`foo \${"bar"}` === 'foo ${"bar"}'); - let a = 27; - assert(`${a}` === "27"); - assert(`foo ${a}` === "foo 27"); - assert(`foo ${a ? "bar" : "baz"}` === "foo bar"); - assert(`foo ${(() => a)()}` === "foo 27"); + assert(`foo ${{}}` === "foo [object Object]"); + assert(`foo ${{ bar: { baz: "qux" } }}` === "foo [object Object]"); + assert(`foo ${"bar"} ${"baz"}` === "foo bar baz"); + assert(`${"foo"} bar baz` === "foo bar baz"); + assert(`${"foo bar baz"}` === "foo bar baz"); - assert(`foo ${`bar`}` === "foo bar"); - assert(`${`${`${`${"foo"}`} bar`}`}` === "foo bar"); - assert(`foo - bar` === "foo\n bar"); - - assertThrowsError(() => { - `${b}`; - }, { - error: ReferenceError, - message: "'b' is not defined", - }) + let a = 27; + assert(`${a}` === "27"); + assert(`foo ${a}` === "foo 27"); + assert(`foo ${a ? "bar" : "baz"}` === "foo bar"); + assert(`foo ${(() => a)()}` === "foo 27"); - console.log("PASS"); + assert(`foo ${`bar`}` === "foo bar"); + assert(`${`${`${`${"foo"}`} bar`}`}` === "foo bar"); + assert( + `foo + bar` === "foo\n bar" + ); + + assertThrowsError( + () => { + `${b}`; + }, + { + error: ReferenceError, + message: "'b' is not defined", + } + ); + + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/test-common-tests.js b/Libraries/LibJS/Tests/test-common-tests.js index 7077662ef1..ba3a0ba996 100644 --- a/Libraries/LibJS/Tests/test-common-tests.js +++ b/Libraries/LibJS/Tests/test-common-tests.js @@ -1,414 +1,416 @@ test("toBe", () => { - expect(null).toBe(null); - expect(undefined).toBe(undefined); - expect(null).not.toBe(undefined); + expect(null).toBe(null); + expect(undefined).toBe(undefined); + expect(null).not.toBe(undefined); - expect(1).toBe(1); - expect(1).not.toBe(2); + expect(1).toBe(1); + expect(1).not.toBe(2); - expect("1").toBe("1"); - expect("1").not.toBe("2"); + expect("1").toBe("1"); + expect("1").not.toBe("2"); - expect(true).toBeTrue(); - expect(true).not.toBeFalse(); + expect(true).toBeTrue(); + expect(true).not.toBeFalse(); - expect({}).not.toBe({}); - expect([]).not.toBe([]); + expect({}).not.toBe({}); + expect([]).not.toBe([]); - function foo() {}; - expect(foo).toBe(foo); - expect(function(){}).not.toBe(function(){}); + function foo() {} + expect(foo).toBe(foo); + expect(function () {}).not.toBe(function () {}); - let s = Symbol("foo"); - expect(s).toBe(s); - expect(Symbol("foo")).not.toBe(Symbol("foo")); + let s = Symbol("foo"); + expect(s).toBe(s); + expect(Symbol("foo")).not.toBe(Symbol("foo")); - expect(1n).toBe(1n); - expect(1n).not.toBe(1); + expect(1n).toBe(1n); + expect(1n).not.toBe(1); }); test("toBeCloseTo", () => { - expect(1).toBeCloseTo(1); - expect(1).not.toBeCloseTo(1.1); - expect(1).not.toBeCloseTo(1.01); - expect(1).not.toBeCloseTo(1.001); - expect(1).not.toBeCloseTo(1.0001); - expect(1).not.toBeCloseTo(1.00001); - expect(1).toBeCloseTo(1.000001); + expect(1).toBeCloseTo(1); + expect(1).not.toBeCloseTo(1.1); + expect(1).not.toBeCloseTo(1.01); + expect(1).not.toBeCloseTo(1.001); + expect(1).not.toBeCloseTo(1.0001); + expect(1).not.toBeCloseTo(1.00001); + expect(1).toBeCloseTo(1.000001); - [ - ["foo", 1], - [1, "foo"], - [1n, 1], - ].forEach(arr => { - expect(() => { - expect(arr[0]).toBeCloseTo(arr[1]); - }).toThrow(ExpectationError); - }); + [ + ["foo", 1], + [1, "foo"], + [1n, 1], + ].forEach(arr => { + expect(() => { + expect(arr[0]).toBeCloseTo(arr[1]); + }).toThrow(ExpectationError); + }); }); test("toHaveLength", () => { - expect([]).toHaveLength(0); - expect([]).not.toHaveLength(1); - expect([1]).toHaveLength(1); - expect({ length: 1 }).toHaveLength(1); + expect([]).toHaveLength(0); + expect([]).not.toHaveLength(1); + expect([1]).toHaveLength(1); + expect({ length: 1 }).toHaveLength(1); - expect(() => { - expect(1).toHaveLength(); - }).toThrow(ExpectationError); + expect(() => { + expect(1).toHaveLength(); + }).toThrow(ExpectationError); }); test("toHaveProperty", () => { - expect([]).toHaveProperty("length"); - expect([]).toHaveProperty("length", 0); - expect([1]).not.toHaveProperty("length", 0); - expect({ foo: "bar" }).toHaveProperty("foo") - expect({ foo: "bar" }).toHaveProperty("foo", "bar"); + expect([]).toHaveProperty("length"); + expect([]).toHaveProperty("length", 0); + expect([1]).not.toHaveProperty("length", 0); + expect({ foo: "bar" }).toHaveProperty("foo"); + expect({ foo: "bar" }).toHaveProperty("foo", "bar"); - expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"]); - expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"], "baz"); - expect({ foo: { bar: "baz" } }).toHaveProperty("foo.bar"); - expect({ foo: { bar: "baz" } }).toHaveProperty("foo.bar", "baz"); + expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"]); + expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"], "baz"); + expect({ foo: { bar: "baz" } }).toHaveProperty("foo.bar"); + expect({ foo: { bar: "baz" } }).toHaveProperty("foo.bar", "baz"); - expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"]); - expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"], "baz"); - expect({ foo: { bar: "baz" } }).not.toHaveProperty(["foo", "baz"]); - expect({ foo: { bar: "baz" } }).not.toHaveProperty(["foo", "baz"], "qux"); - expect({ foo: { bar: "baz" } }).not.toHaveProperty("foo.baz"); - expect({ foo: { bar: "baz" } }).not.toHaveProperty("foo.baz", "qux"); + expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"]); + expect({ foo: { bar: "baz" } }).toHaveProperty(["foo", "bar"], "baz"); + expect({ foo: { bar: "baz" } }).not.toHaveProperty(["foo", "baz"]); + expect({ foo: { bar: "baz" } }).not.toHaveProperty(["foo", "baz"], "qux"); + expect({ foo: { bar: "baz" } }).not.toHaveProperty("foo.baz"); + expect({ foo: { bar: "baz" } }).not.toHaveProperty("foo.baz", "qux"); }); test("toBeDefined", () => { - expect(1).toBeDefined(); - expect(true).toBeDefined(); - expect(false).toBeDefined(); - expect({}).toBeDefined(); - expect([]).toBeDefined(); - expect("a").toBeDefined(); - expect(null).toBeDefined(); - expect(undefined).not.toBeDefined(); + expect(1).toBeDefined(); + expect(true).toBeDefined(); + expect(false).toBeDefined(); + expect({}).toBeDefined(); + expect([]).toBeDefined(); + expect("a").toBeDefined(); + expect(null).toBeDefined(); + expect(undefined).not.toBeDefined(); }); test("toBeInstanceOf", () => { - expect(new Error).toBeInstanceOf(Error); - expect(Error).not.toBeInstanceOf(Error); + expect(new Error()).toBeInstanceOf(Error); + expect(Error).not.toBeInstanceOf(Error); - class Parent {}; - class Child extends Parent {}; + class Parent {} + class Child extends Parent {} - expect(new Child).toBeInstanceOf(Child); - expect(new Child).toBeInstanceOf(Parent); - expect(new Parent).toBeInstanceOf(Parent); - expect(new Parent).not.toBeInstanceOf(Child); + expect(new Child()).toBeInstanceOf(Child); + expect(new Child()).toBeInstanceOf(Parent); + expect(new Parent()).toBeInstanceOf(Parent); + expect(new Parent()).not.toBeInstanceOf(Child); }); test("toBeNull", () => { - expect(null).toBeNull(); - expect(undefined).not.toBeNull(); - expect(5).not.toBeNull(); + expect(null).toBeNull(); + expect(undefined).not.toBeNull(); + expect(5).not.toBeNull(); }); test("toBeUndefined", () => { - expect(undefined).toBeUndefined(); - expect(null).not.toBeUndefined(); - expect().toBeUndefined(); - expect(5).not.toBeUndefined(); + expect(undefined).toBeUndefined(); + expect(null).not.toBeUndefined(); + expect().toBeUndefined(); + expect(5).not.toBeUndefined(); }); test("toBeNaN", () => { - expect(NaN).toBeNaN(); - expect(5).not.toBeNaN(); + expect(NaN).toBeNaN(); + expect(5).not.toBeNaN(); }); test("toBeTrue", () => { - expect(true).toBeTrue(); - expect(false).not.toBeTrue(); - expect(null).not.toBeTrue(); - expect(undefined).not.toBeTrue(); - expect(0).not.toBeTrue(); + expect(true).toBeTrue(); + expect(false).not.toBeTrue(); + expect(null).not.toBeTrue(); + expect(undefined).not.toBeTrue(); + expect(0).not.toBeTrue(); }); test("toBeFalse", () => { - expect(true).not.toBeFalse(); - expect(false).toBeFalse(); - expect(null).not.toBeFalse(); - expect(undefined).not.toBeFalse(); - expect(0).not.toBeFalse(); + expect(true).not.toBeFalse(); + expect(false).toBeFalse(); + expect(null).not.toBeFalse(); + expect(undefined).not.toBeFalse(); + expect(0).not.toBeFalse(); }); test("toBeLessThan", () => { - expect(0).toBeLessThan(1); - expect(0).toBeLessThan(0.1); - expect(1).not.toBeLessThan(1); - expect(1).not.toBeLessThan(0); + expect(0).toBeLessThan(1); + expect(0).toBeLessThan(0.1); + expect(1).not.toBeLessThan(1); + expect(1).not.toBeLessThan(0); - expect(0n).toBeLessThan(1n); - expect(1n).not.toBeLessThan(1n); - expect(1n).not.toBeLessThan(0n); + expect(0n).toBeLessThan(1n); + expect(1n).not.toBeLessThan(1n); + expect(1n).not.toBeLessThan(0n); - [ - ["foo", 0], - [0, "foo"], - [0, 0n], - [0n, 0], - ].forEach(arr => { - expect(() => { - expect(arr[0]).toBeLessThan(arr[1]); - }).toThrow(ExpectationError); - }); + [ + ["foo", 0], + [0, "foo"], + [0, 0n], + [0n, 0], + ].forEach(arr => { + expect(() => { + expect(arr[0]).toBeLessThan(arr[1]); + }).toThrow(ExpectationError); + }); }); test("toBeLessThanOrEqual", () => { - expect(0).toBeLessThanOrEqual(1); - expect(0).toBeLessThanOrEqual(0.1); - expect(1).toBeLessThanOrEqual(1); - expect(1).not.toBeLessThanOrEqual(0); + expect(0).toBeLessThanOrEqual(1); + expect(0).toBeLessThanOrEqual(0.1); + expect(1).toBeLessThanOrEqual(1); + expect(1).not.toBeLessThanOrEqual(0); - expect(0n).toBeLessThanOrEqual(1n); - expect(1n).toBeLessThanOrEqual(1n); - expect(1n).not.toBeLessThanOrEqual(0n); + expect(0n).toBeLessThanOrEqual(1n); + expect(1n).toBeLessThanOrEqual(1n); + expect(1n).not.toBeLessThanOrEqual(0n); - [ - ["foo", 0], - [0, "foo"], - [0, 0n], - [0n, 0], - ].forEach(arr => { - expect(() => { - expect(arr[0]).toBeLessThanOrEqual(arr[1]); - }).toThrow(ExpectationError); - }); + [ + ["foo", 0], + [0, "foo"], + [0, 0n], + [0n, 0], + ].forEach(arr => { + expect(() => { + expect(arr[0]).toBeLessThanOrEqual(arr[1]); + }).toThrow(ExpectationError); + }); }); test("toBeGreaterThan", () => { - expect(1).toBeGreaterThan(0); - expect(0.1).toBeGreaterThan(0); - expect(1).not.toBeGreaterThan(1); - expect(0).not.toBeGreaterThan(1); + expect(1).toBeGreaterThan(0); + expect(0.1).toBeGreaterThan(0); + expect(1).not.toBeGreaterThan(1); + expect(0).not.toBeGreaterThan(1); - expect(1n).toBeGreaterThan(0n); - expect(1n).not.toBeGreaterThan(1n); - expect(0n).not.toBeGreaterThan(1n); + expect(1n).toBeGreaterThan(0n); + expect(1n).not.toBeGreaterThan(1n); + expect(0n).not.toBeGreaterThan(1n); - [ - ["foo", 0], - [0, "foo"], - [0, 0n], - [0n, 0], - ].forEach(arr => { - expect(() => { - expect(arr[0]).toBeGreaterThan(arr[1]); - }).toThrow(ExpectationError); - }); + [ + ["foo", 0], + [0, "foo"], + [0, 0n], + [0n, 0], + ].forEach(arr => { + expect(() => { + expect(arr[0]).toBeGreaterThan(arr[1]); + }).toThrow(ExpectationError); + }); }); test("toBeGreaterThanOrEqual", () => { - expect(1).toBeGreaterThanOrEqual(0); - expect(0.1).toBeGreaterThanOrEqual(0); - expect(1).toBeGreaterThanOrEqual(1); - expect(0).not.toBeGreaterThanOrEqual(1); + expect(1).toBeGreaterThanOrEqual(0); + expect(0.1).toBeGreaterThanOrEqual(0); + expect(1).toBeGreaterThanOrEqual(1); + expect(0).not.toBeGreaterThanOrEqual(1); - expect(1n).toBeGreaterThanOrEqual(0n); - expect(1n).toBeGreaterThanOrEqual(1n); - expect(0n).not.toBeGreaterThanOrEqual(1n); + expect(1n).toBeGreaterThanOrEqual(0n); + expect(1n).toBeGreaterThanOrEqual(1n); + expect(0n).not.toBeGreaterThanOrEqual(1n); - [ - ["foo", 0], - [0, "foo"], - [0, 0n], - [0n, 0], - ].forEach(arr => { - expect(() => { - expect(arr[0]).toBeGreaterThanOrEqual(arr[1]); - }).toThrow(ExpectationError); - }); + [ + ["foo", 0], + [0, "foo"], + [0, 0n], + [0n, 0], + ].forEach(arr => { + expect(() => { + expect(arr[0]).toBeGreaterThanOrEqual(arr[1]); + }).toThrow(ExpectationError); + }); }); test("toContain", () => { - expect([1, 2, 3]).toContain(1); - expect([1, 2, 3]).toContain(2); - expect([1, 2, 3]).toContain(3); - expect([{ foo: 1 }]).not.toContain({ foo: 1 }); + expect([1, 2, 3]).toContain(1); + expect([1, 2, 3]).toContain(2); + expect([1, 2, 3]).toContain(3); + expect([{ foo: 1 }]).not.toContain({ foo: 1 }); }); test("toContainEqual", () => { - expect([1, 2, 3]).toContainEqual(1); - expect([1, 2, 3]).toContainEqual(2); - expect([1, 2, 3]).toContainEqual(3); - expect([{ foo: 1 }]).toContainEqual({ foo: 1 }); + expect([1, 2, 3]).toContainEqual(1); + expect([1, 2, 3]).toContainEqual(2); + expect([1, 2, 3]).toContainEqual(3); + expect([{ foo: 1 }]).toContainEqual({ foo: 1 }); }); test("toEqual", () => { - expect(undefined).toEqual(undefined); - expect(null).toEqual(null); - expect(undefined).not.toEqual(null); - expect(null).not.toEqual(undefined); - expect(NaN).toEqual(NaN); + expect(undefined).toEqual(undefined); + expect(null).toEqual(null); + expect(undefined).not.toEqual(null); + expect(null).not.toEqual(undefined); + expect(NaN).toEqual(NaN); - expect(1).toEqual(1); - expect("abcd").toEqual("abcd"); + expect(1).toEqual(1); + expect("abcd").toEqual("abcd"); - let s = Symbol(); - expect(s).toEqual(s); - expect(Symbol()).not.toEqual(Symbol()); - expect(Symbol.for("foo")).toEqual(Symbol.for("foo")); + let s = Symbol(); + expect(s).toEqual(s); + expect(Symbol()).not.toEqual(Symbol()); + expect(Symbol.for("foo")).toEqual(Symbol.for("foo")); - expect({ foo: 1, bar: { baz: [1, 2, 3 ] } }) - .toEqual({ foo: 1, bar: { baz: [1, 2, 3 ] } }); - expect([1, 2, { foo: 1 }, [3, [4, 5]]]) - .toEqual([1, 2, { foo: 1 }, [3, [4, 5]]]); + expect({ foo: 1, bar: { baz: [1, 2, 3] } }).toEqual({ foo: 1, bar: { baz: [1, 2, 3] } }); + expect([1, 2, { foo: 1 }, [3, [4, 5]]]).toEqual([1, 2, { foo: 1 }, [3, [4, 5]]]); - function foo() {} - expect(foo).toEqual(foo); - expect(function(){}).not.toEqual(function(){}); + function foo() {} + expect(foo).toEqual(foo); + expect(function () {}).not.toEqual(function () {}); }); test("toThrow", () => { - expect(() => {}).not.toThrow(); - expect(() => {}).not.toThrow("foo"); - expect(() => {}).not.toThrow(TypeError); - expect(() => {}).not.toThrow(new TypeError("foo")); + expect(() => {}).not.toThrow(); + expect(() => {}).not.toThrow("foo"); + expect(() => {}).not.toThrow(TypeError); + expect(() => {}).not.toThrow(new TypeError("foo")); - let thrower = () => { - throw new TypeError("foo bar"); - }; + let thrower = () => { + throw new TypeError("foo bar"); + }; - expect(thrower).toThrow(); - expect(thrower).toThrow(TypeError); - expect(thrower).toThrow("o ba"); - expect(thrower).toThrow("foo bar"); - expect(thrower).not.toThrow("baz"); - expect(thrower).not.toThrow(ReferenceError); - expect(thrower).toThrow(new TypeError("foo bar")); - expect(thrower).not.toThrow(new TypeError("o ba")); - expect(thrower).toThrow(new ReferenceError("foo bar")); - expect(thrower).toThrow({ message: "foo bar" }); + expect(thrower).toThrow(); + expect(thrower).toThrow(TypeError); + expect(thrower).toThrow("o ba"); + expect(thrower).toThrow("foo bar"); + expect(thrower).not.toThrow("baz"); + expect(thrower).not.toThrow(ReferenceError); + expect(thrower).toThrow(new TypeError("foo bar")); + expect(thrower).not.toThrow(new TypeError("o ba")); + expect(thrower).toThrow(new ReferenceError("foo bar")); + expect(thrower).toThrow({ message: "foo bar" }); }); test("pass", () => { - expect().pass(); - expect({}).pass(); + expect().pass(); + expect({}).pass(); }); test("fail", () => { - // FIXME: Doesn't really make sense; this is a great candidate - // for expect.assertions() - try { - expect().fail(); - } catch (e) { - expect(e.name).toBe("ExpectationError"); - } + // FIXME: Doesn't really make sense; this is a great candidate + // for expect.assertions() + try { + expect().fail(); + } catch (e) { + expect(e.name).toBe("ExpectationError"); + } }); test("toThrowWithMessage", () => { - let incorrectUsages = [ - [1, undefined, undefined], - [() => {}, undefined, undefined], - [() => {}, function(){}, undefined], - [() => {}, undefined, "test"] - ]; + let incorrectUsages = [ + [1, undefined, undefined], + [() => {}, undefined, undefined], + [() => {}, function () {}, undefined], + [() => {}, undefined, "test"], + ]; - incorrectUsages.forEach(arr => { - expect(() => { - expect(arr[0]).toThrowWithMessage(arr[1], arr[2]); - }).toThrow(); - }); + incorrectUsages.forEach(arr => { + expect(() => { + expect(arr[0]).toThrowWithMessage(arr[1], arr[2]); + }).toThrow(); + }); - let thrower = () => { - throw new TypeError("foo bar"); - }; + let thrower = () => { + throw new TypeError("foo bar"); + }; - expect(thrower).toThrowWithMessage(TypeError, "foo bar"); - expect(thrower).toThrowWithMessage(TypeError, "foo"); - expect(thrower).toThrowWithMessage(TypeError, "o ba"); - expect(thrower).not.toThrowWithMessage(ReferenceError, "foo bar"); - expect(thrower).not.toThrowWithMessage(TypeError, "foo baz"); + expect(thrower).toThrowWithMessage(TypeError, "foo bar"); + expect(thrower).toThrowWithMessage(TypeError, "foo"); + expect(thrower).toThrowWithMessage(TypeError, "o ba"); + expect(thrower).not.toThrowWithMessage(ReferenceError, "foo bar"); + expect(thrower).not.toThrowWithMessage(TypeError, "foo baz"); }); // FIXME: Will have to change when this matcher changes to use the // "eval" function test("toEval", () => { - expect("let a = 1").toEval(); - expect("a < 1").not.toEval(); - expect("&&*^%#%@").not.toEval(); - expect("function foo() { return 1; }; return foo();").toEval(); + expect("let a = 1").toEval(); + expect("a < 1").not.toEval(); + expect("&&*^%#%@").not.toEval(); + expect("function foo() { return 1; }; return foo();").toEval(); }); // FIXME: Will have to change when this matcher changes to use the // "eval" function test("toEvalTo", () => { - expect("let a = 1").toEvalTo(); - expect("let a = 1").toEvalTo(undefined); - expect("return 10").toEvalTo(10); - expect("return 10").not.toEvalTo(5); + expect("let a = 1").toEvalTo(); + expect("let a = 1").toEvalTo(undefined); + expect("return 10").toEvalTo(10); + expect("return 10").not.toEvalTo(5); - expect(() => { - expect("*^&%%").not.toEvalTo(); - }).toThrow(); + expect(() => { + expect("*^&%%").not.toEvalTo(); + }).toThrow(); }); test("toHaveConfigurableProperty", () => { - expect({ foo: 1 }).toHaveConfigurableProperty("foo"); + expect({ foo: 1 }).toHaveConfigurableProperty("foo"); - expect(() => { - expect({ foo: 1 }).not.toHaveConfigurableProperty("bar"); - }).toThrow(); + expect(() => { + expect({ foo: 1 }).not.toHaveConfigurableProperty("bar"); + }).toThrow(); - let o = {}; - Object.defineProperty(o, "foo", { configurable: true, value: 1 }); - Object.defineProperty(o, "bar", { configurable: false, value: 1 }); - expect(o).toHaveConfigurableProperty("foo"); - expect(o).not.toHaveConfigurableProperty("bar"); + let o = {}; + Object.defineProperty(o, "foo", { configurable: true, value: 1 }); + Object.defineProperty(o, "bar", { configurable: false, value: 1 }); + expect(o).toHaveConfigurableProperty("foo"); + expect(o).not.toHaveConfigurableProperty("bar"); }); test("toHaveEnumerableProperty", () => { - expect({ foo: 1 }).toHaveEnumerableProperty("foo"); + expect({ foo: 1 }).toHaveEnumerableProperty("foo"); - expect(() => { - expect({ foo: 1 }).not.toHaveEnumerableProperty("bar"); - }).toThrow(); + expect(() => { + expect({ foo: 1 }).not.toHaveEnumerableProperty("bar"); + }).toThrow(); - let o = {}; - Object.defineProperty(o, "foo", { enumerable: true, value: 1 }); - Object.defineProperty(o, "bar", { enumerable: false, value: 1 }); - expect(o).toHaveEnumerableProperty("foo"); - expect(o).not.toHaveEnumerableProperty("bar"); + let o = {}; + Object.defineProperty(o, "foo", { enumerable: true, value: 1 }); + Object.defineProperty(o, "bar", { enumerable: false, value: 1 }); + expect(o).toHaveEnumerableProperty("foo"); + expect(o).not.toHaveEnumerableProperty("bar"); }); test("toHaveWritableProperty", () => { - expect({ foo: 1 }).toHaveWritableProperty("foo"); + expect({ foo: 1 }).toHaveWritableProperty("foo"); - expect(() => { - expect({ foo: 1 }).not.toHaveWritableProperty("bar"); - }).toThrow(); + expect(() => { + expect({ foo: 1 }).not.toHaveWritableProperty("bar"); + }).toThrow(); - let o = {}; - Object.defineProperty(o, "foo", { writable: true, value: 1 }); - Object.defineProperty(o, "bar", { writable: false, value: 1 }); - expect(o).toHaveWritableProperty("foo"); - expect(o).not.toHaveWritableProperty("bar"); + let o = {}; + Object.defineProperty(o, "foo", { writable: true, value: 1 }); + Object.defineProperty(o, "bar", { writable: false, value: 1 }); + expect(o).toHaveWritableProperty("foo"); + expect(o).not.toHaveWritableProperty("bar"); }); test("toHaveGetterProperty", () => { - expect(() => { - expect({ foo: 1 }).not.toHaveGetterProperty("bar"); - }).toThrow(); + expect(() => { + expect({ foo: 1 }).not.toHaveGetterProperty("bar"); + }).toThrow(); - let o = {}; - Object.defineProperty(o, "foo", { get() { return 1; }}); - Object.defineProperty(o, "bar", { value: 1 }); - expect(o).toHaveGetterProperty("foo"); - expect(o).not.toHaveGetterProperty("bar"); + let o = {}; + Object.defineProperty(o, "foo", { + get() { + return 1; + }, + }); + Object.defineProperty(o, "bar", { value: 1 }); + expect(o).toHaveGetterProperty("foo"); + expect(o).not.toHaveGetterProperty("bar"); }); test("toHaveSetterProperty", () => { - expect(() => { - expect({ foo: 1 }).not.toHaveSetterProperty("bar"); - }).toThrow(); + expect(() => { + expect({ foo: 1 }).not.toHaveSetterProperty("bar"); + }).toThrow(); - let o = {}; - Object.defineProperty(o, "foo", { set(_) { }}); - Object.defineProperty(o, "bar", { value: 1 }); - expect(o).toHaveSetterProperty("foo"); - expect(o).not.toHaveSetterProperty("bar"); + let o = {}; + Object.defineProperty(o, "foo", { set(_) {} }); + Object.defineProperty(o, "bar", { value: 1 }); + expect(o).toHaveSetterProperty("foo"); + expect(o).not.toHaveSetterProperty("bar"); }); diff --git a/Libraries/LibJS/Tests/test-common.js b/Libraries/LibJS/Tests/test-common.js index d99f48be1c..a3b207938e 100644 --- a/Libraries/LibJS/Tests/test-common.js +++ b/Libraries/LibJS/Tests/test-common.js @@ -16,456 +16,439 @@ let __UserOutput__ = []; // We also rebind console.log here to use the array above console.log = (...args) => { - __UserOutput__.push(args.join(" ")); + __UserOutput__.push(args.join(" ")); }; class ExpectationError extends Error { - constructor(message, fileName, lineNumber) { - super(message, fileName, lineNumber); - this.name = "ExpectationError"; - } + constructor(message, fileName, lineNumber) { + super(message, fileName, lineNumber); + this.name = "ExpectationError"; + } } // Use an IIFE to avoid polluting the global namespace as much as possible (() => { - -// FIXME: This is a very naive deepEquals algorithm -const deepEquals = (a, b) => { - if (Array.isArray(a)) - return Array.isArray(b) && deepArrayEquals(a, b); - if (typeof a === "object") - return typeof b === "object" && deepObjectEquals(a, b); + // FIXME: This is a very naive deepEquals algorithm + const deepEquals = (a, b) => { + if (Array.isArray(a)) return Array.isArray(b) && deepArrayEquals(a, b); + if (typeof a === "object") return typeof b === "object" && deepObjectEquals(a, b); return Object.is(a, b); -} + }; -const deepArrayEquals = (a, b) => { - if (a.length !== b.length) - return false; + const deepArrayEquals = (a, b) => { + if (a.length !== b.length) return false; for (let i = 0; i < a.length; ++i) { - if (!deepEquals(a[i], b[i])) - return false; + if (!deepEquals(a[i], b[i])) return false; } return true; -} + }; -const deepObjectEquals = (a, b) => { - if (a === null) - return b === null; + const deepObjectEquals = (a, b) => { + if (a === null) return b === null; for (let key of Reflect.ownKeys(a)) { - if (!deepEquals(a[key], b[key])) - return false; + if (!deepEquals(a[key], b[key])) return false; } return true; -} + }; -class Expector { + class Expector { constructor(target, inverted) { - this.target = target; - this.inverted = !!inverted; + this.target = target; + this.inverted = !!inverted; } get not() { - return new Expector(this.target, !this.inverted); + return new Expector(this.target, !this.inverted); } toBe(value) { - this.__doMatcher(() => { - this.__expect(Object.is(this.target, value)); - }); + this.__doMatcher(() => { + this.__expect(Object.is(this.target, value)); + }); } // FIXME: Take a precision argument like jest's toBeCloseTo matcher toBeCloseTo(value) { - this.__expect(typeof this.target === "number"); - this.__expect(typeof value === "number"); + this.__expect(typeof this.target === "number"); + this.__expect(typeof value === "number"); - this.__doMatcher(() => { - this.__expect(Math.abs(this.target - value) < 0.000001); - }) + this.__doMatcher(() => { + this.__expect(Math.abs(this.target - value) < 0.000001); + }); } toHaveLength(length) { - this.__expect(typeof this.target.length === "number"); + this.__expect(typeof this.target.length === "number"); - this.__doMatcher(() => { - this.__expect(Object.is(this.target.length, length)); - }); + this.__doMatcher(() => { + this.__expect(Object.is(this.target.length, length)); + }); } toHaveProperty(property, value) { - this.__doMatcher(() => { - let object = this.target; + this.__doMatcher(() => { + let object = this.target; - if (typeof property === "string" && property.includes(".")) { - let propertyArray = []; + if (typeof property === "string" && property.includes(".")) { + let propertyArray = []; - while (property.includes(".")) { - let index = property.indexOf("."); - propertyArray.push(property.substring(0, index)); - if (index + 1 >= property.length) - break; - property = property.substring(index + 1, property.length); - } + while (property.includes(".")) { + let index = property.indexOf("."); + propertyArray.push(property.substring(0, index)); + if (index + 1 >= property.length) break; + property = property.substring(index + 1, property.length); + } - propertyArray.push(property); + propertyArray.push(property); - property = propertyArray; - } + property = propertyArray; + } - if (Array.isArray(property)) { - for (let key of property) { - this.__expect(object !== undefined && object !== null); - object = object[key]; - } - } else { - object = object[property]; - } + if (Array.isArray(property)) { + for (let key of property) { + this.__expect(object !== undefined && object !== null); + object = object[key]; + } + } else { + object = object[property]; + } - this.__expect(object !== undefined); - if (value !== undefined) - this.__expect(deepEquals(object, value)); - }); + this.__expect(object !== undefined); + if (value !== undefined) this.__expect(deepEquals(object, value)); + }); } toBeDefined() { - this.__doMatcher(() => { - this.__expect(this.target !== undefined); - }); + this.__doMatcher(() => { + this.__expect(this.target !== undefined); + }); } toBeInstanceOf(class_) { - this.__doMatcher(() => { - this.__expect(this.target instanceof class_); - }); + this.__doMatcher(() => { + this.__expect(this.target instanceof class_); + }); } toBeNull() { - this.__doMatcher(() => { - this.__expect(this.target === null); - }); + this.__doMatcher(() => { + this.__expect(this.target === null); + }); } toBeUndefined() { - this.__doMatcher(() => { - this.__expect(this.target === undefined); - }); + this.__doMatcher(() => { + this.__expect(this.target === undefined); + }); } toBeNaN() { - this.__doMatcher(() => { - this.__expect(isNaN(this.target)); - }); + this.__doMatcher(() => { + this.__expect(isNaN(this.target)); + }); } toBeTrue() { - this.__doMatcher(() => { - this.__expect(this.target === true); - }); + this.__doMatcher(() => { + this.__expect(this.target === true); + }); } toBeFalse() { - this.__doMatcher(() => { - this.__expect(this.target === false); - }); + this.__doMatcher(() => { + this.__expect(this.target === false); + }); } __validateNumericComparisonTypes(value) { - this.__expect(typeof this.target === "number" || typeof this.target === "bigint"); - this.__expect(typeof value === "number" || typeof value === "bigint"); - this.__expect(typeof this.target === typeof value); + this.__expect(typeof this.target === "number" || typeof this.target === "bigint"); + this.__expect(typeof value === "number" || typeof value === "bigint"); + this.__expect(typeof this.target === typeof value); } toBeLessThan(value) { - this.__validateNumericComparisonTypes(value); + this.__validateNumericComparisonTypes(value); - this.__doMatcher(() => { - this.__expect(this.target < value); - }); + this.__doMatcher(() => { + this.__expect(this.target < value); + }); } toBeLessThanOrEqual(value) { - this.__validateNumericComparisonTypes(value); + this.__validateNumericComparisonTypes(value); - this.__doMatcher(() => { - this.__expect(this.target <= value); - }); + this.__doMatcher(() => { + this.__expect(this.target <= value); + }); } toBeGreaterThan(value) { - this.__validateNumericComparisonTypes(value); + this.__validateNumericComparisonTypes(value); - this.__doMatcher(() => { - this.__expect(this.target > value); - }); + this.__doMatcher(() => { + this.__expect(this.target > value); + }); } toBeGreaterThanOrEqual(value) { - this.__validateNumericComparisonTypes(value); + this.__validateNumericComparisonTypes(value); - this.__doMatcher(() => { - this.__expect(this.target >= value); - }); + this.__doMatcher(() => { + this.__expect(this.target >= value); + }); } toContain(item) { - this.__doMatcher(() => { - // FIXME: Iterator check - for (let element of this.target) { - if (item === element) - return; - } + this.__doMatcher(() => { + // FIXME: Iterator check + for (let element of this.target) { + if (item === element) return; + } - throw new ExpectationError(); - }); + throw new ExpectationError(); + }); } toContainEqual(item) { - this.__doMatcher(() => { - // FIXME: Iterator check - for (let element of this.target) { - if (deepEquals(item, element)) - return; - } + this.__doMatcher(() => { + // FIXME: Iterator check + for (let element of this.target) { + if (deepEquals(item, element)) return; + } - throw new ExpectationError(); - }); + throw new ExpectationError(); + }); } toEqual(value) { - this.__doMatcher(() => { - this.__expect(deepEquals(this.target, value)); - }); + this.__doMatcher(() => { + this.__expect(deepEquals(this.target, value)); + }); } toThrow(value) { - this.__expect(typeof this.target === "function"); - this.__expect(typeof value === "string" - || typeof value === "function" - || typeof value === "object" - || value === undefined); + this.__expect(typeof this.target === "function"); + this.__expect( + typeof value === "string" || + typeof value === "function" || + typeof value === "object" || + value === undefined + ); - this.__doMatcher(() => { - let threw = true; - try { - this.target(); - threw = false; - } catch (e) { - if (typeof value === "string") { - this.__expect(e.message.includes(value)); - } else if (typeof value === "function") { - this.__expect(e instanceof value); - } else if (typeof value === "object") { - this.__expect(e.message === value.message); - } - } - this.__expect(threw); - }); + this.__doMatcher(() => { + let threw = true; + try { + this.target(); + threw = false; + } catch (e) { + if (typeof value === "string") { + this.__expect(e.message.includes(value)); + } else if (typeof value === "function") { + this.__expect(e instanceof value); + } else if (typeof value === "object") { + this.__expect(e.message === value.message); + } + } + this.__expect(threw); + }); } pass(message) { - // FIXME: This does nothing. If we want to implement things - // like assertion count, this will have to do something + // FIXME: This does nothing. If we want to implement things + // like assertion count, this will have to do something } // jest-extended fail(message) { - // FIXME: message is currently ignored - this.__doMatcher(() => { - this.__expect(false); - }) + // FIXME: message is currently ignored + this.__doMatcher(() => { + this.__expect(false); + }); } // jest-extended toThrowWithMessage(class_, message) { - this.__expect(typeof this.target === "function"); - this.__expect(class_ !== undefined); - this.__expect(message !== undefined); + this.__expect(typeof this.target === "function"); + this.__expect(class_ !== undefined); + this.__expect(message !== undefined); - this.__doMatcher(() => { - try { - this.target(); - this.__expect(false); - } catch (e) { - this.__expect(e instanceof class_); - this.__expect(e.message.includes(message)); - } - }); + this.__doMatcher(() => { + try { + this.target(); + this.__expect(false); + } catch (e) { + this.__expect(e instanceof class_); + this.__expect(e.message.includes(message)); + } + }); } // Test for syntax errors; target must be a string toEval() { - this.__expect(typeof this.target === "string"); + this.__expect(typeof this.target === "string"); - if (!this.inverted) { - try { - new Function(this.target)(); - } catch (e) { - throw new ExpectationError(); - } - } else { - let threw; - try { - new Function(this.target)(); - threw = false; - } catch (e) { - threw = true; - } - this.__expect(threw); + if (!this.inverted) { + try { + new Function(this.target)(); + } catch (e) { + throw new ExpectationError(); } + } else { + let threw; + try { + new Function(this.target)(); + threw = false; + } catch (e) { + threw = true; + } + this.__expect(threw); + } } // Must compile regardless of inverted-ness toEvalTo(value) { - this.__expect(typeof this.target === "string"); + this.__expect(typeof this.target === "string"); - let result; + let result; - try { - result = new Function(this.target)(); - } catch (e) { - throw new ExpectationError(); - } + try { + result = new Function(this.target)(); + } catch (e) { + throw new ExpectationError(); + } - this.__doMatcher(() => { - this.__expect(deepEquals(value, result)); - }); + this.__doMatcher(() => { + this.__expect(deepEquals(value, result)); + }); } toHaveConfigurableProperty(property) { - this.__expect(this.target !== undefined && this.target !== null); - let d = Object.getOwnPropertyDescriptor(this.target, property); - this.__expect(d !== undefined); + this.__expect(this.target !== undefined && this.target !== null); + let d = Object.getOwnPropertyDescriptor(this.target, property); + this.__expect(d !== undefined); - this.__doMatcher(() => { - this.__expect(d.configurable); - }); + this.__doMatcher(() => { + this.__expect(d.configurable); + }); } toHaveEnumerableProperty(property) { - this.__expect(this.target !== undefined && this.target !== null); - let d = Object.getOwnPropertyDescriptor(this.target, property); - this.__expect(d !== undefined); + this.__expect(this.target !== undefined && this.target !== null); + let d = Object.getOwnPropertyDescriptor(this.target, property); + this.__expect(d !== undefined); - this.__doMatcher(() => { - this.__expect(d.enumerable); - }); + this.__doMatcher(() => { + this.__expect(d.enumerable); + }); } toHaveWritableProperty(property) { - this.__expect(this.target !== undefined && this.target !== null); - let d = Object.getOwnPropertyDescriptor(this.target, property); - this.__expect(d !== undefined); + this.__expect(this.target !== undefined && this.target !== null); + let d = Object.getOwnPropertyDescriptor(this.target, property); + this.__expect(d !== undefined); - this.__doMatcher(() => { - this.__expect(d.writable); - }); + this.__doMatcher(() => { + this.__expect(d.writable); + }); } toHaveValueProperty(property, value) { - this.__expect(this.target !== undefined && this.target !== null); - let d = Object.getOwnPropertyDescriptor(this.target, property); - this.__expect(d !== undefined); + this.__expect(this.target !== undefined && this.target !== null); + let d = Object.getOwnPropertyDescriptor(this.target, property); + this.__expect(d !== undefined); - this.__doMatcher(() => { - this.__expect(d.value !== undefined); - if (value !== undefined) - this.__expect(deepEquals(value, d.value)); - }); + this.__doMatcher(() => { + this.__expect(d.value !== undefined); + if (value !== undefined) this.__expect(deepEquals(value, d.value)); + }); } toHaveGetterProperty(property) { - this.__expect(this.target !== undefined && this.target !== null); - let d = Object.getOwnPropertyDescriptor(this.target, property); - this.__expect(d !== undefined); + this.__expect(this.target !== undefined && this.target !== null); + let d = Object.getOwnPropertyDescriptor(this.target, property); + this.__expect(d !== undefined); - this.__doMatcher(() => { - this.__expect(d.get !== undefined); - }); + this.__doMatcher(() => { + this.__expect(d.get !== undefined); + }); } toHaveSetterProperty(property) { - this.__expect(this.target !== undefined && this.target !== null); - let d = Object.getOwnPropertyDescriptor(this.target, property); - this.__expect(d !== undefined); + this.__expect(this.target !== undefined && this.target !== null); + let d = Object.getOwnPropertyDescriptor(this.target, property); + this.__expect(d !== undefined); - this.__doMatcher(() => { - this.__expect(d.set !== undefined); - }); + this.__doMatcher(() => { + this.__expect(d.set !== undefined); + }); } __doMatcher(matcher) { - if (!this.inverted) { - matcher(); - } else { - let threw = false; - try { - matcher(); - } catch (e) { - if (e.name === "ExpectationError") - threw = true; - } - if (!threw) - throw new ExpectationError(); + if (!this.inverted) { + matcher(); + } else { + let threw = false; + try { + matcher(); + } catch (e) { + if (e.name === "ExpectationError") threw = true; } + if (!threw) throw new ExpectationError(); + } } __expect(value) { - if (value !== true) - throw new ExpectationError(); + if (value !== true) throw new ExpectationError(); } -} + } -expect = value => new Expector(value); + expect = value => new Expector(value); -// describe is able to lump test results inside of it by using this context -// variable. Top level tests have the default suite message -const defaultSuiteMessage = "__$$TOP_LEVEL$$__"; -let suiteMessage = defaultSuiteMessage; + // describe is able to lump test results inside of it by using this context + // variable. Top level tests have the default suite message + const defaultSuiteMessage = "__$$TOP_LEVEL$$__"; + let suiteMessage = defaultSuiteMessage; -describe = (message, callback) => { + describe = (message, callback) => { suiteMessage = message; callback(); suiteMessage = defaultSuiteMessage; -} + }; -test = (message, callback) => { - if (!__TestResults__[suiteMessage]) - __TestResults__[suiteMessage] = {}; + test = (message, callback) => { + if (!__TestResults__[suiteMessage]) __TestResults__[suiteMessage] = {}; const suite = __TestResults__[suiteMessage]; if (suite[message]) { - suite[message] = { - result: "fail" - }; - return; + suite[message] = { + result: "fail", + }; + return; } try { - callback(); - suite[message] = { - result: "pass", - }; + callback(); + suite[message] = { + result: "pass", + }; } catch (e) { - suite[message] = { - result: "fail", - }; + suite[message] = { + result: "fail", + }; } -} + }; -test.skip = (message, callback) => { + test.skip = (message, callback) => { if (typeof callback !== "function") - throw new Error("test.skip has invalid second argument (must be a function)"); + throw new Error("test.skip has invalid second argument (must be a function)"); - if (!__TestResults__[suiteMessage]) - __TestResults__[suiteMessage] = {}; + if (!__TestResults__[suiteMessage]) __TestResults__[suiteMessage] = {}; const suite = __TestResults__[suiteMessage]; - if (suite[message]) - throw new Error("Duplicate test name: " + message); + if (suite[message]) throw new Error("Duplicate test name: " + message); suite[message] = { - result: "skip", - } -} - + result: "skip", + }; + }; })(); diff --git a/Libraries/LibJS/Tests/throw-basic.js b/Libraries/LibJS/Tests/throw-basic.js index 2c8190480e..733b14f80a 100644 --- a/Libraries/LibJS/Tests/throw-basic.js +++ b/Libraries/LibJS/Tests/throw-basic.js @@ -1,30 +1,30 @@ load("test-common.js"); try { - throw 1; - assertNotReached(); + throw 1; + assertNotReached(); } catch (e) { - assert(e === 1); + assert(e === 1); } try { - throw [99]; - assertNotReached(); + throw [99]; + assertNotReached(); } catch (e) { - assert(typeof e === "object"); - assert(e.length === 1); + assert(typeof e === "object"); + assert(e.length === 1); } function foo() { - throw "hello"; - assertNotReached(); + throw "hello"; + assertNotReached(); } try { - foo(); - assertNotReached(); + foo(); + assertNotReached(); } catch (e) { - assert(e === "hello"); + assert(e === "hello"); } console.log("PASS"); diff --git a/Libraries/LibJS/Tests/to-number-basic.js b/Libraries/LibJS/Tests/to-number-basic.js index f4659bea0d..91a1f00b10 100644 --- a/Libraries/LibJS/Tests/to-number-basic.js +++ b/Libraries/LibJS/Tests/to-number-basic.js @@ -1,62 +1,62 @@ load("test-common.js"); try { - assert(+false === 0); - assert(-false === 0); - assert(+true === 1); - assert(-true === -1); - assert(+null === 0); - assert(-null === 0); - assert(+[] === 0); - assert(-[] === 0); - assert(+[,] === 0); - assert(-[,] === 0); - assert(+[null] === 0); - assert(-[null] === 0); - assert(+[undefined] === 0); - assert(-[undefined] === 0); - assert(+[[[[[]]]]] === 0); - assert(-[[[[[]]]]] === 0); - assert(+[[[[[42]]]]] === 42); - assert(-[[[[[42]]]]] === -42); - assert(+"" === 0); - assert(-"" === 0); - assert(+"42" === 42); - assert(-"42" === -42); - assert(+42 === 42); - assert(-42 === -42); - assert(+1.23 === 1.23); - assert(-1.23 === -1.23); - assert(+"1.23" === 1.23) - assert(-"1.23" === -1.23) - assert(+"Infinity" === Infinity); - assert(+"+Infinity" === Infinity); - assert(+"-Infinity" === -Infinity); - assert(-"Infinity" === -Infinity); - assert(-"+Infinity" === -Infinity); - assert(-"-Infinity" === Infinity); - assert(+" \r \t \n " === 0); - assert(+" \n \t Infinity \r " === Infinity); - assert(+"\r \n1.23 \t\t\t \n" === 1.23); + assert(+false === 0); + assert(-false === 0); + assert(+true === 1); + assert(-true === -1); + assert(+null === 0); + assert(-null === 0); + assert(+[] === 0); + assert(-[] === 0); + assert(+[,] === 0); + assert(-[,] === 0); + assert(+[null] === 0); + assert(-[null] === 0); + assert(+[undefined] === 0); + assert(-[undefined] === 0); + assert(+[[[[[]]]]] === 0); + assert(-[[[[[]]]]] === 0); + assert(+[[[[[42]]]]] === 42); + assert(-[[[[[42]]]]] === -42); + assert(+"" === 0); + assert(-"" === 0); + assert(+"42" === 42); + assert(-"42" === -42); + assert(+42 === 42); + assert(-42 === -42); + assert(+1.23 === 1.23); + assert(-1.23 === -1.23); + assert(+"1.23" === 1.23); + assert(-"1.23" === -1.23); + assert(+"Infinity" === Infinity); + assert(+"+Infinity" === Infinity); + assert(+"-Infinity" === -Infinity); + assert(-"Infinity" === -Infinity); + assert(-"+Infinity" === -Infinity); + assert(-"-Infinity" === Infinity); + assert(+" \r \t \n " === 0); + assert(+" \n \t Infinity \r " === Infinity); + assert(+"\r \n1.23 \t\t\t \n" === 1.23); - assert(isNaN(+undefined)); - assert(isNaN(-undefined)); - assert(isNaN(+{})); - assert(isNaN(-{})); - assert(isNaN(+{ a: 1 })); - assert(isNaN(-{ a: 1 })); - assert(isNaN(+[, , ,])); - assert(isNaN(-[, , ,])); - assert(isNaN(+[undefined, undefined])); - assert(isNaN(-[undefined, undefined])); - assert(isNaN(+[1, 2, 3])); - assert(isNaN(-[1, 2, 3])); - assert(isNaN(+[[[["foo"]]]])); - assert(isNaN(-[[[["foo"]]]])); - assert(isNaN(+"foo")); - assert(isNaN(-"foo")); + assert(isNaN(+undefined)); + assert(isNaN(-undefined)); + assert(isNaN(+{})); + assert(isNaN(-{})); + assert(isNaN(+{ a: 1 })); + assert(isNaN(-{ a: 1 })); + assert(isNaN(+[, , ,])); + assert(isNaN(-[, , ,])); + assert(isNaN(+[undefined, undefined])); + assert(isNaN(-[undefined, undefined])); + assert(isNaN(+[1, 2, 3])); + assert(isNaN(-[1, 2, 3])); + assert(isNaN(+[[[["foo"]]]])); + assert(isNaN(-[[[["foo"]]]])); + assert(isNaN(+"foo")); + assert(isNaN(-"foo")); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/to-number-exception.js b/Libraries/LibJS/Tests/to-number-exception.js index 0deec450d5..3eed7253f6 100644 --- a/Libraries/LibJS/Tests/to-number-exception.js +++ b/Libraries/LibJS/Tests/to-number-exception.js @@ -1,38 +1,54 @@ load("test-common.js"); try { - const message = "oops, Value::to_number() failed"; - const o = { toString() { throw new Error(message); } }; + const message = "oops, Value::to_number() failed"; + const o = { + toString() { + throw new Error(message); + }, + }; - assertThrowsError(() => { - +o; - }, { - error: Error, - message - }); + assertThrowsError( + () => { + +o; + }, + { + error: Error, + message, + } + ); - assertThrowsError(() => { - o - 1; - }, { - error: Error, - message - }); + assertThrowsError( + () => { + o - 1; + }, + { + error: Error, + message, + } + ); - assertThrowsError(() => { - "foo".charAt(o); - }, { - error: Error, - message - }); + assertThrowsError( + () => { + "foo".charAt(o); + }, + { + error: Error, + message, + } + ); - assertThrowsError(() => { - "bar".repeat(o); - }, { - error: Error, - message - }); + assertThrowsError( + () => { + "bar".repeat(o); + }, + { + error: Error, + message, + } + ); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/update-expression-on-member-expression.js b/Libraries/LibJS/Tests/update-expression-on-member-expression.js index 1d199152b2..3ddb8a1869 100644 --- a/Libraries/LibJS/Tests/update-expression-on-member-expression.js +++ b/Libraries/LibJS/Tests/update-expression-on-member-expression.js @@ -1,8 +1,8 @@ test("basic update expression", () => { - var o = {}; - o.f = 1; + var o = {}; + o.f = 1; - expect(o.f++).toBe(1); - expect(++o.f).toBe(3); - expect(++o.missing).toBeNaN(); + expect(o.f++).toBe(1); + expect(++o.f).toBe(3); + expect(++o.missing).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/update-expressions-basic.js b/Libraries/LibJS/Tests/update-expressions-basic.js index a097d52e50..32add75d2e 100644 --- a/Libraries/LibJS/Tests/update-expressions-basic.js +++ b/Libraries/LibJS/Tests/update-expressions-basic.js @@ -1,54 +1,57 @@ load("test-common.js"); try { - assertThrowsError(() => { - ++x; - }, { - error: ReferenceError, - message: "'x' is not defined", - }); + assertThrowsError( + () => { + ++x; + }, + { + error: ReferenceError, + message: "'x' is not defined", + } + ); - var n = 0; - assert(++n === 1); - assert(n === 1); + var n = 0; + assert(++n === 1); + assert(n === 1); - var n = 0; - assert(n++ === 0); - assert(n === 1); + var n = 0; + assert(n++ === 0); + assert(n === 1); - var n = 0; - assert(--n === -1); - assert(n === -1); + var n = 0; + assert(--n === -1); + assert(n === -1); - var n = 0; - assert(n-- === 0); - assert(n === -1); + var n = 0; + assert(n-- === 0); + assert(n === -1); - var a = []; - assert(a++ === 0); - assert(a === 1); + var a = []; + assert(a++ === 0); + assert(a === 1); - var b = true; - assert(b-- === 1); - assert(b === 0); + var b = true; + assert(b-- === 1); + assert(b === 0); - var s = "foo"; - assert(isNaN(++s)); - assert(isNaN(s)); + var s = "foo"; + assert(isNaN(++s)); + assert(isNaN(s)); - var s = "foo"; - assert(isNaN(s++)); - assert(isNaN(s)); + var s = "foo"; + assert(isNaN(s++)); + assert(isNaN(s)); - var s = "foo"; - assert(isNaN(--s)); - assert(isNaN(s)); + var s = "foo"; + assert(isNaN(--s)); + assert(isNaN(s)); - var s = "foo"; - assert(isNaN(s--)); - assert(isNaN(s)); + var s = "foo"; + assert(isNaN(s--)); + assert(isNaN(s)); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/var-multiple-declarator.js b/Libraries/LibJS/Tests/var-multiple-declarator.js index e4cac238c5..0596f4057c 100644 --- a/Libraries/LibJS/Tests/var-multiple-declarator.js +++ b/Libraries/LibJS/Tests/var-multiple-declarator.js @@ -1,11 +1,13 @@ load("test-common.js"); try { - var a = 1, b = 2, c = a + b; - assert(a === 1); - assert(b === 2); - assert(c === 3); - console.log("PASS"); + var a = 1, + b = 2, + c = a + b; + assert(a === 1); + assert(b === 2); + assert(c === 3); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/var-scoping.js b/Libraries/LibJS/Tests/var-scoping.js index 4e88a9de0b..44cb2af741 100644 --- a/Libraries/LibJS/Tests/var-scoping.js +++ b/Libraries/LibJS/Tests/var-scoping.js @@ -1,23 +1,23 @@ load("test-common.js"); try { - function foo() { - i = 3; - assert(i === 3); - var i; - } + function foo() { + i = 3; + assert(i === 3); + var i; + } - foo(); + foo(); - var caught_exception; - try { - j = i; - } catch (e) { - caught_exception = e; - } - assert(caught_exception !== undefined); + var caught_exception; + try { + j = i; + } catch (e) { + caught_exception = e; + } + assert(caught_exception !== undefined); - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/variable-declaration.js b/Libraries/LibJS/Tests/variable-declaration.js index 6adafc7459..7a6c0b85b3 100644 --- a/Libraries/LibJS/Tests/variable-declaration.js +++ b/Libraries/LibJS/Tests/variable-declaration.js @@ -1,25 +1,27 @@ load("test-common.js"); try { + const constantValue = 1; + assertThrowsError( + () => { + constantValue = 2; + }, + { + error: TypeError, + message: "Invalid assignment to const variable", + } + ); + assert(constantValue === 1); - const constantValue = 1; - assertThrowsError(() => { - constantValue = 2; - }, { - error: TypeError, - message: "Invalid assignment to const variable" - }); - assert(constantValue === 1); + // Make sure we can define new constants in inner scopes. + const constantValue2 = 1; + do { + const constantValue2 = 2; + assert(constantValue2 === 2); + } while (false); + assert(constantValue2 === 1); - // Make sure we can define new constants in inner scopes. - const constantValue2 = 1; - do { - const constantValue2 = 2; - assert(constantValue2 === 2); - } while (false); - assert(constantValue2 === 1); - - console.log("PASS"); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); } diff --git a/Libraries/LibJS/Tests/variable-undefined.js b/Libraries/LibJS/Tests/variable-undefined.js index 604ace3ced..c853a3e8c2 100644 --- a/Libraries/LibJS/Tests/variable-undefined.js +++ b/Libraries/LibJS/Tests/variable-undefined.js @@ -1,19 +1,19 @@ load("test-common.js"); function foo(a) { - return a; + return a; } try { - var x = undefined; - assert(x === undefined); - assert(foo(x) === undefined); + var x = undefined; + assert(x === undefined); + assert(foo(x) === undefined); - var o = {}; - o.x = x; - assert(o.x === undefined); - assert(o.x === x); - console.log("PASS"); + var o = {}; + o.x = x; + assert(o.x === undefined); + assert(o.x === x); + console.log("PASS"); } catch (e) { - console.log("FAIL: " + e); + console.log("FAIL: " + e); }