diff --git a/Libraries/LibJS/Tests/.prettierrc b/Libraries/LibJS/Tests/.prettierrc index 24f9031ebc..ea1532270e 100644 --- a/Libraries/LibJS/Tests/.prettierrc +++ b/Libraries/LibJS/Tests/.prettierrc @@ -1,13 +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 + "arrowParens": "avoid", + "bracketSpacing": true, + "endOfLine": "lf", + "insertPragma": false, + "printWidth": 100, + "quoteProps": "as-needed", + "semi": true, + "singleQuote": false, + "tabWidth": 4, + "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 7d10739183..3bef2209ba 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 ba971aa31f..924ff20b91 100644 --- a/Libraries/LibJS/Tests/automatic-semicolon-insertion.js +++ b/Libraries/LibJS/Tests/automatic-semicolon-insertion.js @@ -1,5 +1,5 @@ test("Issue #1829, if-else without braces or semicolons", () => { - const source = `if (1) + const source = `if (1) return 1; else return 0; @@ -14,11 +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 @@ -39,11 +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: @@ -57,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 7216ca4c34..714f6e08ea 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 0fa6e4dd20..9da2d9de37 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.js @@ -1,55 +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 e8e60c23a0..d44eb78e9f 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.of.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.of.js @@ -1,50 +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 778e9fe619..3e0dca3759 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js @@ -1,159 +1,164 @@ 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.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.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); - } - - 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"] - ); - } - - ["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" + { + 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" ); - }, - ["foo", "bar", "baz"] - ); - } - - { - assertVisitsAll( - visit => { - Array.prototype.reduceRight.call( - o, - function (_, value) { - visit(value); - return false; - }, - "initial" + 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" ); - }, - ["baz", "bar", "foo"] - ); - } + } - console.log("PASS"); + { + 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.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); + } + + 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"] + ); + } + + ["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"] + ); + } + + { + assertVisitsAll( + visit => { + Array.prototype.reduceRight.call( + o, + function (_, value) { + visit(value); + return false; + }, + "initial" + ); + }, + ["baz", "bar", "foo"] + ); + } + + 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 55e9a96bd5..4b44972094 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.concat.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.concat.js @@ -1,36 +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 cf71b5ec8a..5de04d8db0 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.every.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.every.js @@ -1,49 +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 0cb58ced9c..80705bbde3 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.fill.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.fill.js @@ -1,23 +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 06c0b754dc..176434b137 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.filter.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.filter.js @@ -1,78 +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 638ff2a5b7..17c46b22b2 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.find.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.find.js @@ -1,54 +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 f2c0e8d01e..1653edb67b 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.findIndex.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.findIndex.js @@ -1,54 +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 beeb929475..7d9d605693 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.forEach.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.forEach.js @@ -1,70 +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 433abe78b0..1a98212716 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 b6c6077d11..51fa66484f 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 52219e1bfe..fc82deb20c 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 91d5e6c025..f5153b8140 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 d04c687df1..344ac2ea86 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.map.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.map.js @@ -1,63 +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 2b1c5d6e41..a4d09a2311 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 722ee62ecc..f739aec463 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 cd0e291d9e..c7afdbfffb 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduce.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduce.js @@ -1,132 +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.reduceRight.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduceRight.js index 6e20d9ea48..8bcc083a1b 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduceRight.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduceRight.js @@ -1,134 +1,134 @@ load("test-common.js"); try { - assert(Array.prototype.reduceRight.length === 1); + assert(Array.prototype.reduceRight.length === 1); - assertThrowsError( - () => { - [1].reduceRight(); - }, - { - error: TypeError, - message: "Array.prototype.reduceRight() requires at least one argument", - } - ); + assertThrowsError( + () => { + [1].reduceRight(); + }, + { + error: TypeError, + message: "Array.prototype.reduceRight() requires at least one argument", + } + ); - assertThrowsError( - () => { - [1].reduceRight(undefined); - }, - { - error: TypeError, - message: "undefined is not a function", - } - ); + assertThrowsError( + () => { + [1].reduceRight(undefined); + }, + { + error: TypeError, + message: "undefined is not a function", + } + ); - assertThrowsError( - () => { - [].reduceRight((a, x) => x); - }, - { - error: TypeError, - message: "Reduce of empty array with no initial value", - } - ); + assertThrowsError( + () => { + [].reduceRight((a, x) => x); + }, + { + error: TypeError, + message: "Reduce of empty array with no initial value", + } + ); - assertThrowsError( - () => { - [, ,].reduceRight((a, x) => x); - }, - { - error: TypeError, - message: "Reduce of empty array with no initial value", - } - ); + assertThrowsError( + () => { + [, ,].reduceRight((a, x) => x); + }, + { + error: TypeError, + message: "Reduce of empty array with no initial value", + } + ); - [1, 2].reduceRight(function () { - assert(this === undefined); - }); + [1, 2].reduceRight(function () { + assert(this === undefined); + }); - var callbackCalled = 0; - var callback = () => { - callbackCalled++; - return true; - }; + var callbackCalled = 0; + var callback = () => { + callbackCalled++; + return true; + }; - assert([1].reduceRight(callback) === 1); - assert(callbackCalled === 0); + assert([1].reduceRight(callback) === 1); + assert(callbackCalled === 0); - assert([1].reduceRight(callback) === 1); - assert(callbackCalled === 0); + assert([1].reduceRight(callback) === 1); + assert(callbackCalled === 0); - callbackCalled = 0; - assert([1, 2, 3].reduceRight(callback) === true); - assert(callbackCalled === 2); + callbackCalled = 0; + assert([1, 2, 3].reduceRight(callback) === true); + assert(callbackCalled === 2); - callbackCalled = 0; - assert([1, 2, 3, ,].reduceRight(callback) === true); - assert(callbackCalled === 2); + callbackCalled = 0; + assert([1, 2, 3, ,].reduceRight(callback) === true); + assert(callbackCalled === 2); - callbackCalled = 0; - assert([, , , 1, , , 10, , 100, , ,].reduceRight(callback) === true); - assert(callbackCalled === 2); + callbackCalled = 0; + assert([, , , 1, , , 10, , 100, , ,].reduceRight(callback) === true); + assert(callbackCalled === 2); - var constantlySad = () => ":^("; - var result = [].reduceRight(constantlySad, ":^)"); - assert(result === ":^)"); + var constantlySad = () => ":^("; + var result = [].reduceRight(constantlySad, ":^)"); + assert(result === ":^)"); - result = [":^0"].reduceRight(constantlySad, ":^)"); - assert(result === ":^("); + result = [":^0"].reduceRight(constantlySad, ":^)"); + assert(result === ":^("); - result = [":^0"].reduceRight(constantlySad); - assert(result === ":^0"); + result = [":^0"].reduceRight(constantlySad); + assert(result === ":^0"); - result = [5, 4, 3, 2, 1].reduceRight((accum, elem) => "" + accum + elem); - assert(result === "12345"); + result = [5, 4, 3, 2, 1].reduceRight((accum, elem) => "" + accum + elem); + assert(result === "12345"); - result = [1, 2, 3, 4, 5, 6].reduceRight((accum, elem) => { - return "" + accum + elem; - }, 100); - assert(result === "100654321"); + result = [1, 2, 3, 4, 5, 6].reduceRight((accum, elem) => { + return "" + accum + elem; + }, 100); + assert(result === "100654321"); - result = [6, 5, 4, 3, 2, 1].reduceRight((accum, elem) => { - return "" + accum + elem; - }, 100); - assert(result === "100123456"); + result = [6, 5, 4, 3, 2, 1].reduceRight((accum, elem) => { + return "" + accum + elem; + }, 100); + assert(result === "100123456"); - var indexes = []; - result = ["foo", 1, true].reduceRight((a, v, i) => { - indexes.push(i); - }); - assert(result === undefined); - assert(indexes.length === 2); - assert(indexes[0] === 1); - assert(indexes[1] === 0); + var indexes = []; + result = ["foo", 1, true].reduceRight((a, v, i) => { + indexes.push(i); + }); + assert(result === undefined); + assert(indexes.length === 2); + assert(indexes[0] === 1); + assert(indexes[1] === 0); - indexes = []; - result = ["foo", 1, true].reduceRight((a, v, i) => { - indexes.push(i); - }, "foo"); - assert(result === undefined); - assert(indexes.length === 3); - assert(indexes[0] === 2); - assert(indexes[1] === 1); - assert(indexes[2] === 0); + indexes = []; + result = ["foo", 1, true].reduceRight((a, v, i) => { + indexes.push(i); + }, "foo"); + assert(result === undefined); + assert(indexes.length === 3); + assert(indexes[0] === 2); + assert(indexes[1] === 1); + assert(indexes[2] === 0); - var mutable = { prop: 0 }; - result = ["foo", 1, true].reduceRight((a, v) => { - a.prop = v; - return a; - }, mutable); - assert(result === mutable); - assert(result.prop === "foo"); + var mutable = { prop: 0 }; + result = ["foo", 1, true].reduceRight((a, v) => { + a.prop = v; + return a; + }, mutable); + assert(result === mutable); + assert(result.prop === "foo"); - var a1 = [1, 2]; - var a2 = null; - a1.reduceRight((a, v, i, t) => { - a2 = t; - }); - assert(a1 === a2); + var a1 = [1, 2]; + var a2 = null; + a1.reduceRight((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 049562395e..16cae9147c 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]; + 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); - array.reverse(); + array.reverse(); - assert(array[0] === 3); - assert(array[1] === 2); - assert(array[2] === 1); + assert(array[0] === 3); + assert(array[1] === 2); + assert(array[2] === 1); - var array_ref = array.reverse(); + var array_ref = array.reverse(); - assert(array_ref[0] === 1); - assert(array_ref[1] === 2); - assert(array_ref[2] === 3); + 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); + assert(array[0] === 1); + assert(array[1] === 2); + assert(array[2] === 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.shift.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js index 7332615431..2b48e7bf20 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 8b6c00670c..ca7d087245 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 === 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(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(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); + 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"); + 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 7fb7fb8467..9c8c095ec9 100644 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.some.js +++ b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.some.js @@ -1,37 +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 ff7173aca0..e140631430 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 f2a650d6b9..fb4e3af0f5 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 3243c0f7e4..e5d19be997 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 d6e1f46144..3bae2736b1 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 d25c2f17fc..c13a9de8d5 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 6ea47cb4cf..1616a4f83d 100644 --- a/Libraries/LibJS/Tests/builtins/Array/array-length-setter.js +++ b/Libraries/LibJS/Tests/builtins/Array/array-length-setter.js @@ -1,51 +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; - 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", - } - ); + a.length = 1; assert(a.length === 1); - }); + assert(a[0] === 1); - console.log("PASS"); + 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"); } 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 6586d69c51..16a041a8e7 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 0b114d329f..0e79dc3740 100644 --- a/Libraries/LibJS/Tests/builtins/Array/array-spread.js +++ b/Libraries/LibJS/Tests/builtins/Array/array-spread.js @@ -1,45 +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.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.js index f0fd70122d..7e517754b7 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.js @@ -1,68 +1,68 @@ describe("correct behavior", () => { - test("basic functionality", () => { - expect(BigInt).toHaveLength(1); - expect(BigInt.name).toBe("BigInt"); - }); + test("basic functionality", () => { + expect(BigInt).toHaveLength(1); + expect(BigInt.name).toBe("BigInt"); + }); - test("constructor with numbers", () => { - expect(BigInt(0)).toBe(0n); - expect(BigInt(1)).toBe(1n); - expect(BigInt(+1)).toBe(1n); - expect(BigInt(-1)).toBe(-1n); - expect(BigInt(123n)).toBe(123n); - }); + test("constructor with numbers", () => { + expect(BigInt(0)).toBe(0n); + expect(BigInt(1)).toBe(1n); + expect(BigInt(+1)).toBe(1n); + expect(BigInt(-1)).toBe(-1n); + expect(BigInt(123n)).toBe(123n); + }); - test("constructor with strings", () => { - expect(BigInt("")).toBe(0n); - expect(BigInt("0")).toBe(0n); - expect(BigInt("1")).toBe(1n); - expect(BigInt("+1")).toBe(1n); - expect(BigInt("-1")).toBe(-1n); - expect(BigInt("-1")).toBe(-1n); - expect(BigInt("42")).toBe(42n); - expect(BigInt(" \n 00100 \n ")).toBe(100n); - expect(BigInt("3323214327642987348732109829832143298746432437532197321")).toBe( - 3323214327642987348732109829832143298746432437532197321n - ); - }); + test("constructor with strings", () => { + expect(BigInt("")).toBe(0n); + expect(BigInt("0")).toBe(0n); + expect(BigInt("1")).toBe(1n); + expect(BigInt("+1")).toBe(1n); + expect(BigInt("-1")).toBe(-1n); + expect(BigInt("-1")).toBe(-1n); + expect(BigInt("42")).toBe(42n); + expect(BigInt(" \n 00100 \n ")).toBe(100n); + expect(BigInt("3323214327642987348732109829832143298746432437532197321")).toBe( + 3323214327642987348732109829832143298746432437532197321n + ); + }); - test("constructor with objects", () => { - expect(BigInt([])).toBe(0n); - }); + test("constructor with objects", () => { + expect(BigInt([])).toBe(0n); + }); }); describe("errors", () => { - test('cannot be constructed with "new"', () => { - expect(() => { - new BigInt(); - }).toThrowWithMessage(TypeError, "BigInt is not a constructor"); - }); - - test("invalid arguments", () => { - expect(() => { - BigInt(null); - }).toThrowWithMessage(TypeError, "Cannot convert null to BigInt"); - - expect(() => { - BigInt(undefined); - }).toThrowWithMessage(TypeError, "Cannot convert undefined to BigInt"); - - expect(() => { - BigInt(Symbol()); - }).toThrowWithMessage(TypeError, "Cannot convert symbol to BigInt"); - - ["foo", "123n", "1+1", {}, function () {}].forEach(value => { - expect(() => { - BigInt(value); - }).toThrowWithMessage(SyntaxError, `Invalid value for BigInt: ${value}`); + test('cannot be constructed with "new"', () => { + expect(() => { + new BigInt(); + }).toThrowWithMessage(TypeError, "BigInt is not a constructor"); }); - }); - test("invalid numeric arguments", () => { - [1.23, Infinity, -Infinity, NaN].forEach(value => { - expect(() => { - BigInt(value); - }).toThrowWithMessage(RangeError, "BigInt argument must be an integer"); + test("invalid arguments", () => { + expect(() => { + BigInt(null); + }).toThrowWithMessage(TypeError, "Cannot convert null to BigInt"); + + expect(() => { + BigInt(undefined); + }).toThrowWithMessage(TypeError, "Cannot convert undefined to BigInt"); + + expect(() => { + BigInt(Symbol()); + }).toThrowWithMessage(TypeError, "Cannot convert symbol to BigInt"); + + ["foo", "123n", "1+1", {}, function () {}].forEach(value => { + expect(() => { + BigInt(value); + }).toThrowWithMessage(SyntaxError, `Invalid value for BigInt: ${value}`); + }); + }); + + test("invalid numeric arguments", () => { + [1.23, Infinity, -Infinity, NaN].forEach(value => { + expect(() => { + BigInt(value); + }).toThrowWithMessage(RangeError, "BigInt argument must be an integer"); + }); }); - }); }); diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js index b257edab30..1c111c516d 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js @@ -1,10 +1,10 @@ test("basic functionality", () => { - expect(BigInt.prototype.toLocaleString).toHaveLength(0); - expect(BigInt(123).toLocaleString()).toBe("123"); + expect(BigInt.prototype.toLocaleString).toHaveLength(0); + expect(BigInt(123).toLocaleString()).toBe("123"); }); test("calling with non-BigInt |this|", () => { - expect(() => { - BigInt.prototype.toLocaleString.call("foo"); - }).toThrowWithMessage(TypeError, "Not a BigInt object"); + expect(() => { + BigInt.prototype.toLocaleString.call("foo"); + }).toThrowWithMessage(TypeError, "Not a BigInt object"); }); diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js index d75940234a..040dec60d9 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js @@ -1,10 +1,10 @@ test("basic functionality", () => { - expect(BigInt.prototype.toString).toHaveLength(0); - expect(BigInt(123).toString()).toBe("123"); + expect(BigInt.prototype.toString).toHaveLength(0); + expect(BigInt(123).toString()).toBe("123"); }); test("calling with non-BigInt |this|", () => { - expect(() => { - BigInt.prototype.toString.call("foo"); - }).toThrowWithMessage(TypeError, "Not a BigInt object"); + expect(() => { + BigInt.prototype.toString.call("foo"); + }).toThrowWithMessage(TypeError, "Not a BigInt object"); }); diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js index 2453de327d..d30a81f824 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js @@ -1,12 +1,12 @@ test("basic functionality", () => { - expect(BigInt.prototype.valueOf).toHaveLength(0); - expect(typeof BigInt(123).valueOf()).toBe("bigint"); - // FIXME: Uncomment once we support Object() with argument - // expect(typeof Object(123n).valueOf()).toBe("bigint"); + expect(BigInt.prototype.valueOf).toHaveLength(0); + expect(typeof BigInt(123).valueOf()).toBe("bigint"); + // FIXME: Uncomment once we support Object() with argument + // expect(typeof Object(123n).valueOf()).toBe("bigint"); }); test("calling with non-BigInt |this|", () => { - expect(() => { - BigInt.prototype.valueOf.call("foo"); - }).toThrowWithMessage(TypeError, "Not a BigInt object"); + expect(() => { + BigInt.prototype.valueOf.call("foo"); + }).toThrowWithMessage(TypeError, "Not a BigInt object"); }); diff --git a/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js b/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js index c32681792f..3092bef41c 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js @@ -1,80 +1,80 @@ describe("correct behavior", () => { - test("typeof bigint", () => { - expect(typeof 1n).toBe("bigint"); - }); + test("typeof bigint", () => { + expect(typeof 1n).toBe("bigint"); + }); - test("bigint string coersion", () => { - expect("" + 123n).toBe("123"); - }); + test("bigint string coersion", () => { + expect("" + 123n).toBe("123"); + }); - test("arithmetic operators", () => { - let bigint = 123n; - expect(-bigint).toBe(-123n); + test("arithmetic operators", () => { + let bigint = 123n; + expect(-bigint).toBe(-123n); - expect(12n + 34n).toBe(46n); - expect(12n - 34n).toBe(-22n); - expect(8n * 12n).toBe(96n); - expect(123n / 10n).toBe(12n); - expect(2n ** 3n).toBe(8n); - expect(5n % 3n).toBe(2n); - expect( - 45977665298704210987n + - (714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n - ).toBe(199365500239020623962n); - }); + expect(12n + 34n).toBe(46n); + expect(12n - 34n).toBe(-22n); + expect(8n * 12n).toBe(96n); + expect(123n / 10n).toBe(12n); + expect(2n ** 3n).toBe(8n); + expect(5n % 3n).toBe(2n); + expect( + 45977665298704210987n + + (714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n + ).toBe(199365500239020623962n); + }); - test("bitwise operators", () => { - expect(12n & 5n).toBe(4n); - expect(1n | 2n).toBe(3n); - expect(5n ^ 3n).toBe(6n); - expect(~1n).toBe(-2n); - }); + test("bitwise operators", () => { + expect(12n & 5n).toBe(4n); + expect(1n | 2n).toBe(3n); + expect(5n ^ 3n).toBe(6n); + expect(~1n).toBe(-2n); + }); - test("increment operators", () => { - let bigint = 1n; - expect(bigint++).toBe(1n); - expect(bigint).toBe(2n); - expect(bigint--).toBe(2n); - expect(bigint).toBe(1n); - expect(++bigint).toBe(2n); - expect(bigint).toBe(2n); - expect(--bigint).toBe(1n); - expect(bigint).toBe(1n); - }); + test("increment operators", () => { + let bigint = 1n; + expect(bigint++).toBe(1n); + expect(bigint).toBe(2n); + expect(bigint--).toBe(2n); + expect(bigint).toBe(1n); + expect(++bigint).toBe(2n); + expect(bigint).toBe(2n); + expect(--bigint).toBe(1n); + expect(bigint).toBe(1n); + }); - test("weak equality operators", () => { - expect(1n == 1n).toBeTrue(); - expect(1n == 1).toBeTrue(); - expect(1 == 1n).toBeTrue(); - expect(1n == 1.23).toBeFalse(); - expect(1.23 == 1n).toBeFalse(); + test("weak equality operators", () => { + expect(1n == 1n).toBeTrue(); + expect(1n == 1).toBeTrue(); + expect(1 == 1n).toBeTrue(); + expect(1n == 1.23).toBeFalse(); + expect(1.23 == 1n).toBeFalse(); - expect(1n != 1n).toBeFalse(); - expect(1n != 1).toBeFalse(); - expect(1 != 1n).toBeFalse(); - expect(1n != 1.23).toBeTrue(); - expect(1.23 != 1n).toBeTrue(); - }); + expect(1n != 1n).toBeFalse(); + expect(1n != 1).toBeFalse(); + expect(1 != 1n).toBeFalse(); + expect(1n != 1.23).toBeTrue(); + expect(1.23 != 1n).toBeTrue(); + }); - test("strong equality operators", () => { - expect(1n === 1n).toBeTrue(); - expect(1n === 1).toBeFalse(); - expect(1 === 1n).toBeFalse(); - expect(1n === 1.23).toBeFalse(); - expect(1.23 === 1n).toBeFalse(); + test("strong equality operators", () => { + expect(1n === 1n).toBeTrue(); + expect(1n === 1).toBeFalse(); + expect(1 === 1n).toBeFalse(); + expect(1n === 1.23).toBeFalse(); + expect(1.23 === 1n).toBeFalse(); - expect(1n !== 1n).toBeFalse(); - expect(1n !== 1).toBeTrue(); - expect(1 !== 1n).toBeTrue(); - expect(1n !== 1.23).toBeTrue(); - expect(1.23 !== 1n).toBeTrue(); - }); + expect(1n !== 1n).toBeFalse(); + expect(1n !== 1).toBeTrue(); + expect(1 !== 1n).toBeTrue(); + expect(1n !== 1.23).toBeTrue(); + expect(1.23 !== 1n).toBeTrue(); + }); }); describe("errors", () => { - test("conversion to number", () => { - expect(() => { - +123n; - }).toThrowWithMessage(TypeError, "Cannot convert BigInt to number"); - }); + test("conversion to number", () => { + expect(() => { + +123n; + }).toThrowWithMessage(TypeError, "Cannot convert BigInt to number"); + }); }); 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 aa3eaa301d..de80b92b3a 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/bigint-number-mix-errors.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/bigint-number-mix-errors.js @@ -1,31 +1,31 @@ const doTest = (operatorName, executeOperation) => { - [1, null, undefined].forEach(value => { - const messageSuffix = operatorName === "unsigned right-shift" ? "" : " and other type"; + [1, null, undefined].forEach(value => { + const messageSuffix = operatorName === "unsigned right-shift" ? "" : " and other type"; - expect(() => { - executeOperation(1n, value); - }).toThrowWithMessage( - TypeError, - `Cannot use ${operatorName} operator with BigInt${messageSuffix}` - ); - }); + expect(() => { + executeOperation(1n, value); + }).toThrowWithMessage( + TypeError, + `Cannot use ${operatorName} operator with BigInt${messageSuffix}` + ); + }); }; [ - ["addition", (a, b) => a + b], - ["subtraction", (a, b) => a - b], - ["multiplication", (a, b) => a * b], - ["division", (a, b) => a / b], - ["modulo", (a, b) => a % b], - ["exponentiation", (a, b) => a ** b], - ["bitwise OR", (a, b) => a | b], - ["bitwise AND", (a, b) => a & b], - ["bitwise XOR", (a, b) => a ^ b], - ["left-shift", (a, b) => a << b], - ["right-shift", (a, b) => a >> b], - ["unsigned right-shift", (a, b) => a >>> b], + ["addition", (a, b) => a + b], + ["subtraction", (a, b) => a - b], + ["multiplication", (a, b) => a * b], + ["division", (a, b) => a / b], + ["modulo", (a, b) => a % b], + ["exponentiation", (a, b) => a ** b], + ["bitwise OR", (a, b) => a | b], + ["bitwise AND", (a, b) => a & b], + ["bitwise XOR", (a, b) => a ^ b], + ["left-shift", (a, b) => a << b], + ["right-shift", (a, b) => a >> b], + ["unsigned right-shift", (a, b) => a >>> b], ].forEach(testCase => { - test(`using ${testCase[0]} operator with BigInt and other type`, () => { - doTest(testCase[0], testCase[1]); - }); + test(`using ${testCase[0]} operator with BigInt and other type`, () => { + doTest(testCase[0], testCase[1]); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js index 944cf1d79c..a2cf07b998 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 dd5a4e6abd..d818d91edb 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).not.toHaveProperty("length"); + 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 8e652e5851..506b23feac 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 82515e6a19..d510523c5b 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 2d50f22c88..3934fb5142 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 323ac46c8d..46c1b6d8cd 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 20d1957aa8..647e43a997 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 65e15776b6..534efeeee5 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 c495f78f4b..3748e835cf 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 fe69137273..7e562288f2 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 c10b3f8c6e..90c686f729 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 b862339916..5b87b8251d 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 0bd5efa5be..7d52866ce7 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 09b2fd3000..df30881c9a 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 9956dec489..b9ada6fcc9 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 11b609c7ba..a452bd7a88 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 cc4e0a5623..acfcb039fb 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"); + expect(Error.prototype).not.toHaveProperty("length"); - var changedInstance = new Error(""); - changedInstance.name = "NewCustomError"; - expect(changedInstance.name).toBe("NewCustomError"); + var changedInstance = new Error(""); + changedInstance.name = "NewCustomError"; + expect(changedInstance.name).toBe("NewCustomError"); - var normalInstance = new Error(""); - expect(normalInstance.name).toBe("Error"); + 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 c09570fbe2..b5d2f7dceb 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 6f239f2a3e..2076968ae1 100644 --- a/Libraries/LibJS/Tests/builtins/Function/Function.js +++ b/Libraries/LibJS/Tests/builtins/Function/Function.js @@ -1,49 +1,51 @@ 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()()).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); + 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 a09d166ce7..1c57e4a657 100644 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js +++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js @@ -1,51 +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 d6189e849e..1bd5269f1d 100644 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js +++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js @@ -1,149 +1,149 @@ describe("basic behavior", () => { - test("basic binding", () => { - expect(Function.prototype.bind).toHaveLength(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)).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); - }); + 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; - } - - 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; + function identity() { + return this; } - expect(strictIdentity.bind()()).toBeUndefined(); - expect(strictIdentity.bind(null)()).toBeNull(); - expect(strictIdentity.bind(undefined)()).toBeUndefined(); - }); + 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); - 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); - }); + function Foo() { + expect(identity.bind()()).toBe(globalThis); + expect(identity.bind(this)()).toBe(this); + } + new Foo(); + }); - test("bound functions retain |this| values passed to them", () => { - var obj = { foo: "bar" }; - expect(identity.bind(obj)()).toBe(obj); - }); + test("does not capture global object as |this| if |this| is null or undefined in strict mode", () => { + "use strict"; - test("bound |this| cannot be changed after being set", () => { - expect(identity.bind("foo").bind(123)()).toBeInstanceOf(String); - }); + function strictIdentity() { + return this; + } - test("arrow functions cannot be bound", () => { - expect((() => this).bind("foo")()).toBe(globalThis); - }); + 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); + }); }); 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 e7c2e4e8e1..136f69b2bd 100644 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js +++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js @@ -1,53 +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 66bddb9867..a8ed197930 100644 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js @@ -1,17 +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 78c1020a7e..0c88544f7f 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 cbd810352b..4044e0200a 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js @@ -1,9 +1,11 @@ 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 4f21c11728..7f82392666 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 ddab27212e..3c2c8e3161 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js @@ -1,30 +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 805d49fc61..eb4f4c85e8 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js @@ -1,11 +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 007e558ef9..156edffee7 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js @@ -1,38 +1,38 @@ test("basic functionality", () => { - let o = { - var1: "foo", - var2: 42, - arr: [ - 1, - 2, - { - nested: { - hello: "world", + let o = { + var1: "foo", + var2: 42, + arr: [ + 1, + 2, + { + nested: { + hello: "world", + }, + get x() { + return 10; + }, + }, + ], + obj: { + subarr: [3], }, - 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 251f033d69..75873367bf 100644 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js +++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js @@ -1,20 +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": { @@ -27,10 +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": { @@ -43,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 912053b94c..1e5c174312 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("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("length", () => { + expect(JSON.stringify).toHaveLength(3); }); - }); - 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("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"}'); + }); }); 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 c58b901c67..f8c75c269b 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 1bf4b526b4..a43482c28f 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 9e91b15eff..e7705e1e2e 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 13d9bc8ccc..84502b9420 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 a9bf482708..1403f207cf 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 75eb0b71d6..a77ed22322 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 9a49226513..93e35babca 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 f39e8736e4..e80f9f023e 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 39b04d25f6..8186bc4199 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 ac35ccec53..d7111be916 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 6efde6278a..791eb8730a 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.63212); - 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 5f95ea559f..f1420fe202 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 908cd7ccff..6b15c29b31 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 5632e4490e..f99a39cc9c 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 320728f636..fedfcabe27 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 124e48e055..036060b238 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 b7e3d9f892..a1e8a6eb72 100644 --- a/Libraries/LibJS/Tests/builtins/Math/Math.sign.js +++ b/Libraries/LibJS/Tests/builtins/Math/Math.sign.js @@ -1,36 +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(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 6f179f0e1b..f5434d94c7 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 3e218992f0..1e7b2115e0 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 5eb0906349..ef1f32f163 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 3fd2530673..baf8418d1e 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 1372eb5135..9c496238b9 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 586469e046..2958821546 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 d9ecfc4638..19a23c0292 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 a586a4ab5f..ff0bc9370c 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 238f1b6430..6a7df463df 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 b6f982a991..3bba1682a6 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 d9ff9a911b..7fd7067449 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 f1fb4c41ae..89de9ff0d9 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/Number/Number.prototype.js b/Libraries/LibJS/Tests/builtins/Number/Number.prototype.js index 4c4f68b296..91f2e93c0e 100644 --- a/Libraries/LibJS/Tests/builtins/Number/Number.prototype.js +++ b/Libraries/LibJS/Tests/builtins/Number/Number.prototype.js @@ -1,4 +1,4 @@ test("basic functionality", () => { - expect(typeof Number.prototype).toBe("object"); - expect(Number.prototype.valueOf()).toBe(0); + expect(typeof Number.prototype).toBe("object"); + expect(Number.prototype.valueOf()).toBe(0); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js b/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js index 2b1b78f6b9..7b44e0810e 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js @@ -1,137 +1,143 @@ 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); - }); - - 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; - }, + expect(o).not.toHaveConfigurableProperty("foo"); + expect(o).not.toHaveEnumerableProperty("foo"); + expect(o).not.toHaveWritableProperty("foo"); + expect(o).toHaveValueProperty("foo", 1); }); - o.foo = 10; - expect(o.foo).toBe(12); - o.foo = 20; - expect(o.foo).toBe(22); + test("array index getter", () => { + let o = {}; + Object.defineProperty(o, 2, { + get() { + return 10; + }, + }); + expect(o[2]).toBe(10); + }); - Object.defineProperty(o, "foo", { configurable: true, value: 4 }); + test("configurable property", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: "hi", writable: true, enumerable: true }); - expect(o.foo).toBe(4); - expect((o.foo = 5)).toBe(5); - expect((o.foo = 4)).toBe(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); + }); }); 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'"); - }); - - 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", { value: 2, writable: false, enumerable: true }); + }).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'"); - }); + 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'" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.entries.js b/Libraries/LibJS/Tests/builtins/Object/Object.entries.js index 2a48d6468a..0296074072 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.entries.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.entries.js @@ -1,55 +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("entries with object", () => { - let entries = Object.entries({ 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("ignores non-enumerable properties", () => { - let obj = { foo: 1 }; - Object.defineProperty(obj, "getFoo", { - value: function () { - return this.foo; - }, + 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 }); + + 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("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]]); }); - 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 46dec2a485..a1783add2c 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 9c319fced3..69ab0685df 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 23d08332ea..8679efc7dc 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))).toBeNull(); + 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 c4effe6807..fcad3484da 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 5fad4bde4b..b426114f20 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 3134ff324d..3ff78623da 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).not.toHaveProperty("length"); + 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 2c2e163fe3..ae7847a424 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.keys.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.keys.js @@ -1,46 +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("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("ignores non-enumerable properties", () => { - let obj = { foo: 1 }; - Object.defineProperty(obj, "getFoo", { - value: function () { - return this.foo; - }, + 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("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"]); }); - 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 e063dedd65..776fc81d3f 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 2fe5e51fb3..50e4935c75 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 ec14384baa..11063f42ec 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 e04787de3f..eab7093b3b 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 082545c9de..b64cb099e4 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js @@ -1,35 +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 e1a1a29cfc..95001ed3f6 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 33ee035bb5..69a7b24ab3 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 8ae5f68af2..ba6867a34a 100644 --- a/Libraries/LibJS/Tests/builtins/Object/Object.values.js +++ b/Libraries/LibJS/Tests/builtins/Object/Object.values.js @@ -1,46 +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("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("ignores non-enumerable properties", () => { - let obj = { foo: 1 }; - Object.defineProperty(obj, "getFoo", { - value: function () { - return this.foo; - }, + 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("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]); }); - 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 4c2664e927..0e59d4f473 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-apply.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-apply.js @@ -1,36 +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 834dc8abc3..73a63346a3 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-construct.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-construct.js @@ -1,72 +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 c5fffa3239..2044ea8084 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js @@ -1,133 +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("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("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); }); - Object.defineProperty(p, "foo", { configurable: true, writable: true, value: 10 }); - }); + 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("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", { configurable: true, writable: true, value: 10 }); }); - 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"); + 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: 20, - enumerable: true, - configurable: false, - writable: 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"); }); - 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"); - }); - - 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, "Object's [[DefineProperty]] method returned false"); }); - 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-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-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, "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, "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 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 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, "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, "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" - ); - }); + 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" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js index 2ec4ae4a28..26ef993789 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js @@ -1,58 +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("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("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(); }); - delete p.foo; - }); + 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("conditional deletion", () => { - o = { foo: 1, bar: 2 }; - p = new Proxy(o, { - deleteProperty(target, property) { - if (property === "foo") { - delete target[property]; - return true; - } - return false; - }, + delete p.foo; }); - expect(delete p.foo).toBeTrue(); - expect(delete p.bar).toBeFalse(); + 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(o.foo).toBeUndefined(); - expect(o.bar).toBe(2); - }); + expect(delete p.foo).toBeTrue(); + expect(delete p.bar).toBeFalse(); + + 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; - }, - }); + 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" - ); - }); + 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 02505c9d49..0bae932340 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-get.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-get.js @@ -1,82 +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("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("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(); }); - p.foo; - }); + 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("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]; - }, + p.foo; }); - expect(p.foo).toBe(1); - expect(p.bar).toBe(2); - expect(p.baz).toBe(3); - expect(p.qux).toBe(3); - expect(p.test).toBeUndefined(); - }); + 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(); + }); }); 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; - }, + 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" + ); }); - 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" - ); - }); + 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(_) {} }); - 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(_) {} }); + let p = new Proxy(o, { + get() { + return 8; + }, + }); - 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" + ); }); - - 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 78f7061daa..9b9addf14a 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js @@ -1,212 +1,220 @@ 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("correct arguments supplied to trap", () => { - let o = {}; - let p = new Proxy(o, { - getOwnPropertyDescriptor(target, property) { - expect(target).toBe(o); - expect(property).toBe("foo"); - }, + 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(); }); - Object.getOwnPropertyDescriptor(p, "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"); + }, + }); - test("conditional returned descriptor", () => { - let o = { foo: "bar" }; - Object.defineProperty(o, "baz", { - value: "qux", - enumerable: false, - configurable: true, - writable: false, + Object.getOwnPropertyDescriptor(p, "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 }; - }, + 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"); }); - - 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( - {}, - { + 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, { getOwnPropertyDescriptor() { - return 1; + return undefined; }, - } - ) - ); - }).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 }); + 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, "bar")).toBeUndefined(); + 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, "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); - - let p = new Proxy(o, { - getOwnPropertyDescriptor() { - return undefined; - }, + 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(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("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("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( + 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" + ); }); - 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" - ); - }); + 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 5cce8c6c48..823e1ff392 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getPrototypeOf.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getPrototypeOf.js @@ -1,95 +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); - }); - - test("correct arguments supplied to trap", () => { - let o = {}; - let p = new Proxy(o, { - getPrototypeOf(target) { - expect(target).toBe(o); - return null; - }, + 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); }); - Object.getPrototypeOf(p); - }); + test("correct arguments supplied to trap", () => { + let o = {}; + let p = new Proxy(o, { + getPrototypeOf(target) { + expect(target).toBe(o); + return null; + }, + }); - test("conditional return", () => { - let o = {}; - let p = new Proxy(o, { - getPrototypeOf(target) { - if (target.foo) return { bar: 1 }; - return { bar: 2 }; - }, + Object.getPrototypeOf(p); }); - expect(Object.getPrototypeOf(p).bar).toBe(2); - o.foo = 20; - expect(Object.getPrototypeOf(p).bar).toBe(1); - }); + test("conditional return", () => { + let o = {}; + let p = new Proxy(o, { + getPrototypeOf(target) { + if (target.foo) return { bar: 1 }; + return { bar: 2 }; + }, + }); - 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).bar).toBe(2); + o.foo = 20; + expect(Object.getPrototypeOf(p).bar).toBe(1); }); - expect(Object.getPrototypeOf(p).foo).toBe("bar"); - }); + 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"); + }); }); 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("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("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" + ); }); - expect(() => { - Object.getPrototypeOf(p); - }).toThrowWithMessage( - TypeError, - "Proxy handler's getPrototypeOf trap violates invariant: cannot return a different prototype object for a non-extensible target" - ); - }); + 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" + ); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js index d43ceba970..b9e2df94ee 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js @@ -1,74 +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("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("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(); }); - "foo" in p; - }); + 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("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; - }, + "foo" in p; }); - expect("foo" in p).toBeFalse(); - expect("foo" in p).toBeTrue(); - }); + 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(); + }); }); 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; - }, + 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" + ); }); - 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" - ); - }); + test("cannot return false if the property exists and the target is non-extensible", () => { + let o = {}; + Object.defineProperty(o, "foo", { value: 10, configurable: true }); - test("cannot return false if the property exists and the target is non-extensible", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 10, configurable: true }); + let p = new Proxy(o, { + has() { + return false; + }, + }); - 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" + ); }); - - 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 510eb296da..430b0fde56 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js @@ -1,39 +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("correct arguments supplied to trap", () => { - let o = {}; - let p = new Proxy(o, { - isExtensible(target) { - expect(target).toBe(o); - return true; - }, + 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(); }); - expect(Object.isExtensible(p)).toBeTrue(); - }); + 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(); + }); }); 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; - }, + 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" + ); }); - - 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 43cb6ef0c6..13a960faea 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-preventExtensions.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-preventExtensions.js @@ -1,59 +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("correct arguments supplied to trap", () => { - let o = {}; - p = new Proxy(o, { - preventExtensions(target) { - expect(target).toBe(o); - return true; - }, + 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); }); - Object.preventExtensions(o); - Object.preventExtensions(p); - }); + 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); + }); }); 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"); - }); - - 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, "Object's [[PreventExtensions]] method returned false"); }); - expect(() => { - Object.preventExtensions(p); - }).toThrowWithMessage( - TypeError, - "Proxy handler's preventExtensions trap violates invariant: cannot return true if the target object is extensible" - ); + test("cannot return true if the target is extensible", () => { + let o = {}; + let p = new Proxy(o, { + preventExtensions() { + return true; + }, + }); - Object.preventExtensions(o); - expect(Object.preventExtensions(p)).toBe(p); - }); + 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); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-set.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-set.js index f3cc7a665f..868741181f 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-set.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-set.js @@ -1,82 +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("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("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); }); - p.foo = 10; - }); + 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("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; + }); - p.foo = 10; - expect(p.foo).toBe(10); - p.foo = 10; - expect(p.foo).toBe(20); - p.foo = 10; - expect(p.foo).toBe(10); - }); + 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); + }); }); 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; - }, + 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" + ); }); - 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" - ); - }); + test("cannot return true for a non-configurable accessor property with no setter", () => { + let o = {}; + Object.defineProperty(o, "foo", { get() {} }); - test("cannot return true for a non-configurable accessor property with no setter", () => { - let o = {}; - Object.defineProperty(o, "foo", { get() {} }); + let p = new Proxy(o, { + set() { + return true; + }, + }); - 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" + ); }); - - 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 14e90d0dd9..30909c90f5 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js @@ -1,96 +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); - }); - - 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; - }, + 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); }); - Object.setPrototypeOf(p, theNewProto); - }); + test("correct arguments supplied to trap", () => { + let o = {}; + let theNewProto = { foo: "bar" }; - test("conditional setting", () => { - let o = {}; + let p = new Proxy(o, { + setPrototypeOf(target, newProto) { + expect(target).toBe(o); + expect(newProto).toBe(theNewProto); + return true; + }, + }); - let p = new Proxy(o, { - setPrototypeOf(target, newProto) { - if (target.shouldSet) Object.setPrototypeOf(target, newProto); - return true; - }, + Object.setPrototypeOf(p, theNewProto); }); - 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); - }); + test("conditional setting", () => { + let o = {}; - test("non-extensible targets", () => { - let o = {}; - let proto = {}; - Object.setPrototypeOf(o, proto); - Object.preventExtensions(o); + let p = new Proxy(o, { + setPrototypeOf(target, newProto) { + if (target.shouldSet) Object.setPrototypeOf(target, newProto); + return true; + }, + }); - p = new Proxy(o, { - setPrototypeOf() { - return true; - }, + 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); }); - expect(Object.setPrototypeOf(p, proto)).toBe(p); - expect(Object.getPrototypeOf(p)).toBe(proto); - }); + 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); + }); }); describe("[[SetPrototypeOf]] invariants", () => { - test("cannot return false", () => { - let o = {}; - p = new Proxy(o, { - setPrototypeOf() { - return false; - }, + 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"); }); - expect(() => { - Object.setPrototypeOf(p, {}); - }).toThrowWithMessage(TypeError, "Object's [[SetPrototypeOf]] method returned false"); - }); + test("the argument must match the target's prototype if the target is non-extensible", () => { + let o = {}; + Object.preventExtensions(o); - test("the argument must match the target's prototype if the target is non-extensible", () => { - let o = {}; - Object.preventExtensions(o); + let p = new Proxy(o, { + setPrototypeOf() { + return true; + }, + }); - 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" + ); }); - - 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 3f25cdb96b..67515ae1ee 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js @@ -1,37 +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 06cde6eb5e..7e6a67d16d 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js @@ -1,39 +1,44 @@ 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 412f76f4c2..a14a016ee0 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js @@ -1,72 +1,75 @@ 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"; - } + test("user-defined function with different new target", () => { + function Foo() { + this.name = "foo"; + } - function Bar() { - this.name = "bar"; - } + 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(); - }); + 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 69d8ffc4e2..786d4c0178 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.defineProperty.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.defineProperty.js @@ -1,82 +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 b5df4bfc93..a0dcbbada7 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.deleteProperty.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.deleteProperty.js @@ -1,66 +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 d22322450b..862f0afee1 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 7f00ad8e9d..e343a3f6fc 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getOwnPropertyDescriptor.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getOwnPropertyDescriptor.js @@ -1,41 +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 19f8b833d2..87c9a63e87 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getPrototypeOf.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getPrototypeOf.js @@ -1,37 +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 c374ac6f13..f343daeafa 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 39f31c001f..2f873da66c 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.isExtensible.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.isExtensible.js @@ -1,33 +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 e5707fa66e..b262775f1a 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.ownKeys.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.ownKeys.js @@ -1,48 +1,51 @@ 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 f37ab52739..0055ef7741 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.preventExtensions.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.preventExtensions.js @@ -1,36 +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 2bb3da68a4..2c82f62d72 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); + 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(); + expect(foo.setPropCalled).toBeUndefined(); + expect(bar.setPropCalled).toBeUndefined(); - Reflect.set(bar, "prop", 42); - expect(foo.setPropCalled).toBeUndefined(); - 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(); - }); + 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 86bf927f63..70bbdf9d9c 100644 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.setPrototypeOf.js +++ b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.setPrototypeOf.js @@ -1,57 +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 2a76ee29c9..c6b52fd2e1 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 9457209d5c..687e0929d4 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 367b9affed..3d7d7468b6 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 f3cc6506fa..7747331885 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 d082e91981..7a38877e9e 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 ec83a56efc..14a2230530 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")).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(); + 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 bea486323a..8e2ca2f892 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 fe44a81ce0..a66207e96c 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(String.prototype).toHaveLength(0); - expect(typeof Object.getPrototypeOf("")).toBe("object"); - expect(Object.getPrototypeOf("").valueOf()).toBe(""); + expect(typeof Object.getPrototypeOf("")).toBe("object"); + expect(Object.getPrototypeOf("").valueOf()).toBe(""); - expect(typeof String.prototype).toBe("object"); - expect(String.prototype.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 40bb9cb233..ce69fc3214 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 cecd5a241f..a103084c3a 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 2c588bdbbb..a2f0f0b710 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 9ffd4edc31..8427698509 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 6d54170eb4..2141e0f6f3 100644 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js +++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js @@ -1,17 +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 6687bb4df2..5114da78f9 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 f2b06bcb62..49a9888d7f 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 0be8bfb68b..4c7cbad50a 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 726d33b8e2..418f2da5f8 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 419b68abac..03f463c6e1 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 0ccfd207d4..d60522cad4 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 6d21cbc501..87fb50fa21 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.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()).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 603d88e974..a866276034 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.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js index a38dcbad61..2533f593c7 100644 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js +++ b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js @@ -1,19 +1,19 @@ test("basic functionality", () => { - const s1 = Symbol("foo"); - const s2 = Symbol("foo"); + const s1 = Symbol("foo"); + const s2 = Symbol("foo"); - expect(s1).not.toBe(s2); - expect(s1.description).toBe("foo"); - expect(s2.description).toBe("foo"); + expect(s1).not.toBe(s2); + expect(s1.description).toBe("foo"); + expect(s2.description).toBe("foo"); - s1.description = "bar"; - expect(s1.description).toBe("foo"); + s1.description = "bar"; + expect(s1.description).toBe("foo"); - expect(typeof s1).toBe("symbol"); + expect(typeof s1).toBe("symbol"); }); test("constructing symbol from symbol is an error", () => { - expect(() => { - Symbol(Symbol("foo")); - }).toThrowWithMessage(TypeError, "Cannot convert symbol to string"); + expect(() => { + Symbol(Symbol("foo")); + }).toThrowWithMessage(TypeError, "Cannot convert symbol to string"); }); diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js index a94167b5f1..734b7a2191 100644 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js +++ b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js @@ -1,23 +1,23 @@ describe("correct behavior", () => { - test("basic functionality", () => { - const s1 = Symbol("baz"); - // const s2 = Symbol.for("qux"); + test("basic functionality", () => { + const s1 = Symbol("baz"); + // const s2 = Symbol.for("qux"); - expect(s1.toString()).toBe("Symbol(baz)"); - // expect(s2.toString()).toBe("Symbol(qux)"); - }); + expect(s1.toString()).toBe("Symbol(baz)"); + // expect(s2.toString()).toBe("Symbol(qux)"); + }); }); describe("errors", () => { - test("convert to string", () => { - expect(() => { - Symbol() + ""; - }).toThrowWithMessage(TypeError, "Cannot convert symbol to string"); - }); + test("convert to string", () => { + expect(() => { + Symbol() + ""; + }).toThrowWithMessage(TypeError, "Cannot convert symbol to string"); + }); - test("convert to number", () => { - expect(() => { - Symbol() + 1; - }).toThrowWithMessage(TypeError, "Cannot convert symbol to number"); - }); + test("convert to number", () => { + expect(() => { + Symbol() + 1; + }).toThrowWithMessage(TypeError, "Cannot convert symbol to number"); + }); }); diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.valueOf.js index 84a9188406..0bfbfef912 100644 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.valueOf.js +++ b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.valueOf.js @@ -1,15 +1,15 @@ test("basic functionality", () => { - const local = Symbol("foo"); - // const global = Symbol.for("foo"); - expect(local.valueOf()).toBe(local); - // expect(global.valueOf()).toBe(global); + const local = Symbol("foo"); + // const global = Symbol.for("foo"); + expect(local.valueOf()).toBe(local); + // expect(global.valueOf()).toBe(global); - expect(Symbol.prototype.valueOf.call(local)).toBe(local); - // expect(Symbol.prototype.valueOf.call(global)).toBe(global); + expect(Symbol.prototype.valueOf.call(local)).toBe(local); + // expect(Symbol.prototype.valueOf.call(global)).toBe(global); }); test("|this| must be a symbol", () => { - expect(() => { - Symbol.prototype.valueOf.call("foo"); - }).toThrowWithMessage(TypeError, "Not a Symbol object"); + expect(() => { + Symbol.prototype.valueOf.call("foo"); + }).toThrowWithMessage(TypeError, "Not a Symbol object"); }); diff --git a/Libraries/LibJS/Tests/builtins/functions/isFinite.js b/Libraries/LibJS/Tests/builtins/functions/isFinite.js index fc4ef12092..71f4f70655 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 3ad781a649..188050ef6e 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 63c016535b..20ed2633dd 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], - [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]); - }); + [ + [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-advanced-extends.js b/Libraries/LibJS/Tests/classes/class-advanced-extends.js index 749f65003c..5cbeb90404 100644 --- a/Libraries/LibJS/Tests/classes/class-advanced-extends.js +++ b/Libraries/LibJS/Tests/classes/class-advanced-extends.js @@ -1,35 +1,35 @@ test("extending function", () => { - class A extends function () { - this.foo = 10; - } {} + class A extends function () { + this.foo = 10; + } {} - expect(new A().foo).toBe(10); + expect(new A().foo).toBe(10); }); test("extending null", () => { - class A extends null {} + class A extends null {} - expect(Object.getPrototypeOf(A.prototype)).toBeNull(); + expect(Object.getPrototypeOf(A.prototype)).toBeNull(); - expect(() => { - new A(); - }).toThrowWithMessage(ReferenceError, "|this| has not been initialized"); + expect(() => { + new A(); + }).toThrowWithMessage(ReferenceError, "|this| has not been initialized"); }); test("extending String", () => { - class MyString extends String {} + class MyString extends String {} - const ms = new MyString("abc"); - expect(ms).toBeInstanceOf(MyString); - expect(ms).toBeInstanceOf(String); - expect(ms.charAt(1)).toBe("b"); + const ms = new MyString("abc"); + expect(ms).toBeInstanceOf(MyString); + expect(ms).toBeInstanceOf(String); + expect(ms.charAt(1)).toBe("b"); - class MyString2 extends MyString { - charAt(i) { - return `#${super.charAt(i)}`; + class MyString2 extends MyString { + charAt(i) { + return `#${super.charAt(i)}`; + } } - } - const ms2 = new MyString2("abc"); - expect(ms2.charAt(1)).toBe("#b"); + const ms2 = new MyString2("abc"); + expect(ms2.charAt(1)).toBe("#b"); }); diff --git a/Libraries/LibJS/Tests/classes/class-basic.js b/Libraries/LibJS/Tests/classes/class-basic.js index 844bbe68fc..0fae88c033 100644 --- a/Libraries/LibJS/Tests/classes/class-basic.js +++ b/Libraries/LibJS/Tests/classes/class-basic.js @@ -1,5 +1,5 @@ test("class properties", () => { - class A {} - expect(A.name).toBe("A"); - expect(A).toHaveLength(0); + class A {} + expect(A.name).toBe("A"); + expect(A).toHaveLength(0); }); diff --git a/Libraries/LibJS/Tests/classes/class-constructor.js b/Libraries/LibJS/Tests/classes/class-constructor.js index 367c1e77ea..9800ffabba 100644 --- a/Libraries/LibJS/Tests/classes/class-constructor.js +++ b/Libraries/LibJS/Tests/classes/class-constructor.js @@ -1,67 +1,67 @@ test("property initialization", () => { - class A { - constructor() { - this.x = 3; + class A { + constructor() { + this.x = 3; + } } - } - expect(new A().x).toBe(3); + expect(new A().x).toBe(3); }); test("method initialization", () => { - class A { - constructor() { - this.x = () => 10; + class A { + constructor() { + this.x = () => 10; + } } - } - expect(new A().x()).toBe(10); + expect(new A().x()).toBe(10); }); test("initialize to class method", () => { - class A { - constructor() { - this.x = this.method; + class A { + constructor() { + this.x = this.method; + } + + method() { + return 10; + } } - method() { - return 10; - } - } - - expect(new A().x()).toBe(10); + expect(new A().x()).toBe(10); }); test("constructor length affects class length", () => { - class A { - constructor() {} - } + class A { + constructor() {} + } - expect(A).toHaveLength(0); + expect(A).toHaveLength(0); - class B { - constructor(a, b, c = 2) {} - } + class B { + constructor(a, b, c = 2) {} + } - expect(B).toHaveLength(2); + expect(B).toHaveLength(2); }); test.skip("must be invoked with 'new'", () => { - class A { - constructor() {} - } + class A { + constructor() {} + } - expect(() => { - A(); - }).toThrow(TypeError); // FIXME: Add message when this test works + expect(() => { + A(); + }).toThrow(TypeError); // FIXME: Add message when this test works - expect(() => { - A.prototype.constructor(); - }).toThrow(TypeError); // FIXME: Add message when this test works + expect(() => { + A.prototype.constructor(); + }).toThrow(TypeError); // FIXME: Add message when this test works }); test("implicit constructor", () => { - class A {} + class A {} - expect(new A()).toBeInstanceOf(A); + expect(new A()).toBeInstanceOf(A); }); diff --git a/Libraries/LibJS/Tests/classes/class-errors.js b/Libraries/LibJS/Tests/classes/class-errors.js index acef9ee3c9..93c50829d0 100644 --- a/Libraries/LibJS/Tests/classes/class-errors.js +++ b/Libraries/LibJS/Tests/classes/class-errors.js @@ -1,80 +1,80 @@ describe("non-syntax errors", () => { - test("super reference inside nested-but-same |this| scope with no base class", () => { - expect(` + test("super reference inside nested-but-same |this| scope with no base class", () => { + expect(` class A { foo() { () => { super.bar; } } }`).toEval(); - }); + }); - test("super reference property lookup with no base class", () => { - expect(` + test("super reference property lookup with no base class", () => { + expect(` class A { constructor() { super.foo; } }`).toEval(); - }); + }); }); describe("reference errors", () => { - test("derived class doesn't call super in constructor before using this", () => { - class Parent {} - class Child extends Parent { - constructor() { - this; - } - } + test("derived class doesn't call super in constructor before using this", () => { + class Parent {} + class Child extends Parent { + constructor() { + this; + } + } - expect(() => { - new Child(); - }).toThrowWithMessage(ReferenceError, "|this| has not been initialized"); - }); + expect(() => { + new Child(); + }).toThrowWithMessage(ReferenceError, "|this| has not been initialized"); + }); - test("derived class calls super twice in constructor", () => { - class Parent {} - class Child extends Parent { - constructor() { - super(); - super(); - } - } + test("derived class calls super twice in constructor", () => { + class Parent {} + class Child extends Parent { + constructor() { + super(); + super(); + } + } - expect(() => { - new Child(); - }).toThrowWithMessage(ReferenceError, "|this| is already initialized"); - }); + expect(() => { + new Child(); + }).toThrowWithMessage(ReferenceError, "|this| is already initialized"); + }); }); describe("syntax errors", () => { - test("getter with argument", () => { - expect(` + test("getter with argument", () => { + expect(` class A { get foo(v) { return 0; } }`).not.toEval(); - }); + }); - test("setter with no arguments", () => { - expect(` + test("setter with no arguments", () => { + expect(` class A { set foo() { } }`).not.toEval(); - }); + }); - test("setter with more than one argument", () => { - expect(` + test("setter with more than one argument", () => { + expect(` class A { set foo(bar, baz) { } }`).not.toEval(); - }); + }); - test("super reference inside different |this| scope", () => { - expect(` + test("super reference inside different |this| scope", () => { + expect(` class Parent {} class Child extends Parent { @@ -82,14 +82,14 @@ describe("syntax errors", () => { function f() { super.foo; } } }`).not.toEval(); - }); + }); - test("super reference call with no base class", () => { - expect(` + test("super reference call with no base class", () => { + expect(` class A { constructor() { super(); } }`).not.toEval(); - }); + }); }); diff --git a/Libraries/LibJS/Tests/classes/class-expressions.js b/Libraries/LibJS/Tests/classes/class-expressions.js index 3dbea6d8fc..d714b37f63 100644 --- a/Libraries/LibJS/Tests/classes/class-expressions.js +++ b/Libraries/LibJS/Tests/classes/class-expressions.js @@ -2,68 +2,68 @@ // respects the .prettierignore file! test("basic functionality", () => { - const A = class { - constructor(x) { - this.x = x; - } + const A = class { + constructor(x) { + this.x = x; + } - getX() { - return this.x * 2; - } - }; + getX() { + return this.x * 2; + } + }; - expect(new A(10).getX()).toBe(20); + expect(new A(10).getX()).toBe(20); }); test("inline instantiation", () => { - const a = new class { - constructor() { - this.x = 10; - } + const a = new class { + constructor() { + this.x = 10; + } - getX() { - return this.x * 2; - } - }; + getX() { + return this.x * 2; + } + }; - expect(a.getX()).toBe(20); + expect(a.getX()).toBe(20); }); test("inline instantiation with argument", () => { - const a = new class { - constructor(x) { - this.x = x; - } + const a = new class { + constructor(x) { + this.x = x; + } - getX() { - return this.x * 2; - } - }(10); + getX() { + return this.x * 2; + } + }(10); - expect(a.getX()).toBe(20); + expect(a.getX()).toBe(20); }); test("extending class expressions", () => { - class A extends class { - constructor(x) { - this.x = x; - } - } { - constructor(y) { - super(y); - this.y = y * 2; - } - }; + class A extends class { + constructor(x) { + this.x = x; + } + } { + constructor(y) { + super(y); + this.y = y * 2; + } + }; - const a = new A(10); - expect(a.x).toBe(10); - expect(a.y).toBe(20); + const a = new A(10); + expect(a.x).toBe(10); + expect(a.y).toBe(20); }); test("class expression name", () => { - let A = class {} - expect(A.name).toBe("A"); + let A = class {} + expect(A.name).toBe("A"); - let B = class C {} - expect(B.name).toBe("C"); + let B = class C {} + expect(B.name).toBe("C"); }); diff --git a/Libraries/LibJS/Tests/classes/class-getters.js b/Libraries/LibJS/Tests/classes/class-getters.js index b1cf7ad229..f3ee040994 100644 --- a/Libraries/LibJS/Tests/classes/class-getters.js +++ b/Libraries/LibJS/Tests/classes/class-getters.js @@ -1,68 +1,68 @@ test("basic functionality", () => { - class A { - get x() { - return 10; + class A { + get x() { + return 10; + } } - } - expect(A).not.toHaveProperty("x"); - expect(new A().x).toBe(10); + expect(A).not.toHaveProperty("x"); + expect(new A().x).toBe(10); }); test("name", () => { - class A { - get x() {} - } + class A { + get x() {} + } - const d = Object.getOwnPropertyDescriptor(A.prototype, "x"); - expect(d.get.name).toBe("get x"); + const d = Object.getOwnPropertyDescriptor(A.prototype, "x"); + expect(d.get.name).toBe("get x"); }); test("extended name syntax", () => { - class A { - get "method with space"() { - return 1; + class A { + get "method with space"() { + return 1; + } + + get 12() { + return 2; + } + + get [`he${"llo"}`]() { + return 3; + } } - get 12() { - return 2; - } - - get [`he${"llo"}`]() { - return 3; - } - } - - const a = new A(); - expect(a["method with space"]).toBe(1); - expect(a[12]).toBe(2); - expect(a.hello).toBe(3); + const a = new A(); + expect(a["method with space"]).toBe(1); + expect(a[12]).toBe(2); + expect(a.hello).toBe(3); }); test("inherited getter", () => { - class Parent { - get x() { - return 3; + class Parent { + get x() { + return 3; + } } - } - class Child extends Parent {} + class Child extends Parent {} - expect(Child).not.toHaveProperty("x"); - expect(new Child().x).toBe(3); + expect(Child).not.toHaveProperty("x"); + expect(new Child().x).toBe(3); }); test("inherited getter overriding", () => { - class Parent { - get x() { - return 3; + class Parent { + get x() { + return 3; + } } - } - class Child extends Parent { - get x() { - return 10; + class Child extends Parent { + get x() { + return 10; + } } - } - expect(new Child().x).toBe(10); + expect(new Child().x).toBe(10); }); diff --git a/Libraries/LibJS/Tests/classes/class-inheritance.js b/Libraries/LibJS/Tests/classes/class-inheritance.js index 5fb273ba52..0e6778dbf5 100644 --- a/Libraries/LibJS/Tests/classes/class-inheritance.js +++ b/Libraries/LibJS/Tests/classes/class-inheritance.js @@ -1,133 +1,133 @@ test("method inheritance", () => { - class Parent { - method() { - return 3; + class Parent { + method() { + return 3; + } } - } - class Child extends Parent {} + class Child extends Parent {} - const p = new Parent(); - const c = new Child(); - expect(p.method()).toBe(3); - expect(c.method()).toBe(3); + const p = new Parent(); + const c = new Child(); + expect(p.method()).toBe(3); + expect(c.method()).toBe(3); }); test("method overriding", () => { - class Parent { - method() { - return 3; + class Parent { + method() { + return 3; + } } - } - class Child extends Parent { - method() { - return 10; + class Child extends Parent { + method() { + return 10; + } } - } - const p = new Parent(); - const c = new Child(); - expect(p.method()).toBe(3); - expect(c.method()).toBe(10); + const p = new Parent(); + const c = new Child(); + expect(p.method()).toBe(3); + expect(c.method()).toBe(10); }); test("parent method reference with super", () => { - class Parent { - method() { - return 3; + class Parent { + method() { + return 3; + } } - } - class Child extends Parent { - method() { - return super.method() * 2; + class Child extends Parent { + method() { + return super.method() * 2; + } } - } - const p = new Parent(); - const c = new Child(); - expect(p.method()).toBe(3); - expect(c.method()).toBe(6); + const p = new Parent(); + const c = new Child(); + expect(p.method()).toBe(3); + expect(c.method()).toBe(6); }); test("child class access to parent class initialized properties", () => { - class Parent { - constructor() { - this.x = 3; + class Parent { + constructor() { + this.x = 3; + } } - } - class Child extends Parent {} + class Child extends Parent {} - const p = new Parent(); - const c = new Child(); - expect(p.x).toBe(3); - expect(c.x).toBe(3); + const p = new Parent(); + const c = new Child(); + expect(p.x).toBe(3); + expect(c.x).toBe(3); }); test("child class modification of parent class properties", () => { - class Parent { - constructor() { - this.x = 3; + class Parent { + constructor() { + this.x = 3; + } } - } - class Child extends Parent { - change() { - this.x = 10; + class Child extends Parent { + change() { + this.x = 10; + } } - } - const p = new Parent(); - const c = new Child(); - expect(p.x).toBe(3); - expect(c.x).toBe(3); + const p = new Parent(); + const c = new Child(); + expect(p.x).toBe(3); + expect(c.x).toBe(3); - c.change(); - expect(c.x).toBe(10); + c.change(); + expect(c.x).toBe(10); }); test("inheritance and hasOwnProperty", () => { - class Parent { - constructor() { - this.x = 3; + class Parent { + constructor() { + this.x = 3; + } } - } - class Child extends Parent { - method() { - this.y = 10; + class Child extends Parent { + method() { + this.y = 10; + } } - } - const p = new Parent(); - const c = new Child(); - expect(p.hasOwnProperty("x")).toBeTrue(); - expect(p.hasOwnProperty("y")).toBeFalse(); - expect(c.hasOwnProperty("x")).toBeTrue(); - expect(c.hasOwnProperty("y")).toBeFalse(); + const p = new Parent(); + const c = new Child(); + expect(p.hasOwnProperty("x")).toBeTrue(); + expect(p.hasOwnProperty("y")).toBeFalse(); + expect(c.hasOwnProperty("x")).toBeTrue(); + expect(c.hasOwnProperty("y")).toBeFalse(); - c.method(); - expect(c.hasOwnProperty("x")).toBeTrue(); - expect(c.hasOwnProperty("y")).toBeTrue(); + c.method(); + expect(c.hasOwnProperty("x")).toBeTrue(); + expect(c.hasOwnProperty("y")).toBeTrue(); }); test("super constructor call from child class with argument", () => { - class Parent { - constructor(x) { - this.x = x; + class Parent { + constructor(x) { + this.x = x; + } } - } - class Child extends Parent { - constructor() { - super(10); + class Child extends Parent { + constructor() { + super(10); + } } - } - const p = new Parent(3); - const c = new Child(3); - expect(p.x).toBe(3); - expect(c.x).toBe(10); + const p = new Parent(3); + const c = new Child(3); + expect(p.x).toBe(3); + expect(c.x).toBe(10); }); diff --git a/Libraries/LibJS/Tests/classes/class-methods.js b/Libraries/LibJS/Tests/classes/class-methods.js index 4bc04ea5a5..0add75635c 100644 --- a/Libraries/LibJS/Tests/classes/class-methods.js +++ b/Libraries/LibJS/Tests/classes/class-methods.js @@ -1,51 +1,51 @@ test("basic functionality", () => { - class A { - number() { - return 2; + class A { + number() { + return 2; + } + + string() { + return "foo"; + } } - string() { - return "foo"; - } - } - - const a = new A(); - expect(a.number()).toBe(2); - expect(a.string()).toBe("foo"); + const a = new A(); + expect(a.number()).toBe(2); + expect(a.string()).toBe("foo"); }); test("length", () => { - class A { - method1() {} + class A { + method1() {} - method2(a, b, c, d) {} + method2(a, b, c, d) {} - method3(a, b, ...c) {} - } + method3(a, b, ...c) {} + } - const a = new A(); - expect(a.method1).toHaveLength(0); - expect(a.method2).toHaveLength(4); - expect(a.method3).toHaveLength(2); + const a = new A(); + expect(a.method1).toHaveLength(0); + expect(a.method2).toHaveLength(4); + expect(a.method3).toHaveLength(2); }); test("extended name syntax", () => { - class A { - "method with space"() { - return 1; + class A { + "method with space"() { + return 1; + } + + 12() { + return 2; + } + + [`he${"llo"}`]() { + return 3; + } } - 12() { - return 2; - } - - [`he${"llo"}`]() { - return 3; - } - } - - const a = new A(); - expect(a["method with space"]()).toBe(1); - expect(a[12]()).toBe(2); - expect(a.hello()).toBe(3); + const a = new A(); + expect(a["method with space"]()).toBe(1); + expect(a[12]()).toBe(2); + expect(a.hello()).toBe(3); }); diff --git a/Libraries/LibJS/Tests/classes/class-setters.js b/Libraries/LibJS/Tests/classes/class-setters.js index 19dbd6ecd2..024ad42ac9 100644 --- a/Libraries/LibJS/Tests/classes/class-setters.js +++ b/Libraries/LibJS/Tests/classes/class-setters.js @@ -1,100 +1,100 @@ test("basic functionality", () => { - class A { - get x() { - return this._x; + class A { + get x() { + return this._x; + } + + set x(value) { + this._x = value * 2; + } } - set x(value) { - this._x = value * 2; - } - } - - expect(A.x).toBeUndefined(); - expect(A).not.toHaveProperty("_x"); - const a = new A(); - expect(a.x).toBeUndefined(); - expect(a).not.toHaveProperty("_x"); - a.x = 3; - expect(a.x).toBe(6); - expect(a).toHaveProperty("_x", 6); + expect(A.x).toBeUndefined(); + expect(A).not.toHaveProperty("_x"); + const a = new A(); + expect(a.x).toBeUndefined(); + expect(a).not.toHaveProperty("_x"); + a.x = 3; + expect(a.x).toBe(6); + expect(a).toHaveProperty("_x", 6); }); test("name", () => { - class A { - set x(v) {} - } + class A { + set x(v) {} + } - const d = Object.getOwnPropertyDescriptor(A.prototype, "x"); - expect(d.set.name).toBe("set x"); + const d = Object.getOwnPropertyDescriptor(A.prototype, "x"); + expect(d.set.name).toBe("set x"); }); test("extended name syntax", () => { - class A { - set "method with space"(value) { - this.a = value; + class A { + set "method with space"(value) { + this.a = value; + } + + set 12(value) { + this.b = value; + } + + set [`he${"llo"}`](value) { + this.c = value; + } } - set 12(value) { - this.b = value; - } - - set [`he${"llo"}`](value) { - this.c = value; - } - } - - const a = new A(); - a["method with space"] = 1; - a[12] = 2; - a.hello = 3; - expect(a.a).toBe(1); - expect(a.b).toBe(2); - expect(a.c).toBe(3); + const a = new A(); + a["method with space"] = 1; + a[12] = 2; + a.hello = 3; + expect(a.a).toBe(1); + expect(a.b).toBe(2); + expect(a.c).toBe(3); }); test("inherited setter", () => { - class Parent { - get x() { - return this._x; + class Parent { + get x() { + return this._x; + } + + set x(value) { + this._x = value * 2; + } } - set x(value) { - this._x = value * 2; - } - } + class Child extends Parent {} - class Child extends Parent {} + const c = new Child(); - const c = new Child(); - - expect(c.x).toBeUndefined(); - c.x = 10; - expect(c.x).toBe(20); + expect(c.x).toBeUndefined(); + c.x = 10; + expect(c.x).toBe(20); }); test("inherited static setter overriding", () => { - class Parent { - get x() { - return this._x; + class Parent { + get x() { + return this._x; + } + + set x(value) { + this._x = value * 2; + } } - set x(value) { - this._x = value * 2; - } - } + class Child extends Parent { + get x() { + return this._x; + } - class Child extends Parent { - get x() { - return this._x; + set x(value) { + this._x = value * 3; + } } - set x(value) { - this._x = value * 3; - } - } - - const c = new Child(); - expect(c.x).toBeUndefined(); - c.x = 10; - expect(c.x).toBe(30); + const c = new Child(); + expect(c.x).toBeUndefined(); + c.x = 10; + expect(c.x).toBe(30); }); diff --git a/Libraries/LibJS/Tests/classes/class-static-getters.js b/Libraries/LibJS/Tests/classes/class-static-getters.js index 0407bd9a48..2fb54b501c 100644 --- a/Libraries/LibJS/Tests/classes/class-static-getters.js +++ b/Libraries/LibJS/Tests/classes/class-static-getters.js @@ -1,80 +1,80 @@ describe("correct behavior", () => { - test("basic functionality", () => { - class A { - static get x() { - return 10; - } - } + test("basic functionality", () => { + class A { + static get x() { + return 10; + } + } - expect(A.x).toBe(10); - expect(new A()).not.toHaveProperty("x"); - }); + expect(A.x).toBe(10); + expect(new A()).not.toHaveProperty("x"); + }); - test("name", () => { - class A { - static get x() {} - } + test("name", () => { + class A { + static get x() {} + } - const d = Object.getOwnPropertyDescriptor(A, "x"); - expect(d.get.name).toBe("get x"); - }); + const d = Object.getOwnPropertyDescriptor(A, "x"); + expect(d.get.name).toBe("get x"); + }); - test("extended name syntax", () => { - class A { - static get "method with space"() { - return 1; - } + test("extended name syntax", () => { + class A { + static get "method with space"() { + return 1; + } - static get 12() { - return 2; - } + static get 12() { + return 2; + } - static get [`he${"llo"}`]() { - return 3; - } - } + static get [`he${"llo"}`]() { + return 3; + } + } - expect(A["method with space"]).toBe(1); - expect(A[12]).toBe(2); - expect(A.hello).toBe(3); - }); + expect(A["method with space"]).toBe(1); + expect(A[12]).toBe(2); + expect(A.hello).toBe(3); + }); - test("inherited static getter", () => { - class Parent { - static get x() { - return 3; - } - } + test("inherited static getter", () => { + class Parent { + static get x() { + return 3; + } + } - class Child extends Parent {} + class Child extends Parent {} - expect(Parent.x).toBe(3); - expect(Child.x).toBe(3); - }); + expect(Parent.x).toBe(3); + expect(Child.x).toBe(3); + }); - test("inherited static getter overriding", () => { - class Parent { - static get x() { - return 3; - } - } + test("inherited static getter overriding", () => { + class Parent { + static get x() { + return 3; + } + } - class Child extends Parent { - static get x() { - return 10; - } - } + class Child extends Parent { + static get x() { + return 10; + } + } - expect(Parent.x).toBe(3); - expect(Child.x).toBe(10); - }); + expect(Parent.x).toBe(3); + expect(Child.x).toBe(10); + }); }); describe("errors", () => { - test('"get static" is a syntax error', () => { - expect(` + test('"get static" is a syntax error', () => { + expect(` class A { get static foo() {} }`).not.toEval(); - }); + }); }); diff --git a/Libraries/LibJS/Tests/classes/class-static-setters.js b/Libraries/LibJS/Tests/classes/class-static-setters.js index 41d867a7e5..0989a6ae03 100644 --- a/Libraries/LibJS/Tests/classes/class-static-setters.js +++ b/Libraries/LibJS/Tests/classes/class-static-setters.js @@ -1,104 +1,104 @@ describe("correct behavior", () => { - test("basic functionality", () => { - class A { - static get x() { - return this._x; - } + test("basic functionality", () => { + class A { + static get x() { + return this._x; + } - static set x(value) { - this._x = value * 2; - } - } + static set x(value) { + this._x = value * 2; + } + } - expect(A.x).toBeUndefined(); - expect(A).not.toHaveProperty("_x"); - A.x = 3; - expect(A.x).toBe(6); - expect(A).toHaveProperty("_x", 6); - }); + expect(A.x).toBeUndefined(); + expect(A).not.toHaveProperty("_x"); + A.x = 3; + expect(A.x).toBe(6); + expect(A).toHaveProperty("_x", 6); + }); - test("name", () => { - class A { - static set x(v) {} - } + test("name", () => { + class A { + static set x(v) {} + } - const d = Object.getOwnPropertyDescriptor(A, "x"); - expect(d.set.name).toBe("set x"); - }); + const d = Object.getOwnPropertyDescriptor(A, "x"); + expect(d.set.name).toBe("set x"); + }); - test("extended name syntax", () => { - class A { - static set "method with space"(value) { - this.a = value; - } + test("extended name syntax", () => { + class A { + static set "method with space"(value) { + this.a = value; + } - static set 12(value) { - this.b = value; - } + static set 12(value) { + this.b = value; + } - static set [`he${"llo"}`](value) { - this.c = value; - } - } + static set [`he${"llo"}`](value) { + this.c = value; + } + } - A["method with space"] = 1; - A[12] = 2; - A.hello = 3; - expect(A.a).toBe(1); - expect(A.b).toBe(2); - expect(A.c).toBe(3); - }); + A["method with space"] = 1; + A[12] = 2; + A.hello = 3; + expect(A.a).toBe(1); + expect(A.b).toBe(2); + expect(A.c).toBe(3); + }); - test("inherited static setter", () => { - class Parent { - static get x() { - return this._x; - } + test("inherited static setter", () => { + class Parent { + static get x() { + return this._x; + } - static set x(value) { - this._x = value * 2; - } - } + static set x(value) { + this._x = value * 2; + } + } - class Child extends Parent {} + class Child extends Parent {} - expect(Child.x).toBeUndefined(); - Child.x = 10; - expect(Child.x).toBe(20); - }); + expect(Child.x).toBeUndefined(); + Child.x = 10; + expect(Child.x).toBe(20); + }); - test("inherited static setter overriding", () => { - class Parent { - static get x() { - return this._x; - } + test("inherited static setter overriding", () => { + class Parent { + static get x() { + return this._x; + } - static set x(value) { - this._x = value * 2; - } - } + static set x(value) { + this._x = value * 2; + } + } - class Child extends Parent { - static get x() { - return this._x; - } + class Child extends Parent { + static get x() { + return this._x; + } - static set x(value) { - this._x = value * 3; - } - } + static set x(value) { + this._x = value * 3; + } + } - expect(Child.x).toBeUndefined(); - Child.x = 10; - expect(Child.x).toBe(30); - }); + expect(Child.x).toBeUndefined(); + Child.x = 10; + expect(Child.x).toBe(30); + }); }); describe("errors", () => { - test('"set static" is a syntax error', () => { - expect(` + test('"set static" is a syntax error', () => { + expect(` class A { set static foo(value) {} }`).not.toEval(); - }); + }); }); diff --git a/Libraries/LibJS/Tests/classes/class-static.js b/Libraries/LibJS/Tests/classes/class-static.js index a58cdd7f5d..5bfd28c3da 100644 --- a/Libraries/LibJS/Tests/classes/class-static.js +++ b/Libraries/LibJS/Tests/classes/class-static.js @@ -1,72 +1,72 @@ test("basic functionality", () => { - class A { - static method() { - return 10; + class A { + static method() { + return 10; + } } - } - expect(A.method()).toBe(10); - expect(new A().method).toBeUndefined(); + expect(A.method()).toBe(10); + expect(new A().method).toBeUndefined(); }); test("extended name syntax", () => { - class A { - static method() { - return 1; + class A { + static method() { + return 1; + } + + static 12() { + return 2; + } + + static [`he${"llo"}`]() { + return 3; + } } - static 12() { - return 2; - } - - static [`he${"llo"}`]() { - return 3; - } - } - - expect(A.method()).toBe(1); - expect(A[12]()).toBe(2); - expect(A.hello()).toBe(3); + expect(A.method()).toBe(1); + expect(A[12]()).toBe(2); + expect(A.hello()).toBe(3); }); test("bound |this|", () => { - class A { - static method() { - expect(this).toBe(A); + class A { + static method() { + expect(this).toBe(A); + } } - } - A.method(); + A.method(); }); test("inherited static methods", () => { - class Parent { - static method() { - return 3; + class Parent { + static method() { + return 3; + } } - } - class Child extends Parent {} + class Child extends Parent {} - expect(Parent.method()).toBe(3); - expect(Child.method()).toBe(3); - expect(new Parent()).not.toHaveProperty("method"); - expect(new Child()).not.toHaveProperty("method"); + expect(Parent.method()).toBe(3); + expect(Child.method()).toBe(3); + expect(new Parent()).not.toHaveProperty("method"); + expect(new Child()).not.toHaveProperty("method"); }); test("static method overriding", () => { - class Parent { - static method() { - return 3; + class Parent { + static method() { + return 3; + } } - } - class Child extends Parent { - static method() { - return 10; + class Child extends Parent { + static method() { + return 10; + } } - } - expect(Parent.method()).toBe(3); - expect(Child.method()).toBe(10); + expect(Parent.method()).toBe(3); + expect(Child.method()).toBe(10); }); diff --git a/Libraries/LibJS/Tests/classes/class-strict-mode.js b/Libraries/LibJS/Tests/classes/class-strict-mode.js index 90ead4490f..016d2d2eba 100644 --- a/Libraries/LibJS/Tests/classes/class-strict-mode.js +++ b/Libraries/LibJS/Tests/classes/class-strict-mode.js @@ -1,19 +1,19 @@ test("constructors are always strict mode", () => { - class A { - constructor() { - expect(isStrictMode()).toBeTrue(); + class A { + constructor() { + expect(isStrictMode()).toBeTrue(); + } } - } - new A(); + new A(); }); test("methods are always strict mode", () => { - class A { - method() { - expect(isStrictMode()).toBeTrue(); + class A { + method() { + expect(isStrictMode()).toBeTrue(); + } } - } - new A().method(); + new A().method(); }); diff --git a/Libraries/LibJS/Tests/comments-basic.js b/Libraries/LibJS/Tests/comments-basic.js index 460525d28b..1a7d281087 100644 --- a/Libraries/LibJS/Tests/comments-basic.js +++ b/Libraries/LibJS/Tests/comments-basic.js @@ -1,5 +1,5 @@ test("regular comments", () => { - const source = `var i = 0; + const source = `var i = 0; // i++; /* i++; */ @@ -8,16 +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;`; - expect(source).toEvalTo(1); + expect(source).toEvalTo(1); }); diff --git a/Libraries/LibJS/Tests/const-reassignment.js b/Libraries/LibJS/Tests/const-reassignment.js index 44d9cab173..1c66fc24ce 100644 --- a/Libraries/LibJS/Tests/const-reassignment.js +++ b/Libraries/LibJS/Tests/const-reassignment.js @@ -1,17 +1,17 @@ // I'm not sure how this test passed before the refactor, but it definitely doesn't work at all test.skip("reassignment to const", () => { - const constantValue = 1; - expect(() => { - constantValue = 2; - }).toThrowWithMessage(TypeError, "Invalid assignment to const variable"); - expect(constantValue).toBe(1); + const constantValue = 1; + expect(() => { + constantValue = 2; + }).toThrowWithMessage(TypeError, "Invalid assignment to const variable"); + expect(constantValue).toBe(1); }); test("const creation in inner scope", () => { - const constantValue = 1; - do { - const constantValue = 2; - expect(constantValue).toBe(2); - } while (false); - expect(constantValue).toBe(1); + const constantValue = 1; + do { + const constantValue = 2; + expect(constantValue).toBe(2); + } while (false); + expect(constantValue).toBe(1); }); diff --git a/Libraries/LibJS/Tests/debugger-statement.js b/Libraries/LibJS/Tests/debugger-statement.js index f97fcc212a..e5b0b14761 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 982c831c72..1c8fe467b8 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 3713340717..5cd436d0bf 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 5796b644b9..e26933aad5 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); + expect(2 ** -3).toBe(0.125); + expect((-2) ** 3).toBe(-8); - // FIXME: This should fail :) - // expect("-2 ** 3").not.toEval(); + // 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 3b3ab09ed1..ac8f4b2f2d 100644 --- a/Libraries/LibJS/Tests/functions/arrow-functions.js +++ b/Libraries/LibJS/Tests/functions/arrow-functions.js @@ -1,150 +1,150 @@ test("no arguments", () => { - let getNumber = () => { - return 42; - }; - expect(getNumber()).toBe(42); + let getNumber = () => { + return 42; + }; + expect(getNumber()).toBe(42); - getNumber = () => 42; - expect(getNumber()).toBe(42); + getNumber = () => 42; + expect(getNumber()).toBe(42); - getNumber = () => { - return 99; - }; - expect(getNumber()).toBe(99); - getNumber = () => 99; - expect(getNumber()).toBe(99); + getNumber = () => { + return 99; + }; + expect(getNumber()).toBe(99); + getNumber = () => 99; + expect(getNumber()).toBe(99); }); test("arguments", () => { - let add = (a, b) => a + b; - expect(add(2, 3)).toBe(5); + let add = (a, b) => a + b; + expect(add(2, 3)).toBe(5); - const addBlock = (a, b) => { - let res = a + b; - return res; - }; - expect(addBlock(5, 4)).toBe(9); + const addBlock = (a, b) => { + let res = a + b; + return res; + }; + expect(addBlock(5, 4)).toBe(9); }); test("inside an array", () => { - let chompy = [x => x, 2]; - expect(chompy).toHaveLength(2); - expect(chompy[0](1)).toBe(1); + let chompy = [x => x, 2]; + expect(chompy).toHaveLength(2); + expect(chompy[0](1)).toBe(1); }); test("return object literal", () => { - const makeObject = (a, b) => ({ a, b }); - const obj = makeObject(33, 44); - expect(typeof obj).toBe("object"); - expect(obj.a).toBe(33); - expect(obj.b).toBe(44); + const makeObject = (a, b) => ({ a, b }); + const obj = makeObject(33, 44); + expect(typeof obj).toBe("object"); + expect(obj.a).toBe(33); + expect(obj.b).toBe(44); }); test("return undefined", () => { - let returnUndefined = () => {}; - expect(returnUndefined()).toBeUndefined(); + let returnUndefined = () => {}; + expect(returnUndefined()).toBeUndefined(); }); test("return array literal", () => { - const makeArray = (a, b) => [a, b]; - const array = makeArray("3", { foo: 4 }); - expect(array[0]).toBe("3"); - expect(array[1].foo).toBe(4); + const makeArray = (a, b) => [a, b]; + const array = makeArray("3", { foo: 4 }); + expect(array[0]).toBe("3"); + expect(array[1].foo).toBe(4); }); test("return numeric expression", () => { - let square = x => x * x; - expect(square(3)).toBe(9); + let square = x => x * x; + expect(square(3)).toBe(9); - let squareBlock = x => { - return x * x; - }; - expect(squareBlock(4)).toBe(16); + let squareBlock = x => { + return x * x; + }; + expect(squareBlock(4)).toBe(16); }); test("return called arrow function expression", () => { - const message = (who => "Hello " + who)("friends!"); - expect(message).toBe("Hello friends!"); + const message = (who => "Hello " + who)("friends!"); + expect(message).toBe("Hello friends!"); - const sum = ((x, y, z) => x + y + z)(1, 2, 3); - expect(sum).toBe(6); + const sum = ((x, y, z) => x + y + z)(1, 2, 3); + expect(sum).toBe(6); - const product = ((x, y, z) => { - let res = x * y * z; - return res; - })(5, 4, 2); - expect(product).toBe(40); + const product = ((x, y, z) => { + let res = x * y * z; + return res; + })(5, 4, 2); + expect(product).toBe(40); - const half = (x => { - return x / 2; - })(10); - expect(half).toBe(5); + const half = (x => { + return x / 2; + })(10); + expect(half).toBe(5); }); test("currying", () => { - let add = a => b => a + b; - expect(typeof add(1)).toBe("function"); - expect(typeof add(1, 2)).toBe("function"); - expect(add(1)(2)).toBe(3); + let add = a => b => a + b; + expect(typeof add(1)).toBe("function"); + expect(typeof add(1, 2)).toBe("function"); + expect(add(1)(2)).toBe(3); }); test("with comma operator", () => { - let foo, bar; - (foo = bar), baz => {}; - expect(foo).toBe(undefined); - expect(bar).toBe(undefined); + let foo, bar; + (foo = bar), baz => {}; + expect(foo).toBe(undefined); + expect(bar).toBe(undefined); }); test("arrow functions in objects", () => { - function FooBar() { - this.x = { - y: () => this, - z: function () { - return (() => this)(); - }, - }; - } + function FooBar() { + this.x = { + y: () => this, + z: function () { + return (() => this)(); + }, + }; + } - const foobar = new FooBar(); - expect(foobar.x.y()).toBe(foobar); - expect(foobar.x.z()).toBe(foobar.x); + const foobar = new FooBar(); + expect(foobar.x.y()).toBe(foobar); + expect(foobar.x.z()).toBe(foobar.x); }); test("strict mode propogation", () => { - (() => { - "use strict"; - expect(isStrictMode()).toBeTrue(); - (() => { - expect(isStrictMode()).toBeTrue(); - })(); - })(); + "use strict"; + expect(isStrictMode()).toBeTrue(); - (() => { - "use strict"; - expect(isStrictMode()).toBeTrue(); - })(); - - (() => { - expect(isStrictMode()).toBeFalse(); - - (() => { - "use strict"; - expect(isStrictMode()).toBeTrue(); + (() => { + expect(isStrictMode()).toBeTrue(); + })(); })(); - expect(isStrictMode()).toBeFalse(); - })(); + (() => { + "use strict"; + expect(isStrictMode()).toBeTrue(); + })(); + + (() => { + expect(isStrictMode()).toBeFalse(); + + (() => { + "use strict"; + expect(isStrictMode()).toBeTrue(); + })(); + + expect(isStrictMode()).toBeFalse(); + })(); }); test("no prototype", () => { - let foo = () => {}; - expect(foo).not.toHaveProperty("prototype"); + let foo = () => {}; + expect(foo).not.toHaveProperty("prototype"); }); test("cannot be constructed", () => { - let foo = () => {}; - expect(() => { - new foo(); - }).toThrowWithMessage(TypeError, "foo is not a constructor"); + let foo = () => {}; + expect(() => { + new foo(); + }).toThrowWithMessage(TypeError, "foo is not a constructor"); }); diff --git a/Libraries/LibJS/Tests/functions/constructor-basic.js b/Libraries/LibJS/Tests/functions/constructor-basic.js index c672e71529..cf58525634 100644 --- a/Libraries/LibJS/Tests/functions/constructor-basic.js +++ b/Libraries/LibJS/Tests/functions/constructor-basic.js @@ -1,11 +1,11 @@ test("basic functionality", () => { - function Foo() { - this.x = 123; - } + function Foo() { + this.x = 123; + } - expect(Foo.prototype.constructor).toBe(Foo); + expect(Foo.prototype.constructor).toBe(Foo); - const foo = new Foo(); - expect(foo.constructor).toBe(Foo); - expect(foo.x).toBe(123); + const foo = new Foo(); + expect(foo.constructor).toBe(Foo); + expect(foo.x).toBe(123); }); diff --git a/Libraries/LibJS/Tests/functions/function-TypeError.js b/Libraries/LibJS/Tests/functions/function-TypeError.js index 289d109f6a..41fb6ae196 100644 --- a/Libraries/LibJS/Tests/functions/function-TypeError.js +++ b/Libraries/LibJS/Tests/functions/function-TypeError.js @@ -1,44 +1,47 @@ test("calling non-function", () => { - expect(() => { - const a = true; - a(); - }).toThrowWithMessage(TypeError, "true is not a function (evaluated from 'a')"); + expect(() => { + const a = true; + a(); + }).toThrowWithMessage(TypeError, "true is not a function (evaluated from 'a')"); }); test("calling number", () => { - expect(() => { - const a = 100 + 20 + 3; - a(); - }).toThrowWithMessage(TypeError, "123 is not a function (evaluated from 'a')"); + expect(() => { + const a = 100 + 20 + 3; + a(); + }).toThrowWithMessage(TypeError, "123 is not a function (evaluated from 'a')"); }); test("calling undefined object key", () => { - expect(() => { - const o = {}; - o.a(); - }).toThrowWithMessage(TypeError, "undefined is not a function (evaluated from 'o.a')"); + expect(() => { + const o = {}; + o.a(); + }).toThrowWithMessage(TypeError, "undefined is not a function (evaluated from 'o.a')"); }); test("calling object", () => { - expect(() => { - Math(); - }).toThrowWithMessage(TypeError, "[object MathObject] is not a function (evaluated from 'Math')"); + expect(() => { + Math(); + }).toThrowWithMessage( + TypeError, + "[object MathObject] is not a function (evaluated from 'Math')" + ); }); test("constructing object", () => { - expect(() => { - new Math(); - }).toThrowWithMessage( - TypeError, - "[object MathObject] is not a constructor (evaluated from 'Math')" - ); + expect(() => { + new Math(); + }).toThrowWithMessage( + TypeError, + "[object MathObject] is not a constructor (evaluated from 'Math')" + ); }); test("constructing native function", () => { - expect(() => { - new isNaN(); - }).toThrowWithMessage( - TypeError, - "[object NativeFunction] is not a constructor (evaluated from 'isNaN')" - ); + expect(() => { + new isNaN(); + }).toThrowWithMessage( + TypeError, + "[object NativeFunction] is not a constructor (evaluated from 'isNaN')" + ); }); diff --git a/Libraries/LibJS/Tests/functions/function-default-parameters.js b/Libraries/LibJS/Tests/functions/function-default-parameters.js index 49d3f40a05..ca50a6a90b 100644 --- a/Libraries/LibJS/Tests/functions/function-default-parameters.js +++ b/Libraries/LibJS/Tests/functions/function-default-parameters.js @@ -1,143 +1,143 @@ test("single default parameter", () => { - function func(a = 6) { - return typeof a; - } + function func(a = 6) { + return typeof a; + } - const arrowFunc = (a = 6) => typeof a; + const arrowFunc = (a = 6) => typeof a; - expect(func()).toBe("number"); - expect(func(5)).toBe("number"); - expect(func(undefined)).toBe("number"); - expect(func(false)).toBe("boolean"); - expect(func(null)).toBe("object"); - expect(func({})).toBe("object"); + expect(func()).toBe("number"); + expect(func(5)).toBe("number"); + expect(func(undefined)).toBe("number"); + expect(func(false)).toBe("boolean"); + expect(func(null)).toBe("object"); + expect(func({})).toBe("object"); - expect(arrowFunc()).toBe("number"); - expect(arrowFunc(5)).toBe("number"); - expect(arrowFunc(undefined)).toBe("number"); - expect(arrowFunc(false)).toBe("boolean"); - expect(arrowFunc(null)).toBe("object"); - expect(arrowFunc({})).toBe("object"); + expect(arrowFunc()).toBe("number"); + expect(arrowFunc(5)).toBe("number"); + expect(arrowFunc(undefined)).toBe("number"); + expect(arrowFunc(false)).toBe("boolean"); + expect(arrowFunc(null)).toBe("object"); + expect(arrowFunc({})).toBe("object"); }); test("two parameters, second one is default", () => { - function func(a, b = 1) { - return a + b; - } + function func(a, b = 1) { + return a + b; + } - const arrowFunc = (a, b = 1) => a + b; + const arrowFunc = (a, b = 1) => a + b; - expect(func(4, 5)).toBe(9); - expect(func(4)).toBe(5); - expect(func(4, undefined)).toBe(5); - expect(func()).toBeNaN(); + expect(func(4, 5)).toBe(9); + expect(func(4)).toBe(5); + expect(func(4, undefined)).toBe(5); + expect(func()).toBeNaN(); - expect(arrowFunc(4, 5)).toBe(9); - expect(arrowFunc(4)).toBe(5); - expect(arrowFunc(4, undefined)).toBe(5); - expect(arrowFunc()).toBeNaN(); + expect(arrowFunc(4, 5)).toBe(9); + expect(arrowFunc(4)).toBe(5); + expect(arrowFunc(4, undefined)).toBe(5); + expect(arrowFunc()).toBeNaN(); }); test("two parameters, first one is default", () => { - function func(a = 5, b) { - return a + b; - } + function func(a = 5, b) { + return a + b; + } - const arrowFunc = (a = 5, b) => a + b; + const arrowFunc = (a = 5, b) => a + b; - expect(func(4, 5)).toBe(9); - expect(func(undefined, 4)).toBe(9); - expect(func()).toBeNaN(); + expect(func(4, 5)).toBe(9); + expect(func(undefined, 4)).toBe(9); + expect(func()).toBeNaN(); - expect(arrowFunc(4, 5)).toBe(9); - expect(arrowFunc(undefined, 4)).toBe(9); - expect(arrowFunc()).toBeNaN(); + expect(arrowFunc(4, 5)).toBe(9); + expect(arrowFunc(undefined, 4)).toBe(9); + expect(arrowFunc()).toBeNaN(); }); test("default parameter references a previous parameter", () => { - function func(a, b = a) { - return a + b; - } + function func(a, b = a) { + return a + b; + } - const arrowFunc = (a, b = a) => a + b; + const arrowFunc = (a, b = a) => a + b; - expect(func(4, 5)).toBe(9); - expect(func(4)).toBe(8); - expect(func("hf")).toBe("hfhf"); - expect(func(true)).toBe(2); - expect(func()).toBeNaN(); + expect(func(4, 5)).toBe(9); + expect(func(4)).toBe(8); + expect(func("hf")).toBe("hfhf"); + expect(func(true)).toBe(2); + expect(func()).toBeNaN(); - expect(arrowFunc(4, 5)).toBe(9); - expect(arrowFunc(4)).toBe(8); - expect(arrowFunc("hf")).toBe("hfhf"); - expect(arrowFunc(true)).toBe(2); - expect(arrowFunc()).toBeNaN(); + expect(arrowFunc(4, 5)).toBe(9); + expect(arrowFunc(4)).toBe(8); + expect(arrowFunc("hf")).toBe("hfhf"); + expect(arrowFunc(true)).toBe(2); + expect(arrowFunc()).toBeNaN(); }); test("parameter with a function default value", () => { - function func( - a = function () { - return 5; + function func( + a = function () { + return 5; + } + ) { + return a(); } - ) { - return a(); - } - const arrowFunc = ( - a = function () { - return 5; - } - ) => a(); + const arrowFunc = ( + a = function () { + return 5; + } + ) => a(); - expect(func()).toBe(5); - expect( - func(function () { - return 10; - }) - ).toBe(10); - expect(func(() => 10)).toBe(10); + expect(func()).toBe(5); + expect( + func(function () { + return 10; + }) + ).toBe(10); + expect(func(() => 10)).toBe(10); - expect(arrowFunc()).toBe(5); - expect( - arrowFunc(function () { - return 10; - }) - ).toBe(10); - expect(arrowFunc(() => 10)).toBe(10); + expect(arrowFunc()).toBe(5); + expect( + arrowFunc(function () { + return 10; + }) + ).toBe(10); + expect(arrowFunc(() => 10)).toBe(10); }); test("parameter with an arrow function default vlaue", () => { - function func(a = () => 5) { - return a(); - } + function func(a = () => 5) { + return a(); + } - const arrowFunc = (a = () => 5) => a(); + const arrowFunc = (a = () => 5) => a(); - expect(func()).toBe(5); - expect( - func(function () { - return 10; - }) - ).toBe(10); - expect(func(() => 10)).toBe(10); - expect(arrowFunc()).toBe(5); - expect( - arrowFunc(function () { - return 10; - }) - ).toBe(10); - expect(arrowFunc(() => 10)).toBe(10); + expect(func()).toBe(5); + expect( + func(function () { + return 10; + }) + ).toBe(10); + expect(func(() => 10)).toBe(10); + expect(arrowFunc()).toBe(5); + expect( + arrowFunc(function () { + return 10; + }) + ).toBe(10); + expect(arrowFunc(() => 10)).toBe(10); }); test("parameter with an object default value", () => { - function func(a = { foo: "bar" }) { - return a.foo; - } + function func(a = { foo: "bar" }) { + return a.foo; + } - const arrowFunc = (a = { foo: "bar" }) => a.foo; + const arrowFunc = (a = { foo: "bar" }) => a.foo; - expect(func()).toBe("bar"); - expect(func({ foo: "baz" })).toBe("baz"); - expect(arrowFunc()).toBe("bar"); - expect(arrowFunc({ foo: "baz" })).toBe("baz"); + expect(func()).toBe("bar"); + expect(func({ foo: "baz" })).toBe("baz"); + expect(arrowFunc()).toBe("bar"); + expect(arrowFunc({ foo: "baz" })).toBe("baz"); }); diff --git a/Libraries/LibJS/Tests/functions/function-hoisting.js b/Libraries/LibJS/Tests/functions/function-hoisting.js index 5a10f210c3..3345cc4d5f 100644 --- a/Libraries/LibJS/Tests/functions/function-hoisting.js +++ b/Libraries/LibJS/Tests/functions/function-hoisting.js @@ -1,39 +1,39 @@ test("basic functionality", () => { - let callHoisted = hoisted(); - function hoisted() { - return "foo"; - } - expect(hoisted()).toBe("foo"); - expect(callHoisted).toBe("foo"); + let callHoisted = hoisted(); + function hoisted() { + return "foo"; + } + expect(hoisted()).toBe("foo"); + expect(callHoisted).toBe("foo"); }); // First two calls produce a ReferenceError, but the declarations should be hoisted test.skip("functions are hoisted across non-lexical scopes", () => { - expect(scopedHoisted).toBeUndefined(); - expect(callScopedHoisted).toBeUndefined(); - { - var callScopedHoisted = scopedHoisted(); - function scopedHoisted() { - return "foo"; + expect(scopedHoisted).toBeUndefined(); + expect(callScopedHoisted).toBeUndefined(); + { + var callScopedHoisted = scopedHoisted(); + function scopedHoisted() { + return "foo"; + } + expect(scopedHoisted()).toBe("foo"); + expect(callScopedHoisted).toBe("foo"); } expect(scopedHoisted()).toBe("foo"); expect(callScopedHoisted).toBe("foo"); - } - expect(scopedHoisted()).toBe("foo"); - expect(callScopedHoisted).toBe("foo"); }); test("functions are not hoisted across lexical scopes", () => { - const test = () => { - var iife = (function () { - return declaredLater(); - })(); - function declaredLater() { - return "yay"; - } - return iife; - }; + const test = () => { + var iife = (function () { + return declaredLater(); + })(); + function declaredLater() { + return "yay"; + } + return iife; + }; - expect(() => declaredLater).toThrow(ReferenceError); - expect(test()).toBe("yay"); + expect(() => declaredLater).toThrow(ReferenceError); + expect(test()).toBe("yay"); }); diff --git a/Libraries/LibJS/Tests/functions/function-length.js b/Libraries/LibJS/Tests/functions/function-length.js index 36858526c8..d57b773c09 100644 --- a/Libraries/LibJS/Tests/functions/function-length.js +++ b/Libraries/LibJS/Tests/functions/function-length.js @@ -1,23 +1,23 @@ test("basic functionality", () => { - function foo() {} - expect(foo).toHaveLength(0); - expect((foo.length = 5)).toBe(5); - expect(foo).toHaveLength(0); + function foo() {} + expect(foo).toHaveLength(0); + expect((foo.length = 5)).toBe(5); + expect(foo).toHaveLength(0); - function bar(a, b, c) {} - expect(bar).toHaveLength(3); - expect((bar.length = 5)).toBe(5); - expect(bar).toHaveLength(3); + function bar(a, b, c) {} + expect(bar).toHaveLength(3); + expect((bar.length = 5)).toBe(5); + expect(bar).toHaveLength(3); }); test("functions with special parameter lists", () => { - function baz(a, b = 1, c) {} - expect(baz).toHaveLength(1); - expect((baz.length = 5)).toBe(5); - expect(baz).toHaveLength(1); + function baz(a, b = 1, c) {} + expect(baz).toHaveLength(1); + expect((baz.length = 5)).toBe(5); + expect(baz).toHaveLength(1); - function qux(a, b, ...c) {} - expect(qux).toHaveLength(2); - expect((qux.length = 2)).toBe(2); - expect(qux).toHaveLength(2); + function qux(a, b, ...c) {} + expect(qux).toHaveLength(2); + expect((qux.length = 2)).toBe(2); + expect(qux).toHaveLength(2); }); diff --git a/Libraries/LibJS/Tests/functions/function-missing-arg.js b/Libraries/LibJS/Tests/functions/function-missing-arg.js index af4d514a6e..f599d05ced 100644 --- a/Libraries/LibJS/Tests/functions/function-missing-arg.js +++ b/Libraries/LibJS/Tests/functions/function-missing-arg.js @@ -1,10 +1,10 @@ test("basic functionality", () => { - function foo(a, b) { - return a + b; - } + function foo(a, b) { + return a + b; + } - expect(foo()).toBeNaN(); - expect(foo(1)).toBeNaN(); - expect(foo(2, 3)).toBe(5); - expect(foo(2, 3, 4)).toBe(5); + expect(foo()).toBeNaN(); + expect(foo(1)).toBeNaN(); + expect(foo(2, 3)).toBe(5); + expect(foo(2, 3, 4)).toBe(5); }); diff --git a/Libraries/LibJS/Tests/functions/function-name.js b/Libraries/LibJS/Tests/functions/function-name.js index 052669c3cb..b00ec614f2 100644 --- a/Libraries/LibJS/Tests/functions/function-name.js +++ b/Libraries/LibJS/Tests/functions/function-name.js @@ -1,50 +1,50 @@ test("basic functionality", () => { - expect(function () {}.name).toBe(""); + expect(function () {}.name).toBe(""); - function bar() {} - expect(bar.name).toBe("bar"); - expect((bar.name = "baz")).toBe("baz"); - expect(bar.name).toBe("bar"); + function bar() {} + expect(bar.name).toBe("bar"); + expect((bar.name = "baz")).toBe("baz"); + expect(bar.name).toBe("bar"); }); test("function assigned to variable", () => { - let foo = function () {}; - expect(foo.name).toBe("foo"); - expect((foo.name = "bar")).toBe("bar"); - expect(foo.name).toBe("foo"); + let foo = function () {}; + expect(foo.name).toBe("foo"); + expect((foo.name = "bar")).toBe("bar"); + expect(foo.name).toBe("foo"); - let a, b; - a = b = function () {}; - expect(a.name).toBe("b"); - expect(b.name).toBe("b"); + let a, b; + a = b = function () {}; + expect(a.name).toBe("b"); + expect(b.name).toBe("b"); }); test("functions in array assigned to variable", () => { - const arr = [function () {}, function () {}, function () {}]; - expect(arr[0].name).toBe("arr"); - expect(arr[1].name).toBe("arr"); - expect(arr[2].name).toBe("arr"); + const arr = [function () {}, function () {}, function () {}]; + expect(arr[0].name).toBe("arr"); + expect(arr[1].name).toBe("arr"); + expect(arr[2].name).toBe("arr"); }); test("functions in objects", () => { - let f; - let o = { a: function () {} }; + let f; + let o = { a: function () {} }; - expect(o.a.name).toBe("a"); - f = o.a; - expect(f.name).toBe("a"); - expect(o.a.name).toBe("a"); + expect(o.a.name).toBe("a"); + f = o.a; + expect(f.name).toBe("a"); + expect(o.a.name).toBe("a"); - o = { ...o, b: f }; - expect(o.a.name).toBe("a"); - expect(o.b.name).toBe("a"); + o = { ...o, b: f }; + expect(o.a.name).toBe("a"); + expect(o.b.name).toBe("a"); - o.c = function () {}; - expect(o.c.name).toBe("c"); + o.c = function () {}; + expect(o.c.name).toBe("c"); }); test("names of native functions", () => { - expect(console.debug.name).toBe("debug"); - expect((console.debug.name = "warn")).toBe("warn"); - expect(console.debug.name).toBe("debug"); + expect(console.debug.name).toBe("debug"); + expect((console.debug.name = "warn")).toBe("warn"); + expect(console.debug.name).toBe("debug"); }); diff --git a/Libraries/LibJS/Tests/functions/function-rest-params.js b/Libraries/LibJS/Tests/functions/function-rest-params.js index 144880e865..83ed411675 100644 --- a/Libraries/LibJS/Tests/functions/function-rest-params.js +++ b/Libraries/LibJS/Tests/functions/function-rest-params.js @@ -1,47 +1,47 @@ test("rest parameter with no arguments", () => { - function foo(...a) { - expect(a).toBeInstanceOf(Array); - expect(a).toHaveLength(0); - } - foo(); + function foo(...a) { + expect(a).toBeInstanceOf(Array); + expect(a).toHaveLength(0); + } + foo(); }); test("rest parameter with arguments", () => { - function foo(...a) { - expect(a).toEqual(["foo", 123, undefined, { foo: "bar" }]); - } - foo("foo", 123, undefined, { foo: "bar" }); + function foo(...a) { + expect(a).toEqual(["foo", 123, undefined, { foo: "bar" }]); + } + foo("foo", 123, undefined, { foo: "bar" }); }); test("rest parameter after normal parameters with no arguments", () => { - function foo(a, b, ...c) { - expect(a).toBe("foo"); - expect(b).toBe(123); - expect(c).toEqual([]); - } - foo("foo", 123); + function foo(a, b, ...c) { + expect(a).toBe("foo"); + expect(b).toBe(123); + expect(c).toEqual([]); + } + foo("foo", 123); }); test("rest parameter after normal parameters with arguments", () => { - function foo(a, b, ...c) { - expect(a).toBe("foo"); - expect(b).toBe(123); - expect(c).toEqual([undefined, { foo: "bar" }]); - } - foo("foo", 123, undefined, { foo: "bar" }); + function foo(a, b, ...c) { + expect(a).toBe("foo"); + expect(b).toBe(123); + expect(c).toEqual([undefined, { foo: "bar" }]); + } + foo("foo", 123, undefined, { foo: "bar" }); }); test("basic arrow function rest parameters", () => { - let foo = (...a) => { - expect(a).toBeInstanceOf(Array); - expect(a).toHaveLength(0); - }; - foo(); + let foo = (...a) => { + expect(a).toBeInstanceOf(Array); + expect(a).toHaveLength(0); + }; + foo(); - foo = (a, b, ...c) => { - expect(a).toBe("foo"); - expect(b).toBe(123); - expect(c).toEqual([undefined, { foo: "bar" }]); - }; - foo("foo", 123, undefined, { foo: "bar" }); + foo = (a, b, ...c) => { + expect(a).toBe("foo"); + expect(b).toBe(123); + expect(c).toEqual([undefined, { foo: "bar" }]); + }; + foo("foo", 123, undefined, { foo: "bar" }); }); diff --git a/Libraries/LibJS/Tests/functions/function-spread.js b/Libraries/LibJS/Tests/functions/function-spread.js index abe3d4bc5d..3cbd848b9c 100644 --- a/Libraries/LibJS/Tests/functions/function-spread.js +++ b/Libraries/LibJS/Tests/functions/function-spread.js @@ -1,20 +1,20 @@ test("basic functionality", () => { - 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]; - expect(sum(...a)).toBe(6); - expect(sum(1, ...a)).toBe(4); - expect(sum(...a, 10)).toBe(6); + expect(sum(...a)).toBe(6); + expect(sum(1, ...a)).toBe(4); + expect(sum(...a, 10)).toBe(6); - const foo = (a, b, c) => c; + const foo = (a, b, c) => c; - const o = { bar: [1, 2, 3] }; - expect(foo(...o.bar)).toBe(3); - expect(foo(..."abc")).toBe("c"); + const o = { bar: [1, 2, 3] }; + expect(foo(...o.bar)).toBe(3); + expect(foo(..."abc")).toBe("c"); }); test("spreading non iterable", () => { - expect(() => { - [...1]; - }).toThrowWithMessage(TypeError, "1 is not iterable"); + expect(() => { + [...1]; + }).toThrowWithMessage(TypeError, "1 is not iterable"); }); diff --git a/Libraries/LibJS/Tests/functions/function-strict-mode.js b/Libraries/LibJS/Tests/functions/function-strict-mode.js index 46c93b1e5c..9138bddb0d 100644 --- a/Libraries/LibJS/Tests/functions/function-strict-mode.js +++ b/Libraries/LibJS/Tests/functions/function-strict-mode.js @@ -2,52 +2,52 @@ // respects the .prettierignore file! test("non strict-mode by default", () => { - expect(isStrictMode()).toBeFalse(); + expect(isStrictMode()).toBeFalse(); }); test("use strict with double quotes", () => { - "use strict"; - expect(isStrictMode()).toBeTrue(); + "use strict"; + expect(isStrictMode()).toBeTrue(); }); test("use strict with single quotes", () => { - 'use strict'; - expect(isStrictMode()).toBeTrue(); + 'use strict'; + expect(isStrictMode()).toBeTrue(); }); test("use strict with backticks does not yield strict mode", () => { - `use strict`; - expect(isStrictMode()).toBeFalse(); + `use strict`; + expect(isStrictMode()).toBeFalse(); }); test("use strict with single quotes after statement does not yield strict mode code", () => { - ;'use strict'; - expect(isStrictMode()).toBeFalse(); + ;'use strict'; + expect(isStrictMode()).toBeFalse(); }); test("use strict with double quotes after statement does not yield strict mode code", () => { - ;"use strict"; - expect(isStrictMode()).toBeFalse(); + ;"use strict"; + expect(isStrictMode()).toBeFalse(); }); test("strict mode propogates down the scope chain", () => { - "use strict"; - expect(isStrictMode()).toBeTrue(); - (function() { + "use strict"; expect(isStrictMode()).toBeTrue(); - })(); + (function() { + expect(isStrictMode()).toBeTrue(); + })(); }); test("strict mode does not propogate up the scope chain", () => { - expect(isStrictMode()).toBeFalse(); - (function() { - "use strict"; - expect(isStrictMode()).toBeTrue(); - })(); - expect(isStrictMode()).toBeFalse(); + expect(isStrictMode()).toBeFalse(); + (function() { + "use strict"; + expect(isStrictMode()).toBeTrue(); + })(); + expect(isStrictMode()).toBeFalse(); }); test('only the string "use strict" yields strict mode code', () => { - "use stric"; - expect(isStrictMode()).toBeFalse(); + "use stric"; + expect(isStrictMode()).toBeFalse(); }); diff --git a/Libraries/LibJS/Tests/functions/function-this-in-arguments.js b/Libraries/LibJS/Tests/functions/function-this-in-arguments.js index 69d58310d5..cf24b6f8aa 100644 --- a/Libraries/LibJS/Tests/functions/function-this-in-arguments.js +++ b/Libraries/LibJS/Tests/functions/function-this-in-arguments.js @@ -1,16 +1,16 @@ test("basic functionality", () => { - expect(typeof this).toBe("object"); - expect(this).toBe(globalThis); + expect(typeof this).toBe("object"); + expect(this).toBe(globalThis); }); test("this inside instantiated functions is not globalThis", () => { - let functionThis; - function Foo() { - this.x = 5; - functionThis = this; - } + let functionThis; + function Foo() { + this.x = 5; + functionThis = this; + } - new Foo(); - expect(typeof functionThis).toBe("object"); - expect(functionThis.x).toBe(5); + new Foo(); + expect(typeof functionThis).toBe("object"); + expect(functionThis.x).toBe(5); }); diff --git a/Libraries/LibJS/Tests/indexed-access-string-object.js b/Libraries/LibJS/Tests/indexed-access-string-object.js index 362f112748..7946cbfbf4 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 a2cff0af23..7abad0f08d 100644 --- a/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js +++ b/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js @@ -1,12 +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 315f9f7343..6e9231eb96 100644 --- a/Libraries/LibJS/Tests/labels.js +++ b/Libraries/LibJS/Tests/labels.js @@ -1,39 +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; + outer: { + { + break outer; + } + expect().fail(); } - 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 ff2eaddeb5..27c92e23f9 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 73e7dce40f..765a9ead18 100644 --- a/Libraries/LibJS/Tests/loops/continue-basic.js +++ b/Libraries/LibJS/Tests/loops/continue-basic.js @@ -1,10 +1,10 @@ test("basic functionality", () => { - var j = 0; - for (var i = 0; i < 9; ++i) { - if (i == 3) { - continue; + var j = 0; + for (var i = 0; i < 9; ++i) { + if (i == 3) { + continue; + } + ++j; } - ++j; - } - expect(j).toBe(8); + expect(j).toBe(8); }); diff --git a/Libraries/LibJS/Tests/loops/do-while-basic.js b/Libraries/LibJS/Tests/loops/do-while-basic.js index 943490996b..baf428760e 100644 --- a/Libraries/LibJS/Tests/loops/do-while-basic.js +++ b/Libraries/LibJS/Tests/loops/do-while-basic.js @@ -1,14 +1,14 @@ test("basic functionality", () => { - let number = 0; - do { - number++; - } while (number < 9); - expect(number).toBe(9); + let number = 0; + do { + number++; + } while (number < 9); + expect(number).toBe(9); }); test("no braces", () => { - let number = 0; - do number++; - while (number < 3); - expect(number).toBe(3); + let number = 0; + do number++; + while (number < 3); + expect(number).toBe(3); }); diff --git a/Libraries/LibJS/Tests/loops/for-basic.js b/Libraries/LibJS/Tests/loops/for-basic.js index a6d7e85e99..8a270ddee6 100644 --- a/Libraries/LibJS/Tests/loops/for-basic.js +++ b/Libraries/LibJS/Tests/loops/for-basic.js @@ -1,15 +1,15 @@ test("basic functionality", () => { - let a = []; - for (let i = 0; i < 3; ++i) { - a.push(i); - } - expect(a).toEqual([0, 1, 2]); + let a = []; + for (let i = 0; i < 3; ++i) { + a.push(i); + } + expect(a).toEqual([0, 1, 2]); }); test("only condition", () => { - let a = []; - for (; a.length < 3; ) { - a.push("x"); - } - expect(a).toEqual(["x", "x", "x"]); + let a = []; + for (; a.length < 3; ) { + a.push("x"); + } + expect(a).toEqual(["x", "x", "x"]); }); diff --git a/Libraries/LibJS/Tests/loops/for-head-errors.js b/Libraries/LibJS/Tests/loops/for-head-errors.js index 94fea40f5d..c1b96014b8 100644 --- a/Libraries/LibJS/Tests/loops/for-head-errors.js +++ b/Libraries/LibJS/Tests/loops/for-head-errors.js @@ -1,23 +1,23 @@ test("using undefined variable in initializer", () => { - expect(() => { - for (let i = foo; i < 100; ++i) {} - }).toThrowWithMessage(ReferenceError, "'foo' is not defined"); + expect(() => { + for (let i = foo; i < 100; ++i) {} + }).toThrowWithMessage(ReferenceError, "'foo' is not defined"); }); test("using undefined variable in condition", () => { - expect(() => { - for (let i = 0; i < foo; ++i) {} - }).toThrowWithMessage(ReferenceError, "'foo' is not defined"); + expect(() => { + for (let i = 0; i < foo; ++i) {} + }).toThrowWithMessage(ReferenceError, "'foo' is not defined"); }); test("using undefined variable in updater", () => { - let loopCount = 0; + let loopCount = 0; - expect(() => { - for (let i = 0; i < 100; ++foo) { - loopCount++; - } - }).toThrowWithMessage(ReferenceError, "'foo' is not defined"); + expect(() => { + for (let i = 0; i < 100; ++foo) { + loopCount++; + } + }).toThrowWithMessage(ReferenceError, "'foo' is not defined"); - expect(loopCount).toBe(1); + expect(loopCount).toBe(1); }); diff --git a/Libraries/LibJS/Tests/loops/for-in-basic.js b/Libraries/LibJS/Tests/loops/for-in-basic.js index f0e4fc1f51..5a35ee1c91 100644 --- a/Libraries/LibJS/Tests/loops/for-in-basic.js +++ b/Libraries/LibJS/Tests/loops/for-in-basic.js @@ -1,45 +1,45 @@ test("iterate through empty string", () => { - const a = []; - for (const property in "") { - a.push(property); - } - expect(a).toEqual([]); + const a = []; + for (const property in "") { + a.push(property); + } + expect(a).toEqual([]); }); test("iterate through number", () => { - const a = []; - for (const property in 123) { - a.push(property); - } - expect(a).toEqual([]); + const a = []; + for (const property in 123) { + a.push(property); + } + expect(a).toEqual([]); }); test("iterate through empty object", () => { - const a = []; - for (const property in {}) { - a.push(property); - } - expect(a).toEqual([]); + const a = []; + for (const property in {}) { + a.push(property); + } + expect(a).toEqual([]); }); test("iterate through string", () => { - const a = []; - for (const property in "hello") { - a.push(property); - } - expect(a).toEqual(["0", "1", "2", "3", "4"]); + const a = []; + for (const property in "hello") { + a.push(property); + } + expect(a).toEqual(["0", "1", "2", "3", "4"]); }); test("iterate through object", () => { - const a = []; - for (const property in { a: 1, b: 2, c: 2 }) { - a.push(property); - } - expect(a).toEqual(["a", "b", "c"]); + const a = []; + for (const property in { a: 1, b: 2, c: 2 }) { + a.push(property); + } + expect(a).toEqual(["a", "b", "c"]); }); test("use already-declared variable", () => { - var property; - for (property in "abc"); - expect(property).toBe("2"); + var property; + for (property in "abc"); + expect(property).toBe("2"); }); diff --git a/Libraries/LibJS/Tests/loops/for-no-curlies.js b/Libraries/LibJS/Tests/loops/for-no-curlies.js index a8c94ed19f..913347c395 100644 --- a/Libraries/LibJS/Tests/loops/for-no-curlies.js +++ b/Libraries/LibJS/Tests/loops/for-no-curlies.js @@ -1,5 +1,5 @@ test("basic functionality", () => { - let number = 0; - for (let i = 0; i < 3; ++i) for (let j = 0; j < 3; ++j) number++; - expect(number).toBe(9); + let number = 0; + for (let i = 0; i < 3; ++i) for (let j = 0; j < 3; ++j) number++; + expect(number).toBe(9); }); diff --git a/Libraries/LibJS/Tests/loops/for-of-basic.js b/Libraries/LibJS/Tests/loops/for-of-basic.js index b415f0e753..0a1d38a778 100644 --- a/Libraries/LibJS/Tests/loops/for-of-basic.js +++ b/Libraries/LibJS/Tests/loops/for-of-basic.js @@ -1,47 +1,47 @@ describe("correct behavior", () => { - test("iterate through array", () => { - const a = []; - for (const num of [1, 2, 3]) { - a.push(num); - } - expect(a).toEqual([1, 2, 3]); - }); + test("iterate through array", () => { + const a = []; + for (const num of [1, 2, 3]) { + a.push(num); + } + expect(a).toEqual([1, 2, 3]); + }); - test("iterate through string", () => { - const a = []; - for (const char of "hello") { - a.push(char); - } - expect(a).toEqual(["h", "e", "l", "l", "o"]); - }); + test("iterate through string", () => { + const a = []; + for (const char of "hello") { + a.push(char); + } + expect(a).toEqual(["h", "e", "l", "l", "o"]); + }); - test("iterate through string object", () => { - const a = []; - for (const char of new String("hello")) { - a.push(char); - } - expect(a).toEqual(["h", "e", "l", "l", "o"]); - }); + test("iterate through string object", () => { + const a = []; + for (const char of new String("hello")) { + a.push(char); + } + expect(a).toEqual(["h", "e", "l", "l", "o"]); + }); - test("use already-declared variable", () => { - var char; - for (char of "abc"); - expect(char).toBe("c"); - }); + test("use already-declared variable", () => { + var char; + for (char of "abc"); + expect(char).toBe("c"); + }); }); describe("errors", () => { - test("right hand side is a primitive", () => { - expect(() => { - for (const _ of 123) { - } - }).toThrowWithMessage(TypeError, "for..of right-hand side must be iterable"); - }); + test("right hand side is a primitive", () => { + expect(() => { + for (const _ of 123) { + } + }).toThrowWithMessage(TypeError, "for..of right-hand side must be iterable"); + }); - test("right hand side is an object", () => { - expect(() => { - for (const _ of { foo: 1, bar: 2 }) { - } - }).toThrowWithMessage(TypeError, "for..of right-hand side must be iterable"); - }); + test("right hand side is an object", () => { + expect(() => { + for (const _ of { foo: 1, bar: 2 }) { + } + }).toThrowWithMessage(TypeError, "for..of right-hand side must be iterable"); + }); }); diff --git a/Libraries/LibJS/Tests/loops/for-scopes.js b/Libraries/LibJS/Tests/loops/for-scopes.js index 0fae8fc501..2f89bd1229 100644 --- a/Libraries/LibJS/Tests/loops/for-scopes.js +++ b/Libraries/LibJS/Tests/loops/for-scopes.js @@ -1,18 +1,18 @@ test("var in for head", () => { - for (var v = 5; false; ); - expect(v).toBe(5); + for (var v = 5; false; ); + expect(v).toBe(5); }); test("let in for head", () => { - for (let l = 5; false; ); - expect(() => { - l; - }).toThrowWithMessage(ReferenceError, "'l' is not defined"); + for (let l = 5; false; ); + expect(() => { + l; + }).toThrowWithMessage(ReferenceError, "'l' is not defined"); }); test("const in for head", () => { - for (const c = 5; false; ); - expect(() => { - c; - }).toThrowWithMessage(ReferenceError, "'c' is not defined"); + for (const c = 5; false; ); + expect(() => { + c; + }).toThrowWithMessage(ReferenceError, "'c' is not defined"); }); diff --git a/Libraries/LibJS/Tests/loops/while-basic.js b/Libraries/LibJS/Tests/loops/while-basic.js index cd1ded3e13..ce25d27345 100644 --- a/Libraries/LibJS/Tests/loops/while-basic.js +++ b/Libraries/LibJS/Tests/loops/while-basic.js @@ -1,19 +1,19 @@ test("basic functionality", () => { - let number = 0; - while (number < 9) { - number++; - } - expect(number).toBe(9); + let number = 0; + while (number < 9) { + number++; + } + expect(number).toBe(9); }); test("no braces", () => { - let number = 0; - while (number < 3) number++; - expect(number).toBe(3); + let number = 0; + while (number < 3) number++; + expect(number).toBe(3); }); test("does not loop when initially false", () => { - while (false) { - expect().fail(); - } + while (false) { + expect().fail(); + } }); diff --git a/Libraries/LibJS/Tests/new-expression.js b/Libraries/LibJS/Tests/new-expression.js index eedbd671b3..9c23ce336b 100644 --- a/Libraries/LibJS/Tests/new-expression.js +++ b/Libraries/LibJS/Tests/new-expression.js @@ -2,53 +2,53 @@ // respects the .prettierignore file! test("new-expression parsing", () => { - function Foo() { - this.x = 1; - } + function Foo() { + this.x = 1; + } - let foo = new Foo(); - expect(foo.x).toBe(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 - (); - expect(foo.x).toBe(1); + foo = new + Foo + (); + expect(foo.x).toBe(1); - foo = new Foo + 2 - expect(foo).toBe("[object Object]2"); + foo = new Foo + 2 + expect(foo).toBe("[object Object]2"); }); test("new-expressions with object keys", () => { - let a = { - b: function () { - this.x = 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); + 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).toBeUndefined(); - foo = new (funcGetter())(1, 5); - expect(foo.x).toBe(6); + 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 be3841fd92..48d09a255c 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(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); + 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(0.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((0.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 d35ff1ed06..754d281dc7 100644 --- a/Libraries/LibJS/Tests/object-basic.js +++ b/Libraries/LibJS/Tests/object-basic.js @@ -1,149 +1,149 @@ describe("correct behavior", () => { - test("numeric indexing", () => { - const o = { 1: 23 }; + test("numeric indexing", () => { + const o = { 1: 23 }; - expect(o[1]).toBe(23); - expect(o[1n]).toBe(23); - expect(o["1"]).toBe(23); + expect(o[1]).toBe(23); + expect(o[1n]).toBe(23); + expect(o["1"]).toBe(23); - o[10] = "123"; - expect(o[10]).toBe("123"); - expect(o["10"]).toBe("123"); + o[10] = "123"; + expect(o[10]).toBe("123"); + expect(o["10"]).toBe("123"); - o[10n] = "1234"; - expect(o[10]).toBe("1234"); - expect(o["10"]).toBe("1234"); - }); + o[10n] = "1234"; + expect(o[10]).toBe("1234"); + expect(o["10"]).toBe("1234"); + }); - test("string indexing", () => { - let foo = "bar"; + test("string indexing", () => { + let foo = "bar"; - const o = { - foo, - bar: "baz", - qux: true ? 10 : 20, - hello: "friends", - }; + const o = { + foo, + bar: "baz", + qux: true ? 10 : 20, + hello: "friends", + }; - expect(o.foo).toBe("bar"); - expect(o["foo"]).toBe("bar"); - expect(o.qux).toBe(10), expect(o.hello).toBe("friends"); - expect(o["hello"]).toBe("friends"); - }); + expect(o.foo).toBe("bar"); + expect(o["foo"]).toBe("bar"); + expect(o.qux).toBe(10), expect(o.hello).toBe("friends"); + expect(o["hello"]).toBe("friends"); + }); - test("computed properties", () => { - const foo = "bar"; - const computed = "computed"; - const o = { - [1 + 2]: 42, - [`I am a ${computed} key`]: foo, - }; + test("computed properties", () => { + const foo = "bar"; + const computed = "computed"; + const o = { + [1 + 2]: 42, + [`I am a ${computed} key`]: foo, + }; - expect(o[3]).toBe(42); - expect(o["I am a computed key"]).toBe("bar"); - }); + expect(o[3]).toBe(42); + expect(o["I am a computed key"]).toBe("bar"); + }); - test("duplicate keys", () => { - const o = { - duplicate: "hello", - duplicate: "world", - }; - expect(o.duplicate).toBe("world"); - }); + test("duplicate keys", () => { + const o = { + duplicate: "hello", + duplicate: "world", + }; + expect(o.duplicate).toBe("world"); + }); - test("assigning after creation", () => { - const o = {}; - o.baz = "test"; + test("assigning after creation", () => { + const o = {}; + o.baz = "test"; - expect(o.baz).toBe("test"); - expect(o["baz"]).toBe("test"); + expect(o.baz).toBe("test"); + expect(o["baz"]).toBe("test"); - expect(o[-1]).toBeUndefined(); - o[-1] = "hello friends"; - expect(o[-1]).toBe("hello friends"); - expect(o["-1"]).toBe("hello friends"); - }); + expect(o[-1]).toBeUndefined(); + o[-1] = "hello friends"; + expect(o[-1]).toBe("hello friends"); + expect(o["-1"]).toBe("hello friends"); + }); - test("floating point keys", () => { - const math = { 3.14: "pi" }; - expect(math["3.14"]).toBe("pi"); - // FIXME: Floating point literals are coerced to i32 - // expect(math[3.14]).toBe("pi"); - }); + test("floating point keys", () => { + const math = { 3.14: "pi" }; + expect(math["3.14"]).toBe("pi"); + // FIXME: Floating point literals are coerced to i32 + // expect(math[3.14]).toBe("pi"); + }); - test("keywords as property keys", () => { - const o2 = { - return: 1, - yield: 1, - for: 1, - catch: 1, - break: 1, - }; + test("keywords as property keys", () => { + const o2 = { + return: 1, + yield: 1, + for: 1, + catch: 1, + break: 1, + }; - expect(o2.return).toBe(1); - expect(o2.yield).toBe(1); - expect(o2.for).toBe(1); - expect(o2.catch).toBe(1); - expect(o2.break).toBe(1); - }); + expect(o2.return).toBe(1); + expect(o2.yield).toBe(1); + expect(o2.for).toBe(1); + expect(o2.catch).toBe(1); + expect(o2.break).toBe(1); + }); - test("prototypical inheritance", () => { - var base = { - getNumber() { - return 10; - }, - }; + test("prototypical inheritance", () => { + var base = { + getNumber() { + return 10; + }, + }; - var derived = { - getNumber() { - return 20 + super.getNumber(); - }, - }; + var derived = { + getNumber() { + return 20 + super.getNumber(); + }, + }; - Object.setPrototypeOf(derived, base); - expect(derived.getNumber()).toBe(30); - }); + Object.setPrototypeOf(derived, base); + expect(derived.getNumber()).toBe(30); + }); }); describe("side effects", () => { - let a; - const append = x => { - a.push(x); - }; + let a; + const append = x => { + a.push(x); + }; - test("computed key side effects", () => { - a = []; - const o3 = { [append(1)]: 1, [append(2)]: 2, [append(3)]: 3 }; - expect(a).toHaveLength(3); - expect(a[0]).toBe(1); - expect(a[1]).toBe(2); - expect(a[2]).toBe(3); - expect(o3.undefined).toBe(3); - }); + test("computed key side effects", () => { + a = []; + const o3 = { [append(1)]: 1, [append(2)]: 2, [append(3)]: 3 }; + expect(a).toHaveLength(3); + expect(a[0]).toBe(1); + expect(a[1]).toBe(2); + expect(a[2]).toBe(3); + expect(o3.undefined).toBe(3); + }); - test("value side effects", () => { - a = []; - const o4 = { test: append(1), test: append(2), test: append(3) }; - expect(a).toHaveLength(3); - expect(a[0]).toBe(1); - expect(a[1]).toBe(2); - expect(a[2]).toBe(3); - expect(o4.test).toBeUndefined(); - }); + test("value side effects", () => { + a = []; + const o4 = { test: append(1), test: append(2), test: append(3) }; + expect(a).toHaveLength(3); + expect(a[0]).toBe(1); + expect(a[1]).toBe(2); + expect(a[2]).toBe(3); + expect(o4.test).toBeUndefined(); + }); }); describe("errors", () => { - test("syntax errors", () => { - expect("({ foo: function() { super.bar; } })").not.toEval(); - expect("({ get ...foo })").not.toEval(); - expect("({ get... foo })").not.toEval(); - expect("({ get foo })").not.toEval(); - expect("({ get foo: bar })").not.toEval(); - expect("({ get [foo]: bar })").not.toEval(); - expect("({ get ...[foo] })").not.toEval(); - expect("({ get foo(bar) {} })").not.toEval(); - expect("({ set foo() {} })").not.toEval(); - expect("({ set foo(bar, baz) {} })").not.toEval(); - expect("({ ...foo: bar })").not.toEval(); - }); + test("syntax errors", () => { + expect("({ foo: function() { super.bar; } })").not.toEval(); + expect("({ get ...foo })").not.toEval(); + expect("({ get... foo })").not.toEval(); + expect("({ get foo })").not.toEval(); + expect("({ get foo: bar })").not.toEval(); + expect("({ get [foo]: bar })").not.toEval(); + expect("({ get ...[foo] })").not.toEval(); + expect("({ get foo(bar) {} })").not.toEval(); + expect("({ set foo() {} })").not.toEval(); + expect("({ set foo(bar, baz) {} })").not.toEval(); + expect("({ ...foo: bar })").not.toEval(); + }); }); diff --git a/Libraries/LibJS/Tests/object-getter-setter-shorthand.js b/Libraries/LibJS/Tests/object-getter-setter-shorthand.js index ced18d827e..02b513800b 100644 --- a/Libraries/LibJS/Tests/object-getter-setter-shorthand.js +++ b/Libraries/LibJS/Tests/object-getter-setter-shorthand.js @@ -1,62 +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 1e7bd9bf11..aedff10bf9 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 70c2cd09b1..c9da1a1ac7 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 c236f628cc..cbe9ee26fa 100644 --- a/Libraries/LibJS/Tests/operators/assignment-operators.js +++ b/Libraries/LibJS/Tests/operators/assignment-operators.js @@ -1,55 +1,55 @@ let x; test("basic functionality", () => { - x = 1; - expect((x = 2)).toBe(2); - expect(x).toBe(2); + x = 1; + expect((x = 2)).toBe(2); + expect(x).toBe(2); - x = 1; - expect((x += 2)).toBe(3); - expect(x).toBe(3); + x = 1; + expect((x += 2)).toBe(3); + expect(x).toBe(3); - x = 3; - expect((x -= 2)).toBe(1); - expect(x).toBe(1); + x = 3; + expect((x -= 2)).toBe(1); + expect(x).toBe(1); - x = 3; - expect((x *= 2)).toBe(6); - expect(x).toBe(6); + x = 3; + expect((x *= 2)).toBe(6); + expect(x).toBe(6); - x = 6; - expect((x /= 2)).toBe(3); - expect(x).toBe(3); + x = 6; + expect((x /= 2)).toBe(3); + expect(x).toBe(3); - x = 6; - expect((x %= 4)).toBe(2); - expect(x).toBe(2); + x = 6; + expect((x %= 4)).toBe(2); + expect(x).toBe(2); - x = 2; - expect((x **= 3)).toBe(8); - expect(x).toBe(8); + x = 2; + expect((x **= 3)).toBe(8); + expect(x).toBe(8); - x = 3; - expect((x &= 2)).toBe(2); - expect(x).toBe(2); + x = 3; + expect((x &= 2)).toBe(2); + expect(x).toBe(2); - x = 3; - expect((x |= 4)).toBe(7); - expect(x).toBe(7); + x = 3; + expect((x |= 4)).toBe(7); + expect(x).toBe(7); - x = 6; - expect((x ^= 2)).toBe(4); - expect(x).toBe(4); + x = 6; + expect((x ^= 2)).toBe(4); + expect(x).toBe(4); - x = 2; - expect((x <<= 2)).toBe(8); - expect(x).toBe(8); + x = 2; + expect((x <<= 2)).toBe(8); + expect(x).toBe(8); - x = 8; - expect((x >>= 2)).toBe(2); - expect(x).toBe(2); + x = 8; + expect((x >>= 2)).toBe(2); + expect(x).toBe(2); - x = -(2 ** 32 - 10); - expect((x >>>= 2)).toBe(2); - expect(x).toBe(2); + x = -(2 ** 32 - 10); + expect((x >>>= 2)).toBe(2); + expect(x).toBe(2); }); diff --git a/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js b/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js index 6955b7b791..d0c9d8d5f9 100644 --- a/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js +++ b/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js @@ -1,60 +1,60 @@ test("basic numeric shifting", () => { - expect(0 << 0).toBe(0); - expect(0 << 1).toBe(0); - expect(0 << 2).toBe(0); - expect(0 << 3).toBe(0); - expect(0 << 4).toBe(0); - expect(0 << 5).toBe(0); + expect(0 << 0).toBe(0); + expect(0 << 1).toBe(0); + expect(0 << 2).toBe(0); + expect(0 << 3).toBe(0); + expect(0 << 4).toBe(0); + expect(0 << 5).toBe(0); - expect(1 << 0).toBe(1); - expect(1 << 1).toBe(2); - expect(1 << 2).toBe(4); - expect(1 << 3).toBe(8); - expect(1 << 4).toBe(16); - expect(1 << 5).toBe(32); + expect(1 << 0).toBe(1); + expect(1 << 1).toBe(2); + expect(1 << 2).toBe(4); + expect(1 << 3).toBe(8); + expect(1 << 4).toBe(16); + expect(1 << 5).toBe(32); - expect(2 << 0).toBe(2); - expect(2 << 1).toBe(4); - expect(2 << 2).toBe(8); - expect(2 << 3).toBe(16); - expect(2 << 4).toBe(32); - expect(2 << 5).toBe(64); + expect(2 << 0).toBe(2); + expect(2 << 1).toBe(4); + expect(2 << 2).toBe(8); + expect(2 << 3).toBe(16); + expect(2 << 4).toBe(32); + expect(2 << 5).toBe(64); - expect(3 << 0).toBe(3); - expect(3 << 1).toBe(6); - expect(3 << 2).toBe(12); - expect(3 << 3).toBe(24); - expect(3 << 4).toBe(48); - expect(3 << 5).toBe(96); + expect(3 << 0).toBe(3); + expect(3 << 1).toBe(6); + expect(3 << 2).toBe(12); + expect(3 << 3).toBe(24); + expect(3 << 4).toBe(48); + expect(3 << 5).toBe(96); - expect(4 << 0).toBe(4); - expect(4 << 1).toBe(8); - expect(4 << 2).toBe(16); - expect(4 << 3).toBe(32); - expect(4 << 4).toBe(64); - expect(4 << 5).toBe(128); + expect(4 << 0).toBe(4); + expect(4 << 1).toBe(8); + expect(4 << 2).toBe(16); + expect(4 << 3).toBe(32); + expect(4 << 4).toBe(64); + expect(4 << 5).toBe(128); - expect(5 << 0).toBe(5); - expect(5 << 1).toBe(10); - expect(5 << 2).toBe(20); - expect(5 << 3).toBe(40); - expect(5 << 4).toBe(80); - expect(5 << 5).toBe(160); + expect(5 << 0).toBe(5); + expect(5 << 1).toBe(10); + expect(5 << 2).toBe(20); + expect(5 << 3).toBe(40); + expect(5 << 4).toBe(80); + expect(5 << 5).toBe(160); }); test("shifting with non-numeric values", () => { - let x = 3; - let y = 7; + let x = 3; + let y = 7; - expect("42" << 6).toBe(2688); - expect(x << y).toBe(384); - expect(x << [[[[12]]]]).toBe(12288); - expect(undefined << y).toBe(0); - expect("a" << "b").toBe(0); - expect(null << null).toBe(0); - expect(undefined << undefined).toBe(0); - expect(NaN << NaN).toBe(0); - expect(NaN << 6).toBe(0); - expect(Infinity << Infinity).toBe(0); - expect(-Infinity << Infinity).toBe(0); + expect("42" << 6).toBe(2688); + expect(x << y).toBe(384); + expect(x << [[[[12]]]]).toBe(12288); + expect(undefined << y).toBe(0); + expect("a" << "b").toBe(0); + expect(null << null).toBe(0); + expect(undefined << undefined).toBe(0); + expect(NaN << NaN).toBe(0); + expect(NaN << 6).toBe(0); + expect(Infinity << Infinity).toBe(0); + expect(-Infinity << Infinity).toBe(0); }); diff --git a/Libraries/LibJS/Tests/operators/binary-bitwise-or.js b/Libraries/LibJS/Tests/operators/binary-bitwise-or.js index 74edcbd9ec..485d1226d2 100644 --- a/Libraries/LibJS/Tests/operators/binary-bitwise-or.js +++ b/Libraries/LibJS/Tests/operators/binary-bitwise-or.js @@ -1,60 +1,60 @@ test("basic numeric or", () => { - expect(0 | 0).toBe(0); - expect(0 | 1).toBe(1); - expect(0 | 2).toBe(2); - expect(0 | 3).toBe(3); - expect(0 | 4).toBe(4); - expect(0 | 5).toBe(5); + expect(0 | 0).toBe(0); + expect(0 | 1).toBe(1); + expect(0 | 2).toBe(2); + expect(0 | 3).toBe(3); + expect(0 | 4).toBe(4); + expect(0 | 5).toBe(5); - expect(1 | 0).toBe(1); - expect(1 | 1).toBe(1); - expect(1 | 2).toBe(3); - expect(1 | 3).toBe(3); - expect(1 | 4).toBe(5); - expect(1 | 5).toBe(5); + expect(1 | 0).toBe(1); + expect(1 | 1).toBe(1); + expect(1 | 2).toBe(3); + expect(1 | 3).toBe(3); + expect(1 | 4).toBe(5); + expect(1 | 5).toBe(5); - expect(2 | 0).toBe(2); - expect(2 | 1).toBe(3); - expect(2 | 2).toBe(2); - expect(2 | 3).toBe(3); - expect(2 | 4).toBe(6); - expect(2 | 5).toBe(7); + expect(2 | 0).toBe(2); + expect(2 | 1).toBe(3); + expect(2 | 2).toBe(2); + expect(2 | 3).toBe(3); + expect(2 | 4).toBe(6); + expect(2 | 5).toBe(7); - expect(3 | 0).toBe(3); - expect(3 | 1).toBe(3); - expect(3 | 2).toBe(3); - expect(3 | 3).toBe(3); - expect(3 | 4).toBe(7); - expect(3 | 5).toBe(7); + expect(3 | 0).toBe(3); + expect(3 | 1).toBe(3); + expect(3 | 2).toBe(3); + expect(3 | 3).toBe(3); + expect(3 | 4).toBe(7); + expect(3 | 5).toBe(7); - expect(4 | 0).toBe(4); - expect(4 | 1).toBe(5); - expect(4 | 2).toBe(6); - expect(4 | 3).toBe(7); - expect(4 | 4).toBe(4); - expect(4 | 5).toBe(5); + expect(4 | 0).toBe(4); + expect(4 | 1).toBe(5); + expect(4 | 2).toBe(6); + expect(4 | 3).toBe(7); + expect(4 | 4).toBe(4); + expect(4 | 5).toBe(5); - expect(5 | 0).toBe(5); - expect(5 | 1).toBe(5); - expect(5 | 2).toBe(7); - expect(5 | 3).toBe(7); - expect(5 | 4).toBe(5); - expect(5 | 5).toBe(5); + expect(5 | 0).toBe(5); + expect(5 | 1).toBe(5); + expect(5 | 2).toBe(7); + expect(5 | 3).toBe(7); + expect(5 | 4).toBe(5); + expect(5 | 5).toBe(5); }); test("or with non-numeric values", () => { - let x = 3; - let y = 7; + let x = 3; + let y = 7; - expect("42" | 6).toBe(46); - expect(x | y).toBe(7); - expect(x | [[[[12]]]]).toBe(15); - expect(undefined | y).toBe(7); - expect("a" | "b").toBe(0); - expect(null | null).toBe(0); - expect(undefined | undefined).toBe(0); - expect(NaN | NaN).toBe(0); - expect(NaN | 6).toBe(6); - expect(Infinity | Infinity).toBe(0); - expect(-Infinity | Infinity).toBe(0); + expect("42" | 6).toBe(46); + expect(x | y).toBe(7); + expect(x | [[[[12]]]]).toBe(15); + expect(undefined | y).toBe(7); + expect("a" | "b").toBe(0); + expect(null | null).toBe(0); + expect(undefined | undefined).toBe(0); + expect(NaN | NaN).toBe(0); + expect(NaN | 6).toBe(6); + expect(Infinity | Infinity).toBe(0); + expect(-Infinity | Infinity).toBe(0); }); diff --git a/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js b/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js index ec8982b0ae..f071c5da92 100644 --- a/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js +++ b/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js @@ -1,62 +1,62 @@ test("basic numeric shifting", () => { - expect(0 >> 0).toBe(0); - expect(0 >> 1).toBe(0); - expect(0 >> 2).toBe(0); - expect(0 >> 3).toBe(0); - expect(0 >> 4).toBe(0); - expect(0 >> 5).toBe(0); + expect(0 >> 0).toBe(0); + expect(0 >> 1).toBe(0); + expect(0 >> 2).toBe(0); + expect(0 >> 3).toBe(0); + expect(0 >> 4).toBe(0); + expect(0 >> 5).toBe(0); - expect(1 >> 0).toBe(1); - expect(1 >> 1).toBe(0); - expect(1 >> 2).toBe(0); - expect(1 >> 3).toBe(0); - expect(1 >> 4).toBe(0); - expect(1 >> 5).toBe(0); + expect(1 >> 0).toBe(1); + expect(1 >> 1).toBe(0); + expect(1 >> 2).toBe(0); + expect(1 >> 3).toBe(0); + expect(1 >> 4).toBe(0); + expect(1 >> 5).toBe(0); - expect(5 >> 0).toBe(5); - expect(5 >> 1).toBe(2); - expect(5 >> 2).toBe(1); - expect(5 >> 3).toBe(0); - expect(5 >> 4).toBe(0); - expect(5 >> 5).toBe(0); + expect(5 >> 0).toBe(5); + expect(5 >> 1).toBe(2); + expect(5 >> 2).toBe(1); + expect(5 >> 3).toBe(0); + expect(5 >> 4).toBe(0); + expect(5 >> 5).toBe(0); - expect(42 >> 0).toBe(42); - expect(42 >> 1).toBe(21); - expect(42 >> 2).toBe(10); - expect(42 >> 3).toBe(5); - expect(42 >> 4).toBe(2); - expect(42 >> 5).toBe(1); + expect(42 >> 0).toBe(42); + expect(42 >> 1).toBe(21); + expect(42 >> 2).toBe(10); + expect(42 >> 3).toBe(5); + expect(42 >> 4).toBe(2); + expect(42 >> 5).toBe(1); }); test("numeric shifting with negative lhs values", () => { - expect(-1 >> 0).toBe(-1); - expect(-1 >> 1).toBe(-1); - expect(-1 >> 2).toBe(-1); - expect(-1 >> 3).toBe(-1); - expect(-1 >> 4).toBe(-1); - expect(-1 >> 5).toBe(-1); + expect(-1 >> 0).toBe(-1); + expect(-1 >> 1).toBe(-1); + expect(-1 >> 2).toBe(-1); + expect(-1 >> 3).toBe(-1); + expect(-1 >> 4).toBe(-1); + expect(-1 >> 5).toBe(-1); - expect(-5 >> 0).toBe(-5); - expect(-5 >> 1).toBe(-3); - expect(-5 >> 2).toBe(-2); - expect(-5 >> 3).toBe(-1); - expect(-5 >> 4).toBe(-1); - expect(-5 >> 5).toBe(-1); + expect(-5 >> 0).toBe(-5); + expect(-5 >> 1).toBe(-3); + expect(-5 >> 2).toBe(-2); + expect(-5 >> 3).toBe(-1); + expect(-5 >> 4).toBe(-1); + expect(-5 >> 5).toBe(-1); }); test("shifting with non-numeric values", () => { - let x = 67; - let y = 4; + let x = 67; + let y = 4; - expect("42" >> 3).toBe(5); - expect(x >> y).toBe(4); - expect(x >> [[[[5]]]]).toBe(2); - expect(undefined >> y).toBe(0); - expect("a" >> "b").toBe(0); - expect(null >> null).toBe(0); - expect(undefined >> undefined).toBe(0); - expect(NaN >> NaN).toBe(0); - expect(6 >> NaN).toBe(6); - expect(Infinity >> Infinity).toBe(0); - expect(-Infinity >> Infinity).toBe(0); + expect("42" >> 3).toBe(5); + expect(x >> y).toBe(4); + expect(x >> [[[[5]]]]).toBe(2); + expect(undefined >> y).toBe(0); + expect("a" >> "b").toBe(0); + expect(null >> null).toBe(0); + expect(undefined >> undefined).toBe(0); + expect(NaN >> NaN).toBe(0); + expect(6 >> NaN).toBe(6); + expect(Infinity >> Infinity).toBe(0); + expect(-Infinity >> Infinity).toBe(0); }); 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 cddad0eb7a..4a950e18ef 100644 --- a/Libraries/LibJS/Tests/operators/binary-bitwise-unsigned-right-shift.js +++ b/Libraries/LibJS/Tests/operators/binary-bitwise-unsigned-right-shift.js @@ -1,62 +1,62 @@ test("basic numeric shifting", () => { - expect(0 >>> 0).toBe(0); - expect(0 >>> 1).toBe(0); - expect(0 >>> 2).toBe(0); - expect(0 >>> 3).toBe(0); - expect(0 >>> 4).toBe(0); - expect(0 >>> 5).toBe(0); + expect(0 >>> 0).toBe(0); + expect(0 >>> 1).toBe(0); + expect(0 >>> 2).toBe(0); + expect(0 >>> 3).toBe(0); + expect(0 >>> 4).toBe(0); + expect(0 >>> 5).toBe(0); - expect(1 >>> 0).toBe(1); - expect(1 >>> 1).toBe(0); - expect(1 >>> 2).toBe(0); - expect(1 >>> 3).toBe(0); - expect(1 >>> 4).toBe(0); - expect(1 >>> 5).toBe(0); + expect(1 >>> 0).toBe(1); + expect(1 >>> 1).toBe(0); + expect(1 >>> 2).toBe(0); + expect(1 >>> 3).toBe(0); + expect(1 >>> 4).toBe(0); + expect(1 >>> 5).toBe(0); - expect(5 >>> 0).toBe(5); - expect(5 >>> 1).toBe(2); - expect(5 >>> 2).toBe(1); - expect(5 >>> 3).toBe(0); - expect(5 >>> 4).toBe(0); - expect(5 >>> 5).toBe(0); + expect(5 >>> 0).toBe(5); + expect(5 >>> 1).toBe(2); + expect(5 >>> 2).toBe(1); + expect(5 >>> 3).toBe(0); + expect(5 >>> 4).toBe(0); + expect(5 >>> 5).toBe(0); - expect(42 >>> 0).toBe(42); - expect(42 >>> 1).toBe(21); - expect(42 >>> 2).toBe(10); - expect(42 >>> 3).toBe(5); - expect(42 >>> 4).toBe(2); - expect(42 >>> 5).toBe(1); + expect(42 >>> 0).toBe(42); + expect(42 >>> 1).toBe(21); + expect(42 >>> 2).toBe(10); + expect(42 >>> 3).toBe(5); + expect(42 >>> 4).toBe(2); + expect(42 >>> 5).toBe(1); }); test("numeric shifting with negative lhs values", () => { - expect(-1 >>> 0).toBe(4294967295); - expect(-1 >>> 1).toBe(2147483647); - expect(-1 >>> 2).toBe(1073741823); - expect(-1 >>> 3).toBe(536870911); - expect(-1 >>> 4).toBe(268435455); - expect(-1 >>> 5).toBe(134217727); + expect(-1 >>> 0).toBe(4294967295); + expect(-1 >>> 1).toBe(2147483647); + expect(-1 >>> 2).toBe(1073741823); + expect(-1 >>> 3).toBe(536870911); + expect(-1 >>> 4).toBe(268435455); + expect(-1 >>> 5).toBe(134217727); - expect(-5 >>> 0).toBe(4294967291); - expect(-5 >>> 1).toBe(2147483645); - expect(-5 >>> 2).toBe(1073741822); - expect(-5 >>> 3).toBe(536870911); - expect(-5 >>> 4).toBe(268435455); - expect(-5 >>> 5).toBe(134217727); + expect(-5 >>> 0).toBe(4294967291); + expect(-5 >>> 1).toBe(2147483645); + expect(-5 >>> 2).toBe(1073741822); + expect(-5 >>> 3).toBe(536870911); + expect(-5 >>> 4).toBe(268435455); + expect(-5 >>> 5).toBe(134217727); }); test("shifting with non-numeric values", () => { - let x = -67; - let y = 4; + let x = -67; + let y = 4; - expect("-42" >>> 3).toBe(536870906); - expect(x >>> y).toBe(268435451); - expect(x >>> [[[[5]]]]).toBe(134217725); - expect(undefined >>> y).toBe(0); - expect("a" >>> "b").toBe(0); - expect(null >>> null).toBe(0); - expect(undefined >>> undefined).toBe(0); - expect(NaN >>> NaN).toBe(0); - expect(6 >>> NaN).toBe(6); - expect(Infinity >>> Infinity).toBe(0); - expect(-Infinity >>> Infinity).toBe(0); + expect("-42" >>> 3).toBe(536870906); + expect(x >>> y).toBe(268435451); + expect(x >>> [[[[5]]]]).toBe(134217725); + expect(undefined >>> y).toBe(0); + expect("a" >>> "b").toBe(0); + expect(null >>> null).toBe(0); + expect(undefined >>> undefined).toBe(0); + expect(NaN >>> NaN).toBe(0); + expect(6 >>> NaN).toBe(6); + expect(Infinity >>> Infinity).toBe(0); + expect(-Infinity >>> Infinity).toBe(0); }); diff --git a/Libraries/LibJS/Tests/operators/binary-relational.js b/Libraries/LibJS/Tests/operators/binary-relational.js index 64336d12c1..307f7164e4 100644 --- a/Libraries/LibJS/Tests/operators/binary-relational.js +++ b/Libraries/LibJS/Tests/operators/binary-relational.js @@ -1,729 +1,729 @@ test("basic functionality", () => { - 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]]; - expect(x < y).toBe(test[2]); - expect(x > y).toBe(test[3]); - expect(x <= y).toBe(test[4]); - expect(x >= y).toBe(test[5]); - } + expect(x < y).toBe(test[2]); + expect(x > y).toBe(test[3]); + expect(x <= y).toBe(test[4]); + expect(x >= y).toBe(test[5]); + } }); diff --git a/Libraries/LibJS/Tests/operators/comma-operator.js b/Libraries/LibJS/Tests/operators/comma-operator.js index 3b47757370..368a43fff5 100644 --- a/Libraries/LibJS/Tests/operators/comma-operator.js +++ b/Libraries/LibJS/Tests/operators/comma-operator.js @@ -1,24 +1,24 @@ test("inside parenthesis", () => { - expect((1, 2, 3)).toBe(3); - expect((1, 2 + 3, 4)).toBe(4); + expect((1, 2, 3)).toBe(3); + expect((1, 2 + 3, 4)).toBe(4); }); test("with post-increment operator", () => { - let foo = 0; - foo = (foo++, foo); - expect(foo).toBe(1); + let foo = 0; + foo = (foo++, foo); + expect(foo).toBe(1); }); test("with assignment operator", () => { - var a, b, c; - expect(((a = b = 3), (c = 4))).toBe(4); - expect(a).toBe(3); - expect(b).toBe(3); - expect(c).toBe(4); + var a, b, c; + expect(((a = b = 3), (c = 4))).toBe(4); + expect(a).toBe(3); + expect(b).toBe(3); + expect(c).toBe(4); - var x, y, z; - expect((x = ((y = 5), (z = 6)))).toBe(6); - expect(x).toBe(6); - expect(y).toBe(5); - expect(z).toBe(6); + var x, y, z; + expect((x = ((y = 5), (z = 6)))).toBe(6); + expect(x).toBe(6); + expect(y).toBe(5); + expect(z).toBe(6); }); diff --git a/Libraries/LibJS/Tests/operators/delete-basic.js b/Libraries/LibJS/Tests/operators/delete-basic.js index dc2345f7b2..eb1796cfae 100644 --- a/Libraries/LibJS/Tests/operators/delete-basic.js +++ b/Libraries/LibJS/Tests/operators/delete-basic.js @@ -1,58 +1,58 @@ test("deleting object properties", () => { - const o = {}; - o.x = 1; - o.y = 2; - o.z = 3; - expect(Object.getOwnPropertyNames(o)).toHaveLength(3); + const o = {}; + o.x = 1; + o.y = 2; + o.z = 3; + expect(Object.getOwnPropertyNames(o)).toHaveLength(3); - expect(delete o.x).toBeTrue(); - expect(o.hasOwnProperty("x")).toBeFalse(); - expect(o.hasOwnProperty("y")).toBeTrue(); - expect(o.hasOwnProperty("z")).toBeTrue(); - expect(Object.getOwnPropertyNames(o)).toHaveLength(2); + expect(delete o.x).toBeTrue(); + expect(o.hasOwnProperty("x")).toBeFalse(); + expect(o.hasOwnProperty("y")).toBeTrue(); + expect(o.hasOwnProperty("z")).toBeTrue(); + expect(Object.getOwnPropertyNames(o)).toHaveLength(2); - expect(delete o.y).toBeTrue(); - expect(o.hasOwnProperty("x")).toBeFalse(); - expect(o.hasOwnProperty("y")).toBeFalse(); - expect(o.hasOwnProperty("z")).toBeTrue(); - expect(Object.getOwnPropertyNames(o)).toHaveLength(1); + expect(delete o.y).toBeTrue(); + expect(o.hasOwnProperty("x")).toBeFalse(); + expect(o.hasOwnProperty("y")).toBeFalse(); + expect(o.hasOwnProperty("z")).toBeTrue(); + expect(Object.getOwnPropertyNames(o)).toHaveLength(1); - expect(delete o.z).toBeTrue(); - expect(o.hasOwnProperty("x")).toBeFalse(); - expect(o.hasOwnProperty("y")).toBeFalse(); - expect(o.hasOwnProperty("z")).toBeFalse(); - expect(Object.getOwnPropertyNames(o)).toHaveLength(0); + expect(delete o.z).toBeTrue(); + expect(o.hasOwnProperty("x")).toBeFalse(); + expect(o.hasOwnProperty("y")).toBeFalse(); + expect(o.hasOwnProperty("z")).toBeFalse(); + expect(Object.getOwnPropertyNames(o)).toHaveLength(0); }); test("deleting array indices", () => { - const a = [3, 5, 7]; + const a = [3, 5, 7]; - expect(Object.getOwnPropertyNames(a)).toHaveLength(4); + expect(Object.getOwnPropertyNames(a)).toHaveLength(4); - expect(delete a[0]).toBeTrue(); - expect(a.hasOwnProperty(0)).toBeFalse(); - expect(a.hasOwnProperty(1)).toBeTrue(); - expect(a.hasOwnProperty(2)).toBeTrue(); - expect(Object.getOwnPropertyNames(a)).toHaveLength(3); + expect(delete a[0]).toBeTrue(); + expect(a.hasOwnProperty(0)).toBeFalse(); + expect(a.hasOwnProperty(1)).toBeTrue(); + expect(a.hasOwnProperty(2)).toBeTrue(); + expect(Object.getOwnPropertyNames(a)).toHaveLength(3); - expect(delete a[1]).toBeTrue(); - expect(a.hasOwnProperty(0)).toBeFalse(); - expect(a.hasOwnProperty(1)).toBeFalse(); - expect(a.hasOwnProperty(2)).toBeTrue(); - expect(Object.getOwnPropertyNames(a)).toHaveLength(2); + expect(delete a[1]).toBeTrue(); + expect(a.hasOwnProperty(0)).toBeFalse(); + expect(a.hasOwnProperty(1)).toBeFalse(); + expect(a.hasOwnProperty(2)).toBeTrue(); + expect(Object.getOwnPropertyNames(a)).toHaveLength(2); - expect(delete a[2]).toBeTrue(); - expect(a.hasOwnProperty(0)).toBeFalse(); - expect(a.hasOwnProperty(1)).toBeFalse(); - expect(a.hasOwnProperty(2)).toBeFalse(); - expect(Object.getOwnPropertyNames(a)).toHaveLength(1); + expect(delete a[2]).toBeTrue(); + expect(a.hasOwnProperty(0)).toBeFalse(); + expect(a.hasOwnProperty(1)).toBeFalse(); + expect(a.hasOwnProperty(2)).toBeFalse(); + expect(Object.getOwnPropertyNames(a)).toHaveLength(1); }); test("deleting non-configurable property", () => { - const q = {}; - Object.defineProperty(q, "foo", { value: 1, writable: false, enumerable: false }); - expect(q.foo).toBe(1); + const q = {}; + Object.defineProperty(q, "foo", { value: 1, writable: false, enumerable: false }); + expect(q.foo).toBe(1); - expect(delete q.foo).toBeFalse(); - expect(q.hasOwnProperty("foo")).toBeTrue(); + expect(delete q.foo).toBeFalse(); + expect(q.hasOwnProperty("foo")).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/operators/delete-global-variable.js b/Libraries/LibJS/Tests/operators/delete-global-variable.js index 2c0f500169..81c5ccac66 100644 --- a/Libraries/LibJS/Tests/operators/delete-global-variable.js +++ b/Libraries/LibJS/Tests/operators/delete-global-variable.js @@ -1,9 +1,9 @@ a = 1; test("basic functionality", () => { - expect(delete a).toBeTrue(); + expect(delete a).toBeTrue(); - expect(() => { - a; - }).toThrowWithMessage(ReferenceError, "'a' is not defined"); + expect(() => { + a; + }).toThrowWithMessage(ReferenceError, "'a' is not defined"); }); diff --git a/Libraries/LibJS/Tests/operators/delete-globalThis-property-crash.js b/Libraries/LibJS/Tests/operators/delete-globalThis-property-crash.js index 1a51bd6962..27a219c5d6 100644 --- a/Libraries/LibJS/Tests/operators/delete-globalThis-property-crash.js +++ b/Libraries/LibJS/Tests/operators/delete-globalThis-property-crash.js @@ -1,8 +1,8 @@ a = 1; test("basic functionality", () => { - expect(delete globalThis.a).toBeTrue(); - expect(() => { - a = 2; - }).not.toThrow(); + expect(delete globalThis.a).toBeTrue(); + expect(() => { + a = 2; + }).not.toThrow(); }); diff --git a/Libraries/LibJS/Tests/operators/in-operator-basic.js b/Libraries/LibJS/Tests/operators/in-operator-basic.js index 54880993e9..1deec41f76 100644 --- a/Libraries/LibJS/Tests/operators/in-operator-basic.js +++ b/Libraries/LibJS/Tests/operators/in-operator-basic.js @@ -1,32 +1,32 @@ test("in operator with objects", () => { - const o = { foo: "bar", bar: undefined }; - expect("" in o).toBeFalse(); - expect("foo" in o).toBeTrue(); - expect("bar" in o).toBeTrue(); - expect("baz" in o).toBeFalse(); - expect("toString" in o).toBeTrue(); + const o = { foo: "bar", bar: undefined }; + expect("" in o).toBeFalse(); + expect("foo" in o).toBeTrue(); + expect("bar" in o).toBeTrue(); + expect("baz" in o).toBeFalse(); + expect("toString" in o).toBeTrue(); }); test("in operator with arrays", () => { - const a = ["hello", "friends"]; - expect(0 in a).toBeTrue(); - expect(1 in a).toBeTrue(); - expect(2 in a).toBeFalse(); - expect("0" in a).toBeTrue(); - expect("hello" in a).toBeFalse(); - expect("friends" in a).toBeFalse(); - expect("length" in a).toBeTrue(); + const a = ["hello", "friends"]; + expect(0 in a).toBeTrue(); + expect(1 in a).toBeTrue(); + expect(2 in a).toBeFalse(); + expect("0" in a).toBeTrue(); + expect("hello" in a).toBeFalse(); + expect("friends" in a).toBeFalse(); + expect("length" in a).toBeTrue(); }); test("in operator with string object", () => { - const s = new String("foo"); - expect("length" in s).toBeTrue(); + const s = new String("foo"); + expect("length" in s).toBeTrue(); }); test("error when used with primitives", () => { - ["foo", 123, null, undefined].forEach(value => { - expect(() => { - "prop" in value; - }).toThrowWithMessage(TypeError, "'in' operator must be used on an object"); - }); + ["foo", 123, null, undefined].forEach(value => { + expect(() => { + "prop" in value; + }).toThrowWithMessage(TypeError, "'in' operator must be used on an object"); + }); }); diff --git a/Libraries/LibJS/Tests/operators/instanceof-basic.js b/Libraries/LibJS/Tests/operators/instanceof-basic.js index 8d9935d769..e1050b7c02 100644 --- a/Libraries/LibJS/Tests/operators/instanceof-basic.js +++ b/Libraries/LibJS/Tests/operators/instanceof-basic.js @@ -1,24 +1,24 @@ test("basic functionality", () => { - function Foo() { - this.x = 123; - } + function Foo() { + this.x = 123; + } - const foo = new Foo(); - expect(foo instanceof Foo).toBeTrue(); + const foo = new Foo(); + expect(foo instanceof Foo).toBeTrue(); }); test("derived ES5 classes", () => { - 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); - const d = new Derived(); - expect(d instanceof Derived).toBeTrue(); - expect(d instanceof Base).toBeTrue(); + const d = new Derived(); + expect(d instanceof Derived).toBeTrue(); + expect(d instanceof Base).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/operators/logical-and.js b/Libraries/LibJS/Tests/operators/logical-and.js index 2ddbe1feea..6d916a5b0e 100644 --- a/Libraries/LibJS/Tests/operators/logical-and.js +++ b/Libraries/LibJS/Tests/operators/logical-and.js @@ -1,50 +1,50 @@ test("booleans", () => { - expect(true && true).toBeTrue(); - expect(false && false).toBeFalse(); - expect(true && false).toBeFalse(); - expect(false && true).toBeFalse(); + expect(true && true).toBeTrue(); + expect(false && false).toBeFalse(); + expect(true && false).toBeFalse(); + expect(false && true).toBeFalse(); }); test("strings", () => { - expect("" && "").toBe(""); - expect("" && false).toBe(""); - expect("" && true).toBe(""); - expect(false && "").toBeFalse(); - expect(true && "").toBe(""); - expect("foo" && "bar").toBe("bar"); - expect("foo" && false).toBeFalse(); - expect("foo" && true).toBeTrue(); - expect(false && "bar").toBeFalse(); - expect(true && "bar").toBe("bar"); + expect("" && "").toBe(""); + expect("" && false).toBe(""); + expect("" && true).toBe(""); + expect(false && "").toBeFalse(); + expect(true && "").toBe(""); + expect("foo" && "bar").toBe("bar"); + expect("foo" && false).toBeFalse(); + expect("foo" && true).toBeTrue(); + expect(false && "bar").toBeFalse(); + expect(true && "bar").toBe("bar"); }); test("numbers", () => { - expect(false && 1 === 2).toBeFalse(); - expect(true && 1 === 2).toBeFalse(); - expect(0 && false).toBe(0); - expect(0 && true).toBe(0); - expect(42 && false).toBeFalse(); - expect(42 && true).toBeTrue(); - expect(false && 0).toBeFalse(); - expect(true && 0).toBe(0); - expect(false && 42).toBeFalse(); - expect(true && 42).toBe(42); + expect(false && 1 === 2).toBeFalse(); + expect(true && 1 === 2).toBeFalse(); + expect(0 && false).toBe(0); + expect(0 && true).toBe(0); + expect(42 && false).toBeFalse(); + expect(42 && true).toBeTrue(); + expect(false && 0).toBeFalse(); + expect(true && 0).toBe(0); + expect(false && 42).toBeFalse(); + expect(true && 42).toBe(42); }); test("objects", () => { - expect([] && false).toBeFalse(); - expect([] && true).toBeTrue(); - expect(false && []).toBeFalse(); - expect(true && []).toHaveLength(0); + expect([] && false).toBeFalse(); + expect([] && true).toBeTrue(); + expect(false && []).toBeFalse(); + expect(true && []).toHaveLength(0); }); test("null & undefined", () => { - expect(null && false).toBeNull(); - expect(null && true).toBeNull(); - expect(false && null).toBeFalse(); - expect(true && null).toBeNull(); - expect(undefined && false).toBeUndefined(); - expect(undefined && true).toBeUndefined(); - expect(false && undefined).toBeFalse(); - expect(true && undefined).toBeUndefined(); + expect(null && false).toBeNull(); + expect(null && true).toBeNull(); + expect(false && null).toBeFalse(); + expect(true && null).toBeNull(); + expect(undefined && false).toBeUndefined(); + expect(undefined && true).toBeUndefined(); + expect(false && undefined).toBeFalse(); + expect(true && undefined).toBeUndefined(); }); diff --git a/Libraries/LibJS/Tests/operators/logical-expressions-short-circuit.js b/Libraries/LibJS/Tests/operators/logical-expressions-short-circuit.js index a095fefd91..28ad1b3d81 100644 --- a/Libraries/LibJS/Tests/operators/logical-expressions-short-circuit.js +++ b/Libraries/LibJS/Tests/operators/logical-expressions-short-circuit.js @@ -1,13 +1,13 @@ test("basic functionality", () => { - let foo = 1; - false && (foo = 2); - expect(foo).toBe(1); + let foo = 1; + false && (foo = 2); + expect(foo).toBe(1); - foo = 1; - true || (foo = 2); - expect(foo).toBe(1); + foo = 1; + true || (foo = 2); + expect(foo).toBe(1); - foo = 1; - true ?? (foo = 2); - expect(foo).toBe(1); + foo = 1; + true ?? (foo = 2); + expect(foo).toBe(1); }); diff --git a/Libraries/LibJS/Tests/operators/logical-nullish-coalescing.js b/Libraries/LibJS/Tests/operators/logical-nullish-coalescing.js index 9a4ad82e94..f8d778208f 100644 --- a/Libraries/LibJS/Tests/operators/logical-nullish-coalescing.js +++ b/Libraries/LibJS/Tests/operators/logical-nullish-coalescing.js @@ -1,50 +1,50 @@ test("booleans", () => { - expect(true ?? true).toBeTrue(); - expect(false ?? false).toBeFalse(); - expect(true ?? false).toBeTrue(); - expect(false ?? true).toBeFalse(); + expect(true ?? true).toBeTrue(); + expect(false ?? false).toBeFalse(); + expect(true ?? false).toBeTrue(); + expect(false ?? true).toBeFalse(); }); test("strings", () => { - expect("" ?? "").toBe(""); - expect("" ?? false).toBe(""); - expect("" ?? true).toBe(""); - expect(false ?? "").toBeFalse(); - expect(true ?? "").toBeTrue(); - expect("foo" ?? "bar").toBe("foo"); - expect("foo" ?? false).toBe("foo"); - expect("foo" ?? true).toBe("foo"); - expect(false ?? "bar").toBeFalse(); - expect(true ?? "bar").toBeTrue(); + expect("" ?? "").toBe(""); + expect("" ?? false).toBe(""); + expect("" ?? true).toBe(""); + expect(false ?? "").toBeFalse(); + expect(true ?? "").toBeTrue(); + expect("foo" ?? "bar").toBe("foo"); + expect("foo" ?? false).toBe("foo"); + expect("foo" ?? true).toBe("foo"); + expect(false ?? "bar").toBeFalse(); + expect(true ?? "bar").toBeTrue(); }); test("numbers", () => { - expect(false ?? 1 === 2).toBeFalse(); - expect(true ?? 1 === 2).toBeTrue(); - expect(0 ?? false).toBe(0); - expect(0 ?? true).toBe(0); - expect(42 ?? false).toBe(42); - expect(42 ?? true).toBe(42); - expect(false ?? 0).toBeFalse(); - expect(true ?? 0).toBeTrue(); - expect(false ?? 42).toBeFalse(); - expect(true ?? 42).toBeTrue(); + expect(false ?? 1 === 2).toBeFalse(); + expect(true ?? 1 === 2).toBeTrue(); + expect(0 ?? false).toBe(0); + expect(0 ?? true).toBe(0); + expect(42 ?? false).toBe(42); + expect(42 ?? true).toBe(42); + expect(false ?? 0).toBeFalse(); + expect(true ?? 0).toBeTrue(); + expect(false ?? 42).toBeFalse(); + expect(true ?? 42).toBeTrue(); }); test("objects", () => { - expect([] ?? false).toHaveLength(0); - expect([] ?? true).toHaveLength(0); - expect(false ?? []).toBeFalse(); - expect(true ?? []).toBeTrue(); + expect([] ?? false).toHaveLength(0); + expect([] ?? true).toHaveLength(0); + expect(false ?? []).toBeFalse(); + expect(true ?? []).toBeTrue(); }); test("null & undefined", () => { - expect(null ?? false).toBeFalse(); - expect(null ?? true).toBeTrue(); - expect(false ?? null).toBeFalse(); - expect(true ?? null).toBeTrue(); - expect(undefined ?? false).toBeFalse(); - expect(undefined ?? true).toBeTrue(); - expect(false ?? undefined).toBeFalse(); - expect(true ?? undefined).toBeTrue(); + expect(null ?? false).toBeFalse(); + expect(null ?? true).toBeTrue(); + expect(false ?? null).toBeFalse(); + expect(true ?? null).toBeTrue(); + expect(undefined ?? false).toBeFalse(); + expect(undefined ?? true).toBeTrue(); + expect(false ?? undefined).toBeFalse(); + expect(true ?? undefined).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/operators/logical-or.js b/Libraries/LibJS/Tests/operators/logical-or.js index 5499c1e4ab..9d5d71c5a0 100644 --- a/Libraries/LibJS/Tests/operators/logical-or.js +++ b/Libraries/LibJS/Tests/operators/logical-or.js @@ -1,50 +1,50 @@ test("booleans", () => { - expect(true || true).toBeTrue(); - expect(false || false).toBeFalse(); - expect(true || false).toBeTrue(); - expect(false || true).toBeTrue(); + expect(true || true).toBeTrue(); + expect(false || false).toBeFalse(); + expect(true || false).toBeTrue(); + expect(false || true).toBeTrue(); }); test("strings", () => { - expect("" || "").toBe(""); - expect("" || false).toBeFalse(); - expect("" || true).toBeTrue(); - expect(false || "").toBe(""); - expect(true || "").toBeTrue(); - expect("foo" || "bar").toBe("foo"); - expect("foo" || false).toBe("foo"); - expect("foo" || true).toBe("foo"); - expect(false || "bar").toBe("bar"); - expect(true || "bar").toBeTrue(); + expect("" || "").toBe(""); + expect("" || false).toBeFalse(); + expect("" || true).toBeTrue(); + expect(false || "").toBe(""); + expect(true || "").toBeTrue(); + expect("foo" || "bar").toBe("foo"); + expect("foo" || false).toBe("foo"); + expect("foo" || true).toBe("foo"); + expect(false || "bar").toBe("bar"); + expect(true || "bar").toBeTrue(); }); test("numbers", () => { - expect(false || 1 === 2).toBeFalse(); - expect(true || 1 === 2).toBeTrue(); - expect(0 || false).toBeFalse(); - expect(0 || true).toBeTrue(); - expect(42 || false).toBe(42); - expect(42 || true).toBe(42); - expect(false || 0).toBe(0); - expect(true || 0).toBeTrue(); - expect(false || 42).toBe(42); - expect(true || 42).toBeTrue(); + expect(false || 1 === 2).toBeFalse(); + expect(true || 1 === 2).toBeTrue(); + expect(0 || false).toBeFalse(); + expect(0 || true).toBeTrue(); + expect(42 || false).toBe(42); + expect(42 || true).toBe(42); + expect(false || 0).toBe(0); + expect(true || 0).toBeTrue(); + expect(false || 42).toBe(42); + expect(true || 42).toBeTrue(); }); test("objects", () => { - expect([] || false).toHaveLength(0); - expect([] || true).toHaveLength(0); - expect(false || []).toHaveLength(0); - expect(true || []).toBeTrue(); + expect([] || false).toHaveLength(0); + expect([] || true).toHaveLength(0); + expect(false || []).toHaveLength(0); + expect(true || []).toBeTrue(); }); test("null & undefined", () => { - expect(null || false).toBeFalse(); - expect(null || true).toBeTrue(); - expect(false || null).toBeNull(); - expect(true || null).toBeTrue(); - expect(undefined || false).toBeFalse(); - expect(undefined || true).toBeTrue(); - expect(false || undefined).toBeUndefined(); - expect(true || undefined).toBeTrue(); + expect(null || false).toBeFalse(); + expect(null || true).toBeTrue(); + expect(false || null).toBeNull(); + expect(true || null).toBeTrue(); + expect(undefined || false).toBeFalse(); + expect(undefined || true).toBeTrue(); + expect(false || undefined).toBeUndefined(); + expect(true || undefined).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/operators/modulo-basic.js b/Libraries/LibJS/Tests/operators/modulo-basic.js index b6e97bac0f..22b60ea256 100644 --- a/Libraries/LibJS/Tests/operators/modulo-basic.js +++ b/Libraries/LibJS/Tests/operators/modulo-basic.js @@ -1,16 +1,16 @@ test("basic functionality", () => { - expect(10 % 3).toBe(1); - expect(10.5 % 2.5).toBe(0.5); - expect(-0.99 % 0.99).toBe(-0); + expect(10 % 3).toBe(1); + expect(10.5 % 2.5).toBe(0.5); + expect(-0.99 % 0.99).toBe(-0); - // Examples from MDN: - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - expect(12 % 5).toBe(2); - expect(-1 % 2).toBe(-1); - expect(1 % -2).toBe(1); - expect(1 % 2).toBe(1); - expect(2 % 3).toBe(2); - expect(-4 % 2).toBe(-0); - expect(5.5 % 2).toBe(1.5); - expect(NaN % 2).toBeNaN(); + // Examples from MDN: + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators + expect(12 % 5).toBe(2); + expect(-1 % 2).toBe(-1); + expect(1 % -2).toBe(1); + expect(1 % 2).toBe(1); + expect(2 % 3).toBe(2); + expect(-4 % 2).toBe(-0); + expect(5.5 % 2).toBe(1.5); + expect(NaN % 2).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/operators/ternary-basic.js b/Libraries/LibJS/Tests/operators/ternary-basic.js index e3b6ff7a18..164d01e534 100644 --- a/Libraries/LibJS/Tests/operators/ternary-basic.js +++ b/Libraries/LibJS/Tests/operators/ternary-basic.js @@ -1,16 +1,16 @@ test("basic functionality", () => { - const x = 1; + const x = 1; - expect(x === 1 ? true : false).toBeTrue(); - expect(x ? x : 0).toBe(x); - expect(1 < 2 ? true : false).toBeTrue(); - expect(0 ? 1 : 1 ? 10 : 20).toBe(10); - expect(0 ? (1 ? 1 : 10) : 20).toBe(20); + expect(x === 1 ? true : false).toBeTrue(); + expect(x ? x : 0).toBe(x); + expect(1 < 2 ? true : false).toBeTrue(); + expect(0 ? 1 : 1 ? 10 : 20).toBe(10); + expect(0 ? (1 ? 1 : 10) : 20).toBe(20); }); test("object values", () => { - const o = {}; - o.f = true; - expect(o.f ? true : false).toBeTrue(); - expect(1 ? o.f : null).toBeTrue(); + const o = {}; + o.f = true; + expect(o.f ? true : false).toBeTrue(); + expect(1 ? o.f : null).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/operators/typeof-basic.js b/Libraries/LibJS/Tests/operators/typeof-basic.js index 0a1ab0effe..8a84b5a72b 100644 --- a/Libraries/LibJS/Tests/operators/typeof-basic.js +++ b/Libraries/LibJS/Tests/operators/typeof-basic.js @@ -1,27 +1,27 @@ test("basic functionality", () => { - expect(typeof "foo").toBe("string"); - expect(typeof (1 + 2)).toBe("number"); - expect(typeof {}).toBe("object"); - expect(typeof null).toBe("object"); - expect(typeof undefined).toBe("undefined"); - expect(typeof 1n).toBe("bigint"); - expect(typeof Symbol()).toBe("symbol"); - expect(typeof function () {}).toBe("function"); + expect(typeof "foo").toBe("string"); + expect(typeof (1 + 2)).toBe("number"); + expect(typeof {}).toBe("object"); + expect(typeof null).toBe("object"); + expect(typeof undefined).toBe("undefined"); + expect(typeof 1n).toBe("bigint"); + expect(typeof Symbol()).toBe("symbol"); + expect(typeof function () {}).toBe("function"); - var iExist = 1; - expect(typeof iExist).toBe("number"); - expect(typeof iDontExist).toBe("undefined"); + var iExist = 1; + expect(typeof iExist).toBe("number"); + expect(typeof iDontExist).toBe("undefined"); }); test("typeof calls property getter", () => { - var calls = 0; - Object.defineProperty(globalThis, "foo", { - get() { - calls++; - return 10; - }, - }); + var calls = 0; + Object.defineProperty(globalThis, "foo", { + get() { + calls++; + return 10; + }, + }); - expect(typeof foo).toBe("number"); - expect(calls).toBe(1); + expect(typeof foo).toBe("number"); + expect(calls).toBe(1); }); diff --git a/Libraries/LibJS/Tests/operators/void-basic.js b/Libraries/LibJS/Tests/operators/void-basic.js index 2d64eeb4a0..a23becae96 100644 --- a/Libraries/LibJS/Tests/operators/void-basic.js +++ b/Libraries/LibJS/Tests/operators/void-basic.js @@ -1,14 +1,14 @@ test("basic functionality", () => { - expect(void "").toBeUndefined(); - expect(void "foo").toBeUndefined(); - expect(void 1).toBeUndefined(); - expect(void 42).toBeUndefined(); - expect(void true).toBeUndefined(); - expect(void false).toBeUndefined(); - expect(void null).toBeUndefined(); - expect(void undefined).toBeUndefined(); - expect(void function () {}).toBeUndefined(); - expect(void (() => {})).toBeUndefined(); - expect(void (() => "hello friends")()).toBeUndefined(); - expect((() => void "hello friends")()).toBeUndefined(); + expect(void "").toBeUndefined(); + expect(void "foo").toBeUndefined(); + expect(void 1).toBeUndefined(); + expect(void 42).toBeUndefined(); + expect(void true).toBeUndefined(); + expect(void false).toBeUndefined(); + expect(void null).toBeUndefined(); + expect(void undefined).toBeUndefined(); + expect(void function () {}).toBeUndefined(); + expect(void (() => {})).toBeUndefined(); + expect(void (() => "hello friends")()).toBeUndefined(); + expect((() => void "hello friends")()).toBeUndefined(); }); diff --git a/Libraries/LibJS/Tests/parser-unary-associativity.js b/Libraries/LibJS/Tests/parser-unary-associativity.js index cc22b39660..25763eda6c 100644 --- a/Libraries/LibJS/Tests/parser-unary-associativity.js +++ b/Libraries/LibJS/Tests/parser-unary-associativity.js @@ -1,14 +1,14 @@ test("basic functionality", () => { - const o = {}; - o.a = 1; + const o = {}; + o.a = 1; - expect(o.a === 1).toBeTrue(); - expect(!o.a === false).toBeTrue(); - expect(!o.a === !o.a).toBeTrue(); - expect(~o.a === ~o.a).toBeTrue(); - expect(+o.a === +o.a).toBeTrue(); - expect(-o.a === -o.a).toBeTrue(); + expect(o.a === 1).toBeTrue(); + expect(!o.a === false).toBeTrue(); + expect(!o.a === !o.a).toBeTrue(); + expect(~o.a === ~o.a).toBeTrue(); + expect(+o.a === +o.a).toBeTrue(); + expect(-o.a === -o.a).toBeTrue(); - expect((typeof "x" === "string") === true).toBeTrue(); - expect(!(typeof "x" === "string") === false).toBeTrue(); + expect((typeof "x" === "string") === true).toBeTrue(); + expect(!(typeof "x" === "string") === false).toBeTrue(); }); diff --git a/Libraries/LibJS/Tests/program-strict-mode.js b/Libraries/LibJS/Tests/program-strict-mode.js index 87b9da1cbf..d8f8941d0f 100644 --- a/Libraries/LibJS/Tests/program-strict-mode.js +++ b/Libraries/LibJS/Tests/program-strict-mode.js @@ -1,18 +1,18 @@ "use strict"; test("basic functionality", () => { - expect(isStrictMode()).toBeTrue(); - - (function () { expect(isStrictMode()).toBeTrue(); - })(); - (() => { - expect(isStrictMode()).toBeTrue(); - })(); + (function () { + expect(isStrictMode()).toBeTrue(); + })(); - (() => { - "use strict"; - expect(isStrictMode()).toBeTrue(); - })(); + (() => { + expect(isStrictMode()).toBeTrue(); + })(); + + (() => { + "use strict"; + expect(isStrictMode()).toBeTrue(); + })(); }); diff --git a/Libraries/LibJS/Tests/strict-mode-errors.js b/Libraries/LibJS/Tests/strict-mode-errors.js index 827667b729..c5e8b86414 100644 --- a/Libraries/LibJS/Tests/strict-mode-errors.js +++ b/Libraries/LibJS/Tests/strict-mode-errors.js @@ -1,9 +1,9 @@ "use strict"; test("basic functionality", () => { - [true, false, "foo", 123].forEach(primitive => { - expect(() => { - primitive.foo = "bar"; - }).toThrowWithMessage(TypeError, "Cannot assign property foo to primitive value"); - }); + [true, false, "foo", 123].forEach(primitive => { + expect(() => { + primitive.foo = "bar"; + }).toThrowWithMessage(TypeError, "Cannot assign property foo to primitive value"); + }); }); diff --git a/Libraries/LibJS/Tests/string-escapes.js b/Libraries/LibJS/Tests/string-escapes.js index e6d9752695..f62820a01f 100644 --- a/Libraries/LibJS/Tests/string-escapes.js +++ b/Libraries/LibJS/Tests/string-escapes.js @@ -1,13 +1,13 @@ test("hex escapes", () => { - expect("\x55").toBe("U"); - expect("X55").toBe("X55"); - expect(`\x55`).toBe("U"); - expect(`\X55`).toBe("X55"); + expect("\x55").toBe("U"); + expect("X55").toBe("X55"); + expect(`\x55`).toBe("U"); + expect(`\X55`).toBe("X55"); }); test("unicode escapes", () => { - expect("\u26a0").toBe("⚠"); - expect(`\u26a0`).toBe("⚠"); - expect("\u{1f41e}").toBe("🐞"); - expect(`\u{1f41e}`).toBe("🐞"); + expect("\u26a0").toBe("⚠"); + expect(`\u26a0`).toBe("⚠"); + expect("\u{1f41e}").toBe("🐞"); + expect(`\u{1f41e}`).toBe("🐞"); }); diff --git a/Libraries/LibJS/Tests/string-spread.js b/Libraries/LibJS/Tests/string-spread.js index 5443e997eb..507bab7710 100644 --- a/Libraries/LibJS/Tests/string-spread.js +++ b/Libraries/LibJS/Tests/string-spread.js @@ -1,25 +1,25 @@ 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"; } test("spreading string literal", () => { - expect(["a", ..."bc", "d"]).toEqual(["a", "b", "c", "d"]); + expect(["a", ..."bc", "d"]).toEqual(["a", "b", "c", "d"]); }); test("spreading string variable", () => { - const s = "bc"; - expect(["a", ...s, "d"]).toEqual(["a", "b", "c", "d"]); + const s = "bc"; + expect(["a", ...s, "d"]).toEqual(["a", "b", "c", "d"]); }); test("spreading string in object", () => { - const obj = { a: "bc" }; - expect(["a", ...obj.a, "d"]).toEqual(["a", "b", "c", "d"]); + const obj = { a: "bc" }; + expect(["a", ...obj.a, "d"]).toEqual(["a", "b", "c", "d"]); }); test("spreading empty string", () => { - expect([..."", "a", ..."bc", ..."", "d", ...""]).toEqual(["a", "b", "c", "d"]); + expect([..."", "a", ..."bc", ..."", "d", ...""]).toEqual(["a", "b", "c", "d"]); }); test("spreading string objects", () => { - expect([..."", ...[...new String("abc")], "d"]).toEqual(["a", "b", "c", "d"]); + expect([..."", ...[...new String("abc")], "d"]).toEqual(["a", "b", "c", "d"]); }); diff --git a/Libraries/LibJS/Tests/switch-basic.js b/Libraries/LibJS/Tests/switch-basic.js index 37c6f2ce33..31aa6a52e7 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": + 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; + } + expect().fail(); - case 3: - return; - case 5: - case 1: - break; - default: - break; - } + }); - expect().fail(); - }); + test("string concatenation in target", () => { + var a = "foo"; - test("string concatenation in target", () => { - var a = "foo"; - - switch (a + "bar") { - case 1: + switch (a + "bar") { + case 1: + expect().fail(); + case "foobar": + case 2: + return; + } 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 3eb8946d35..c8f30aba7e 100644 --- a/Libraries/LibJS/Tests/switch-break.js +++ b/Libraries/LibJS/Tests/switch-break.js @@ -1,20 +1,20 @@ test("basic functionality", () => { - let i = 0; - let three; - let five; + let i = 0; + let three; + let five; - for (; i < 9; ) { - switch (i) { - case 3: - three = i; - break; - case 5: - five = i; - break; + for (; i < 9; ) { + switch (i) { + case 3: + three = i; + break; + case 5: + five = i; + break; + } + ++i; } - ++i; - } - expect(three).toBe(3); - expect(five).toBe(5); + expect(three).toBe(3); + expect(five).toBe(5); }); diff --git a/Libraries/LibJS/Tests/tagged-template-literals.js b/Libraries/LibJS/Tests/tagged-template-literals.js index 6f491b261e..8372333ff6 100644 --- a/Libraries/LibJS/Tests/tagged-template-literals.js +++ b/Libraries/LibJS/Tests/tagged-template-literals.js @@ -1,106 +1,108 @@ 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; + 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 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"); - }); + 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 bf089f8e26..17cb548641 100644 --- a/Libraries/LibJS/Tests/template-literals.js +++ b/Libraries/LibJS/Tests/template-literals.js @@ -1,58 +1,58 @@ test("plain literals with expression-like characters", () => { - expect(`foo`).toBe("foo"); - expect(`foo{`).toBe("foo{"); - expect(`foo}`).toBe("foo}"); - expect(`foo$`).toBe("foo$"); + expect(`foo`).toBe("foo"); + expect(`foo{`).toBe("foo{"); + expect(`foo}`).toBe("foo}"); + expect(`foo$`).toBe("foo$"); }); test("plain literals with escaped special characters", () => { - expect(`foo\``).toBe("foo`"); - expect(`foo\$`).toBe("foo$"); - expect(`foo \${"bar"}`).toBe('foo ${"bar"}'); + expect(`foo\``).toBe("foo`"); + expect(`foo\$`).toBe("foo$"); + expect(`foo \${"bar"}`).toBe('foo ${"bar"}'); }); test("literals in expressions", () => { - expect(`foo ${undefined}`).toBe("foo undefined"); - expect(`foo ${null}`).toBe("foo null"); - expect(`foo ${5}`).toBe("foo 5"); - expect(`foo ${true}`).toBe("foo true"); - expect(`foo ${"bar"}`).toBe("foo bar"); + expect(`foo ${undefined}`).toBe("foo undefined"); + expect(`foo ${null}`).toBe("foo null"); + expect(`foo ${5}`).toBe("foo 5"); + expect(`foo ${true}`).toBe("foo true"); + expect(`foo ${"bar"}`).toBe("foo bar"); }); test("objects in expressions", () => { - expect(`foo ${{}}`).toBe("foo [object Object]"); - expect(`foo ${{ bar: { baz: "qux" } }}`).toBe("foo [object Object]"); + expect(`foo ${{}}`).toBe("foo [object Object]"); + expect(`foo ${{ bar: { baz: "qux" } }}`).toBe("foo [object Object]"); }); test("expressions at beginning of template literal", () => { - expect(`${"foo"} bar baz`).toBe("foo bar baz"); - expect(`${"foo bar baz"}`).toBe("foo bar baz"); + expect(`${"foo"} bar baz`).toBe("foo bar baz"); + expect(`${"foo bar baz"}`).toBe("foo bar baz"); }); test("multiple template literals", () => { - expect(`foo ${"bar"} ${"baz"}`).toBe("foo bar baz"); + expect(`foo ${"bar"} ${"baz"}`).toBe("foo bar baz"); }); test("variables in expressions", () => { - let a = 27; - expect(`${a}`).toBe("27"); - expect(`foo ${a}`).toBe("foo 27"); - expect(`foo ${a ? "bar" : "baz"}`).toBe("foo bar"); - expect(`foo ${(() => a)()}`).toBe("foo 27"); + let a = 27; + expect(`${a}`).toBe("27"); + expect(`foo ${a}`).toBe("foo 27"); + expect(`foo ${a ? "bar" : "baz"}`).toBe("foo bar"); + expect(`foo ${(() => a)()}`).toBe("foo 27"); }); test("template literals in expressions", () => { - expect(`foo ${`bar`}`).toBe("foo bar"); - expect(`${`${`${`${"foo"}`} bar`}`}`).toBe("foo bar"); + expect(`foo ${`bar`}`).toBe("foo bar"); + expect(`${`${`${`${"foo"}`} bar`}`}`).toBe("foo bar"); }); test("newline literals (not characters)", () => { - expect( - `foo + expect( + `foo bar` - ).toBe("foo\n bar"); + ).toBe("foo\n bar"); }); test("reference error from expressions", () => { - expect(() => `${b}`).toThrowWithMessage(ReferenceError, "'b' is not defined"); + expect(() => `${b}`).toThrowWithMessage(ReferenceError, "'b' is not defined"); }); diff --git a/Libraries/LibJS/Tests/test-common-tests.js b/Libraries/LibJS/Tests/test-common-tests.js index ba3a0ba996..31951fffde 100644 --- a/Libraries/LibJS/Tests/test-common-tests.js +++ b/Libraries/LibJS/Tests/test-common-tests.js @@ -1,416 +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 a3b207938e..3873b2fb99 100644 --- a/Libraries/LibJS/Tests/test-common.js +++ b/Libraries/LibJS/Tests/test-common.js @@ -16,439 +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); - return Object.is(a, b); - }; - - 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; - } - return true; - }; - - 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; - } - return true; - }; - - class Expector { - constructor(target, inverted) { - this.target = target; - this.inverted = !!inverted; - } - - get not() { - return new Expector(this.target, !this.inverted); - } - - toBe(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.__doMatcher(() => { - this.__expect(Math.abs(this.target - value) < 0.000001); - }); - } - - toHaveLength(length) { - this.__expect(typeof this.target.length === "number"); - - this.__doMatcher(() => { - this.__expect(Object.is(this.target.length, length)); - }); - } - - toHaveProperty(property, value) { - this.__doMatcher(() => { - let object = this.target; - - 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); - } - - propertyArray.push(property); - - property = propertyArray; - } - - 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)); - }); - } - - toBeDefined() { - this.__doMatcher(() => { - this.__expect(this.target !== undefined); - }); - } - - toBeInstanceOf(class_) { - this.__doMatcher(() => { - this.__expect(this.target instanceof class_); - }); - } - - toBeNull() { - this.__doMatcher(() => { - this.__expect(this.target === null); - }); - } - - toBeUndefined() { - this.__doMatcher(() => { - this.__expect(this.target === undefined); - }); - } - - toBeNaN() { - this.__doMatcher(() => { - this.__expect(isNaN(this.target)); - }); - } - - toBeTrue() { - this.__doMatcher(() => { - this.__expect(this.target === true); - }); - } - - toBeFalse() { - 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); - } - - toBeLessThan(value) { - this.__validateNumericComparisonTypes(value); - - this.__doMatcher(() => { - this.__expect(this.target < value); - }); - } - - toBeLessThanOrEqual(value) { - this.__validateNumericComparisonTypes(value); - - this.__doMatcher(() => { - this.__expect(this.target <= value); - }); - } - - toBeGreaterThan(value) { - this.__validateNumericComparisonTypes(value); - - this.__doMatcher(() => { - this.__expect(this.target > value); - }); - } - - toBeGreaterThanOrEqual(value) { - this.__validateNumericComparisonTypes(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; - } - - throw new ExpectationError(); - }); - } - - toContainEqual(item) { - this.__doMatcher(() => { - // FIXME: Iterator check - for (let element of this.target) { - if (deepEquals(item, element)) return; - } - - throw new ExpectationError(); - }); - } - - toEqual(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.__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 - } - - // jest-extended - fail(message) { - // 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.__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"); - - 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"); - - let result; - - try { - result = new Function(this.target)(); - } catch (e) { - throw new ExpectationError(); - } - - 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.__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.__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.__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.__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.__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.__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(); - } - } - - __expect(value) { - if (value !== true) throw new ExpectationError(); - } - } - - 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 = (message, callback) => { - suiteMessage = message; - callback(); - suiteMessage = defaultSuiteMessage; - }; - - test = (message, callback) => { - if (!__TestResults__[suiteMessage]) __TestResults__[suiteMessage] = {}; - - const suite = __TestResults__[suiteMessage]; - if (suite[message]) { - suite[message] = { - result: "fail", - }; - return; - } - - try { - callback(); - suite[message] = { - result: "pass", - }; - } catch (e) { - suite[message] = { - result: "fail", - }; - } - }; - - test.skip = (message, callback) => { - if (typeof callback !== "function") - throw new Error("test.skip has invalid second argument (must be a function)"); - - if (!__TestResults__[suiteMessage]) __TestResults__[suiteMessage] = {}; - - const suite = __TestResults__[suiteMessage]; - if (suite[message]) throw new Error("Duplicate test name: " + message); - - suite[message] = { - result: "skip", + // 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; + for (let i = 0; i < a.length; ++i) { + if (!deepEquals(a[i], b[i])) return false; + } + return true; + }; + + 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; + } + return true; + }; + + class Expector { + constructor(target, inverted) { + this.target = target; + this.inverted = !!inverted; + } + + get not() { + return new Expector(this.target, !this.inverted); + } + + toBe(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.__doMatcher(() => { + this.__expect(Math.abs(this.target - value) < 0.000001); + }); + } + + toHaveLength(length) { + this.__expect(typeof this.target.length === "number"); + + this.__doMatcher(() => { + this.__expect(Object.is(this.target.length, length)); + }); + } + + toHaveProperty(property, value) { + this.__doMatcher(() => { + let object = this.target; + + 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); + } + + propertyArray.push(property); + + property = propertyArray; + } + + 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)); + }); + } + + toBeDefined() { + this.__doMatcher(() => { + this.__expect(this.target !== undefined); + }); + } + + toBeInstanceOf(class_) { + this.__doMatcher(() => { + this.__expect(this.target instanceof class_); + }); + } + + toBeNull() { + this.__doMatcher(() => { + this.__expect(this.target === null); + }); + } + + toBeUndefined() { + this.__doMatcher(() => { + this.__expect(this.target === undefined); + }); + } + + toBeNaN() { + this.__doMatcher(() => { + this.__expect(isNaN(this.target)); + }); + } + + toBeTrue() { + this.__doMatcher(() => { + this.__expect(this.target === true); + }); + } + + toBeFalse() { + 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); + } + + toBeLessThan(value) { + this.__validateNumericComparisonTypes(value); + + this.__doMatcher(() => { + this.__expect(this.target < value); + }); + } + + toBeLessThanOrEqual(value) { + this.__validateNumericComparisonTypes(value); + + this.__doMatcher(() => { + this.__expect(this.target <= value); + }); + } + + toBeGreaterThan(value) { + this.__validateNumericComparisonTypes(value); + + this.__doMatcher(() => { + this.__expect(this.target > value); + }); + } + + toBeGreaterThanOrEqual(value) { + this.__validateNumericComparisonTypes(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; + } + + throw new ExpectationError(); + }); + } + + toContainEqual(item) { + this.__doMatcher(() => { + // FIXME: Iterator check + for (let element of this.target) { + if (deepEquals(item, element)) return; + } + + throw new ExpectationError(); + }); + } + + toEqual(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.__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 + } + + // jest-extended + fail(message) { + // 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.__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"); + + 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"); + + let result; + + try { + result = new Function(this.target)(); + } catch (e) { + throw new ExpectationError(); + } + + 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.__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.__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.__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.__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.__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.__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(); + } + } + + __expect(value) { + if (value !== true) throw new ExpectationError(); + } + } + + 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 = (message, callback) => { + suiteMessage = message; + callback(); + suiteMessage = defaultSuiteMessage; + }; + + test = (message, callback) => { + if (!__TestResults__[suiteMessage]) __TestResults__[suiteMessage] = {}; + + const suite = __TestResults__[suiteMessage]; + if (suite[message]) { + suite[message] = { + result: "fail", + }; + return; + } + + try { + callback(); + suite[message] = { + result: "pass", + }; + } catch (e) { + suite[message] = { + result: "fail", + }; + } + }; + + test.skip = (message, callback) => { + if (typeof callback !== "function") + throw new Error("test.skip has invalid second argument (must be a function)"); + + if (!__TestResults__[suiteMessage]) __TestResults__[suiteMessage] = {}; + + const suite = __TestResults__[suiteMessage]; + if (suite[message]) throw new Error("Duplicate test name: " + message); + + suite[message] = { + result: "skip", + }; }; - }; })(); diff --git a/Libraries/LibJS/Tests/throw-basic.js b/Libraries/LibJS/Tests/throw-basic.js index e359a24aa1..b393763d92 100644 --- a/Libraries/LibJS/Tests/throw-basic.js +++ b/Libraries/LibJS/Tests/throw-basic.js @@ -1,34 +1,34 @@ test("throw literal", () => { - try { - throw 1; - expect().fail(); - } catch (e) { - if (e.name === "ExpectationError") throw e; - expect(e).toBe(1); - } + try { + throw 1; + expect().fail(); + } catch (e) { + if (e.name === "ExpectationError") throw e; + expect(e).toBe(1); + } }); test("throw array", () => { - try { - throw [99]; - expect().fail(); - } catch (e) { - if (e.name === "ExpectationError") throw e; - expect(e).toEqual([99]); - } + try { + throw [99]; + expect().fail(); + } catch (e) { + if (e.name === "ExpectationError") throw e; + expect(e).toEqual([99]); + } }); test("call function that throws", () => { - function foo() { - throw "hello"; - expect().fail(); - } + function foo() { + throw "hello"; + expect().fail(); + } - try { - foo(); - expect().fail(); - } catch (e) { - if (e.name === "ExpectationError") throw e; - expect(e).toBe("hello"); - } + try { + foo(); + expect().fail(); + } catch (e) { + if (e.name === "ExpectationError") throw e; + expect(e).toBe("hello"); + } }); diff --git a/Libraries/LibJS/Tests/to-number-basic.js b/Libraries/LibJS/Tests/to-number-basic.js index 5b80f24d53..4509537839 100644 --- a/Libraries/LibJS/Tests/to-number-basic.js +++ b/Libraries/LibJS/Tests/to-number-basic.js @@ -1,75 +1,75 @@ test("non-numeric primitives", () => { - expect(+false).toBe(0); - expect(-false).toBe(-0); - expect(+true).toBe(1); - expect(-true).toBe(-1); - expect(+null).toBe(0); - expect(-null).toBe(-0); - expect(+undefined).toBeNaN(); - expect(-undefined).toBeNaN(); + expect(+false).toBe(0); + expect(-false).toBe(-0); + expect(+true).toBe(1); + expect(-true).toBe(-1); + expect(+null).toBe(0); + expect(-null).toBe(-0); + expect(+undefined).toBeNaN(); + expect(-undefined).toBeNaN(); }); test("arrays", () => { - expect(+[]).toBe(0); - expect(-[]).toBe(-0); - expect(+[,]).toBe(0); - expect(-[,]).toBe(-0); - expect(+[null]).toBe(0); - expect(-[null]).toBe(-0); - expect(+[undefined]).toBe(0); - expect(-[undefined]).toBe(-0); - expect(+[[[[[]]]]]).toBe(0); - expect(-[[[[[]]]]]).toBe(-0); - expect(+[[[[[42]]]]]).toBe(42); - expect(-[[[[[42]]]]]).toBe(-42); + expect(+[]).toBe(0); + expect(-[]).toBe(-0); + expect(+[,]).toBe(0); + expect(-[,]).toBe(-0); + expect(+[null]).toBe(0); + expect(-[null]).toBe(-0); + expect(+[undefined]).toBe(0); + expect(-[undefined]).toBe(-0); + expect(+[[[[[]]]]]).toBe(0); + expect(-[[[[[]]]]]).toBe(-0); + expect(+[[[[[42]]]]]).toBe(42); + expect(-[[[[[42]]]]]).toBe(-42); - expect(+[, , ,]).toBeNaN(); - expect(-[, , ,]).toBeNaN(); - expect(+[undefined, undefined]).toBeNaN(); - expect(-[undefined, undefined]).toBeNaN(); - expect(+[1, 2, 3]).toBeNaN(); - expect(-[1, 2, 3]).toBeNaN(); - expect(+[[[["foo"]]]]).toBeNaN(); - expect(-[[[["foo"]]]]).toBeNaN(); + expect(+[, , ,]).toBeNaN(); + expect(-[, , ,]).toBeNaN(); + expect(+[undefined, undefined]).toBeNaN(); + expect(-[undefined, undefined]).toBeNaN(); + expect(+[1, 2, 3]).toBeNaN(); + expect(-[1, 2, 3]).toBeNaN(); + expect(+[[[["foo"]]]]).toBeNaN(); + expect(-[[[["foo"]]]]).toBeNaN(); }); test("strings", () => { - expect(+"").toBe(0); - expect(-"").toBe(-0); - expect(+"42").toBe(42); - expect(-"42").toBe(-42); - expect(+"1.23").toBe(1.23); - expect(-"1.23").toBe(-1.23); + expect(+"").toBe(0); + expect(-"").toBe(-0); + expect(+"42").toBe(42); + expect(-"42").toBe(-42); + expect(+"1.23").toBe(1.23); + expect(-"1.23").toBe(-1.23); - expect(+"foo").toBeNaN(); - expect(-"foo").toBeNaN(); + expect(+"foo").toBeNaN(); + expect(-"foo").toBeNaN(); }); test("numbers", () => { - expect(+42).toBe(42); - expect(-42).toBe(-42); - expect(+1.23).toBe(1.23); - expect(-1.23).toBe(-1.23); + expect(+42).toBe(42); + expect(-42).toBe(-42); + expect(+1.23).toBe(1.23); + expect(-1.23).toBe(-1.23); }); test("infinity", () => { - expect(+"Infinity").toBe(Infinity); - expect(+"+Infinity").toBe(Infinity); - expect(+"-Infinity").toBe(-Infinity); - expect(-"Infinity").toBe(-Infinity); - expect(-"+Infinity").toBe(-Infinity); - expect(-"-Infinity").toBe(Infinity); + expect(+"Infinity").toBe(Infinity); + expect(+"+Infinity").toBe(Infinity); + expect(+"-Infinity").toBe(-Infinity); + expect(-"Infinity").toBe(-Infinity); + expect(-"+Infinity").toBe(-Infinity); + expect(-"-Infinity").toBe(Infinity); }); test("space and space-like escapes", () => { - expect(+" \r \t \n ").toBe(0); - expect(+" \n \t Infinity \r ").toBe(Infinity); - expect(+"\r \n1.23 \t\t\t \n").toBe(1.23); + expect(+" \r \t \n ").toBe(0); + expect(+" \n \t Infinity \r ").toBe(Infinity); + expect(+"\r \n1.23 \t\t\t \n").toBe(1.23); }); test("object literals", () => { - expect(+{}).toBeNaN(); - expect(-{}).toBeNaN(); - expect(+{ a: 1 }).toBeNaN(); - expect(-{ a: 1 }).toBeNaN(); + expect(+{}).toBeNaN(); + expect(-{}).toBeNaN(); + expect(+{ a: 1 }).toBeNaN(); + expect(-{ a: 1 }).toBeNaN(); }); diff --git a/Libraries/LibJS/Tests/to-number-exception.js b/Libraries/LibJS/Tests/to-number-exception.js index 1174ed195d..b9247d9636 100644 --- a/Libraries/LibJS/Tests/to-number-exception.js +++ b/Libraries/LibJS/Tests/to-number-exception.js @@ -1,25 +1,25 @@ const message = "oops, Value::to_number() failed"; const o = { - toString() { - throw new Error(message); - }, + toString() { + throw new Error(message); + }, }; test("basic functionality", () => { - expect(() => { - +o; - }).toThrowWithMessage(Error, message); + expect(() => { + +o; + }).toThrowWithMessage(Error, message); - expect(() => { - o - 1; - }).toThrowWithMessage(Error, message); + expect(() => { + o - 1; + }).toThrowWithMessage(Error, message); - expect(() => { - "foo".charAt(o); - }).toThrowWithMessage(Error, message); + expect(() => { + "foo".charAt(o); + }).toThrowWithMessage(Error, message); - expect(() => { - "bar".repeat(o); - }).toThrowWithMessage(Error, message); + expect(() => { + "bar".repeat(o); + }).toThrowWithMessage(Error, message); }); diff --git a/Libraries/LibJS/Tests/update-expression-on-member-expression.js b/Libraries/LibJS/Tests/update-expression-on-member-expression.js index f24e76ee51..e9a29d6ea2 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", () => { - const o = {}; - o.f = 1; + const 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 160819b260..5eacc6a069 100644 --- a/Libraries/LibJS/Tests/update-expressions-basic.js +++ b/Libraries/LibJS/Tests/update-expressions-basic.js @@ -1,53 +1,53 @@ describe("correct behavior", () => { - test("basic functionality", () => { - let n = 0; - expect(++n).toBe(1); - expect(n).toBe(1); + test("basic functionality", () => { + let n = 0; + expect(++n).toBe(1); + expect(n).toBe(1); - n = 0; - expect(n++).toBe(0); - expect(n).toBe(1); + n = 0; + expect(n++).toBe(0); + expect(n).toBe(1); - n = 0; - expect(--n).toBe(-1); - expect(n).toBe(-1); + n = 0; + expect(--n).toBe(-1); + expect(n).toBe(-1); - n = 0; - expect(n--).toBe(0); - expect(n).toBe(-1); + n = 0; + expect(n--).toBe(0); + expect(n).toBe(-1); - let a = []; - expect(a++).toBe(0); - expect(a).toBe(1); + let a = []; + expect(a++).toBe(0); + expect(a).toBe(1); - let b = true; - expect(b--).toBe(1); - expect(b).toBe(0); - }); + let b = true; + expect(b--).toBe(1); + expect(b).toBe(0); + }); - test("updates that produce NaN", () => { - let s = "foo"; - expect(++s).toBeNaN(); - expect(s).toBeNaN(); + test("updates that produce NaN", () => { + let s = "foo"; + expect(++s).toBeNaN(); + expect(s).toBeNaN(); - s = "foo"; - expect(s++).toBeNaN(); - expect(s).toBeNaN(); + s = "foo"; + expect(s++).toBeNaN(); + expect(s).toBeNaN(); - s = "foo"; - expect(--s).toBeNaN(); - expect(s).toBeNaN(); + s = "foo"; + expect(--s).toBeNaN(); + expect(s).toBeNaN(); - s = "foo"; - expect(s--).toBeNaN(); - expect(s).toBeNaN(); - }); + s = "foo"; + expect(s--).toBeNaN(); + expect(s).toBeNaN(); + }); }); describe("errors", () => { - test("update expression throws reference error", () => { - expect(() => { - ++x; - }).toThrowWithMessage(ReferenceError, "'x' is not defined"); - }); + test("update expression throws reference error", () => { + expect(() => { + ++x; + }).toThrowWithMessage(ReferenceError, "'x' is not defined"); + }); }); diff --git a/Libraries/LibJS/Tests/var-multiple-declarator.js b/Libraries/LibJS/Tests/var-multiple-declarator.js index 089e67313c..ba40d09b9e 100644 --- a/Libraries/LibJS/Tests/var-multiple-declarator.js +++ b/Libraries/LibJS/Tests/var-multiple-declarator.js @@ -1,8 +1,8 @@ test("basic functionality", () => { - var a = 1, - b = 2, - c = a + b; - expect(a).toBe(1); - expect(b).toBe(2); - expect(c).toBe(3); + var a = 1, + b = 2, + c = a + b; + expect(a).toBe(1); + expect(b).toBe(2); + expect(c).toBe(3); }); diff --git a/Libraries/LibJS/Tests/var-scoping.js b/Libraries/LibJS/Tests/var-scoping.js index 478836a43e..86c5f1d5c7 100644 --- a/Libraries/LibJS/Tests/var-scoping.js +++ b/Libraries/LibJS/Tests/var-scoping.js @@ -1,17 +1,17 @@ test("basic functionality", () => { - function foo() { - i = 3; - expect(i).toBe(3); - var i; - } + function foo() { + i = 3; + expect(i).toBe(3); + var i; + } - foo(); + foo(); - var caught_exception; - try { - j = i; - } catch (e) { - caught_exception = e; - } - expect(caught_exception).not.toBeUndefined(); + var caught_exception; + try { + j = i; + } catch (e) { + caught_exception = e; + } + expect(caught_exception).not.toBeUndefined(); }); diff --git a/Libraries/LibJS/Tests/variable-undefined.js b/Libraries/LibJS/Tests/variable-undefined.js index d9963feaee..4399d5332d 100644 --- a/Libraries/LibJS/Tests/variable-undefined.js +++ b/Libraries/LibJS/Tests/variable-undefined.js @@ -1,14 +1,14 @@ test("basic functionality", () => { - function foo(a) { - return a; - } + function foo(a) { + return a; + } - var x = undefined; - expect(x).toBeUndefined(); - expect(foo(x)).toBeUndefined(); + var x = undefined; + expect(x).toBeUndefined(); + expect(foo(x)).toBeUndefined(); - var o = {}; - o.x = x; - expect(o.x).toBeUndefined(); - expect(o.x).toBe(x); + var o = {}; + o.x = x; + expect(o.x).toBeUndefined(); + expect(o.x).toBe(x); });