diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-12 12:17:30 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-12 12:17:46 +0100 |
commit | 13d7c09125f8eec703d0a43a9a87fc8aa08f7319 (patch) | |
tree | 70fd643c429cea5c1f9362c2674511d17a53f3b5 /Libraries/LibJS/Tests/builtins | |
parent | dc28c07fa526841e05e16161c74a6c23984f1dd5 (diff) | |
download | serenity-13d7c09125f8eec703d0a43a9a87fc8aa08f7319.zip |
Libraries: Move to Userland/Libraries/
Diffstat (limited to 'Libraries/LibJS/Tests/builtins')
225 files changed, 0 insertions, 7683 deletions
diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.from.js b/Libraries/LibJS/Tests/builtins/Array/Array.from.js deleted file mode 100644 index 0a015f8141..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.from.js +++ /dev/null @@ -1,69 +0,0 @@ -test("length is 1", () => { - expect(Array.from).toHaveLength(1); -}); - -describe("normal behavior", () => { - test("empty array", () => { - var a = Array.from([]); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(0); - }); - - test("empty string", () => { - var a = Array.from(""); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(0); - }); - - test("non-empty array", () => { - var a = Array.from([5, 8, 1]); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(3); - expect(a[0]).toBe(5); - expect(a[1]).toBe(8); - expect(a[2]).toBe(1); - }); - - test("non-empty string", () => { - var a = Array.from("what"); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(4); - expect(a[0]).toBe("w"); - expect(a[1]).toBe("h"); - expect(a[2]).toBe("a"); - expect(a[3]).toBe("t"); - }); - - test("shallow array copy", () => { - var a = [1, 2, 3]; - var b = Array.from([a]); - expect(b instanceof Array).toBeTrue(); - expect(b).toHaveLength(1); - b[0][0] = 4; - expect(a[0]).toBe(4); - }); - - test("from iterator", () => { - function rangeIterator(begin, end) { - return { - [Symbol.iterator]() { - let value = begin - 1; - return { - next() { - if (value < end) { - value += 1; - } - return { value: value, done: value >= end }; - }, - }; - }, - }; - } - - var a = Array.from(rangeIterator(8, 10)); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(2); - expect(a[0]).toBe(8); - expect(a[1]).toBe(9); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js b/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js deleted file mode 100644 index bbe12a8c44..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js +++ /dev/null @@ -1,26 +0,0 @@ -test("length is 1", () => { - expect(Array.isArray).toHaveLength(1); -}); - -test("arguments that evaluate to false", () => { - expect(Array.isArray()).toBeFalse(); - expect(Array.isArray("1")).toBeFalse(); - expect(Array.isArray("foo")).toBeFalse(); - expect(Array.isArray(1)).toBeFalse(); - expect(Array.isArray(1, 2, 3)).toBeFalse(); - expect(Array.isArray(undefined)).toBeFalse(); - expect(Array.isArray(null)).toBeFalse(); - expect(Array.isArray(Infinity)).toBeFalse(); - expect(Array.isArray({})).toBeFalse(); -}); - -test("arguments that evaluate to true", () => { - expect(Array.isArray([])).toBeTrue(); - expect(Array.isArray([1])).toBeTrue(); - expect(Array.isArray([1, 2, 3])).toBeTrue(); - expect(Array.isArray(new Array())).toBeTrue(); - expect(Array.isArray(new Array(10))).toBeTrue(); - expect(Array.isArray(new Array("a", "b", "c"))).toBeTrue(); - // FIXME: Array.prototype is supposed to be an array! - // expect(Array.isArray(Array.prototype)).toBeTrue(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.js b/Libraries/LibJS/Tests/builtins/Array/Array.js deleted file mode 100644 index 652e366d2f..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.js +++ /dev/null @@ -1,53 +0,0 @@ -test("constructor properties", () => { - expect(Array).toHaveLength(1); - expect(Array.name).toBe("Array"); - expect(Array.prototype.length).toBe(0); -}); - -describe("errors", () => { - test("invalid array length", () => { - [-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => { - expect(() => { - new Array(value); - }).toThrowWithMessage(RangeError, "Invalid array length"); - }); - }); -}); - -describe("normal behavior", () => { - test("typeof", () => { - expect(typeof Array()).toBe("object"); - expect(typeof new Array()).toBe("object"); - }); - - test("constructor with single numeric argument", () => { - var a = new Array(5); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(5); - }); - - test("constructor with single non-numeric argument", () => { - var a = new Array("5"); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(1); - expect(a[0]).toBe("5"); - }); - - test("constructor with multiple numeric arguments", () => { - var a = new Array(1, 2, 3); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(3); - expect(a[0]).toBe(1); - expect(a[1]).toBe(2); - expect(a[2]).toBe(3); - }); - - test("constructor with single array argument", () => { - var a = new Array([1, 2, 3]); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(1); - expect(a[0][0]).toBe(1); - expect(a[0][1]).toBe(2); - expect(a[0][2]).toBe(3); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.of.js b/Libraries/LibJS/Tests/builtins/Array/Array.of.js deleted file mode 100644 index 8e03470263..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.of.js +++ /dev/null @@ -1,59 +0,0 @@ -test("length is 0", () => { - expect(Array.of).toHaveLength(0); -}); - -describe("normal behavior", () => { - test("single numeric argument", () => { - var a = Array.of(5); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(1); - expect(a[0]).toBe(5); - }); - - test("single non-numeric argument", () => { - var a = Array.of("5"); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(1); - expect(a[0]).toBe("5"); - }); - - test("single infinite numeric argument", () => { - var a = Array.of(Infinity); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(1); - expect(a[0]).toBe(Infinity); - }); - - test("multiple numeric arguments", () => { - var a = Array.of(1, 2, 3); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(3); - expect(a[0]).toBe(1); - expect(a[1]).toBe(2); - expect(a[2]).toBe(3); - }); - - test("single array argument", () => { - var a = Array.of([1, 2, 3]); - expect(a instanceof Array).toBeTrue(); - expect(a).toHaveLength(1); - expect(a[0][0]).toBe(1); - expect(a[0][1]).toBe(2); - expect(a[0][2]).toBe(3); - }); - - test("getter property is included in returned array", () => { - var t = [1, 2, 3]; - Object.defineProperty(t, 3, { - get() { - return 4; - }, - }); - var a = Array.of(...t); - expect(a).toHaveLength(4); - expect(a[0]).toBe(1); - expect(a[1]).toBe(2); - expect(a[2]).toBe(3); - expect(a[3]).toBe(4); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js deleted file mode 100644 index a8afde0ea3..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js +++ /dev/null @@ -1,150 +0,0 @@ -describe("ability to work with generic non-array objects", () => { - test("push, pop", () => { - [undefined, "foo", -42, 0].forEach(length => { - const o = { length }; - - expect(Array.prototype.push.call(o, "foo")).toBe(1); - expect(o).toHaveLength(1); - expect(o[0]).toBe("foo"); - expect(Array.prototype.push.call(o, "bar", "baz")).toBe(3); - expect(o).toHaveLength(3); - expect(o[0]).toBe("foo"); - expect(o[1]).toBe("bar"); - expect(o[2]).toBe("baz"); - - expect(Array.prototype.pop.call(o)).toBe("baz"); - expect(o).toHaveLength(2); - expect(Array.prototype.pop.call(o)).toBe("bar"); - expect(o).toHaveLength(1); - expect(Array.prototype.pop.call(o)).toBe("foo"); - expect(o).toHaveLength(0); - expect(Array.prototype.pop.call(o)).toBeUndefined(); - expect(o).toHaveLength(0); - - o.length = length; - expect(Array.prototype.pop.call(o)).toBeUndefined(); - expect(o).toHaveLength(0); - }); - }); - - test("splice", () => { - const o = { length: 3, 0: "hello", 2: "serenity" }; - const removed = Array.prototype.splice.call(o, 0, 2, "hello", "friends"); - expect(o).toHaveLength(3); - expect(o[0]).toBe("hello"); - expect(o[1]).toBe("friends"); - expect(o[2]).toBe("serenity"); - expect(removed).toHaveLength(2); - expect(removed[0]).toBe("hello"); - expect(removed[1]).toBeUndefined(); - }); - - test("join", () => { - expect(Array.prototype.join.call({})).toBe(""); - expect(Array.prototype.join.call({ length: "foo" })).toBe(""); - expect(Array.prototype.join.call({ length: 3 })).toBe(",,"); - expect(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" })).toBe("foo,bar"); - expect(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" })).toBe( - "foo,bar" - ); - expect(Array.prototype.join.call({ length: 3, 1: "bar" }, "~")).toBe("~bar~"); - expect(Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~")).toBe( - "foo~bar~baz" - ); - }); - - // FIXME: test-js asserts when this is just called "toString" ಠ_ಠ - test("toString (FIXME)", () => { - expect(Array.prototype.toString.call({})).toBe("[object Object]"); - expect(Array.prototype.toString.call({ join: "foo" })).toBe("[object Object]"); - expect(Array.prototype.toString.call({ join: () => "foo" })).toBe("foo"); - }); - - test("indexOf", () => { - expect(Array.prototype.indexOf.call({})).toBe(-1); - expect(Array.prototype.indexOf.call({ 0: undefined })).toBe(-1); - expect(Array.prototype.indexOf.call({ length: 1, 0: undefined })).toBe(0); - expect(Array.prototype.indexOf.call({ length: 1, 2: "foo" }, "foo")).toBe(-1); - expect(Array.prototype.indexOf.call({ length: 5, 2: "foo" }, "foo")).toBe(2); - expect(Array.prototype.indexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", 3)).toBe(4); - }); - - test("lastIndexOf", () => { - expect(Array.prototype.lastIndexOf.call({})).toBe(-1); - expect(Array.prototype.lastIndexOf.call({ 0: undefined })).toBe(-1); - expect(Array.prototype.lastIndexOf.call({ length: 1, 0: undefined })).toBe(0); - expect(Array.prototype.lastIndexOf.call({ length: 1, 2: "foo" }, "foo")).toBe(-1); - expect(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo" }, "foo")).toBe(2); - expect(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo")).toBe(4); - expect(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", -2)).toBe( - 2 - ); - }); - - test("includes", () => { - expect(Array.prototype.includes.call({})).toBeFalse(); - expect(Array.prototype.includes.call({ 0: undefined })).toBeFalse(); - expect(Array.prototype.includes.call({ length: 1, 0: undefined })).toBeTrue(); - expect(Array.prototype.includes.call({ length: 1, 2: "foo" }, "foo")).toBeFalse(); - expect(Array.prototype.includes.call({ length: 5, 2: "foo" }, "foo")).toBeTrue(); - }); - - const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" }; - - test("every", () => { - const visited = []; - Array.prototype.every.call(o, value => { - visited.push(value); - return true; - }); - expect(visited).toEqual(["foo", "bar", "baz"]); - }); - - test("find, findIndex", () => { - ["find", "findIndex"].forEach(name => { - const visited = []; - Array.prototype[name].call(o, value => { - visited.push(value); - return false; - }); - expect(visited).toEqual(["foo", "bar", undefined, "baz", undefined]); - }); - }); - - test("filter, forEach, map, some", () => { - ["filter", "forEach", "map", "some"].forEach(name => { - const visited = []; - Array.prototype[name].call(o, value => { - visited.push(value); - return false; - }); - expect(visited).toEqual(["foo", "bar", "baz"]); - }); - }); - - test("reduce", () => { - const visited = []; - Array.prototype.reduce.call( - o, - (_, value) => { - visited.push(value); - return false; - }, - "initial" - ); - expect(visited).toEqual(["foo", "bar", "baz"]); - }); - - test("reduceRight", () => { - const visited = []; - Array.prototype.reduceRight.call( - o, - (_, value) => { - visited.push(value); - return false; - }, - "initial" - ); - expect(visited).toEqual(["baz", "bar", "foo"]); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.concat.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.concat.js deleted file mode 100644 index c19b0ec13f..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.concat.js +++ /dev/null @@ -1,43 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.concat).toHaveLength(1); -}); - -describe("normal behavior", () => { - var array = ["hello"]; - - test("no arguments", () => { - var concatenated = array.concat(); - expect(array).toHaveLength(1); - expect(concatenated).toHaveLength(1); - }); - - test("single argument", () => { - var concatenated = array.concat("friends"); - expect(array).toHaveLength(1); - expect(concatenated).toHaveLength(2); - expect(concatenated[0]).toBe("hello"); - expect(concatenated[1]).toBe("friends"); - }); - - test("single array argument", () => { - var concatenated = array.concat([1, 2, 3]); - expect(array).toHaveLength(1); - expect(concatenated).toHaveLength(4); - expect(concatenated[0]).toBe("hello"); - expect(concatenated[1]).toBe(1); - expect(concatenated[2]).toBe(2); - expect(concatenated[3]).toBe(3); - }); - - test("multiple arguments", () => { - var concatenated = array.concat(false, "serenity", { name: "libjs" }, [1, [2, 3]]); - expect(array).toHaveLength(1); - expect(concatenated).toHaveLength(6); - expect(concatenated[0]).toBe("hello"); - expect(concatenated[1]).toBeFalse(); - expect(concatenated[2]).toBe("serenity"); - expect(concatenated[3]).toEqual({ name: "libjs" }); - expect(concatenated[4]).toBe(1); - expect(concatenated[5]).toEqual([2, 3]); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.every.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.every.js deleted file mode 100644 index 0215f5b244..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.every.js +++ /dev/null @@ -1,55 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.every).toHaveLength(1); -}); - -describe("errors", () => { - test("requires at least one argument", () => { - expect(() => { - [].every(); - }).toThrowWithMessage(TypeError, "Array.prototype.every() requires at least one argument"); - }); - - test("callback must be a function", () => { - expect(() => { - [].every(undefined); - }).toThrowWithMessage(TypeError, "undefined is not a function"); - }); -}); - -describe("normal behavior", () => { - test("basic functionality", () => { - var arrayOne = ["serenity", { test: "serenity" }]; - var arrayTwo = [true, false, 1, 2, 3, "3"]; - - expect(arrayOne.every(value => value === "hello")).toBeFalse(); - expect(arrayOne.every(value => value === "serenity")).toBeFalse(); - expect(arrayOne.every((value, index, arr) => index < 2)).toBeTrue(); - expect(arrayOne.every(value => typeof value === "string")).toBeFalse(); - expect(arrayOne.every(value => arrayOne.pop())).toBeTrue(); - - expect(arrayTwo.every((value, index, arr) => index > 0)).toBeFalse(); - expect(arrayTwo.every((value, index, arr) => index >= 0)).toBeTrue(); - expect(arrayTwo.every(value => typeof value !== "string")).toBeFalse(); - expect(arrayTwo.every(value => typeof value === "number")).toBeFalse(); - expect(arrayTwo.every(value => value > 0)).toBeFalse(); - expect(arrayTwo.every(value => value >= 0 && value < 4)).toBeTrue(); - expect(arrayTwo.every(value => arrayTwo.pop())).toBeTrue(); - - expect(["", "hello", "friends", "serenity"].every(value => value.length >= 0)).toBeTrue(); - }); - - test("empty array", () => { - expect([].every(value => value === 1)).toBeTrue(); - }); - - test("elements past the initial array size are ignored", () => { - var array = [1, 2, 3, 4, 5]; - - expect( - arrayTwo.every((value, index, arr) => { - arr.push(6); - return value <= 5; - }) - ).toBeTrue(); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.fill.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.fill.js deleted file mode 100644 index 2773ec42cb..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.fill.js +++ /dev/null @@ -1,20 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.fill).toHaveLength(1); -}); - -test("basic functionality", () => { - var array = [1, 2, 3, 4]; - - expect(array.fill(0, 2, 4)).toEqual([1, 2, 0, 0]); - expect(array.fill(5, 1)).toEqual([1, 5, 5, 5]); - expect(array.fill(6)).toEqual([6, 6, 6, 6]); - - expect([1, 2, 3].fill(4)).toEqual([4, 4, 4]); - expect([1, 2, 3].fill(4, 1)).toEqual([1, 4, 4]); - expect([1, 2, 3].fill(4, 1, 2)).toEqual([1, 4, 3]); - expect([1, 2, 3].fill(4, 3, 3)).toEqual([1, 2, 3]); - expect([1, 2, 3].fill(4, -3, -2)).toEqual([4, 2, 3]); - expect([1, 2, 3].fill(4, NaN, NaN)).toEqual([1, 2, 3]); - expect([1, 2, 3].fill(4, 3, 5)).toEqual([1, 2, 3]); - expect(Array(3).fill(4)).toEqual([4, 4, 4]); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.filter.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.filter.js deleted file mode 100644 index 6f481cddb8..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.filter.js +++ /dev/null @@ -1,68 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.filter).toHaveLength(1); -}); - -describe("errors", () => { - test("requires at least one argument", () => { - expect(() => { - [].filter(); - }).toThrowWithMessage(TypeError, "Array.prototype.filter() requires at least one argument"); - }); - - test("callback must be a function", () => { - expect(() => { - [].filter(undefined); - }).toThrowWithMessage(TypeError, "undefined is not a function"); - }); -}); - -describe("normal behavior", () => { - test("never calls callback with empty array", () => { - var callbackCalled = 0; - expect( - [].filter(() => { - callbackCalled++; - }) - ).toEqual([]); - expect(callbackCalled).toBe(0); - }); - - test("calls callback once for every item", () => { - var callbackCalled = 0; - expect( - [1, 2, 3].filter(() => { - callbackCalled++; - }) - ).toEqual([]); - expect(callbackCalled).toBe(3); - }); - - test("can filter based on callback return value", () => { - var evenNumbers = [0, 1, 2, 3, 4, 5, 6, 7].filter(x => x % 2 === 0); - expect(evenNumbers).toEqual([0, 2, 4, 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); - }; - expect(filterItems(fruits, "Berry")).toEqual(["Blueberry", "Raspberry"]); - expect(filterItems(fruits, "P")).toEqual([ - "Apple", - "Grape", - "Peach", - "Pineapple", - "Raspberry", - ]); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.find.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.find.js deleted file mode 100644 index 4d12b61a11..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.find.js +++ /dev/null @@ -1,65 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.find).toHaveLength(1); -}); - -describe("errors", () => { - test("requires at least one argument", () => { - expect(() => { - [].find(); - }).toThrowWithMessage(TypeError, "Array.prototype.find() requires at least one argument"); - }); - - test("callback must be a function", () => { - expect(() => { - [].find(undefined); - }).toThrowWithMessage(TypeError, "undefined is not a function"); - }); -}); - -describe("normal behavior", () => { - test("basic functionality", () => { - var array = ["hello", "friends", 1, 2, false]; - - expect(array.find(value => value === "hello")).toBe("hello"); - expect(array.find((value, index, arr) => index === 1)).toBe("friends"); - expect(array.find(value => value == "1")).toBe(1); - expect(array.find(value => value === 1)).toBe(1); - expect(array.find(value => typeof value !== "string")).toBe(1); - expect(array.find(value => typeof value === "boolean")).toBeFalse(); - expect(array.find(value => value > 1)).toBe(2); - expect(array.find(value => value > 1 && value < 3)).toBe(2); - expect(array.find(value => value > 100)).toBeUndefined(); - expect([].find(value => value === 1)).toBeUndefined(); - }); - - test("never calls callback with empty array", () => { - var callbackCalled = 0; - expect( - [].find(() => { - callbackCalled++; - }) - ).toBeUndefined(); - expect(callbackCalled).toBe(0); - }); - - test("calls callback once for every item", () => { - var callbackCalled = 0; - expect( - [1, 2, 3].find(() => { - callbackCalled++; - }) - ).toBeUndefined(); - expect(callbackCalled).toBe(3); - }); - - test("empty slots are treated as undefined", () => { - var callbackCalled = 0; - expect( - [1, , , "foo", , undefined, , ,].find(value => { - callbackCalled++; - return value === undefined; - }) - ).toBeUndefined(); - expect(callbackCalled).toBe(2); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.findIndex.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.findIndex.js deleted file mode 100644 index 751caa64be..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.findIndex.js +++ /dev/null @@ -1,68 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.findIndex).toHaveLength(1); -}); - -describe("errors", () => { - test("requires at least one argument", () => { - expect(() => { - [].findIndex(); - }).toThrowWithMessage( - TypeError, - "Array.prototype.findIndex() requires at least one argument" - ); - }); - - test("callback must be a function", () => { - expect(() => { - [].findIndex(undefined); - }).toThrowWithMessage(TypeError, "undefined is not a function"); - }); -}); - -describe("normal behavior", () => { - test("basic functionality", () => { - var array = ["hello", "friends", 1, 2, false]; - - expect(array.findIndex(value => value === "hello")).toBe(0); - expect(array.findIndex((value, index, arr) => index === 1)).toBe(1); - expect(array.findIndex(value => value == "1")).toBe(2); - expect(array.findIndex(value => value === 1)).toBe(2); - expect(array.findIndex(value => typeof value !== "string")).toBe(2); - expect(array.findIndex(value => typeof value === "boolean")).toBe(4); - expect(array.findIndex(value => value > 1)).toBe(3); - expect(array.findIndex(value => value > 1 && value < 3)).toBe(3); - expect(array.findIndex(value => value > 100)).toBe(-1); - expect([].findIndex(value => value === 1)).toBe(-1); - }); - - test("never calls callback with empty array", () => { - var callbackCalled = 0; - expect( - [].findIndex(() => { - callbackCalled++; - }) - ).toBe(-1); - expect(callbackCalled).toBe(0); - }); - - test("calls callback once for every item", () => { - var callbackCalled = 0; - expect( - [1, 2, 3].findIndex(() => { - callbackCalled++; - }) - ).toBe(-1); - expect(callbackCalled).toBe(3); - }); - - test("empty slots are treated as undefined", () => { - var callbackCalled = 0; - expect( - [1, , , "foo", , undefined, , ,].findIndex(value => { - callbackCalled++; - return value === undefined; - }) - ).toBe(1); - expect(callbackCalled).toBe(2); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.forEach.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.forEach.js deleted file mode 100644 index 8baa2d5635..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.forEach.js +++ /dev/null @@ -1,70 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.forEach).toHaveLength(1); -}); - -describe("errors", () => { - test("requires at least one argument", () => { - expect(() => { - [].forEach(); - }).toThrowWithMessage( - TypeError, - "Array.prototype.forEach() requires at least one argument" - ); - }); - - test("callback must be a function", () => { - expect(() => { - [].forEach(undefined); - }).toThrowWithMessage(TypeError, "undefined is not a function"); - }); -}); - -describe("normal behavior", () => { - test("never calls callback with empty array", () => { - var callbackCalled = 0; - expect( - [].forEach(() => { - callbackCalled++; - }) - ).toBeUndefined(); - expect(callbackCalled).toBe(0); - }); - - test("calls callback once for every item", () => { - var callbackCalled = 0; - expect( - [1, 2, 3].forEach(() => { - callbackCalled++; - }) - ).toBeUndefined(); - expect(callbackCalled).toBe(3); - }); - - test("callback receives value and index", () => { - var a = [1, 2, 3]; - a.forEach((value, index) => { - expect(value).toBe(a[index]); - expect(index).toBe(a[index] - 1); - }); - }); - - test("callback receives array", () => { - var callbackCalled = 0; - var a = [1, 2, 3]; - a.forEach((_, __, array) => { - callbackCalled++; - expect(a).toEqual(array); - a.push("test"); - }); - expect(callbackCalled).toBe(3); - expect(a).toEqual([1, 2, 3, "test", "test", "test"]); - }); - - test("this value can be modified", () => { - var t = []; - [1, 2, 3].forEach(function (value) { - this.push(value); - }, t); - expect(t).toEqual([1, 2, 3]); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.includes.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.includes.js deleted file mode 100644 index 575cd84e1b..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.includes.js +++ /dev/null @@ -1,18 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.includes).toHaveLength(1); -}); - -test("basic functionality", () => { - var array = ["hello", "friends", 1, 2, false]; - - expect([].includes()).toBeFalse(); - expect([undefined].includes()).toBeTrue(); - expect(array.includes("hello")).toBeTrue(); - expect(array.includes(1)).toBeTrue(); - expect(array.includes(1, -3)).toBeTrue(); - expect(array.includes("serenity")).toBeFalse(); - expect(array.includes(false, -1)).toBeTrue(); - expect(array.includes(2, -1)).toBeFalse(); - expect(array.includes(2, -100)).toBeTrue(); - expect(array.includes("friends", 100)).toBeFalse(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.indexOf.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.indexOf.js deleted file mode 100644 index 74caab93ee..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.indexOf.js +++ /dev/null @@ -1,25 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.indexOf).toHaveLength(1); -}); - -test("basic functionality", () => { - var array = ["hello", "friends", 1, 2, false]; - - expect(array.indexOf("hello")).toBe(0); - expect(array.indexOf("friends")).toBe(1); - expect(array.indexOf(false)).toBe(4); - expect(array.indexOf(false, 2)).toBe(4); - expect(array.indexOf(false, -2)).toBe(4); - expect(array.indexOf(1)).toBe(2); - expect(array.indexOf(1, 1000)).toBe(-1); - expect(array.indexOf(1, -1000)).toBe(2); - expect(array.indexOf("serenity")).toBe(-1); - expect(array.indexOf(false, -1)).toBe(4); - expect(array.indexOf(2, -1)).toBe(-1); - expect(array.indexOf(2, -2)).toBe(3); - expect([].indexOf("serenity")).toBe(-1); - expect([].indexOf("serenity", 10)).toBe(-1); - expect([].indexOf("serenity", -10)).toBe(-1); - expect([].indexOf()).toBe(-1); - expect([undefined].indexOf()).toBe(0); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.join.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.join.js deleted file mode 100644 index 30efb7e2b5..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.join.js +++ /dev/null @@ -1,24 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.join).toHaveLength(1); -}); - -test("basic functionality", () => { - expect(["hello", "friends"].join()).toBe("hello,friends"); - expect(["hello", "friends"].join(undefined)).toBe("hello,friends"); - expect(["hello", "friends"].join(" ")).toBe("hello friends"); - expect(["hello", "friends", "foo"].join("~", "#")).toBe("hello~friends~foo"); - expect([].join()).toBe(""); - expect([null].join()).toBe(""); - expect([undefined].join()).toBe(""); - expect([undefined, null, ""].join()).toBe(",,"); - expect([1, null, 2, undefined, 3].join()).toBe("1,,2,,3"); - expect(Array(3).join()).toBe(",,"); -}); - -test("circular references", () => { - const a = ["foo", [], [1, 2, []], ["bar"]]; - a[1] = a; - a[2][2] = a; - // [ "foo", <circular>, [ 1, 2, <circular> ], [ "bar" ] ] - expect(a.join()).toBe("foo,,1,2,,bar"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.lastIndexOf.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.lastIndexOf.js deleted file mode 100644 index eb0f7c6b37..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.lastIndexOf.js +++ /dev/null @@ -1,22 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.lastIndexOf).toHaveLength(1); -}); - -test("basic functionality", () => { - var array = [1, 2, 3, 1, "hello"]; - - expect(array.lastIndexOf("hello")).toBe(4); - expect(array.lastIndexOf("hello", 1000)).toBe(4); - expect(array.lastIndexOf(1)).toBe(3); - expect(array.lastIndexOf(1, -1)).toBe(3); - expect(array.lastIndexOf(1, -2)).toBe(3); - expect(array.lastIndexOf(2)).toBe(1); - expect(array.lastIndexOf(2, -3)).toBe(1); - expect(array.lastIndexOf(2, -4)).toBe(1); - expect([].lastIndexOf("hello")).toBe(-1); - expect([].lastIndexOf("hello", 10)).toBe(-1); - expect([].lastIndexOf("hello", -10)).toBe(-1); - expect([].lastIndexOf()).toBe(-1); - expect([undefined].lastIndexOf()).toBe(0); - expect([undefined, undefined, undefined].lastIndexOf()).toBe(2); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.map.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.map.js deleted file mode 100644 index a775fa8c32..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.map.js +++ /dev/null @@ -1,57 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.map).toHaveLength(1); -}); - -describe("errors", () => { - test("requires at least one argument", () => { - expect(() => { - [].map(); - }).toThrowWithMessage(TypeError, "Array.prototype.map() requires at least one argument"); - }); - - test("callback must be a function", () => { - expect(() => { - [].map(undefined); - }).toThrowWithMessage(TypeError, "undefined is not a function"); - }); -}); - -describe("normal behavior", () => { - test("never calls callback with empty array", () => { - var callbackCalled = 0; - expect( - [].map(() => { - callbackCalled++; - }) - ).toEqual([]); - expect(callbackCalled).toBe(0); - }); - - test("calls callback once for every item", () => { - var callbackCalled = 0; - expect( - [1, 2, 3].map(() => { - callbackCalled++; - }) - ).toEqual([undefined, undefined, undefined]); - expect(callbackCalled).toBe(3); - }); - - test("can map based on callback return value", () => { - expect( - [undefined, null, true, "foo", 42, {}].map( - (value, index) => "" + index + " -> " + value - ) - ).toEqual([ - "0 -> undefined", - "1 -> null", - "2 -> true", - "3 -> foo", - "4 -> 42", - "5 -> [object Object]", - ]); - - var squaredNumbers = [0, 1, 2, 3, 4].map(x => x ** 2); - expect(squaredNumbers).toEqual([0, 1, 4, 9, 16]); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.pop.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.pop.js deleted file mode 100644 index d1c34ad60e..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.pop.js +++ /dev/null @@ -1,29 +0,0 @@ -test("length is 0", () => { - expect(Array.prototype.pop).toHaveLength(0); -}); - -describe("normal behavior", () => { - test("array with elements", () => { - var a = [1, 2, 3]; - expect(a.pop()).toBe(3); - expect(a).toEqual([1, 2]); - expect(a.pop()).toBe(2); - expect(a).toEqual([1]); - expect(a.pop()).toBe(1); - expect(a).toEqual([]); - expect(a.pop()).toBeUndefined(); - expect(a).toEqual([]); - }); - - test("empty array", () => { - var a = []; - expect(a.pop()).toBeUndefined(); - expect(a).toEqual([]); - }); - - test("array with empty slot", () => { - var a = [,]; - expect(a.pop()).toBeUndefined(); - expect(a).toEqual([]); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.push.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.push.js deleted file mode 100644 index 209cd7a74d..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.push.js +++ /dev/null @@ -1,23 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.push).toHaveLength(1); -}); - -describe("normal behavior", () => { - test("no argument", () => { - var a = ["hello"]; - expect(a.push()).toBe(1); - expect(a).toEqual(["hello"]); - }); - - test("single argument", () => { - var a = ["hello"]; - expect(a.push("friends")).toBe(2); - expect(a).toEqual(["hello", "friends"]); - }); - - test("multiple arguments", () => { - var a = ["hello", "friends"]; - expect(a.push(1, 2, 3)).toBe(5); - expect(a).toEqual(["hello", "friends", 1, 2, 3]); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduce.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduce.js deleted file mode 100644 index 9b984fea03..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduce.js +++ /dev/null @@ -1,113 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.reduce).toHaveLength(1); -}); - -describe("errors", () => { - test("requires at least one argument", () => { - expect(() => { - [].reduce(); - }).toThrowWithMessage(TypeError, "Array.prototype.reduce() requires at least one argument"); - }); - - test("callback must be a function", () => { - expect(() => { - [].reduce(undefined); - }).toThrowWithMessage(TypeError, "undefined is not a function"); - }); - - test("reduce of empty array with no initial value", () => { - expect(() => { - [].reduce((a, x) => x); - }).toThrowWithMessage(TypeError, "Reduce of empty array with no initial value"); - }); - - test("reduce of array with only empty slots and no initial value", () => { - expect(() => { - [, ,].reduce((a, x) => x); - }).toThrowWithMessage(TypeError, "Reduce of empty array with no initial value"); - }); -}); - -describe("normal behavior", () => { - test("basic functionality", () => { - [1, 2].reduce(function () { - expect(this).toBeUndefined(); - }); - - var callbackCalled = 0; - var callback = () => { - callbackCalled++; - return true; - }; - - expect([1].reduce(callback)).toBe(1); - expect(callbackCalled).toBe(0); - - expect([, 1].reduce(callback)).toBe(1); - expect(callbackCalled).toBe(0); - - callbackCalled = 0; - expect([1, 2, 3].reduce(callback)).toBeTrue(); - expect(callbackCalled).toBe(2); - - callbackCalled = 0; - expect([, , 1, 2, 3].reduce(callback)).toBeTrue(); - expect(callbackCalled).toBe(2); - - callbackCalled = 0; - expect([1, , , 10, , 100, , ,].reduce(callback)).toBeTrue(); - expect(callbackCalled).toBe(2); - - var constantlySad = () => ":^("; - var result = [].reduce(constantlySad, ":^)"); - expect(result).toBe(":^)"); - - result = [":^0"].reduce(constantlySad, ":^)"); - expect(result).toBe(":^("); - - result = [":^0"].reduce(constantlySad); - expect(result).toBe(":^0"); - - result = [5, 4, 3, 2, 1].reduce((accum, elem) => accum + elem); - expect(result).toBe(15); - - result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100); - expect(result).toBe(121); - - result = [6, 5, 4, 3, 2, 1].reduce((accum, elem) => { - return accum + elem; - }, 100); - expect(result).toBe(121); - - var indexes = []; - result = ["foo", 1, true].reduce((a, v, i) => { - indexes.push(i); - }); - expect(result).toBeUndefined(); - expect(indexes.length).toBe(2); - expect(indexes[0]).toBe(1); - expect(indexes[1]).toBe(2); - - indexes = []; - result = ["foo", 1, true].reduce((a, v, i) => { - indexes.push(i); - }, "foo"); - expect(result).toBeUndefined(); - expect(indexes).toEqual([0, 1, 2]); - - var mutable = { prop: 0 }; - result = ["foo", 1, true].reduce((a, v) => { - a.prop = v; - return a; - }, mutable); - expect(result).toBe(mutable); - expect(result.prop).toBeTrue(); - - var a1 = [1, 2]; - var a2 = null; - a1.reduce((a, v, i, t) => { - a2 = t; - }); - expect(a1).toBe(a2); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduceRight.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduceRight.js deleted file mode 100644 index 3d718a0446..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reduceRight.js +++ /dev/null @@ -1,118 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.reduceRight).toHaveLength(1); -}); - -describe("errors", () => { - test("requires at least one argument", () => { - expect(() => { - [].reduceRight(); - }).toThrowWithMessage( - TypeError, - "Array.prototype.reduceRight() requires at least one argument" - ); - }); - - test("callback must be a function", () => { - expect(() => { - [].reduceRight(undefined); - }).toThrowWithMessage(TypeError, "undefined is not a function"); - }); - - test("reduce of empty array with no initial value", () => { - expect(() => { - [].reduceRight((a, x) => x); - }).toThrowWithMessage(TypeError, "Reduce of empty array with no initial value"); - }); - - test("reduce of array with only empty slots and no initial value", () => { - expect(() => { - [, ,].reduceRight((a, x) => x); - }).toThrowWithMessage(TypeError, "Reduce of empty array with no initial value"); - }); -}); - -describe("normal behavior", () => { - test("basic functionality", () => { - [1, 2].reduceRight(function () { - expect(this).toBeUndefined(); - }); - - var callbackCalled = 0; - var callback = () => { - callbackCalled++; - return true; - }; - - expect([1].reduceRight(callback)).toBe(1); - expect(callbackCalled).toBe(0); - - expect([1].reduceRight(callback)).toBe(1); - expect(callbackCalled).toBe(0); - - callbackCalled = 0; - expect([1, 2, 3].reduceRight(callback)).toBe(true); - expect(callbackCalled).toBe(2); - - callbackCalled = 0; - expect([1, 2, 3, ,].reduceRight(callback)).toBe(true); - expect(callbackCalled).toBe(2); - - callbackCalled = 0; - expect([, , , 1, , , 10, , 100, , ,].reduceRight(callback)).toBe(true); - expect(callbackCalled).toBe(2); - - var constantlySad = () => ":^("; - var result = [].reduceRight(constantlySad, ":^)"); - expect(result).toBe(":^)"); - - result = [":^0"].reduceRight(constantlySad, ":^)"); - expect(result).toBe(":^("); - - result = [":^0"].reduceRight(constantlySad); - expect(result).toBe(":^0"); - - result = [5, 4, 3, 2, 1].reduceRight((accum, elem) => "" + accum + elem); - expect(result).toBe("12345"); - - result = [1, 2, 3, 4, 5, 6].reduceRight((accum, elem) => { - return "" + accum + elem; - }, 100); - expect(result).toBe("100654321"); - - result = [6, 5, 4, 3, 2, 1].reduceRight((accum, elem) => { - return "" + accum + elem; - }, 100); - expect(result).toBe("100123456"); - - var indexes = []; - result = ["foo", 1, true].reduceRight((a, v, i) => { - indexes.push(i); - }); - expect(result).toBeUndefined(); - expect(indexes.length).toBe(2); - expect(indexes[0]).toBe(1); - expect(indexes[1]).toBe(0); - - indexes = []; - result = ["foo", 1, true].reduceRight((a, v, i) => { - indexes.push(i); - }, "foo"); - expect(result).toBeUndefined(); - expect(indexes).toEqual([2, 1, 0]); - - var mutable = { prop: 0 }; - result = ["foo", 1, true].reduceRight((a, v) => { - a.prop = v; - return a; - }, mutable); - expect(result).toBe(mutable); - expect(result.prop).toBe("foo"); - - var a1 = [1, 2]; - var a2 = null; - a1.reduceRight((a, v, i, t) => { - a2 = t; - }); - expect(a1).toBe(a2); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reverse.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reverse.js deleted file mode 100644 index b2b71b15d6..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.reverse.js +++ /dev/null @@ -1,9 +0,0 @@ -test("length is 0", () => { - expect(Array.prototype.reverse).toHaveLength(0); -}); - -test("basic functionality", () => { - var array = [1, 2, 3]; - expect(array.reverse()).toEqual([3, 2, 1]); - expect(array).toEqual([3, 2, 1]); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js deleted file mode 100644 index 0e154eeeb6..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js +++ /dev/null @@ -1,23 +0,0 @@ -test("length is 0", () => { - expect(Array.prototype.shift).toHaveLength(0); -}); - -describe("normal behavior", () => { - test("array with elements", () => { - var a = [1, 2, 3]; - expect(a.shift()).toBe(1); - expect(a).toEqual([2, 3]); - }); - - test("empty array", () => { - var a = []; - expect(a.shift()).toBeUndefined(); - expect(a).toEqual([]); - }); - - test("array with empty slot", () => { - var a = [,]; - expect(a.shift()).toBeUndefined(); - expect(a).toEqual([]); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.slice.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.slice.js deleted file mode 100644 index c1c45be082..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.slice.js +++ /dev/null @@ -1,39 +0,0 @@ -test("length is 0", () => { - expect(Array.prototype.slice).toHaveLength(2); -}); - -test("basic functionality", () => { - var array = ["hello", "friends", "serenity", 1]; - - var slice = array.slice(); - expect(array).toEqual(["hello", "friends", "serenity", 1]); - expect(slice).toEqual(["hello", "friends", "serenity", 1]); - - slice = array.slice(1); - expect(array).toEqual(["hello", "friends", "serenity", 1]); - expect(slice).toEqual(["friends", "serenity", 1]); - - slice = array.slice(0, 2); - expect(array).toEqual(["hello", "friends", "serenity", 1]); - expect(slice).toEqual(["hello", "friends"]); - - slice = array.slice(-1); - expect(array).toEqual(["hello", "friends", "serenity", 1]); - expect(slice).toEqual([1]); - - slice = array.slice(1, 1); - expect(array).toEqual(["hello", "friends", "serenity", 1]); - expect(slice).toEqual([]); - - slice = array.slice(1, -1); - expect(array).toEqual(["hello", "friends", "serenity", 1]); - expect(slice).toEqual(["friends", "serenity"]); - - slice = array.slice(2, -1); - expect(array).toEqual(["hello", "friends", "serenity", 1]); - expect(slice).toEqual(["serenity"]); - - slice = array.slice(0, 100); - expect(array).toEqual(["hello", "friends", "serenity", 1]); - expect(slice).toEqual(["hello", "friends", "serenity", 1]); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.some.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.some.js deleted file mode 100644 index ff9e62f2d1..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.some.js +++ /dev/null @@ -1,37 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.some).toHaveLength(1); -}); - -describe("errors", () => { - test("requires at least one argument", () => { - expect(() => { - [].some(); - }).toThrowWithMessage(TypeError, "Array.prototype.some() requires at least one argument"); - }); - - test("callback must be a function", () => { - expect(() => { - [].some(undefined); - }).toThrowWithMessage(TypeError, "undefined is not a function"); - }); -}); - -test("basic functionality", () => { - var array = ["hello", "friends", 1, 2, false, -42, { name: "serenityos" }]; - - expect(array.some(value => value === "hello")).toBeTrue(); - expect(array.some(value => value === "serenity")).toBeFalse(); - expect(array.some((value, index, arr) => index === 1)).toBeTrue(); - expect(array.some(value => value == "1")).toBeTrue(); - expect(array.some(value => value === 1)).toBeTrue(); - expect(array.some(value => value === 13)).toBeFalse(); - expect(array.some(value => typeof value !== "string")).toBeTrue(); - expect(array.some(value => typeof value === "boolean")).toBeTrue(); - expect(array.some(value => value > 1)).toBeTrue(); - expect(array.some(value => value > 1 && value < 3)).toBeTrue(); - expect(array.some(value => value > 100)).toBeFalse(); - expect(array.some(value => value < 0)).toBeTrue(); - expect(array.some(value => array.pop())).toBeTrue(); - expect(["", "hello", "friends", "serenity"].some(value => value.length === 0)).toBeTrue(); - expect([].some(value => value === 1)).toBeFalse(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.sort.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.sort.js deleted file mode 100644 index 1b05995be2..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.sort.js +++ /dev/null @@ -1,204 +0,0 @@ -describe("Array.prototype.sort", () => { - test("basic functionality", () => { - expect(Array.prototype.sort).toHaveLength(1); - - var arr = ["c", "b", "d", "a"]; - expect(arr.sort()).toEqual(arr); - expect(arr).toEqual(["a", "b", "c", "d"]); - - arr = ["aa", "a"]; - expect(arr.sort()).toEqual(arr); - expect(arr).toEqual(["a", "aa"]); - - arr = [1, 0]; - expect(arr.sort()).toBe(arr); // should be exactly same object - expect(arr).toEqual([0, 1]); - - // numbers are sorted as strings - arr = [205, -123, 22, 200, 3, -20, -2, -1, 25, 2, 0, 1]; - expect(arr.sort()).toEqual([-1, -123, -2, -20, 0, 1, 2, 200, 205, 22, 25, 3]); - - // mix of data, including empty slots and undefined - arr = ["2", Infinity, null, null, , undefined, 5, , undefined, null, 54, "5"]; - expect(arr.sort()).toEqual([ - "2", - 5, - "5", - 54, - Infinity, - null, - null, - null, - undefined, - undefined, - , - , - ]); - expect(arr.length).toEqual(12); - - // undefined compare function - arr = ["2", Infinity, null, null, , undefined, 5n, , undefined, null, 54, "5"]; - expect(arr.sort(undefined)).toEqual([ - "2", - 5n, - "5", - 54, - Infinity, - null, - null, - null, - undefined, - undefined, - , - , - ]); - expect(arr.length).toEqual(12); - - // numeric data with compare function to sort numerically - arr = [50, 500, 5, Infinity, -Infinity, 0, 10, -10, 1, -1, 5, 0, 15, Infinity]; - expect(arr.sort((a, b) => a - b)).toEqual([ - -Infinity, - -10, - -1, - 0, - 0, - 1, - 5, - 5, - 10, - 15, - 50, - 500, - Infinity, - Infinity, - ]); - expect(arr.length).toEqual(14); - - // numeric data with compare function to sort reverse numerically - arr = [50, 500, 5, Infinity, -Infinity, 0, 10, -10, 1, -1, 5, 0, 15, Infinity]; - expect(arr.sort((a, b) => b - a)).toEqual([ - Infinity, - Infinity, - 500, - 50, - 15, - 10, - 5, - 5, - 1, - 0, - 0, - -1, - -10, - -Infinity, - ]); - - // small/edge cases - expect([].sort()).toEqual([]); - expect([5].sort()).toEqual([5]); - expect([5, 5].sort()).toEqual([5, 5]); - expect([undefined].sort()).toEqual([undefined]); - expect([undefined, undefined].sort()).toEqual([undefined, undefined]); - expect([,].sort()).toEqual([,]); - expect([, ,].sort()).toEqual([, ,]); - expect([5, ,].sort()).toEqual([5, ,]); - expect([, , 5].sort()).toEqual([5, , ,]); - - // sorting should be stable - arr = [ - { sorted_key: 2, other_property: 1 }, - { sorted_key: 2, other_property: 2 }, - { sorted_key: 1, other_property: 3 }, - ]; - arr.sort((a, b) => a.sorted_key - b.sorted_key); - expect(arr[1].other_property == 1); - expect(arr[2].other_property == 2); - }); - - test("that it makes no unnecessary calls to compare function", () => { - expectNoCallCompareFunction = function (a, b) { - expect().fail(); - }; - - expect([].sort(expectNoCallCompareFunction)).toEqual([]); - expect([1].sort(expectNoCallCompareFunction)).toEqual([1]); - expect([1, undefined].sort(expectNoCallCompareFunction)).toEqual([1, undefined]); - expect([undefined, undefined].sort(expectNoCallCompareFunction)).toEqual([ - undefined, - undefined, - ]); - expect([, , 1, ,].sort(expectNoCallCompareFunction)).toEqual([1, , , ,]); - expect([undefined, , 1, , undefined, ,].sort(expectNoCallCompareFunction)).toEqual([ - 1, - undefined, - undefined, - , - , - , - ]); - }); - - test("that it works on non-arrays", () => { - var obj = { length: 0 }; - expect(Array.prototype.sort.call(obj)).toBe(obj); - expect(obj).toEqual({ length: 0 }); - - obj = { 0: 1, length: 0 }; - expect(Array.prototype.sort.call(obj, undefined)).toBe(obj); - expect(obj).toEqual({ 0: 1, length: 0 }); - - obj = { 0: 3, 1: 2, 2: 1, 3: 0, length: 2 }; - expect(Array.prototype.sort.call(obj)).toBe(obj); - expect(obj).toEqual({ 0: 2, 1: 3, 2: 1, 3: 0, length: 2 }); - - obj = { 0: 3, 1: 2, 2: 1, a: "b", hello: "friends!", length: 2 }; - expect(Array.prototype.sort.call(obj)).toBe(obj); - expect(obj).toEqual({ 0: 2, 1: 3, 2: 1, 3: 0, a: "b", hello: "friends!", length: 2 }); - - obj = { 0: 2, 1: 3, 2: 1, a: "b", hello: "friends!", length: 2 }; - expect( - Array.prototype.sort.call(obj, (a, b) => { - expect(a == 2 || a == 3).toBeTrue(); - expect(b == 2 || b == 3).toBeTrue(); - return b - a; - }) - ).toBe(obj); - expect(obj).toEqual({ 0: 3, 1: 2, 2: 1, 3: 0, a: "b", hello: "friends!", length: 2 }); - }); - - test("that it handles abrupt completions correctly", () => { - class TestError extends Error { - constructor() { - super(); - this.name = "TestError"; - } - } - - arr = [1, 2, 3]; - expect(() => - arr.sort((a, b) => { - throw new TestError(); - }) - ).toThrow(TestError); - - class DangerousToString { - toString() { - throw new TestError(); - } - } - arr = [new DangerousToString(), new DangerousToString()]; - expect(() => arr.sort()).toThrow(TestError); - }); - - test("that it does not use deleteProperty unnecessarily", () => { - var obj = new Proxy( - { 0: 5, 1: 4, 2: 3, length: 3 }, - { - deleteProperty: function (target, property) { - expect().fail(); - }, - } - ); - Array.prototype.sort.call(obj); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.splice.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.splice.js deleted file mode 100644 index 245648760a..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.splice.js +++ /dev/null @@ -1,49 +0,0 @@ -test("length is 2", () => { - expect(Array.prototype.splice).toHaveLength(2); -}); - -test("basic functionality", () => { - var array = ["hello", "friends", "serenity", 1, 2]; - var removed = array.splice(3); - expect(array).toEqual(["hello", "friends", "serenity"]); - expect(removed).toEqual([1, 2]); - - array = ["hello", "friends", "serenity", 1, 2]; - removed = array.splice(-2); - expect(array).toEqual(["hello", "friends", "serenity"]); - expect(removed).toEqual([1, 2]); - - array = ["hello", "friends", "serenity", 1, 2]; - removed = array.splice(-2, 1); - expect(array).toEqual(["hello", "friends", "serenity", 2]); - expect(removed).toEqual([1]); - - array = ["serenity"]; - removed = array.splice(0, 0, "hello", "friends"); - expect(array).toEqual(["hello", "friends", "serenity"]); - expect(removed).toEqual([]); - - array = ["goodbye", "friends", "serenity"]; - removed = array.splice(0, 1, "hello"); - expect(array).toEqual(["hello", "friends", "serenity"]); - expect(removed).toEqual(["goodbye"]); - - array = ["foo", "bar", "baz"]; - removed = array.splice(); - expect(array).toEqual(["foo", "bar", "baz"]); - expect(removed).toEqual([]); - - removed = array.splice(0, 123); - expect(array).toEqual([]); - expect(removed).toEqual(["foo", "bar", "baz"]); - - array = ["foo", "bar", "baz"]; - removed = array.splice(123, 123); - expect(array).toEqual(["foo", "bar", "baz"]); - expect(removed).toEqual([]); - - array = ["foo", "bar", "baz"]; - removed = array.splice(-123, 123); - expect(array).toEqual([]); - expect(removed).toEqual(["foo", "bar", "baz"]); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toLocaleString.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toLocaleString.js deleted file mode 100644 index 05854a1d0c..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toLocaleString.js +++ /dev/null @@ -1,62 +0,0 @@ -test("length is 0", () => { - expect(Array.prototype.toLocaleString).toHaveLength(0); -}); - -describe("normal behavior", () => { - test("array with no elements", () => { - expect([].toLocaleString()).toBe(""); - }); - - test("array with one element", () => { - expect(["foo"].toLocaleString()).toBe("foo"); - }); - - test("array with multiple elements", () => { - expect(["foo", "bar", "baz"].toLocaleString()).toBe("foo,bar,baz"); - }); - - test("null and undefined result in empty strings", () => { - expect([null].toLocaleString()).toBe(""); - expect([undefined].toLocaleString()).toBe(""); - expect([undefined, null].toLocaleString()).toBe(","); - }); - - test("empty values result in empty strings", () => { - expect(new Array(1).toLocaleString()).toBe(""); - expect(new Array(3).toLocaleString()).toBe(",,"); - var a = new Array(5); - a[2] = "foo"; - a[4] = "bar"; - expect(a.toLocaleString()).toBe(",,foo,,bar"); - }); - - test("getter property is included in returned string", () => { - var a = ["foo"]; - Object.defineProperty(a, 1, { - get() { - return "bar"; - }, - }); - expect(a.toLocaleString()).toBe("foo,bar"); - }); - - test("array with elements that have a custom toString() function", () => { - var toStringCalled = 0; - var o = { - toString() { - toStringCalled++; - return "o"; - }, - }; - expect([o, undefined, o, null, o].toLocaleString()).toBe("o,,o,,o"); - expect(toStringCalled).toBe(3); - }); - - test("array with circular references", () => { - const a = ["foo", [], [1, 2, []], ["bar"]]; - a[1] = a; - a[2][2] = a; - // [ "foo", <circular>, [ 1, 2, <circular> ], [ "bar" ] ] - expect(a.toLocaleString()).toBe("foo,,1,2,,bar"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toString.js deleted file mode 100644 index 1c18fb54ed..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.toString.js +++ /dev/null @@ -1,66 +0,0 @@ -test("length is 0", () => { - expect(Array.prototype.toString).toHaveLength(0); -}); - -describe("normal behavior", () => { - test("array with no elements", () => { - expect([].toString()).toBe(""); - }); - - test("array with one element", () => { - expect([1].toString()).toBe("1"); - }); - - test("array with multiple elements", () => { - expect([1, 2, 3].toString()).toBe("1,2,3"); - }); - - test("string and array concatenation", () => { - expect("rgb(" + [10, 11, 12] + ")").toBe("rgb(10,11,12)"); - }); - - test("null and undefined result in empty strings", () => { - expect([null].toString()).toBe(""); - expect([undefined].toString()).toBe(""); - expect([undefined, null].toString()).toBe(","); - }); - - test("empty values result in empty strings", () => { - expect(new Array(1).toString()).toBe(""); - expect(new Array(3).toString()).toBe(",,"); - var a = new Array(5); - a[2] = "foo"; - a[4] = "bar"; - expect(a.toString()).toBe(",,foo,,bar"); - }); - - test("getter property is included in returned string", () => { - var a = [1, 2, 3]; - Object.defineProperty(a, 3, { - get() { - return 10; - }, - }); - expect(a.toString()).toBe("1,2,3,10"); - }); - - test("array with elements that have a custom toString() function", () => { - var toStringCalled = 0; - var o = { - toString() { - toStringCalled++; - return "o"; - }, - }; - expect([o, undefined, o, null, o].toString()).toBe("o,,o,,o"); - expect(toStringCalled).toBe(3); - }); - - test("array with circular references", () => { - const a = ["foo", [], [1, 2, []], ["bar"]]; - a[1] = a; - a[2][2] = a; - // [ "foo", <circular>, [ 1, 2, <circular> ], [ "bar" ] ] - expect(a.toString()).toBe("foo,,1,2,,bar"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.unshift.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.unshift.js deleted file mode 100644 index 8e65e89775..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.unshift.js +++ /dev/null @@ -1,23 +0,0 @@ -test("length is 1", () => { - expect(Array.prototype.unshift).toHaveLength(1); -}); - -describe("normal behavior", () => { - test("no argument", () => { - var a = ["hello"]; - expect(a.unshift()).toBe(1); - expect(a).toEqual(["hello"]); - }); - - test("single argument", () => { - var a = ["hello"]; - expect(a.unshift("friends")).toBe(2); - expect(a).toEqual(["friends", "hello"]); - }); - - test("multiple arguments", () => { - var a = ["friends", "hello"]; - expect(a.unshift(1, 2, 3)).toBe(5); - expect(a).toEqual([1, 2, 3, "friends", "hello"]); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.values.js b/Libraries/LibJS/Tests/builtins/Array/Array.prototype.values.js deleted file mode 100644 index 368f34429f..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/Array.prototype.values.js +++ /dev/null @@ -1,44 +0,0 @@ -test("length", () => { - expect(Array.prototype.values.length).toBe(0); -}); - -test("basic functionality", () => { - const a = [1, 2, 3]; - const it = a.values(); - expect(it.next()).toEqual({ value: 1, done: false }); - expect(it.next()).toEqual({ value: 2, done: false }); - expect(it.next()).toEqual({ value: 3, done: false }); - expect(it.next()).toEqual({ value: undefined, done: true }); - expect(it.next()).toEqual({ value: undefined, done: true }); - expect(it.next()).toEqual({ value: undefined, done: true }); -}); - -test("works when applied to non-object", () => { - [true, false, 9, 2n, Symbol()].forEach(primitive => { - const it = [].values.call(primitive); - expect(it.next()).toEqual({ value: undefined, done: true }); - expect(it.next()).toEqual({ value: undefined, done: true }); - expect(it.next()).toEqual({ value: undefined, done: true }); - }); -}); - -test("item added to array before exhaustion is accessible", () => { - const a = [1, 2]; - const it = a.values(); - expect(it.next()).toEqual({ value: 1, done: false }); - expect(it.next()).toEqual({ value: 2, done: false }); - a.push(3); - expect(it.next()).toEqual({ value: 3, done: false }); - expect(it.next()).toEqual({ value: undefined, done: true }); - expect(it.next()).toEqual({ value: undefined, done: true }); -}); - -test("item added to array after exhaustion is inaccessible", () => { - const a = [1, 2]; - const it = a.values(); - expect(it.next()).toEqual({ value: 1, done: false }); - expect(it.next()).toEqual({ value: 2, done: false }); - expect(it.next()).toEqual({ value: undefined, done: true }); - a.push(3); - expect(it.next()).toEqual({ value: undefined, done: true }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/array-basic.js b/Libraries/LibJS/Tests/builtins/Array/array-basic.js deleted file mode 100644 index d6e6976421..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/array-basic.js +++ /dev/null @@ -1,57 +0,0 @@ -test("basic functionality", () => { - var a = [1, 2, 3]; - - expect(typeof a).toBe("object"); - expect(a).toHaveLength(3); - expect(a[0]).toBe(1); - expect(a[1]).toBe(2); - expect(a[2]).toBe(3); - - a[1] = 5; - expect(a[1]).toBe(5); - expect(a).toHaveLength(3); - - a.push(7); - expect(a[3]).toBe(7); - expect(a).toHaveLength(4); - - a = [,]; - expect(a).toHaveLength(1); - expect(a.toString()).toBe(""); - expect(a[0]).toBeUndefined(); - - a = [, , , ,]; - expect(a).toHaveLength(4); - expect(a.toString()).toBe(",,,"); - expect(a[0]).toBeUndefined(); - expect(a[1]).toBeUndefined(); - expect(a[2]).toBeUndefined(); - expect(a[3]).toBeUndefined(); - - a = [1, , 2, , , 3]; - expect(a).toHaveLength(6); - expect(a.toString()).toBe("1,,2,,,3"); - expect(a[0]).toBe(1); - expect(a[1]).toBeUndefined(); - expect(a[2]).toBe(2); - expect(a[3]).toBeUndefined(); - expect(a[4]).toBeUndefined(); - expect(a[5]).toBe(3); - - a = [1, , 2, , , 3]; - Object.defineProperty(a, 1, { - get() { - return this.getterSetterValue; - }, - set(value) { - this.getterSetterValue = value; - }, - }); - expect(a).toHaveLength(6); - expect(a.toString()).toBe("1,,2,,,3"); - expect(a.getterSetterValue).toBeUndefined(); - a[1] = 20; - expect(a).toHaveLength(6); - expect(a.toString()).toBe("1,20,2,,,3"); - expect(a.getterSetterValue).toBe(20); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/array-length-setter.js b/Libraries/LibJS/Tests/builtins/Array/array-length-setter.js deleted file mode 100644 index 9a1043f5d4..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/array-length-setter.js +++ /dev/null @@ -1,37 +0,0 @@ -describe("errors", () => { - test("invalid array length value", () => { - var a = [1, 2, 3]; - [undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => { - expect(() => { - a.length = value; - }).toThrowWithMessage(RangeError, "Invalid array length"); - expect(a).toHaveLength(3); - }); - }); -}); - -describe("normal behavior", () => { - test("extend array by setting length", () => { - var a = [1, 2, 3]; - a.length = 5; - expect(a).toEqual([1, 2, 3, undefined, undefined]); - }); - - test("truncate array by setting length", () => { - var a = [1, 2, 3]; - a.length = 2; - expect(a).toEqual([1, 2]); - a.length = 0; - expect(a).toEqual([]); - }); - - test("length value is coerced to number if possible", () => { - var a = [1, 2, 3]; - a.length = "42"; - expect(a).toHaveLength(42); - a.length = []; - expect(a).toHaveLength(0); - a.length = true; - expect(a).toHaveLength(1); - }); -}); 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 deleted file mode 100644 index d43c5d0d01..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/array-shrink-during-find-crash.js +++ /dev/null @@ -1,19 +0,0 @@ -test("Issue #1992, shrinking array during find() iteration", () => { - var a, callbackCalled; - - callbackCalled = 0; - a = [1, 2, 3, 4, 5]; - a.find(() => { - callbackCalled++; - a.pop(); - }); - expect(callbackCalled).toBe(5); - - callbackCalled = 0; - a = [1, 2, 3, 4, 5]; - a.findIndex(() => { - callbackCalled++; - a.pop(); - }); - expect(callbackCalled).toBe(5); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/array-simple-and-generic-storage-initialization.js b/Libraries/LibJS/Tests/builtins/Array/array-simple-and-generic-storage-initialization.js deleted file mode 100644 index 3202b02c33..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/array-simple-and-generic-storage-initialization.js +++ /dev/null @@ -1,15 +0,0 @@ -describe("Issue #3382", () => { - test("Creating an array with simple storage (<= 200 initial elements)", () => { - var a = Array(200); - expect(a).toHaveLength(200); - expect(a.push("foo")).toBe(201); - expect(a).toHaveLength(201); - }); - - test("Creating an array with generic storage (> 200 initial elements)", () => { - var a = Array(201); - expect(a).toHaveLength(201); - expect(a.push("foo")).toBe(202); - expect(a).toHaveLength(202); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Array/array-spread.js b/Libraries/LibJS/Tests/builtins/Array/array-spread.js deleted file mode 100644 index cb570edffe..0000000000 --- a/Libraries/LibJS/Tests/builtins/Array/array-spread.js +++ /dev/null @@ -1,25 +0,0 @@ -describe("errors", () => { - test("cannot spread number in array", () => { - expect(() => { - [...1]; - }).toThrowWithMessage(TypeError, "1 is not iterable"); - }); - - test("cannot spread object in array", () => { - expect(() => { - [...{}]; - }).toThrowWithMessage(TypeError, "[object Object] is not iterable"); - }); -}); - -test("basic functionality", () => { - expect([1, ...[2, 3], 4]).toEqual([1, 2, 3, 4]); - - let a = [2, 3]; - expect([1, ...a, 4]).toEqual([1, 2, 3, 4]); - - let obj = { a: [2, 3] }; - expect([1, ...obj.a, 4]).toEqual([1, 2, 3, 4]); - - expect([...[], ...[...[1, 2, 3]], 4]).toEqual([1, 2, 3, 4]); -}); diff --git a/Libraries/LibJS/Tests/builtins/ArrayBuffer/ArrayBuffer.isView.js b/Libraries/LibJS/Tests/builtins/ArrayBuffer/ArrayBuffer.isView.js deleted file mode 100644 index db1be84067..0000000000 --- a/Libraries/LibJS/Tests/builtins/ArrayBuffer/ArrayBuffer.isView.js +++ /dev/null @@ -1,27 +0,0 @@ -// Update when more typed arrays get added -const TYPED_ARRAYS = [ - Uint8Array, - Uint16Array, - Uint32Array, - Int8Array, - Int16Array, - Int32Array, - Float32Array, - Float64Array, -]; - -test("basic functionality", () => { - expect(ArrayBuffer.isView).toHaveLength(1); - - expect(ArrayBuffer.isView()).toBeFalse(); - expect(ArrayBuffer.isView(null)).toBeFalse(); - expect(ArrayBuffer.isView(undefined)).toBeFalse(); - expect(ArrayBuffer.isView([])).toBeFalse(); - expect(ArrayBuffer.isView({})).toBeFalse(); - expect(ArrayBuffer.isView(123)).toBeFalse(); - expect(ArrayBuffer.isView("foo")).toBeFalse(); - expect(ArrayBuffer.isView(new ArrayBuffer())).toBeFalse(); - TYPED_ARRAYS.forEach(T => { - expect(ArrayBuffer.isView(new T())).toBeTrue(); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/ArrayBuffer/ArrayBuffer.js b/Libraries/LibJS/Tests/builtins/ArrayBuffer/ArrayBuffer.js deleted file mode 100644 index 8fb05a250c..0000000000 --- a/Libraries/LibJS/Tests/builtins/ArrayBuffer/ArrayBuffer.js +++ /dev/null @@ -1,13 +0,0 @@ -test("basic functionality", () => { - expect(ArrayBuffer).toHaveLength(1); - expect(ArrayBuffer.name).toBe("ArrayBuffer"); - expect(ArrayBuffer.prototype.constructor).toBe(ArrayBuffer); - expect(new ArrayBuffer()).toBeInstanceOf(ArrayBuffer); - expect(typeof new ArrayBuffer()).toBe("object"); -}); - -test("ArrayBuffer constructor must be invoked with 'new'", () => { - expect(() => { - ArrayBuffer(); - }).toThrowWithMessage(TypeError, "ArrayBuffer constructor must be called with 'new'"); -}); diff --git a/Libraries/LibJS/Tests/builtins/ArrayBuffer/ArrayBuffer.prototype.byteLength.js b/Libraries/LibJS/Tests/builtins/ArrayBuffer/ArrayBuffer.prototype.byteLength.js deleted file mode 100644 index 9880e597aa..0000000000 --- a/Libraries/LibJS/Tests/builtins/ArrayBuffer/ArrayBuffer.prototype.byteLength.js +++ /dev/null @@ -1,6 +0,0 @@ -test("basic functionality", () => { - expect(new ArrayBuffer().byteLength).toBe(0); - expect(new ArrayBuffer(1).byteLength).toBe(1); - expect(new ArrayBuffer(64).byteLength).toBe(64); - expect(new ArrayBuffer(123).byteLength).toBe(123); -}); diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.js deleted file mode 100644 index 7e517754b7..0000000000 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.js +++ /dev/null @@ -1,68 +0,0 @@ -describe("correct behavior", () => { - 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 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); - }); -}); - -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("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.@@toStringTag.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.@@toStringTag.js deleted file mode 100644 index 44812778a4..0000000000 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.@@toStringTag.js +++ /dev/null @@ -1,3 +0,0 @@ -test("basic functionality", () => { - expect(BigInt.prototype[Symbol.toStringTag]).toBe("BigInt"); -}); diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js deleted file mode 100644 index 1c111c516d..0000000000 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toLocaleString.js +++ /dev/null @@ -1,10 +0,0 @@ -test("basic functionality", () => { - 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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js deleted file mode 100644 index 040dec60d9..0000000000 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.toString.js +++ /dev/null @@ -1,10 +0,0 @@ -test("basic functionality", () => { - 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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js deleted file mode 100644 index d30a81f824..0000000000 --- a/Libraries/LibJS/Tests/builtins/BigInt/BigInt.prototype.valueOf.js +++ /dev/null @@ -1,12 +0,0 @@ -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"); -}); - -test("calling with non-BigInt |this|", () => { - 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 deleted file mode 100644 index b3fc47d0ad..0000000000 --- a/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js +++ /dev/null @@ -1,80 +0,0 @@ -describe("correct behavior", () => { - test("typeof bigint", () => { - expect(typeof 1n).toBe("bigint"); - }); - - test("bigint string coercion", () => { - expect("" + 123n).toBe("123"); - }); - - 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); - }); - - 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("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(); - }); - - 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(); - }); -}); - -describe("errors", () => { - test("conversion to number", () => { - expect(() => { - +123n; - }).toThrowWithMessage(TypeError, "Cannot convert BigInt to number"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/BigInt/bigint-minus.js b/Libraries/LibJS/Tests/builtins/BigInt/bigint-minus.js deleted file mode 100644 index 5d88f85ce2..0000000000 --- a/Libraries/LibJS/Tests/builtins/BigInt/bigint-minus.js +++ /dev/null @@ -1,8 +0,0 @@ -describe("minus behavior", () => { - test("the basics", () => { - expect(3n - 4n).toBe(-1n); - expect(3n - -4n).toBe(7n); - expect(-3n - -4n).toBe(-1n); - expect(-3n - 4n).toBe(-7n); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/BigInt/bigint-number-mix-errors.js b/Libraries/LibJS/Tests/builtins/BigInt/bigint-number-mix-errors.js deleted file mode 100644 index de80b92b3a..0000000000 --- a/Libraries/LibJS/Tests/builtins/BigInt/bigint-number-mix-errors.js +++ /dev/null @@ -1,31 +0,0 @@ -const doTest = (operatorName, executeOperation) => { - [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}` - ); - }); -}; - -[ - ["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]); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js deleted file mode 100644 index a2cf07b998..0000000000 --- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js +++ /dev/null @@ -1,32 +0,0 @@ -test("constructor properties", () => { - 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"); -}); - -test("basic functionality", () => { - var foo = new Boolean(true); - var bar = new Boolean(true); - - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js deleted file mode 100644 index d818d91edb..0000000000 --- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js +++ /dev/null @@ -1,5 +0,0 @@ -test("basic functionality", () => { - 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 deleted file mode 100644 index 506b23feac..0000000000 --- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.toString.js +++ /dev/null @@ -1,17 +0,0 @@ -test("basic functionality", () => { - 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(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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js deleted file mode 100644 index d510523c5b..0000000000 --- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js +++ /dev/null @@ -1,16 +0,0 @@ -test("basic functionality", () => { - 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(new Boolean().valueOf()).toBeFalse(); -}); - -test("errors on non-boolean |this|", () => { - expect(() => { - Boolean.prototype.valueOf.call("foo"); - }).toThrowWithMessage(TypeError, "Not a Boolean object"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.UTC.js b/Libraries/LibJS/Tests/builtins/Date/Date.UTC.js deleted file mode 100644 index d5c8082729..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.UTC.js +++ /dev/null @@ -1,51 +0,0 @@ -test("basic functionality", () => { - expect(Date.UTC(2020)).toBe(1577836800000); - expect(Date.UTC(2000, 10)).toBe(973036800000); - expect(Date.UTC(1980, 5, 30)).toBe(331171200000); - expect(Date.UTC(1980, 5, 30, 13)).toBe(331218000000); - expect(Date.UTC(1970, 5, 30, 13, 30)).toBe(15600600000); - expect(Date.UTC(1970, 0, 1, 0, 0, 59)).toBe(59000); - expect(Date.UTC(1970, 0, 1, 0, 0, 0, 999)).toBe(999); - - expect(Date.UTC(1969, 11, 31, 23, 59, 59, 817)).toBe(-183); - - expect(Date.UTC(1799, 0)).toBe(-5396198400000); - expect(Date.UTC(1800, 0)).toBe(-5364662400000); - expect(Date.UTC(1801, 0)).toBe(-5333126400000); - expect(Date.UTC(1802, 0)).toBe(-5301590400000); - expect(Date.UTC(1803, 0)).toBe(-5270054400000); - expect(Date.UTC(1804, 0)).toBe(-5238518400000); - - expect(Date.UTC(1999, 0)).toBe(915148800000); - expect(Date.UTC(2000, 0)).toBe(946684800000); - expect(Date.UTC(2001, 0)).toBe(978307200000); - expect(Date.UTC(2002, 0)).toBe(1009843200000); - expect(Date.UTC(2003, 0)).toBe(1041379200000); - expect(Date.UTC(2004, 0)).toBe(1072915200000); - - expect(Date.UTC(20000, 0)).toBe(568971820800000); -}); - -test("leap year", () => { - expect(Date.UTC(2020, 2, 1)).toBe(1583020800000); -}); - -test("out of range", () => { - expect(Date.UTC(2020, -20)).toBe(1525132800000); - expect(Date.UTC(2020, 20)).toBe(1630454400000); - - expect(Date.UTC(2020, 1, -10)).toBe(1579564800000); - expect(Date.UTC(2020, 1, 40)).toBe(1583884800000); - - expect(Date.UTC(2020, 1, 15, -50)).toBe(1581544800000); - expect(Date.UTC(2020, 1, 15, 50)).toBe(1581904800000); - - expect(Date.UTC(2020, 1, 15, 12, -123)).toBe(1581760620000); - expect(Date.UTC(2020, 1, 15, 12, 123)).toBe(1581775380000); - - expect(Date.UTC(2020, 1, 15, 12, 30, -123)).toBe(1581769677000); - expect(Date.UTC(2020, 1, 15, 12, 30, 123)).toBe(1581769923000); - - expect(Date.UTC(2020, 1, 15, 12, 30, 30, -2345)).toBe(1581769827655); - expect(Date.UTC(2020, 1, 15, 12, 30, 30, 2345)).toBe(1581769832345); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.js b/Libraries/LibJS/Tests/builtins/Date/Date.js deleted file mode 100644 index cc76212e22..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.js +++ /dev/null @@ -1,77 +0,0 @@ -test("basic functionality", () => { - expect(Date).toHaveLength(7); - expect(Date.name === "Date"); - expect(Date.prototype).not.toHaveProperty("length"); -}); - -test("string constructor", () => { - // The string constructor is the same as calling the timestamp constructor with the result of Date.parse(arguments). - // Since that has exhaustive tests in Date.parse.js, just do some light smoke testing here. - expect(new Date("2017-09-07T21:08:59.001Z").toISOString()).toBe("2017-09-07T21:08:59.001Z"); -}); - -test("timestamp constructor", () => { - // The timestamp constructor takes a timestamp in milliseconds since the start of the epoch, in UTC. - - // 50 days and 1234 milliseconds after the start of the epoch. - // Most Date methods return values in local time, but since timezone offsets are less than 17 days, - // these checks will pass in all timezones. - let timestamp = 50 * 24 * 60 * 60 * 1000 + 1234; - - let date = new Date(timestamp); - expect(date.getTime()).toBe(timestamp); // getTime() returns the timestamp in UTC. - expect(date.getMilliseconds()).toBe(234); - expect(date.getSeconds()).toBe(1); - expect(date.getFullYear()).toBe(1970); - expect(date.getMonth()).toBe(1); // Feb -}); - -test("tuple constructor", () => { - // The tuple constructor takes a date in local time. - expect(new Date(2019, 11).getFullYear()).toBe(2019); - expect(new Date(2019, 11).getMonth()).toBe(11); - expect(new Date(2019, 11).getDate()).toBe(1); // getDay() returns day of week, getDate() returns day in month - expect(new Date(2019, 11).getHours()).toBe(0); - expect(new Date(2019, 11).getMinutes()).toBe(0); - expect(new Date(2019, 11).getSeconds()).toBe(0); - expect(new Date(2019, 11).getMilliseconds()).toBe(0); - expect(new Date(2019, 11).getDay()).toBe(0); - - let date = new Date(2019, 11, 15, 9, 16, 14, 123); // Note: Month is 0-based. - expect(date.getFullYear()).toBe(2019); - expect(date.getMonth()).toBe(11); - expect(date.getDate()).toBe(15); - expect(date.getHours()).toBe(9); - expect(date.getMinutes()).toBe(16); - expect(date.getSeconds()).toBe(14); - expect(date.getMilliseconds()).toBe(123); - expect(date.getDay()).toBe(0); - - // getTime() returns a time stamp in UTC, but we can at least check it's in the right interval, which will be true independent of the local timezone if the range is big enough. - let timestamp_lower_bound = 1575072000000; // 2019-12-01T00:00:00Z - let timestamp_upper_bound = 1577750400000; // 2019-12-31T00:00:00Z - expect(date.getTime()).toBeGreaterThan(timestamp_lower_bound); - expect(date.getTime()).toBeLessThan(timestamp_upper_bound); -}); - -test("tuple constructor overflow", () => { - let date = new Date(2019, 13, 33, 30, 70, 80, 2345); - expect(date.getFullYear()).toBe(2020); - expect(date.getMonth()).toBe(2); - expect(date.getDate()).toBe(5); - expect(date.getHours()).toBe(7); - expect(date.getMinutes()).toBe(11); - expect(date.getSeconds()).toBe(22); - expect(date.getMilliseconds()).toBe(345); - expect(date.getDay()).toBe(4); - - let date = new Date(2019, -13, -33, -30, -70, -80, -2345); - expect(date.getFullYear()).toBe(2017); - expect(date.getMonth()).toBe(9); - expect(date.getDate()).toBe(26); - expect(date.getHours()).toBe(16); - expect(date.getMinutes()).toBe(48); - expect(date.getSeconds()).toBe(37); - expect(date.getMilliseconds()).toBe(655); - expect(date.getDay()).toBe(4); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.now.js b/Libraries/LibJS/Tests/builtins/Date/Date.now.js deleted file mode 100644 index 46c1b6d8cd..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.now.js +++ /dev/null @@ -1,10 +0,0 @@ -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; - } -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.parse.js b/Libraries/LibJS/Tests/builtins/Date/Date.parse.js deleted file mode 100644 index ca2766ae34..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.parse.js +++ /dev/null @@ -1,32 +0,0 @@ -test("basic functionality", () => { - expect(Date.parse("2020")).toBe(1577836800000); - expect(Date.parse("2000-11")).toBe(973036800000); - expect(Date.parse("1980-06-30")).toBe(331171200000); - expect(Date.parse("1970-06-30T13:30Z")).toBe(15600600000); - expect(Date.parse("1970-01-01T00:00:59Z")).toBe(59000); - expect(Date.parse("1970-01-01T00:00:00.999Z")).toBe(999); - expect(Date.parse("2020T13:14+15:16")).toBe(1577829480000); - expect(Date.parse("2020T13:14-15:16")).toBe(1577939400000); - expect(Date.parse("2020T23:59Z")).toBe(1577923140000); - - expect(Date.parse("+020000")).toBe(568971820800000); - expect(Date.parse("+020000-01")).toBe(568971820800000); - expect(Date.parse("+020000-01T00:00:00.000Z")).toBe(568971820800000); - - expect(Date.parse(2020)).toBe(1577836800000); - - expect(Date.parse("+1980")).toBe(NaN); - expect(Date.parse("1980-")).toBe(NaN); - expect(Date.parse("1980-05-")).toBe(NaN); - expect(Date.parse("1980-05-00T")).toBe(NaN); - expect(Date.parse("1980-05-00T15:15:")).toBe(NaN); - expect(Date.parse("1980-05-00T15:15:15.")).toBe(NaN); - expect(Date.parse("1980-5-30")).toBe(NaN); - expect(Date.parse("1980-05-30T13")).toBe(NaN); - expect(Date.parse("1980-05-30T13:4")).toBe(NaN); - expect(Date.parse("1980-05-30T13:40+")).toBe(NaN); - expect(Date.parse("1980-05-30T13:40+1")).toBe(NaN); - expect(Date.parse("1980-05-30T13:40+1:10")).toBe(NaN); - expect(Date.parse("1970-06-30T13:30Zoo")).toBe(NaN); - expect(Date.parse("2020T13:30.40:")).toBe(NaN); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js deleted file mode 100644 index 647e43a997..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js +++ /dev/null @@ -1,7 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js deleted file mode 100644 index 534efeeee5..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js +++ /dev/null @@ -1,7 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js deleted file mode 100644 index 3748e835cf..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js +++ /dev/null @@ -1,7 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js deleted file mode 100644 index 7e562288f2..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js +++ /dev/null @@ -1,7 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js deleted file mode 100644 index 90c686f729..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js +++ /dev/null @@ -1,7 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js deleted file mode 100644 index 5b87b8251d..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js +++ /dev/null @@ -1,7 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js deleted file mode 100644 index 7d52866ce7..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js +++ /dev/null @@ -1,7 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js deleted file mode 100644 index df30881c9a..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js +++ /dev/null @@ -1,7 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js deleted file mode 100644 index b9ada6fcc9..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js +++ /dev/null @@ -1,6 +0,0 @@ -test("basic functionality", () => { - 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/Date/Date.prototype.getUTCDate.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCDate.js deleted file mode 100644 index d207385bad..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCDate.js +++ /dev/null @@ -1,7 +0,0 @@ -test("basic functionality", () => { - let d = new Date(); - expect(d.getUTCDate()).toBe(d.getUTCDate()); - expect(d.getUTCDate()).not.toBeNaN(); - expect(d.getUTCDate()).toBeGreaterThanOrEqual(1); - expect(d.getUTCDate()).toBeLessThanOrEqual(31); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCDay.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCDay.js deleted file mode 100644 index aec696be4a..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCDay.js +++ /dev/null @@ -1,7 +0,0 @@ -test("basic functionality", () => { - var d = new Date(); - expect(d.getUTCDay()).toBe(d.getUTCDay()); - expect(d.getUTCDay()).not.toBeNaN(); - expect(d.getUTCDay()).toBeGreaterThanOrEqual(0); - expect(d.getUTCDay()).toBeLessThanOrEqual(6); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCFullYear.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCFullYear.js deleted file mode 100644 index 50336d8178..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCFullYear.js +++ /dev/null @@ -1,7 +0,0 @@ -test("basic functionality", () => { - var d = new Date(); - expect(d.getUTCFullYear()).toBe(d.getUTCFullYear()); - expect(d.getUTCFullYear()).not.toBeNaN(); - expect(d.getUTCFullYear()).toBe(d.getUTCFullYear()); - expect(d.getUTCFullYear()).toBeGreaterThanOrEqual(2020); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCHours.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCHours.js deleted file mode 100644 index 298ed178e5..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCHours.js +++ /dev/null @@ -1,7 +0,0 @@ -test("basic functionality", () => { - var d = new Date(); - expect(d.getUTCHours()).toBe(d.getUTCHours()); - expect(d.getUTCHours()).not.toBeNaN(); - expect(d.getUTCHours()).toBeGreaterThanOrEqual(0); - expect(d.getUTCHours()).toBeLessThanOrEqual(23); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCMilliseconds.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCMilliseconds.js deleted file mode 100644 index f53ea70428..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCMilliseconds.js +++ /dev/null @@ -1,7 +0,0 @@ -test("basic functionality", () => { - var d = new Date(); - expect(d.getUTCMilliseconds()).toBe(d.getUTCMilliseconds()); - expect(d.getUTCMilliseconds()).not.toBeNaN(); - expect(d.getUTCMilliseconds()).toBeGreaterThanOrEqual(0); - expect(d.getUTCMilliseconds()).toBeLessThanOrEqual(999); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCMinutes.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCMinutes.js deleted file mode 100644 index 6b1146331c..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCMinutes.js +++ /dev/null @@ -1,7 +0,0 @@ -test("basic functionality", () => { - var d = new Date(); - expect(d.getUTCMinutes()).toBe(d.getUTCMinutes()); - expect(d.getUTCMinutes()).not.toBeNaN(); - expect(d.getUTCMinutes()).toBeGreaterThanOrEqual(0); - expect(d.getUTCMinutes()).toBeLessThanOrEqual(59); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCMonth.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCMonth.js deleted file mode 100644 index ed6ed64d97..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCMonth.js +++ /dev/null @@ -1,26 +0,0 @@ -test("basic functionality", () => { - var d = new Date(); - expect(d.getUTCMonth()).toBe(d.getUTCMonth()); - expect(d.getUTCMonth()).not.toBeNaN(); - expect(d.getUTCMonth()).toBeGreaterThanOrEqual(0); - expect(d.getUTCMonth()).toBeLessThanOrEqual(11); - - expect(new Date(Date.UTC(2020, 11)).getUTCMonth()).toBe(11); -}); - -test("leap years", () => { - expect(new Date(Date.UTC(2019, 1, 29)).getUTCDate()).toBe(1); - expect(new Date(Date.UTC(2019, 1, 29)).getUTCMonth()).toBe(2); - expect(new Date(Date.UTC(2100, 1, 29)).getUTCDate()).toBe(1); - expect(new Date(Date.UTC(2100, 1, 29)).getUTCMonth()).toBe(2); - - expect(new Date(Date.UTC(2000, 1, 29)).getUTCDate()).toBe(29); - expect(new Date(Date.UTC(2000, 1, 29)).getUTCMonth()).toBe(1); - expect(new Date(Date.UTC(2020, 1, 29)).getUTCDate()).toBe(29); - expect(new Date(Date.UTC(2020, 1, 29)).getUTCMonth()).toBe(1); - - expect(new Date(Date.UTC(2019, 2, 1)).getUTCDate()).toBe(1); - expect(new Date(Date.UTC(2019, 2, 1)).getUTCMonth()).toBe(2); - expect(new Date(Date.UTC(2020, 2, 1)).getUTCDate()).toBe(1); - expect(new Date(Date.UTC(2020, 2, 1)).getUTCMonth()).toBe(2); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCSeconds.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCSeconds.js deleted file mode 100644 index d087a3c4c8..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getUTCSeconds.js +++ /dev/null @@ -1,7 +0,0 @@ -test("basic functionality", () => { - var d = new Date(); - expect(d.getUTCSeconds()).toBe(d.getUTCSeconds()); - expect(d.getUTCSeconds()).not.toBeNaN(); - expect(d.getUTCSeconds()).toBeGreaterThanOrEqual(0); - expect(d.getUTCSeconds()).toBeLessThanOrEqual(59); -}); diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.toISOString.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.toISOString.js deleted file mode 100644 index 2b380fc24d..0000000000 --- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.toISOString.js +++ /dev/null @@ -1,7 +0,0 @@ -test("basic functionality", () => { - expect(new Date(1597955034555).toISOString()).toBe("2020-08-20T20:23:54.555Z"); - expect(new Date(Date.UTC(22020)).toISOString()).toBe("+022020-01-01T00:00:00.000Z"); - expect(new Date(Date.UTC(1950)).toISOString()).toBe("1950-01-01T00:00:00.000Z"); - expect(new Date(Date.UTC(1800)).toISOString()).toBe("1800-01-01T00:00:00.000Z"); - expect(new Date(Date.UTC(-100)).toISOString()).toBe("-000100-01-01T00:00:00.000Z"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Error/Error.js b/Libraries/LibJS/Tests/builtins/Error/Error.js deleted file mode 100644 index a452bd7a88..0000000000 --- a/Libraries/LibJS/Tests/builtins/Error/Error.js +++ /dev/null @@ -1,18 +0,0 @@ -test("basic functionality", () => { - 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"); - }); -}); - -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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js b/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js deleted file mode 100644 index acfcb039fb..0000000000 --- a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js +++ /dev/null @@ -1,10 +0,0 @@ -test("basic functionality", () => { - expect(Error.prototype).not.toHaveProperty("length"); - - var changedInstance = new Error(""); - changedInstance.name = "NewCustomError"; - expect(changedInstance.name).toBe("NewCustomError"); - - var normalInstance = new Error(""); - expect(normalInstance.name).toBe("Error"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js deleted file mode 100644 index b5d2f7dceb..0000000000 --- a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js +++ /dev/null @@ -1,7 +0,0 @@ -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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.js b/Libraries/LibJS/Tests/builtins/Function/Function.js deleted file mode 100644 index 9a972ab81d..0000000000 --- a/Libraries/LibJS/Tests/builtins/Function/Function.js +++ /dev/null @@ -1,53 +0,0 @@ -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("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); - - expect(new Function("-->")()).toBeUndefined(); - - 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: 4, column: 1)" - ); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.@@hasInstance.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.@@hasInstance.js deleted file mode 100644 index d548a635fe..0000000000 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.@@hasInstance.js +++ /dev/null @@ -1,8 +0,0 @@ -test("basic functionality", () => { - expect(Function.prototype[Symbol.hasInstance]).toHaveLength(1); - - function Foo() {} - const foo = new Foo(); - - expect(Function.prototype[Symbol.hasInstance].call(Foo, foo)).toBeTrue(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js deleted file mode 100644 index 1c57e4a657..0000000000 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js +++ /dev/null @@ -1,51 +0,0 @@ -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; - } - - 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 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 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); - - 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); - - 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 deleted file mode 100644 index 1bd5269f1d..0000000000 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js +++ /dev/null @@ -1,149 +0,0 @@ -describe("basic behavior", () => { - 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"); - - 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); - - 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); - }); -}); - -describe("bound function arguments", () => { - 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 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("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; - } - - 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; - } - - 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 functions retain original prototype", () => { - expect(bar.baz).toBe("baz"); - }); - - 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"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js deleted file mode 100644 index 136f69b2bd..0000000000 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js +++ /dev/null @@ -1,53 +0,0 @@ -test("length", () => { - 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; - } - - 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 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"); - - expect(Math.abs.call(null, -1)).toBe(1); - - 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); - - 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 deleted file mode 100644 index a8ed197930..0000000000 --- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js +++ /dev/null @@ -1,17 +0,0 @@ -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}"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Infinity/Infinity.js b/Libraries/LibJS/Tests/builtins/Infinity/Infinity.js deleted file mode 100644 index 0c88544f7f..0000000000 --- a/Libraries/LibJS/Tests/builtins/Infinity/Infinity.js +++ /dev/null @@ -1,22 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.@@toStringTag.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.@@toStringTag.js deleted file mode 100644 index 5a1e51f7c6..0000000000 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.@@toStringTag.js +++ /dev/null @@ -1,4 +0,0 @@ -test("basic functionality", () => { - expect(JSON[Symbol.toStringTag]).toBe("JSON"); - expect(JSON.toString()).toBe("[object JSON]"); -}); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js deleted file mode 100644 index 4044e0200a..0000000000 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js +++ /dev/null @@ -1,11 +0,0 @@ -test("basic functionality", () => { - 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 } }); - - 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 deleted file mode 100644 index 7f82392666..0000000000 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js +++ /dev/null @@ -1,37 +0,0 @@ -test("basic functionality", () => { - 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" }], - ]; - - 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); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-exception-in-property-getter.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-exception-in-property-getter.js deleted file mode 100644 index 18845f842b..0000000000 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-exception-in-property-getter.js +++ /dev/null @@ -1,10 +0,0 @@ -test("Issue #3548, exception in property getter with replacer function", () => { - const o = { - get foo() { - throw Error(); - }, - }; - expect(() => { - JSON.stringify(o, (_, value) => value); - }).toThrow(Error); -}); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js deleted file mode 100644 index 3c2c8e3161..0000000000 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js +++ /dev/null @@ -1,30 +0,0 @@ -test("basic functionality", () => { - let o = { - key1: "key1", - key2: "key2", - key3: "key3", - }; - - Object.defineProperty(o, "defined", { - enumerable: true, - get() { - o.prop = "prop"; - return "defined"; - }, - }); - - o.key4 = "key4"; - - o[2] = 2; - o[0] = 0; - o[1] = 1; - - delete o.key1; - delete o.key3; - - o.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 deleted file mode 100644 index eb4f4c85e8..0000000000 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js +++ /dev/null @@ -1,11 +0,0 @@ -test("basic functionality", () => { - 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]]]"); -}); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js deleted file mode 100644 index 156edffee7..0000000000 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js +++ /dev/null @@ -1,38 +0,0 @@ -test("basic functionality", () => { - let o = { - var1: "foo", - var2: 42, - arr: [ - 1, - 2, - { - nested: { - hello: "world", - }, - get x() { - return 10; - }, - }, - ], - obj: { - subarr: [3], - }, - }; - - let string = JSON.stringify(o, (key, value) => { - if (key === "hello") return undefined; - if (value === 10) return 20; - if (key === "subarr") return [3, 4, 5]; - return value; - }); - - 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", "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 deleted file mode 100644 index 75873367bf..0000000000 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js +++ /dev/null @@ -1,47 +0,0 @@ -test("basic functionality", () => { - 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 = `{ - "foo": 1, - "bar": "baz", - "qux": { - "x": 10, - "arr": [ - 1, - 2, - 3 - ] - } -}`; - - expect(string).toBe(expected); - - string = JSON.stringify(o, null, "abcd"); - expected = `{ -abcd"foo": 1, -abcd"bar": "baz", -abcd"qux": { -abcdabcd"x": 10, -abcdabcd"arr": [ -abcdabcdabcd1, -abcdabcdabcd2, -abcdabcdabcd3 -abcdabcd] -abcd} -}`; - - expect(string).toBe(expected); -}); diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js deleted file mode 100644 index 1e5c174312..0000000000 --- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js +++ /dev/null @@ -1,71 +0,0 @@ -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("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"); - }); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math-constants.js b/Libraries/LibJS/Tests/builtins/Math/Math-constants.js deleted file mode 100644 index f8c75c269b..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math-constants.js +++ /dev/null @@ -1,10 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.@@toStringTag.js b/Libraries/LibJS/Tests/builtins/Math/Math.@@toStringTag.js deleted file mode 100644 index 69815a1499..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.@@toStringTag.js +++ /dev/null @@ -1,4 +0,0 @@ -test("basic functionality", () => { - expect(Math[Symbol.toStringTag]).toBe("Math"); - expect(Math.toString()).toBe("[object Math]"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.abs.js b/Libraries/LibJS/Tests/builtins/Math/Math.abs.js deleted file mode 100644 index a43482c28f..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.abs.js +++ /dev/null @@ -1,14 +0,0 @@ -test("basic functionality", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js b/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js deleted file mode 100644 index 11d16aabeb..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js +++ /dev/null @@ -1,9 +0,0 @@ -test("basic functionality", () => { - 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); - expect(Math.acosh(2)).toBeCloseTo(1.316957); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.asin.js b/Libraries/LibJS/Tests/builtins/Math/Math.asin.js deleted file mode 100644 index 928ce7be5c..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.asin.js +++ /dev/null @@ -1,15 +0,0 @@ -test("basic functionality", () => { - expect(Math.asin).toHaveLength(1); - - expect(Math.asin(0)).toBe(0); - expect(Math.asin(null)).toBe(0); - expect(Math.asin("")).toBe(0); - expect(Math.asin([])).toBe(0); - // FIXME(LibM): expect(Math.asin(1)).toBeCloseTo(1.5707963267948966); - // FIXME(LibM): expect(Math.asin(-1)).toBeCloseTo(-1.5707963267948966); - expect(Math.asin()).toBeNaN(); - expect(Math.asin(undefined)).toBeNaN(); - expect(Math.asin([1, 2, 3])).toBeNaN(); - expect(Math.asin({})).toBeNaN(); - expect(Math.asin("foo")).toBeNaN(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js b/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js deleted file mode 100644 index f52f6c2d0b..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js +++ /dev/null @@ -1,6 +0,0 @@ -test("basic functionality", () => { - expect(Math.asinh).toHaveLength(1); - - expect(Math.asinh(0)).toBeCloseTo(0); - expect(Math.asinh(1)).toBeCloseTo(0.881373); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.atan.js b/Libraries/LibJS/Tests/builtins/Math/Math.atan.js deleted file mode 100644 index ff526fa367..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.atan.js +++ /dev/null @@ -1,12 +0,0 @@ -test("basic functionality", () => { - expect(Math.atan).toHaveLength(1); - - expect(Math.atan(0)).toBe(0); - expect(Math.atan(-0)).toBe(-0); - expect(Math.atan(NaN)).toBeNaN(); - expect(Math.atan(-2)).toBeCloseTo(-1.1071487177940904); - expect(Math.atan(2)).toBeCloseTo(1.1071487177940904); - expect(Math.atan(Infinity)).toBeCloseTo(Math.PI / 2); - expect(Math.atan(-Infinity)).toBeCloseTo(-Math.PI / 2); - expect(Math.atan(0.5)).toBeCloseTo(0.4636476090008061); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.atan2.js b/Libraries/LibJS/Tests/builtins/Math/Math.atan2.js deleted file mode 100644 index 106fee51cc..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.atan2.js +++ /dev/null @@ -1,28 +0,0 @@ -test("basic functionality", () => { - expect(Math.atan2).toHaveLength(2); - - expect(Math.atan2(90, 15)).toBeCloseTo(1.4056476493802699); - expect(Math.atan2(15, 90)).toBeCloseTo(0.16514867741462683); - expect(Math.atan2(+0, -0)).toBeCloseTo(Math.PI); - expect(Math.atan2(-0, -0)).toBeCloseTo(-Math.PI); - expect(Math.atan2(+0, +0)).toBe(0); - expect(Math.atan2(-0, +0)).toBe(-0); - expect(Math.atan2(+0, -1)).toBeCloseTo(Math.PI); - expect(Math.atan2(-0, -1)).toBeCloseTo(-Math.PI); - expect(Math.atan2(+0, 1)).toBe(0); - expect(Math.atan2(-0, 1)).toBe(-0); - expect(Math.atan2(-1, +0)).toBeCloseTo(-Math.PI / 2); - expect(Math.atan2(-1, -0)).toBeCloseTo(-Math.PI / 2); - expect(Math.atan2(1, +0)).toBeCloseTo(Math.PI / 2); - expect(Math.atan2(1, -0)).toBeCloseTo(Math.PI / 2); - expect(Math.atan2(1, -Infinity)).toBeCloseTo(Math.PI); - expect(Math.atan2(-1, -Infinity)).toBeCloseTo(-Math.PI); - expect(Math.atan2(1, +Infinity)).toBe(0); - expect(Math.atan2(-1, +Infinity)).toBe(-0); - expect(Math.atan2(+Infinity, 1)).toBeCloseTo(Math.PI / 2); - expect(Math.atan2(-Infinity, 1)).toBeCloseTo(-Math.PI / 2); - expect(Math.atan2(+Infinity, -Infinity)).toBeCloseTo((3 * Math.PI) / 4); - expect(Math.atan2(-Infinity, -Infinity)).toBeCloseTo((-3 * Math.PI) / 4); - expect(Math.atan2(+Infinity, +Infinity)).toBeCloseTo(Math.PI / 4); - expect(Math.atan2(-Infinity, +Infinity)).toBeCloseTo(-Math.PI / 4); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js b/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js deleted file mode 100644 index 54c8f5c54e..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js +++ /dev/null @@ -1,10 +0,0 @@ -test("basic functionality", () => { - expect(Math.atanh).toHaveLength(1); - - expect(Math.atanh(-2)).toBeNaN(); - expect(Math.atanh(2)).toBeNaN(); - expect(Math.atanh(-1)).toBe(-Infinity); - expect(Math.atanh(0)).toBe(0); - expect(Math.atanh(0.5)).toBeCloseTo(0.549306); - 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 deleted file mode 100644 index 414016a7af..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.cbrt.js +++ /dev/null @@ -1,12 +0,0 @@ -test("basic functionality", () => { - expect(Math.cbrt).toHaveLength(1); - - expect(Math.cbrt(NaN)).toBeNaN(); - expect(Math.cbrt(-1)).toBe(-1); - expect(Math.cbrt(-0)).toBe(-0); - expect(Math.cbrt(-Infinity)).toBe(-Infinity); - expect(Math.cbrt(1)).toBe(1); - expect(Math.cbrt(Infinity)).toBe(Infinity); - expect(Math.cbrt(null)).toBe(0); - 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 deleted file mode 100644 index 93e35babca..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.ceil.js +++ /dev/null @@ -1,13 +0,0 @@ -test("basic functionality", () => { - 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()).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 deleted file mode 100644 index e80f9f023e..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.clz32.js +++ /dev/null @@ -1,44 +0,0 @@ -test("basic functionality", () => { - 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()).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 deleted file mode 100644 index 8186bc4199..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.cos.js +++ /dev/null @@ -1,14 +0,0 @@ -test("basic functionality", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.cosh.js b/Libraries/LibJS/Tests/builtins/Math/Math.cosh.js deleted file mode 100644 index 928b427028..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.cosh.js +++ /dev/null @@ -1,7 +0,0 @@ -test("basic functionality", () => { - expect(Math.cosh).toHaveLength(1); - - expect(Math.cosh(0)).toBe(1); - expect(Math.cosh(1)).toBeCloseTo(1.5430806348152437); - expect(Math.cosh(-1)).toBeCloseTo(1.5430806348152437); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.exp.js b/Libraries/LibJS/Tests/builtins/Math/Math.exp.js deleted file mode 100644 index d7111be916..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.exp.js +++ /dev/null @@ -1,13 +0,0 @@ -test("basic functionality", () => { - 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()).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 deleted file mode 100644 index 791eb8730a..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.expm1.js +++ /dev/null @@ -1,13 +0,0 @@ -test("basic functionality", () => { - 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()).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 deleted file mode 100644 index f1420fe202..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.floor.js +++ /dev/null @@ -1,13 +0,0 @@ -test("basic functionality", () => { - 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()).toBeNaN(); - expect(Math.floor(NaN)).toBeNaN(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.fround.js b/Libraries/LibJS/Tests/builtins/Math/Math.fround.js deleted file mode 100644 index 34b6c3f29f..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.fround.js +++ /dev/null @@ -1,9 +0,0 @@ -test("basic functionality", () => { - expect(Math.fround).toHaveLength(1); - - expect(Math.fround(0)).toBe(0); - expect(Math.fround(1)).toBe(1); - expect(Math.fround(1.337)).toBeCloseTo(1.3370000123977661); - expect(Math.fround(1.5)).toBe(1.5); - expect(Math.fround(NaN)).toBe(NaN); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.hypot.js b/Libraries/LibJS/Tests/builtins/Math/Math.hypot.js deleted file mode 100644 index ee4b1ea1b7..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.hypot.js +++ /dev/null @@ -1,9 +0,0 @@ -test("basic functionality", () => { - expect(Math.hypot(3, 4)).toBe(5); - expect(Math.hypot(3, 4, 5)).toBeCloseTo(7.0710678118654755); - expect(Math.hypot()).toBe(0); - expect(Math.hypot(NaN)).toBe(NaN); - expect(Math.hypot(3, 4, "foo")).toBe(NaN); - expect(Math.hypot(3, 4, "5")).toBeCloseTo(7.0710678118654755); - expect(Math.hypot(-3)).toBe(3); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.log.js b/Libraries/LibJS/Tests/builtins/Math/Math.log.js deleted file mode 100644 index 9b19569dce..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.log.js +++ /dev/null @@ -1,8 +0,0 @@ -test("basic functionality", () => { - expect(Math.log).toHaveLength(1); - - expect(Math.log(-1)).toBe(NaN); - expect(Math.log(0)).toBe(-Infinity); - expect(Math.log(1)).toBe(0); - expect(Math.log(10)).toBeCloseTo(2.302585092994046); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.log10.js b/Libraries/LibJS/Tests/builtins/Math/Math.log10.js deleted file mode 100644 index f63a0daa77..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.log10.js +++ /dev/null @@ -1,9 +0,0 @@ -test("basic functionality", () => { - expect(Math.log10).toHaveLength(1); - - expect(Math.log10(2)).toBeCloseTo(0.3010299956639812); - expect(Math.log10(1)).toBe(0); - expect(Math.log10(0)).toBe(-Infinity); - expect(Math.log10(-2)).toBe(NaN); - expect(Math.log10(100000)).toBe(5); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js b/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js deleted file mode 100644 index 5d35c1d03e..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js +++ /dev/null @@ -1,8 +0,0 @@ -test("basic functionality", () => { - expect(Math.log1p).toHaveLength(1); - - expect(Math.log1p(-2)).toBeNaN(); - expect(Math.log1p(-1)).toBe(-Infinity); - expect(Math.log1p(0)).toBe(0); - expect(Math.log1p(1)).toBeCloseTo(0.693147); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.log2.js b/Libraries/LibJS/Tests/builtins/Math/Math.log2.js deleted file mode 100644 index efa84a2377..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.log2.js +++ /dev/null @@ -1,10 +0,0 @@ -test("basic functionality", () => { - expect(Math.log2).toHaveLength(1); - - expect(Math.log2(3)).toBeCloseTo(1.584962500721156); - expect(Math.log2(2)).toBe(1); - expect(Math.log2(1)).toBe(0); - expect(Math.log2(0)).toBe(-Infinity); - expect(Math.log2(-2)).toBe(NaN); - expect(Math.log2(1024)).toBe(10); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.max.js b/Libraries/LibJS/Tests/builtins/Math/Math.max.js deleted file mode 100644 index f99a39cc9c..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.max.js +++ /dev/null @@ -1,10 +0,0 @@ -test("basic functionality", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.min.js b/Libraries/LibJS/Tests/builtins/Math/Math.min.js deleted file mode 100644 index fedfcabe27..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.min.js +++ /dev/null @@ -1,9 +0,0 @@ -test("basic functionality", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.pow.js b/Libraries/LibJS/Tests/builtins/Math/Math.pow.js deleted file mode 100644 index 036060b238..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.pow.js +++ /dev/null @@ -1,25 +0,0 @@ -test("basic functionality", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sign.js b/Libraries/LibJS/Tests/builtins/Math/Math.sign.js deleted file mode 100644 index a1e8a6eb72..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.sign.js +++ /dev/null @@ -1,36 +0,0 @@ -function isPositiveZero(value) { - return value === 0 && 1 / value === Infinity; -} - -function isNegativeZero(value) { - return value === 0 && 1 / value === -Infinity; -} - -test("basic functionality", () => { - 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(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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sin.js b/Libraries/LibJS/Tests/builtins/Math/Math.sin.js deleted file mode 100644 index f5434d94c7..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.sin.js +++ /dev/null @@ -1,15 +0,0 @@ -test("basic functionality", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sinh.js b/Libraries/LibJS/Tests/builtins/Math/Math.sinh.js deleted file mode 100644 index 6ea3049c4c..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.sinh.js +++ /dev/null @@ -1,6 +0,0 @@ -test("basic functionality", () => { - expect(Math.sinh).toHaveLength(1); - - expect(Math.sinh(0)).toBe(0); - expect(Math.sinh(1)).toBeCloseTo(1.1752011936438014); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js b/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js deleted file mode 100644 index 1e7b2115e0..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js +++ /dev/null @@ -1,4 +0,0 @@ -test("basic functionality", () => { - 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 deleted file mode 100644 index ef1f32f163..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.tan.js +++ /dev/null @@ -1,14 +0,0 @@ -test("basic functionality", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.tanh.js b/Libraries/LibJS/Tests/builtins/Math/Math.tanh.js deleted file mode 100644 index e24dae76c4..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.tanh.js +++ /dev/null @@ -1,8 +0,0 @@ -test("basic functionality", () => { - expect(Math.tanh).toHaveLength(1); - - expect(Math.tanh(0)).toBe(0); - expect(Math.tanh(Infinity)).toBe(1); - expect(Math.tanh(-Infinity)).toBe(-1); - expect(Math.tanh(1)).toBeCloseTo(0.7615941559557649); -}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js b/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js deleted file mode 100644 index baf8418d1e..0000000000 --- a/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js +++ /dev/null @@ -1,12 +0,0 @@ -test("basic functionality", () => { - 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(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 deleted file mode 100644 index 9c496238b9..0000000000 --- a/Libraries/LibJS/Tests/builtins/NaN/NaN.js +++ /dev/null @@ -1,13 +0,0 @@ -test("basic functionality", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number-constants.js b/Libraries/LibJS/Tests/builtins/Number/Number-constants.js deleted file mode 100644 index 2958821546..0000000000 --- a/Libraries/LibJS/Tests/builtins/Number/Number-constants.js +++ /dev/null @@ -1,11 +0,0 @@ -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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js b/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js deleted file mode 100644 index 19a23c0292..0000000000 --- a/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js +++ /dev/null @@ -1,24 +0,0 @@ -test("basic functionality", () => { - 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("")).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 deleted file mode 100644 index ff0bc9370c..0000000000 --- a/Libraries/LibJS/Tests/builtins/Number/Number.isInteger.js +++ /dev/null @@ -1,32 +0,0 @@ -test("basic functionality", () => { - 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(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 deleted file mode 100644 index 6a7df463df..0000000000 --- a/Libraries/LibJS/Tests/builtins/Number/Number.isNaN.js +++ /dev/null @@ -1,25 +0,0 @@ -test("basic functionality", () => { - 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(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 deleted file mode 100644 index 3bba1682a6..0000000000 --- a/Libraries/LibJS/Tests/builtins/Number/Number.isSafeInteger.js +++ /dev/null @@ -1,24 +0,0 @@ -test("basic functionality", () => { - 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()).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 deleted file mode 100644 index 7fd7067449..0000000000 --- a/Libraries/LibJS/Tests/builtins/Number/Number.js +++ /dev/null @@ -1,33 +0,0 @@ -test("basic functionality", () => { - 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(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 deleted file mode 100644 index 89de9ff0d9..0000000000 --- a/Libraries/LibJS/Tests/builtins/Number/Number.parseFloat.js +++ /dev/null @@ -1,5 +0,0 @@ -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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.prototype.js b/Libraries/LibJS/Tests/builtins/Number/Number.prototype.js deleted file mode 100644 index 91f2e93c0e..0000000000 --- a/Libraries/LibJS/Tests/builtins/Number/Number.prototype.js +++ /dev/null @@ -1,4 +0,0 @@ -test("basic functionality", () => { - expect(typeof Number.prototype).toBe("object"); - expect(Number.prototype.valueOf()).toBe(0); -}); diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Number/Number.prototype.toString.js deleted file mode 100644 index c07ca792f6..0000000000 --- a/Libraries/LibJS/Tests/builtins/Number/Number.prototype.toString.js +++ /dev/null @@ -1,83 +0,0 @@ -describe("correct behavior", () => { - test("length", () => { - expect(Number.prototype.toString).toHaveLength(1); - }); - - test("basic functionality", () => { - [ - [+0, "0"], - [-0, "0"], - [Infinity, "Infinity"], - [-Infinity, "-Infinity"], - [NaN, "NaN"], - [12, "12"], - [93465, "93465"], - [358000, "358000"], - ].forEach(testCase => { - expect(testCase[0].toString()).toBe(testCase[1]); - }); - }); - - test("radix", () => { - let number = 7857632; - - [ - [2, "11101111110010111100000"], - [3, "112210012122102"], - [4, "131332113200"], - [5, "4002421012"], - [6, "440225532"], - [7, "123534356"], - [8, "35762740"], - [9, "15705572"], - [10, "7857632"], - [11, "4487612"], - [12, "276b2a8"], - [13, "18216b3"], - [14, "10877d6"], - [15, "a532c2"], - [16, "77e5e0"], - [17, "59160b"], - [18, "42f5h2"], - [19, "335b5b"], - [20, "29241c"], - [21, "1j89fk"], - [22, "1bbkh2"], - [23, "151ih4"], - [24, "ng9h8"], - [25, "k2m57"], - [26, "h51ig"], - [27, "el5hb"], - [28, "clqdk"], - [29, "b355o"], - [30, "9l0l2"], - [31, "8fng0"], - [32, "7fpf0"], - [33, "6klf2"], - [34, "5tv8s"], - [35, "589dr"], - [36, "4oezk"], - ].forEach(testCase => { - expect(number.toString(testCase[0])).toBe(testCase[1]); - }); - }); - - test("decimal radix gets converted to int", () => { - expect((30).toString(10.1)).toBe("30"); - expect((30).toString(10.9)).toBe("30"); - }); -}); - -test("errors", () => { - test("must be called with numeric |this|", () => { - [true, [], {}, Symbol("foo"), "bar", 1n].forEach(value => { - expect(() => Number.prototype.toString.call(value)).toThrow(TypeError); - }); - }); - - test("radix RangeError", () => { - [0, 1, 37, 100].forEach(value => { - expect(() => (0).toString(value)).toThrow(RangeError); - }); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js b/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js deleted file mode 100644 index bebe32997d..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js +++ /dev/null @@ -1,242 +0,0 @@ -describe("normal functionality", () => { - let s = Symbol("foo"); - - test("non-configurable string 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).not.toHaveConfigurableProperty("foo"); - expect(o).not.toHaveEnumerableProperty("foo"); - expect(o).not.toHaveWritableProperty("foo"); - expect(o).toHaveValueProperty("foo", 1); - }); - - test("non-configurable symbol property", () => { - let o = {}; - Object.defineProperty(o, s, { value: 1, writable: false, enumerable: false }); - - expect(o[s]).toBe(1); - o[s] = 2; - expect(o[s]).toBe(1); - - expect(o).not.toHaveConfigurableProperty(s); - expect(o).not.toHaveEnumerableProperty(s); - expect(o).not.toHaveWritableProperty(s); - expect(o).toHaveValueProperty(s, 1); - }); - - test("array index getter", () => { - let o = {}; - Object.defineProperty(o, 2, { - get() { - return 10; - }, - }); - expect(o[2]).toBe(10); - }); - - test("symbol property getter", () => { - let o = {}; - Object.defineProperty(o, s, { - get() { - return 10; - }, - }); - expect(o[s]).toBe(10); - }); - - test("configurable string 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("configurable symbol property", () => { - let o = {}; - Object.defineProperty(o, s, { value: "hi", writable: true, enumerable: true }); - - expect(o[s]).toBe("hi"); - o[s] = "ho"; - expect(o[s]).toBe("ho"); - - expect(o).not.toHaveConfigurableProperty(s); - expect(o).toHaveEnumerableProperty(s); - expect(o).toHaveWritableProperty(s); - expect(o).toHaveValueProperty(s, "ho"); - }); - - test("reconfigure configurable string 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("reconfigure configurable symbol property", () => { - let o = {}; - Object.defineProperty(o, s, { value: 9, configurable: true, writable: false }); - Object.defineProperty(o, s, { configurable: true, writable: true }); - - expect(o).toHaveConfigurableProperty(s); - expect(o).toHaveWritableProperty(s); - expect(o).not.toHaveEnumerableProperty(s); - expect(o).toHaveValueProperty(s, 9); - }); - - test("define string 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); - }); - - test("define symbol accessor", () => { - let o = {}; - - Object.defineProperty(o, s, { - configurable: true, - get() { - return o.secret_foo + 1; - }, - set(value) { - this.secret_foo = value + 1; - }, - }); - - o[s] = 10; - expect(o[s]).toBe(12); - o[s] = 20; - expect(o[s]).toBe(22); - - Object.defineProperty(o, s, { configurable: true, value: 4 }); - - expect(o[s]).toBe(4); - expect((o[s] = 5)).toBe(5); - expect((o[s] = 4)).toBe(4); - }); - - test("issue #3735, reconfiguring property in unique shape", () => { - const o = {}; - // In LibJS an object with more than 100 properties gets a unique shape - for (let i = 0; i < 101; ++i) { - o[`property${i}`] = i; - } - Object.defineProperty(o, "x", { configurable: true }); - Object.defineProperty(o, "x", { configurable: false }); - }); -}); - -describe("errors", () => { - 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("redefine non-configurable symbol property", () => { - let o = {}; - let s = Symbol("foo"); - Object.defineProperty(o, s, { value: 1, writable: true, enumerable: true }); - - expect(() => { - Object.defineProperty(o, s, { value: 2, writable: false, enumerable: true }); - }).toThrowWithMessage( - TypeError, - "Cannot change attributes of non-configurable property 'Symbol(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 deleted file mode 100644 index c8ed8ffc4c..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.entries.js +++ /dev/null @@ -1,64 +0,0 @@ -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 objects with symbol keys", () => { - let entries = Object.entries({ foo: 1, [Symbol("bar")]: 2, baz: 3 }); - - expect(entries).toEqual([ - ["foo", 1], - ["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]]); - }); -}); - -describe("errors", () => { - 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"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js b/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js deleted file mode 100644 index 3b69241d9d..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js +++ /dev/null @@ -1,61 +0,0 @@ -test("plain property", () => { - 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"); -}); - -test("symbol property", () => { - let s = Symbol("foo"); - let o = { [s]: "bar" }; - - expect(o).toHaveConfigurableProperty(s); - expect(o).toHaveEnumerableProperty(s); - expect(o).toHaveWritableProperty(s); - expect(o).toHaveValueProperty(s, "bar"); - expect(o).not.toHaveGetterProperty(s); - expect(o).not.toHaveSetterProperty(s); -}); - -test("getter property", () => { - 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"); -}); - -test("setter property", () => { - 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"); -}); - -test("defined property", () => { - let o = {}; - - 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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js b/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js deleted file mode 100644 index da7bccbeba..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js +++ /dev/null @@ -1,14 +0,0 @@ -test("use with array", () => { - 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"]); -}); - -test("use with object with symbol keys", () => { - let names = Object.getOwnPropertyNames({ foo: 1, [Symbol("bar")]: 2, baz: 3 }); - expect(names).toEqual(["foo", "baz"]); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js deleted file mode 100644 index 8679efc7dc..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js +++ /dev/null @@ -1,10 +0,0 @@ -test("basic functionality", () => { - let o1 = new Object(); - let o2 = {}; - - 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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.is.js b/Libraries/LibJS/Tests/builtins/Object/Object.is.js deleted file mode 100644 index fcad3484da..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.is.js +++ /dev/null @@ -1,54 +0,0 @@ -test("length", () => { - expect(Object.is).toHaveLength(2); -}); - -test("arguments that evaluate to true", () => { - 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(); -}); - -test("arguments that evaluate to false", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js b/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js deleted file mode 100644 index b426114f20..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js +++ /dev/null @@ -1,18 +0,0 @@ -test("basic functionality", () => { - 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(); - - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.js b/Libraries/LibJS/Tests/builtins/Object/Object.js deleted file mode 100644 index 544704c1f0..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.js +++ /dev/null @@ -1,13 +0,0 @@ -test("basic functionality", () => { - 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(42)).toBe("object"); - expect(Object(42).valueOf()).toBe(42); - expect(typeof Object("foo")).toBe("object"); - expect(Object("foo").valueOf()).toBe("foo"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.keys.js b/Libraries/LibJS/Tests/builtins/Object/Object.keys.js deleted file mode 100644 index 64e822abd7..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.keys.js +++ /dev/null @@ -1,51 +0,0 @@ -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("object argument with symbol keys", () => { - let keys = Object.keys({ foo: 1, [Symbol("bar")]: 2, baz: 3 }); - expect(keys).toEqual(["foo", "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"]); - }); -}); - -describe("errors", () => { - 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"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js b/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js deleted file mode 100644 index 292c3f5999..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js +++ /dev/null @@ -1,67 +0,0 @@ -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"); - - 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"); - - expect(Object.preventExtensions(o)).toBe(o); - expect(o.foo).toBe("foo"); - expect(o.bar).toBe("bar"); - - o.baz = "baz"; - expect(o.baz).toBeUndefined(); - }); - - test("modifying existing properties", () => { - const o = { foo: "bar" }; - Object.preventExtensions(o); - o.foo = "baz"; - expect(o.foo).toBe("baz"); - }); - - test("deleting existing properties", () => { - const o = { foo: "bar" }; - Object.preventExtensions(o); - delete o.foo; - expect(o).not.toHaveProperty("foo"); - }); -}); - -describe("errors", () => { - 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(o.baz).toBeUndefined(); - }); - - 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((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 deleted file mode 100644 index 50e4935c75..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.constructor.js +++ /dev/null @@ -1,18 +0,0 @@ -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); - }); - - let o = {}; - expect(o.constructor).toBe(Object); - - 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); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js deleted file mode 100644 index 11063f42ec..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js +++ /dev/null @@ -1,13 +0,0 @@ -test("basic functionality", () => { - 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.undefined = 2; - expect(o.hasOwnProperty()).toBeTrue(); - expect(o.hasOwnProperty(undefined)).toBeTrue(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.isPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.isPrototypeOf.js deleted file mode 100644 index f3f82174d2..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.isPrototypeOf.js +++ /dev/null @@ -1,18 +0,0 @@ -test("basic functionality", () => { - function A() {} - function B() {} - - A.prototype = new B(); - const C = new A(); - - expect(A.prototype.isPrototypeOf(C)).toBeTrue(); - expect(B.prototype.isPrototypeOf(C)).toBeTrue(); - - expect(A.isPrototypeOf(C)).toBeFalse(); - expect(B.isPrototypeOf(C)).toBeFalse(); - - const D = new Object(); - expect(Object.prototype.isPrototypeOf(D)).toBeTrue(); - expect(Function.prototype.isPrototypeOf(D.toString)).toBeTrue(); - expect(Array.prototype.isPrototypeOf([])).toBeTrue(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js deleted file mode 100644 index eab7093b3b..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js +++ /dev/null @@ -1,5 +0,0 @@ -test("basic functionality", () => { - var o = new Object(); - Object.prototype.foo = 123; - expect(o.foo).toBe(123); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.propertyIsEnumerable.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.propertyIsEnumerable.js deleted file mode 100644 index 01f55cd749..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.propertyIsEnumerable.js +++ /dev/null @@ -1,15 +0,0 @@ -test("basic functionality", () => { - var o = {}; - - o.foo = 1; - expect(o.propertyIsEnumerable("foo")).toBeTrue(); - expect(o.propertyIsEnumerable("bar")).toBeFalse(); - expect(o.propertyIsEnumerable()).toBeFalse(); - expect(o.propertyIsEnumerable(undefined)).toBeFalse(); - - o.undefined = 2; - expect(o.propertyIsEnumerable()).toBeTrue(); - expect(o.propertyIsEnumerable(undefined)).toBeTrue(); - - expect(globalThis.propertyIsEnumerable("globalThis")).toBeFalse(); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js deleted file mode 100644 index b64cb099e4..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js +++ /dev/null @@ -1,35 +0,0 @@ -describe("correct behavior", () => { - test("length", () => { - expect(Object.prototype.toLocaleString).toHaveLength(0); - }); - - test("basic functionality", () => { - let o; - - o = {}; - expect(o.toString()).toBe(o.toLocaleString()); - - 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 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 deleted file mode 100644 index 5bdd157de4..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js +++ /dev/null @@ -1,20 +0,0 @@ -test("length", () => { - expect(Object.prototype.toString).toHaveLength(0); -}); - -test("result for various object types", () => { - const oToString = o => Object.prototype.toString.call(o); - - expect(oToString(undefined)).toBe("[object Undefined]"); - expect(oToString(null)).toBe("[object Null]"); - expect(oToString([])).toBe("[object Array]"); - expect(oToString(function () {})).toBe("[object Function]"); - expect(oToString(new Error())).toBe("[object Error]"); - expect(oToString(new Boolean())).toBe("[object Boolean]"); - expect(oToString(new Number())).toBe("[object Number]"); - expect(oToString(new Date())).toBe("[object Date]"); - expect(oToString(new RegExp())).toBe("[object RegExp]"); - expect(oToString({})).toBe("[object Object]"); - - expect(globalThis.toString()).toBe("[object Object]"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js deleted file mode 100644 index 69a7b24ab3..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js +++ /dev/null @@ -1,43 +0,0 @@ -describe("correct behavior", () => { - 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); - }); -}); - -describe("errors", () => { - 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"); - }); - - 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); - - expect(() => { - Object.setPrototypeOf(o, {}); - }).toThrowWithMessage(TypeError, "Object's [[SetPrototypeOf]] method returned false"); - - 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 deleted file mode 100644 index 5917d94cc8..0000000000 --- a/Libraries/LibJS/Tests/builtins/Object/Object.values.js +++ /dev/null @@ -1,51 +0,0 @@ -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("object argument with symbol keys", () => { - let values = Object.values({ foo: 1, [Symbol("bar")]: 2, baz: 3 }); - expect(values).toEqual([1, 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]); - }); -}); - -describe("errors", () => { - 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"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-apply.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-apply.js deleted file mode 100644 index 0e59d4f473..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-apply.js +++ /dev/null @@ -1,36 +0,0 @@ -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("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); - }); -}); - -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"); - }); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-construct.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-construct.js deleted file mode 100644 index 73a63346a3..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-construct.js +++ /dev/null @@ -1,72 +0,0 @@ -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("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); - - 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; - } - - 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); - }); -}); - -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"); - }); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js deleted file mode 100644 index 2044ea8084..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js +++ /dev/null @@ -1,133 +0,0 @@ -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; - }, - }); - - Object.defineProperty(p, "foo", { configurable: true, writable: true, value: 10 }); - }); - - test("optionally ignoring the define call", () => { - let o = {}; - let p = new Proxy(o, { - defineProperty(target, name, descriptor) { - if (target[name] === undefined) Object.defineProperty(target, name, descriptor); - return true; - }, - }); - - Object.defineProperty(p, "foo", { - value: 10, - enumerable: true, - configurable: false, - writable: true, - }); - expect(p).toHaveEnumerableProperty("foo"); - expect(p).not.toHaveConfigurableProperty("foo"); - expect(p).toHaveWritableProperty("foo"); - expect(p).toHaveValueProperty("foo", 10); - expect(p).not.toHaveGetterProperty("foo"); - expect(p).not.toHaveSetterProperty("foo"); - - Object.defineProperty(p, "foo", { - value: 20, - enumerable: true, - configurable: false, - writable: true, - }); - expect(p).toHaveEnumerableProperty("foo"); - expect(p).not.toHaveConfigurableProperty("foo"); - expect(p).toHaveWritableProperty("foo"); - expect(p).toHaveValueProperty("foo", 10); - expect(p).not.toHaveGetterProperty("foo"); - expect(p).not.toHaveSetterProperty("foo"); - }); -}); - -describe("[[DefineProperty]] invariants", () => { - test("trap can't return false", () => { - let p = new Proxy( - {}, - { - defineProperty() { - return false; - }, - } - ); - - 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, - "Proxy handler's defineProperty trap violates invariant: a property cannot be reported as being defined if the property does not exist on the target and the target is non-extensible" - ); - }); - - test("trap cannot return true for a non-configurable property if it doesn't already exist on the target", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 10, configurable: true }); - let p = new Proxy(o, { - defineProperty() { - return true; - }, - }); - - expect(() => { - Object.defineProperty(p, "bar", { value: 6, configurable: false }); - }).toThrowWithMessage( - TypeError, - "Proxy handler's defineProperty trap violates invariant: a property cannot be defined as non-configurable if it does not already exist on the target object" - ); - }); - - test("trap cannot return true for a non-configurable property if it already exists as a configurable property", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 10, configurable: true }); - let p = new Proxy(o, { - defineProperty() { - return true; - }, - }); - - 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 deleted file mode 100644 index 26ef993789..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js +++ /dev/null @@ -1,58 +0,0 @@ -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; - }, - }); - - delete p.foo; - }); - - test("conditional deletion", () => { - o = { foo: 1, bar: 2 }; - p = new Proxy(o, { - deleteProperty(target, property) { - if (property === "foo") { - delete target[property]; - return true; - } - return false; - }, - }); - - 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; - }, - }); - - 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 deleted file mode 100644 index 7919b196fe..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-get.js +++ /dev/null @@ -1,96 +0,0 @@ -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); - }, - }); - - p.foo; - }); - - test("conditional return", () => { - let o = { foo: 1 }; - let p = new Proxy(o, { - get(target, property, receiver) { - if (property === "bar") { - return 2; - } else if (property === "baz") { - return receiver.qux; - } else if (property === "qux") { - return 3; - } - return target[property]; - }, - }); - - expect(p.foo).toBe(1); - expect(p.bar).toBe(2); - expect(p.baz).toBe(3); - expect(p.qux).toBe(3); - expect(p.test).toBeUndefined(); - expect(p[Symbol.hasInstance]).toBeUndefined(); - }); - - test("custom receiver value", () => { - let p = new Proxy( - {}, - { - get(target, property, receiver) { - return receiver; - }, - } - ); - - expect(Reflect.get(p, "foo", 42)).toBe(42); - }); -}); - -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 }); - - 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" - ); - }); - - 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; - }, - }); - - 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 deleted file mode 100644 index 9b9addf14a..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js +++ /dev/null @@ -1,220 +0,0 @@ -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"); - }, - }); - - Object.getOwnPropertyDescriptor(p, "foo"); - }); - - 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"); - }); -}); - -describe("[[GetOwnProperty]] invariants", () => { - test("must return an object or undefined", () => { - expect(() => { - Object.getOwnPropertyDescriptor( - new Proxy( - {}, - { - getOwnPropertyDescriptor() { - return 1; - }, - } - ) - ); - }).toThrowWithMessage( - TypeError, - "Proxy handler's getOwnPropertyDescriptor trap violates invariant: must return an object or undefined" - ); - }); - - test("cannot return undefined for a non-configurable property", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 10, configurable: false }); - - let p = new Proxy(o, { - getOwnPropertyDescriptor() { - return undefined; - }, - }); - - expect(Object.getOwnPropertyDescriptor(p, "bar")).toBeUndefined(); - - 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" - ); - }); - - 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" - ); - }); - - 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" - ); - }); - - 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 deleted file mode 100644 index 823e1ff392..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getPrototypeOf.js +++ /dev/null @@ -1,95 +0,0 @@ -describe("[[GetPrototypeOf]] trap normal behavior", () => { - 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; - }, - }); - - Object.getPrototypeOf(p); - }); - - test("conditional return", () => { - let o = {}; - let p = new Proxy(o, { - getPrototypeOf(target) { - if (target.foo) return { bar: 1 }; - return { bar: 2 }; - }, - }); - - expect(Object.getPrototypeOf(p).bar).toBe(2); - o.foo = 20; - expect(Object.getPrototypeOf(p).bar).toBe(1); - }); - - 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" }; - }, - }); - - 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 deleted file mode 100644 index b9e2df94ee..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js +++ /dev/null @@ -1,74 +0,0 @@ -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; - }, - }); - - "foo" in p; - }); - - test("conditional return", () => { - let o = {}; - let p = new Proxy(o, { - has(target, prop) { - if (target.checkedFoo) return true; - if (prop === "foo") target.checkedFoo = true; - return false; - }, - }); - - 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 }); - - 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" - ); - }); - - 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; - }, - }); - - 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 deleted file mode 100644 index 430b0fde56..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js +++ /dev/null @@ -1,39 +0,0 @@ -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; - }, - }); - - expect(Object.isExtensible(p)).toBeTrue(); - }); -}); - -describe("[[Call]] invariants", () => { - test("return value must match the target's extensibility", () => { - let o = {}; - Object.preventExtensions(o); - - let p = new Proxy(o, { - isExtensible() { - return true; - }, - }); - - expect(() => { - Object.isExtensible(p); - }).toThrowWithMessage( - TypeError, - "Proxy handler's isExtensible trap violates invariant: return value must match the target's extensibility" - ); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-preventExtensions.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-preventExtensions.js deleted file mode 100644 index 13a960faea..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-preventExtensions.js +++ /dev/null @@ -1,59 +0,0 @@ -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; - }, - }); - - Object.preventExtensions(o); - Object.preventExtensions(p); - }); -}); - -describe("[[PreventExtensions]] invariants", () => { - 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, - "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 deleted file mode 100644 index dd45c51b4b..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-set.js +++ /dev/null @@ -1,99 +0,0 @@ -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; - }, - }); - - p.foo = 10; - }); - - test("conditional return value", () => { - let p = new Proxy( - {}, - { - set(target, prop, value) { - if (target[prop] === value) { - target[prop] *= 2; - } else { - target[prop] = value; - } - }, - } - ); - - p.foo = 10; - expect(p.foo).toBe(10); - p.foo = 10; - expect(p.foo).toBe(20); - p.foo = 10; - expect(p.foo).toBe(10); - p[Symbol.hasInstance] = "foo"; - expect(p[Symbol.hasInstance]).toBe("foo"); - }); - - test("custom receiver value", () => { - const o = {}; - const r = {}; - let p = new Proxy(o, { - set(target, property, value, receiver) { - receiver[property] = value; - return true; - }, - }); - - expect(Reflect.set(p, "foo", 42, r)).toBe(true); - expect(o.foo).toBeUndefined(); - expect(r.foo).toBe(42); - }); -}); - -describe("[[Set]] invariants", () => { - test("cannot return true for a non-configurable, non-writable property", () => { - let o = {}; - Object.defineProperty(o, "foo", { value: 10 }); - - let p = new Proxy(o, { - set() { - return true; - }, - }); - - expect(() => { - p.foo = 12; - }).toThrowWithMessage( - TypeError, - "Proxy handler's set trap violates invariant: cannot return true for a property on the target which is a non-configurable, non-writable own data property" - ); - }); - - 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; - }, - }); - - 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 deleted file mode 100644 index 30909c90f5..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js +++ /dev/null @@ -1,96 +0,0 @@ -describe("[[SetPrototypeOf]] trap normal behavior", () => { - 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; - }, - }); - - Object.setPrototypeOf(p, theNewProto); - }); - - test("conditional setting", () => { - let o = {}; - - let p = new Proxy(o, { - setPrototypeOf(target, newProto) { - if (target.shouldSet) Object.setPrototypeOf(target, newProto); - 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); - }); - - 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; - }, - }); - - 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); - - let p = new Proxy(o, { - setPrototypeOf() { - return true; - }, - }); - - expect(() => { - Object.setPrototypeOf(p, {}); - }).toThrowWithMessage( - TypeError, - "Proxy handler's setPrototypeOf trap violates invariant: the argument must match the prototype of the target if the target is non-extensible" - ); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js deleted file mode 100644 index 9e336c2694..0000000000 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js +++ /dev/null @@ -1,37 +0,0 @@ -test("constructs properly", () => { - 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"); -}); - -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 handler argument of Proxy constructor to be object, got 1" - ); -}); - -test("constructor must be invoked with 'new'", () => { - expect(() => { - Proxy({}, {}); - }).toThrowWithMessage(TypeError, "Proxy constructor must be called with 'new'"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js deleted file mode 100644 index 7e6a67d16d..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js +++ /dev/null @@ -1,44 +0,0 @@ -test("length is 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("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("|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"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js deleted file mode 100644 index a14a016ee0..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js +++ /dev/null @@ -1,75 +0,0 @@ -test("length is 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("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" - ); - }); - }); -}); - -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 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"; - } - - var o = Reflect.construct(Foo, []); - expect(o.name).toBe("foo"); - expect(o instanceof Foo).toBeTrue(); - }); - - test("user-defined function with different new target", () => { - function Foo() { - this.name = "foo"; - } - - function Bar() { - this.name = "bar"; - } - - 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 deleted file mode 100644 index 786d4c0178..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.defineProperty.js +++ /dev/null @@ -1,82 +0,0 @@ -test("length is 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("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 = {}; - - 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 = {}; - - 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 = {}; - - 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 = {}; - - 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 = {}; - - 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 deleted file mode 100644 index a0dcbbada7..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.deleteProperty.js +++ /dev/null @@ -1,66 +0,0 @@ -test("length is 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" - ); - }); - }); -}); - -describe("normal behavior", () => { - 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, 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, 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); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.get.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.get.js deleted file mode 100644 index fc9b5f172e..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.get.js +++ /dev/null @@ -1,67 +0,0 @@ -test("length is 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"); - }); - }); -}); - -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("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("getter function", () => { - const foo = { - get prop() { - this.getPropCalled = true; - }, - }; - const bar = {}; - Object.setPrototypeOf(bar, foo); - - expect(foo.getPropCalled).toBeUndefined(); - expect(bar.getPropCalled).toBeUndefined(); - - 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(); - }); - - test("native getter function", () => { - expect(Reflect.get(String.prototype, "length", "foo")).toBe(3); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getOwnPropertyDescriptor.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getOwnPropertyDescriptor.js deleted file mode 100644 index e343a3f6fc..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getOwnPropertyDescriptor.js +++ /dev/null @@ -1,41 +0,0 @@ -test("length is 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" - ); - }); - }); -}); - -describe("normal behavior", () => { - 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 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 deleted file mode 100644 index 87c9a63e87..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.getPrototypeOf.js +++ /dev/null @@ -1,37 +0,0 @@ -test("length is 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" - ); - }); - }); -}); - -describe("normal behavior", () => { - 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 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); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.has.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.has.js deleted file mode 100644 index f343daeafa..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.has.js +++ /dev/null @@ -1,45 +0,0 @@ -test("length is 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"); - }); - }); -}); - -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("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(); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.isExtensible.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.isExtensible.js deleted file mode 100644 index 2f873da66c..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.isExtensible.js +++ /dev/null @@ -1,33 +0,0 @@ -test("length is 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" - ); - }); - }); -}); - -describe("normal behavior", () => { - test("regular object is extensible", () => { - expect(Reflect.isExtensible({})).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(); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.ownKeys.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.ownKeys.js deleted file mode 100644 index b262775f1a..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.ownKeys.js +++ /dev/null @@ -1,51 +0,0 @@ -test("length is 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" - ); - }); - }); -}); - -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 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("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 deleted file mode 100644 index 6b0bfdc1bc..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.preventExtensions.js +++ /dev/null @@ -1,42 +0,0 @@ -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" - ); - }); - }); -}); - -describe("normal behavior", () => { - test("length is 1", () => { - expect(Reflect.preventExtensions).toHaveLength(1); - }); - - 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("modifying existing properties", () => { - const o = {}; - o.foo = "foo"; - expect(Reflect.preventExtensions(o)).toBeTrue(); - o.foo = "bar"; - expect(o.foo).toBe("bar"); - }); - - test("deleting existing properties", () => { - const o = { foo: "bar" }; - Reflect.preventExtensions(o); - delete o.foo; - expect(o).not.toHaveProperty("foo"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.set.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.set.js deleted file mode 100644 index 854fb23888..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.set.js +++ /dev/null @@ -1,102 +0,0 @@ -test("length is 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"); - }); - }); -}); - -describe("normal behavior", () => { - test("setting properties of regular object", () => { - var o = {}; - - expect(Reflect.set(o)).toBeTrue(); - expect(o.undefined).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", 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 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("setting setter property of regular object", () => { - const foo = { - set prop(value) { - this.setPropCalled = true; - }, - }; - expect(foo.setPropCalled).toBeUndefined(); - Reflect.set(foo, "prop", 42); - expect(foo.setPropCalled).toBeTrue(); - }); - - test("setting setter property of regular object with different receiver", () => { - const foo = { - set prop(value) { - this.setPropCalled = true; - }, - }; - const bar = {}; - Object.setPrototypeOf(bar, foo); - - expect(foo.setPropCalled).toBeUndefined(); - expect(bar.setPropCalled).toBeUndefined(); - - 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(); - }); - - test("native setter function", () => { - const e = new Error(); - Reflect.set(Error.prototype, "name", "Foo", e); - expect(e.name).toBe("Foo"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.setPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Reflect/Reflect.setPrototypeOf.js deleted file mode 100644 index 70bbdf9d9c..0000000000 --- a/Libraries/LibJS/Tests/builtins/Reflect/Reflect.setPrototypeOf.js +++ /dev/null @@ -1,57 +0,0 @@ -test("length is 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("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 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 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/RegExp/RegExp.js b/Libraries/LibJS/Tests/builtins/RegExp/RegExp.js deleted file mode 100644 index 9ae8ab97c0..0000000000 --- a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.js +++ /dev/null @@ -1,8 +0,0 @@ -test("basic functionality", () => { - expect(RegExp().toString()).toBe("/(?:)/"); - expect(RegExp(undefined).toString()).toBe("/(?:)/"); - expect(RegExp("foo").toString()).toBe("/foo/"); - expect(RegExp("foo", undefined).toString()).toBe("/foo/"); - expect(RegExp("foo", "g").toString()).toBe("/foo/g"); - expect(RegExp(undefined, "g").toString()).toBe("/(?:)/g"); -}); diff --git a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.exec.js b/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.exec.js deleted file mode 100644 index 7fcbf3582a..0000000000 --- a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.exec.js +++ /dev/null @@ -1,58 +0,0 @@ -test("basic functionality", () => { - let re = /foo/; - expect(re.exec.length).toBe(1); - - let res = re.exec("foo"); - expect(res.length).toBe(1); - expect(res[0]).toBe("foo"); - expect(res.groups).toBe(undefined); - expect(res.index).toBe(0); -}); - -test("basic unnamed captures", () => { - let re = /f(o.*)/; - let res = re.exec("fooooo"); - - expect(res.length).toBe(2); - expect(res[0]).toBe("fooooo"); - expect(res[1]).toBe("ooooo"); - expect(res.groups).toBe(undefined); - expect(res.index).toBe(0); -}); - -test("basic named captures", () => { - let re = /f(?<os>o.*)/; - let res = re.exec("fooooo"); - - expect(res.length).toBe(1); - expect(res.index).toBe(0); - expect(res[0]).toBe("fooooo"); - expect(res.groups).not.toBe(undefined); - expect(res.groups.os).toBe("ooooo"); -}); - -test("basic index", () => { - let re = /foo/; - let res = re.exec("abcfoo"); - - expect(res.length).toBe(1); - expect(res.index).toBe(3); - expect(res[0]).toBe("foo"); -}); - -test("basic index with global and initial offset", () => { - let re = /foo/g; - re.lastIndex = 2; - let res = re.exec("abcfoo"); - - expect(res.length).toBe(1); - expect(res.index).toBe(3); - expect(res[0]).toBe("foo"); -}); - -test("not matching", () => { - let re = /foo/; - let res = re.exec("bar"); - - expect(res).toBe(null); -}); diff --git a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.flags.js b/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.flags.js deleted file mode 100644 index 9ccc0b614e..0000000000 --- a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.flags.js +++ /dev/null @@ -1,11 +0,0 @@ -test("basic functionality", () => { - expect(/foo/.flags).toBe(""); - expect(/foo/g.flags).toBe("g"); - expect(/foo/i.flags).toBe("i"); - expect(/foo/m.flags).toBe("m"); - expect(/foo/s.flags).toBe("s"); - expect(/foo/u.flags).toBe("u"); - expect(/foo/y.flags).toBe("y"); - // prettier-ignore - expect(/foo/sgimyu.flags).toBe("gimsuy"); -}); diff --git a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.source.js b/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.source.js deleted file mode 100644 index 4f0e14297f..0000000000 --- a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.source.js +++ /dev/null @@ -1,8 +0,0 @@ -test("basic functionality", () => { - expect(RegExp.prototype.source).toBe("(?:)"); - expect(RegExp().source).toBe("(?:)"); - expect(/test/.source).toBe("test"); - expect(/\n/.source).toBe("\\n"); - // FIXME: RegExp parse doesn't parse \/ :( - // expect(/foo\/bar/.source).toBe("foo\\/bar"); -}); diff --git a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.test.js b/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.test.js deleted file mode 100644 index df3e8b9771..0000000000 --- a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.test.js +++ /dev/null @@ -1,58 +0,0 @@ -test("basic functionality", () => { - expect(RegExp.prototype.test).toHaveLength(1); -}); - -test("simple test", () => { - let re = /test/; - expect(re.test("test")).toBe(true); - expect(re.test("test")).toBe(true); -}); - -test("simple global test", () => { - let re = /test/g; - expect(re.test("testtest")).toBe(true); - expect(re.test("testtest")).toBe(true); - expect(re.test("testtest")).toBe(false); - expect(re.test("testtest")).toBe(true); - expect(re.test("testtest")).toBe(true); -}); - -test("global test with offset lastIndex", () => { - let re = /test/g; - re.lastIndex = 2; - expect(re.test("testtest")).toBe(true); - expect(re.test("testtest")).toBe(false); - expect(re.test("testtest")).toBe(true); - expect(re.test("testtest")).toBe(true); - expect(re.test("testtest")).toBe(false); -}); - -test("sticky test with offset lastIndex", () => { - let re = /test/y; - re.lastIndex = 2; - expect(re.test("aatest")).toBe(true); - expect(re.test("aatest")).toBe(false); - expect(re.test("aatest")).toBe(false); -}); - -test("flag and options", () => { - expect(/foo/gi.flags).toBe("gi"); - expect(/foo/mu.flags).toBe("mu"); - expect(/foo/gimsuy.flags).toBe("gimsuy"); - - let re = /foo/gim; - expect(re.dotAll).toBe(false); - expect(re.global).toBe(true); - expect(re.ignoreCase).toBe(true); - expect(re.multiline).toBe(true); - expect(re.sticky).toBe(false); - expect(re.unicode).toBe(false); - - expect(() => { - /foo/gg; - }).toThrowWithMessage(SyntaxError, "Repeated RegExp flag 'g'"); - - expect(() => { - /foo/x; - }).toThrowWithMessage(SyntaxError, "Invalid RegExp flag 'x'"); -}); diff --git a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.toString.js b/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.toString.js deleted file mode 100644 index fcf132862d..0000000000 --- a/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.toString.js +++ /dev/null @@ -1,6 +0,0 @@ -test("basic functionality", () => { - expect(RegExp.prototype.toString).toHaveLength(0); - - expect(/test/g.toString()).toBe("/test/g"); - expect(RegExp.prototype.toString.call({ source: "test", flags: "g" })).toBe("/test/g"); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js b/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js deleted file mode 100644 index c6b52fd2e1..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js +++ /dev/null @@ -1,17 +0,0 @@ -test("basic functionality", () => { - 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("äöü"); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.js b/Libraries/LibJS/Tests/builtins/String/String.js deleted file mode 100644 index 687e0929d4..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.js +++ /dev/null @@ -1,9 +0,0 @@ -test("constructor properties", () => { - expect(String).toHaveLength(1); - expect(String.name).toBe("String"); -}); - -test("typeof", () => { - 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 deleted file mode 100644 index a05ca53d8c..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js +++ /dev/null @@ -1,39 +0,0 @@ -test("basic functionality", () => { - const genericStringPrototypeFunctions = [ - "charAt", - "charCodeAt", - "repeat", - "startsWith", - "endsWith", - "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 }); - - 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"); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js deleted file mode 100644 index 7747331885..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js +++ /dev/null @@ -1,20 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype.charAt).toHaveLength(1); - - 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()).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.charCodeAt.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.charCodeAt.js deleted file mode 100644 index e7ebd9d0d3..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.charCodeAt.js +++ /dev/null @@ -1,21 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype.charAt).toHaveLength(1); - - var s = "Foobar"; - expect(typeof s).toBe("string"); - expect(s).toHaveLength(6); - - expect(s.charCodeAt(0)).toBe(70); - expect(s.charCodeAt(1)).toBe(111); - expect(s.charCodeAt(2)).toBe(111); - expect(s.charCodeAt(3)).toBe(98); - expect(s.charCodeAt(4)).toBe(97); - expect(s.charCodeAt(5)).toBe(114); - expect(s.charCodeAt(6)).toBe(NaN); - expect(s.charCodeAt(-1)).toBe(NaN); - - expect(s.charCodeAt()).toBe(70); - expect(s.charCodeAt(NaN)).toBe(70); - expect(s.charCodeAt("foo")).toBe(70); - expect(s.charCodeAt(undefined)).toBe(70); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js deleted file mode 100644 index 7a38877e9e..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js +++ /dev/null @@ -1,17 +0,0 @@ -test("basic functionality", () => { - 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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.endsWith.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.endsWith.js deleted file mode 100644 index 286cc6b1b2..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.endsWith.js +++ /dev/null @@ -1,42 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype.endsWith).toHaveLength(1); - - var s = "foobar"; - expect(s.endsWith("r")).toBeTrue(); - expect(s.endsWith("ar")).toBeTrue(); - expect(s.endsWith("bar")).toBeTrue(); - expect(s.endsWith("obar")).toBeTrue(); - expect(s.endsWith("oobar")).toBeTrue(); - expect(s.endsWith("foobar")).toBeTrue(); - expect(s.endsWith("1foobar")).toBeFalse(); - expect(s.endsWith("r", 6)).toBeTrue(); - expect(s.endsWith("ar", 6)).toBeTrue(); - expect(s.endsWith("bar", 6)).toBeTrue(); - expect(s.endsWith("obar", 6)).toBeTrue(); - expect(s.endsWith("oobar", 6)).toBeTrue(); - expect(s.endsWith("foobar", 6)).toBeTrue(); - expect(s.endsWith("1foobar", 6)).toBeFalse(); - expect(s.endsWith("bar", [])).toBeFalse(); - expect(s.endsWith("bar", null)).toBeFalse(); - expect(s.endsWith("bar", false)).toBeFalse(); - expect(s.endsWith("bar", true)).toBeFalse(); - expect(s.endsWith("f", true)).toBeTrue(); - expect(s.endsWith("bar", -1)).toBeFalse(); - expect(s.endsWith("bar", 42)).toBeTrue(); - expect(s.endsWith("foo", 3)).toBeTrue(); - expect(s.endsWith("foo", "3")).toBeTrue(); - expect(s.endsWith("foo1", 3)).toBeFalse(); - expect(s.endsWith("foo", 3.7)).toBeTrue(); - expect(s.endsWith()).toBeFalse(); - expect(s.endsWith("")).toBeTrue(); - expect(s.endsWith("", 0)).toBeTrue(); - expect(s.endsWith("", 1)).toBeTrue(); - expect(s.endsWith("", -1)).toBeTrue(); - expect(s.endsWith("", 42)).toBeTrue(); - expect("12undefined".endsWith()).toBeTrue(); - expect(() => s.endsWith(/foobar/)).toThrowWithMessage( - TypeError, - "searchString is not a string, but a regular expression" - ); - expect(s.endsWith("bar", undefined)).toBeTrue(); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js deleted file mode 100644 index 14a2230530..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js +++ /dev/null @@ -1,12 +0,0 @@ -test("basic functionality", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js deleted file mode 100644 index 8e2ca2f892..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js +++ /dev/null @@ -1,8 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype.indexOf).toHaveLength(1); - - var s = "hello friends"; - - 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 deleted file mode 100644 index a66207e96c..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.js +++ /dev/null @@ -1,9 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype).toHaveLength(0); - - expect(typeof Object.getPrototypeOf("")).toBe("object"); - expect(Object.getPrototypeOf("").valueOf()).toBe(""); - - expect(typeof String.prototype).toBe("object"); - expect(String.prototype.valueOf()).toBe(""); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js deleted file mode 100644 index ce69fc3214..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js +++ /dev/null @@ -1,22 +0,0 @@ -test("basic functionality", () => { - 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); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js deleted file mode 100644 index a103084c3a..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js +++ /dev/null @@ -1,18 +0,0 @@ -test("basic functionality", () => { - 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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js deleted file mode 100644 index a2f0f0b710..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js +++ /dev/null @@ -1,18 +0,0 @@ -test("basic functionality", () => { - 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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js deleted file mode 100644 index 8427698509..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js +++ /dev/null @@ -1,25 +0,0 @@ -test("basic functionality", () => { - 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(""); -}); - -test("throws correct range errors", () => { - 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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js deleted file mode 100644 index 2141e0f6f3..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js +++ /dev/null @@ -1,17 +0,0 @@ -test("basic functionality", () => { - 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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.split.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.split.js deleted file mode 100644 index 63d6c69a97..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.split.js +++ /dev/null @@ -1,35 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype.split).toHaveLength(2); - - expect("hello friends".split()).toEqual(["hello friends"]); - expect("hello friends".split("")).toEqual([ - "h", - "e", - "l", - "l", - "o", - " ", - "f", - "r", - "i", - "e", - "n", - "d", - "s", - ]); - expect("hello friends".split(" ")).toEqual(["hello", "friends"]); - - expect("a,b,c,d".split(",")).toEqual(["a", "b", "c", "d"]); - expect(",a,b,c,d".split(",")).toEqual(["", "a", "b", "c", "d"]); - expect("a,b,c,d,".split(",")).toEqual(["a", "b", "c", "d", ""]); - expect("a,b,,c,d".split(",")).toEqual(["a", "b", "", "c", "d"]); - expect(",a,b,,c,d,".split(",")).toEqual(["", "a", "b", "", "c", "d", ""]); - expect(",a,b,,,c,d,".split(",,")).toEqual([",a,b", ",c,d,"]); -}); - -test("limits", () => { - expect("a b c d".split(" ", 0)).toEqual([]); - expect("a b c d".split(" ", 1)).toEqual(["a"]); - expect("a b c d".split(" ", 3)).toEqual(["a", "b", "c"]); - expect("a b c d".split(" ", 100)).toEqual(["a", "b", "c", "d"]); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js deleted file mode 100644 index 5114da78f9..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js +++ /dev/null @@ -1,36 +0,0 @@ -test("basic functionality", () => { - 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(); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.substr.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.substr.js deleted file mode 100644 index ade6c3c60a..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.substr.js +++ /dev/null @@ -1,16 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype.substr).toHaveLength(2); - - expect("hello friends".substr()).toBe("hello friends"); - expect("hello friends".substr(1)).toBe("ello friends"); - expect("hello friends".substr(0, 5)).toBe("hello"); - expect("hello friends".substr(5, 6)).toBe(" frien"); - expect("hello friends".substr("", 5)).toBe("hello"); - expect("hello friends".substr(3, 3)).toBe("lo "); - expect("hello friends".substr(-1, 13)).toBe("s"); - expect("hello friends".substr(0, 50)).toBe("hello friends"); - expect("hello friends".substr(0, "5")).toBe("hello"); - expect("hello friends".substr("2", "2")).toBe("ll"); - expect("hello friends".substr(-7)).toBe("friends"); - expect("hello friends".substr(-3, -5)).toBe(""); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js deleted file mode 100644 index 49a9888d7f..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js +++ /dev/null @@ -1,14 +0,0 @@ -test("basic functionality", () => { - 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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js deleted file mode 100644 index 4c7cbad50a..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js +++ /dev/null @@ -1,9 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype.toLowerCase).toHaveLength(0); - - expect("foo".toLowerCase()).toBe("foo"); - expect("Foo".toLowerCase()).toBe("foo"); - expect("FOO".toLowerCase()).toBe("foo"); - - 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 deleted file mode 100644 index 418f2da5f8..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js +++ /dev/null @@ -1,6 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype.toString).toHaveLength(0); - - 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 deleted file mode 100644 index 03f463c6e1..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.toUpperCase.js +++ /dev/null @@ -1,9 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype.toUpperCase).toHaveLength(0); - - expect("foo".toUpperCase()).toBe("FOO"); - expect("Foo".toUpperCase()).toBe("FOO"); - expect("FOO".toUpperCase()).toBe("FOO"); - - 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 deleted file mode 100644 index d60522cad4..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js +++ /dev/null @@ -1,58 +0,0 @@ -test("trim", () => { - 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("\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\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(" 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("\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("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\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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js deleted file mode 100644 index 87fb50fa21..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js +++ /dev/null @@ -1,12 +0,0 @@ -test("basic functionality", () => { - expect(String.prototype.valueOf).toHaveLength(0); - - expect(String()).toBe(""); - expect(new String().valueOf()).toBe(""); - expect(String("foo")).toBe("foo"); - expect(new String("foo").valueOf()).toBe("foo"); - expect(String(123)).toBe("123"); - expect(new String(123).valueOf()).toBe("123"); - expect(String(123)).toBe("123"); - expect(new String(123).valueOf()).toBe("123"); -}); diff --git a/Libraries/LibJS/Tests/builtins/String/String.raw.js b/Libraries/LibJS/Tests/builtins/String/String.raw.js deleted file mode 100644 index a866276034..0000000000 --- a/Libraries/LibJS/Tests/builtins/String/String.raw.js +++ /dev/null @@ -1,31 +0,0 @@ -test("basic functionality", () => { - expect(String.raw).toHaveLength(1); - - 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`${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"] }); - expect(str).toBe("foo \\nbar"); - - str = String.raw({ raw: [] }, 10, "hf!"); - 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"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.for.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.for.js deleted file mode 100644 index c905be3c72..0000000000 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.for.js +++ /dev/null @@ -1,23 +0,0 @@ -test("basic functionality", () => { - const localSym = Symbol("foo"); - const globalSym = Symbol.for("foo"); - - expect(localSym).not.toBe(globalSym); - expect(localSym).not.toBe(Symbol("foo")); - expect(globalSym).not.toBe(Symbol("foo")); - expect(globalSym).toBe(Symbol.for("foo")); - expect(localSym.toString()).toBe("Symbol(foo)"); - expect(globalSym.toString()).toBe("Symbol(foo)"); - - expect(Symbol.for(1).description).toBe("1"); - expect(Symbol.for(true).description).toBe("true"); - expect(Symbol.for({}).description).toBe("[object Object]"); - expect(Symbol.for().description).toBe("undefined"); - expect(Symbol.for(null).description).toBe("null"); -}); - -test("symbol argument throws an error", () => { - expect(() => { - Symbol.for(Symbol()); - }).toThrowWithMessage(TypeError, "Cannot convert symbol to string"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js deleted file mode 100644 index 2533f593c7..0000000000 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.js +++ /dev/null @@ -1,19 +0,0 @@ -test("basic functionality", () => { - const s1 = Symbol("foo"); - const s2 = Symbol("foo"); - - expect(s1).not.toBe(s2); - expect(s1.description).toBe("foo"); - expect(s2.description).toBe("foo"); - - s1.description = "bar"; - expect(s1.description).toBe("foo"); - - expect(typeof s1).toBe("symbol"); -}); - -test("constructing symbol from symbol is an error", () => { - expect(() => { - Symbol(Symbol("foo")); - }).toThrowWithMessage(TypeError, "Cannot convert symbol to string"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.keyFor.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.keyFor.js deleted file mode 100644 index 8b04f652bc..0000000000 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.keyFor.js +++ /dev/null @@ -1,24 +0,0 @@ -test("basic functionality", () => { - const localSym = Symbol("foo"); - const globalSym = Symbol.for("foo"); - - expect(Symbol.keyFor(localSym)).toBeUndefined(); - expect(Symbol.keyFor(globalSym)).toBe("foo"); -}); - -test("bad argument values", () => { - [ - [1, "1"], - [null, "null"], - [undefined, "undefined"], - [[], "[object Array]"], - [{}, "[object Object]"], - [true, "true"], - ["foobar", "foobar"], - [function () {}, "[object ScriptFunction]"], // FIXME: Better function stringification - ].forEach(testCase => { - expect(() => { - Symbol.keyFor(testCase[0]); - }).toThrowWithMessage(TypeError, `${testCase[1]} is not a symbol`); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.@@toStringTag.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.@@toStringTag.js deleted file mode 100644 index c73e637fc4..0000000000 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.@@toStringTag.js +++ /dev/null @@ -1,3 +0,0 @@ -test("basic functionality", () => { - expect(Symbol.prototype[Symbol.toStringTag]).toBe("Symbol"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js deleted file mode 100644 index 4a95fe2397..0000000000 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.toString.js +++ /dev/null @@ -1,25 +0,0 @@ -describe("correct behavior", () => { - test("basic functionality", () => { - const s1 = Symbol("baz"); - const s2 = Symbol.for("qux"); - - // Explicit conversions to string are fine, but implicit toString via concatenation throws. - expect(s1.toString()).toBe("Symbol(baz)"); - expect(String(s1)).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 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 deleted file mode 100644 index 0bfbfef912..0000000000 --- a/Libraries/LibJS/Tests/builtins/Symbol/Symbol.prototype.valueOf.js +++ /dev/null @@ -1,15 +0,0 @@ -test("basic functionality", () => { - 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); -}); - -test("|this| must be a symbol", () => { - expect(() => { - Symbol.prototype.valueOf.call("foo"); - }).toThrowWithMessage(TypeError, "Not a Symbol object"); -}); diff --git a/Libraries/LibJS/Tests/builtins/Symbol/well-known-symbol-existence.js b/Libraries/LibJS/Tests/builtins/Symbol/well-known-symbol-existence.js deleted file mode 100644 index 204e69882c..0000000000 --- a/Libraries/LibJS/Tests/builtins/Symbol/well-known-symbol-existence.js +++ /dev/null @@ -1,15 +0,0 @@ -test("basic functionality", () => { - expect(Symbol).toHaveProperty("iterator"); - expect(Symbol).toHaveProperty("asyncIterator"); - expect(Symbol).toHaveProperty("match"); - expect(Symbol).toHaveProperty("matchAll"); - expect(Symbol).toHaveProperty("replace"); - expect(Symbol).toHaveProperty("search"); - expect(Symbol).toHaveProperty("split"); - expect(Symbol).toHaveProperty("hasInstance"); - expect(Symbol).toHaveProperty("isConcatSpreadable"); - expect(Symbol).toHaveProperty("unscopables"); - expect(Symbol).toHaveProperty("species"); - expect(Symbol).toHaveProperty("toPrimitive"); - expect(Symbol).toHaveProperty("toStringTag"); -}); diff --git a/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.BYTES_PER_ELEMENT.js b/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.BYTES_PER_ELEMENT.js deleted file mode 100644 index c53213ac07..0000000000 --- a/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.BYTES_PER_ELEMENT.js +++ /dev/null @@ -1,10 +0,0 @@ -test("basic functionality", () => { - expect(Uint8Array.BYTES_PER_ELEMENT).toBe(1); - expect(Uint16Array.BYTES_PER_ELEMENT).toBe(2); - expect(Uint32Array.BYTES_PER_ELEMENT).toBe(4); - expect(Int8Array.BYTES_PER_ELEMENT).toBe(1); - expect(Int16Array.BYTES_PER_ELEMENT).toBe(2); - expect(Int32Array.BYTES_PER_ELEMENT).toBe(4); - expect(Float32Array.BYTES_PER_ELEMENT).toBe(4); - expect(Float64Array.BYTES_PER_ELEMENT).toBe(8); -}); diff --git a/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.js b/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.js deleted file mode 100644 index d443d13cd6..0000000000 --- a/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.js +++ /dev/null @@ -1,133 +0,0 @@ -// Update when more typed arrays get added -const TYPED_ARRAYS = [ - Uint8Array, - Uint16Array, - Uint32Array, - Int8Array, - Int16Array, - Int32Array, - Float32Array, - Float64Array, -]; - -const getTypedArrayConstructor = () => Object.getPrototypeOf(TYPED_ARRAYS[0]); - -test("basic functionality", () => { - const TypedArray = getTypedArrayConstructor(); - expect(TypedArray).toHaveLength(0); - expect(TypedArray.name).toBe("TypedArray"); - expect(TypedArray.prototype.constructor).toBe(TypedArray); - TYPED_ARRAYS.forEach(T => { - expect(T.prototype.constructor).toBe(T); - }); - const FunctionPrototype = Object.getPrototypeOf(() => {}); - expect(Object.getPrototypeOf(TypedArray)).toBe(FunctionPrototype); -}); - -test("typed array constructors must be invoked with 'new'", () => { - TYPED_ARRAYS.forEach(T => { - expect(() => { - T(); - }).toThrowWithMessage(TypeError, `${T.name} constructor must be called with 'new'`); - }); -}); - -test("typed array constructors have TypedArray as prototype", () => { - const TypedArray = getTypedArrayConstructor(); - TYPED_ARRAYS.forEach(T => { - expect(Object.getPrototypeOf(T)).toBe(TypedArray); - }); -}); - -test("typed array prototypes have TypedArray.prototype as prototype", () => { - const TypedArray = getTypedArrayConstructor(); - TYPED_ARRAYS.forEach(T => { - const TPrototype = Object.getPrototypeOf(new T()); - expect(Object.getPrototypeOf(TPrototype)).toBe(TypedArray.prototype); - }); -}); - -test("typed arrays inherit from TypedArray", () => { - const TypedArray = getTypedArrayConstructor(); - TYPED_ARRAYS.forEach(T => { - expect(new T()).toBeInstanceOf(TypedArray); - }); -}); - -test("typed array can share the same ArrayBuffer", () => { - const arrayBuffer = new ArrayBuffer(2); - const uint8Array = new Uint8Array(arrayBuffer); - const uint16Array = new Uint16Array(arrayBuffer); - expect(uint8Array[0]).toBe(0); - expect(uint8Array[1]).toBe(0); - expect(uint16Array[0]).toBe(0); - expect(uint16Array[1]).toBeUndefined(); - uint16Array[0] = 54321; - expect(uint8Array[0]).toBe(0x31); - expect(uint8Array[1]).toBe(0xd4); - expect(uint16Array[0]).toBe(54321); - expect(uint16Array[1]).toBeUndefined(); -}); - -test("typed array from ArrayBuffer with custom length and offset", () => { - const arrayBuffer = new ArrayBuffer(10); - const uint8ArrayAll = new Uint8Array(arrayBuffer); - const uint16ArrayPartial = new Uint16Array(arrayBuffer, 2, 4); - // Affects two bytes of the buffer, beginning at offset - uint16ArrayPartial[0] = 52651; - // Out of relative bounds, doesn't affect buffer - uint16ArrayPartial[4] = 123; - expect(uint8ArrayAll[0]).toBe(0); - expect(uint8ArrayAll[1]).toBe(0); - expect(uint8ArrayAll[2]).toBe(0xab); - expect(uint8ArrayAll[3]).toBe(0xcd); - expect(uint8ArrayAll[5]).toBe(0); - expect(uint8ArrayAll[6]).toBe(0); - expect(uint8ArrayAll[7]).toBe(0); - expect(uint8ArrayAll[8]).toBe(0); - expect(uint8ArrayAll[9]).toBe(0); -}); - -test("typed array from ArrayBuffer errors", () => { - expect(() => { - new Uint16Array(new ArrayBuffer(1)); - }).toThrowWithMessage( - RangeError, - "Invalid buffer length for Uint16Array: must be a multiple of 2, got 1" - ); - - expect(() => { - new Uint16Array(new ArrayBuffer(), 1); - }).toThrowWithMessage( - RangeError, - "Invalid byte offset for Uint16Array: must be a multiple of 2, got 1" - ); - - expect(() => { - new Uint16Array(new ArrayBuffer(), 2); - }).toThrowWithMessage( - RangeError, - "Typed array byte offset 2 is out of range for buffer with length 0" - ); - - expect(() => { - new Uint16Array(new ArrayBuffer(7), 2, 3); - }).toThrowWithMessage( - RangeError, - "Typed array range 2:8 is out of range for buffer with length 7" - ); -}); - -test("TypedArray is not exposed on the global object", () => { - expect(globalThis.TypedArray).toBeUndefined(); -}); - -test("TypedArray is abstract", () => { - const TypedArray = getTypedArrayConstructor(); - expect(() => { - TypedArray(); - }).toThrowWithMessage(TypeError, "Abstract class TypedArray cannot be constructed directly"); - expect(() => { - new TypedArray(); - }).toThrowWithMessage(TypeError, "Abstract class TypedArray cannot be constructed directly"); -}); diff --git a/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.length.js b/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.length.js deleted file mode 100644 index ce02c72391..0000000000 --- a/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.length.js +++ /dev/null @@ -1,19 +0,0 @@ -// Update when more typed arrays get added -const TYPED_ARRAYS = [ - Uint8Array, - Uint16Array, - Uint32Array, - Int8Array, - Int16Array, - Int32Array, - Float32Array, - Float64Array, -]; - -test("basic functionality", () => { - TYPED_ARRAYS.forEach(T => { - const typedArray = new T(42); - expect(Object.hasOwnProperty(typedArray, "length")).toBeFalse(); - expect(typedArray.length).toBe(42); - }); -}); diff --git a/Libraries/LibJS/Tests/builtins/TypedArray/typed-array-basic.js b/Libraries/LibJS/Tests/builtins/TypedArray/typed-array-basic.js deleted file mode 100644 index aeefb5bb54..0000000000 --- a/Libraries/LibJS/Tests/builtins/TypedArray/typed-array-basic.js +++ /dev/null @@ -1,86 +0,0 @@ -test("basic Uint8Array", () => { - var a = new Uint8Array(1); - expect(typeof a).toBe("object"); - expect(a instanceof Uint8Array).toBe(true); - expect(a.length).toBe(1); - a[0] = 1; - expect(a[0]).toBe(1); - a[0] -= 2; - expect(a[0]).toBe(0xff); - ++a[0]; - expect(a[0]).toBe(0); -}); - -test("basic Uint16Array", () => { - var a = new Uint16Array(1); - expect(typeof a).toBe("object"); - expect(a instanceof Uint16Array).toBe(true); - expect(a.length).toBe(1); - a[0] = 1; - expect(a[0]).toBe(1); - a[0] -= 2; - expect(a[0]).toBe(0xffff); - ++a[0]; - expect(a[0]).toBe(0); -}); - -test("basic Uint32Array", () => { - var a = new Uint32Array(1); - expect(typeof a).toBe("object"); - expect(a instanceof Uint32Array).toBe(true); - expect(a.length).toBe(1); - a[0] = 1; - expect(a[0]).toBe(1); - a[0] -= 2; - expect(a[0]).toBe(0xffffffff); - ++a[0]; - expect(a[0]).toBe(0); -}); - -test("basic Int8Array", () => { - var a = new Int8Array(1); - expect(typeof a).toBe("object"); - expect(a instanceof Int8Array).toBe(true); - expect(a.length).toBe(1); - a[0] = 1; - expect(a[0]).toBe(1); - a[0] -= 2; - expect(a[0]).toBe(-1); - ++a[0]; - expect(a[0]).toBe(0); - a[0] = 127; - a[0]++; - expect(a[0]).toBe(-128); -}); - -test("basic Int16Array", () => { - var a = new Int16Array(1); - expect(typeof a).toBe("object"); - expect(a instanceof Int16Array).toBe(true); - expect(a.length).toBe(1); - a[0] = 1; - expect(a[0]).toBe(1); - a[0] -= 2; - expect(a[0]).toBe(-1); - ++a[0]; - expect(a[0]).toBe(0); - a[0] = 32767; - a[0]++; - expect(a[0]).toBe(-32768); -}); - -test("basic Int32Array", () => { - var a = new Int32Array(1); - expect(typeof a).toBe("object"); - expect(a instanceof Int32Array).toBe(true); - expect(a.length).toBe(1); - a[0] = 1; - expect(a[0]).toBe(1); - a[0] -= 2; - expect(a[0]).toBe(-1); - ++a[0]; - expect(a[0]).toBe(0); - a[0] = 0x7fffffff; - a[0]++; - expect(a[0]).toBe(-0x80000000); -}); diff --git a/Libraries/LibJS/Tests/builtins/functions/isFinite.js b/Libraries/LibJS/Tests/builtins/functions/isFinite.js deleted file mode 100644 index 71f4f70655..0000000000 --- a/Libraries/LibJS/Tests/builtins/functions/isFinite.js +++ /dev/null @@ -1,23 +0,0 @@ -test("basic functionality", () => { - 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()).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 deleted file mode 100644 index bb0d418bb5..0000000000 --- a/Libraries/LibJS/Tests/builtins/functions/isNaN.js +++ /dev/null @@ -1,26 +0,0 @@ -test("length is 1", () => { - expect(isNaN).toHaveLength(1); -}); - -test("arguments that evaluate to false", () => { - 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(); -}); - -test("arguments that evaluate to true", () => { - 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 deleted file mode 100644 index 20ed2633dd..0000000000 --- a/Libraries/LibJS/Tests/builtins/functions/parseFloat.js +++ /dev/null @@ -1,59 +0,0 @@ -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]); - }); -}); - -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]); - }); -}); - -test("parsing NaN", () => { - [ - "", - [], - [], - 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(); -}); |