1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

test-js: Use prettier and format all files

This commit is contained in:
Matthew Olsson 2020-07-05 09:27:00 -07:00 committed by Andreas Kling
parent e532888242
commit 6d58c48c2f
248 changed files with 8291 additions and 7725 deletions

View file

@ -0,0 +1,13 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "lf",
"insertPragma": false,
"printWidth": 100,
"quoteProps": "as-needed",
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}

View file

@ -1,6 +1,6 @@
test("adding objects", () => { test("adding objects", () => {
expect([] + []).toBe(""); expect([] + []).toBe("");
expect([] + {}).toBe("[object Object]"); expect([] + {}).toBe("[object Object]");
expect({} + {}).toBe("[object Object][object Object]"); expect({} + {}).toBe("[object Object][object Object]");
expect({} + []).toBe("[object Object]"); expect({} + []).toBe("[object Object]");
}); });

View file

@ -1,6 +1,5 @@
test("Issue #1829, if-else without braces or semicolons", () => { test("Issue #1829, if-else without braces or semicolons", () => {
const source = const source = `if (1)
`if (1)
return 1; return 1;
else else
return 0; return 0;
@ -15,12 +14,11 @@ if (1)
else else
return 0;`; return 0;`;
expect(source).toEval(); expect(source).toEval();
}); });
test("break/continue, variable declaration, do-while, and return asi", () => { test("break/continue, variable declaration, do-while, and return asi", () => {
const source = const source = `function foo() {
`function foo() {
label: label:
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
break // semicolon inserted here break // semicolon inserted here
@ -41,12 +39,11 @@ var curly/* semicolon inserted here */}
return foo();`; return foo();`;
expect(source).toEvalTo(undefined); expect(source).toEvalTo(undefined);
}); });
test("more break and continue asi", () => { test("more break and continue asi", () => {
const source = const source = `let counter = 0;
`let counter = 0;
let outer; let outer;
outer: outer:
@ -60,9 +57,9 @@ for (let i = 0; i < 5; ++i) {
return counter;`; return counter;`;
expect(source).toEvalTo(5); expect(source).toEvalTo(5);
}); });
test("eof with no semicolon", () => { test("eof with no semicolon", () => {
expect("var eof").toEval(); expect("var eof").toEval();
}); });

View file

@ -1,28 +1,28 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.isArray.length === 1); assert(Array.isArray.length === 1);
assert(Array.isArray() === false); assert(Array.isArray() === false);
assert(Array.isArray("1") === false); assert(Array.isArray("1") === false);
assert(Array.isArray("foo") === false); assert(Array.isArray("foo") === false);
assert(Array.isArray(1) === false); assert(Array.isArray(1) === false);
assert(Array.isArray(1, 2, 3) === false); assert(Array.isArray(1, 2, 3) === false);
assert(Array.isArray(undefined) === false); assert(Array.isArray(undefined) === false);
assert(Array.isArray(null) === false); assert(Array.isArray(null) === false);
assert(Array.isArray(Infinity) === false); assert(Array.isArray(Infinity) === false);
assert(Array.isArray({}) === false); assert(Array.isArray({}) === false);
assert(Array.isArray([]) === true); assert(Array.isArray([]) === true);
assert(Array.isArray([1]) === true); assert(Array.isArray([1]) === true);
assert(Array.isArray([1, 2, 3]) === true); assert(Array.isArray([1, 2, 3]) === true);
assert(Array.isArray(new Array()) === true); assert(Array.isArray(new Array()) === true);
assert(Array.isArray(new Array(10)) === true); assert(Array.isArray(new Array(10)) === true);
assert(Array.isArray(new Array("a", "b", "c")) === true); assert(Array.isArray(new Array("a", "b", "c")) === true);
// FIXME: Array.prototype is supposed to be an array! // FIXME: Array.prototype is supposed to be an array!
// assert(Array.isArray(Array.prototype) === true); // assert(Array.isArray(Array.prototype) === true);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,48 +1,55 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.length === 1); assert(Array.length === 1);
assert(Array.name === "Array"); assert(Array.name === "Array");
assert(Array.prototype.length === 0); assert(Array.prototype.length === 0);
assert(typeof Array() === "object"); assert(typeof Array() === "object");
assert(typeof new Array() === "object"); assert(typeof new Array() === "object");
var a; var a;
a = new Array(5); a = new Array(5);
assert(a.length === 5); assert(a.length === 5);
a = new Array("5"); a = new Array("5");
assert(a.length === 1); assert(a.length === 1);
assert(a[0] === "5"); assert(a[0] === "5");
a = new Array(1, 2, 3); a = new Array(1, 2, 3);
assert(a.length === 3); assert(a.length === 3);
assert(a[0] === 1); assert(a[0] === 1);
assert(a[1] === 2); assert(a[1] === 2);
assert(a[2] === 3); assert(a[2] === 3);
a = new Array([1, 2, 3]); a = new Array([1, 2, 3]);
assert(a.length === 1); assert(a.length === 1);
assert(a[0][0] === 1); assert(a[0][0] === 1);
assert(a[0][1] === 2); assert(a[0][1] === 2);
assert(a[0][2] === 3); assert(a[0][2] === 3);
a = new Array(1, 2, 3); a = new Array(1, 2, 3);
Object.defineProperty(a, 3, { get() { return 10; } }); Object.defineProperty(a, 3, {
assert(a.toString() === "1,2,3,10"); get() {
return 10;
},
});
assert(a.toString() === "1,2,3,10");
[-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => { [-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => {
assertThrowsError(() => { assertThrowsError(
new Array(value); () => {
}, { new Array(value);
error: TypeError, },
message: "Invalid array length" {
}); error: TypeError,
}); message: "Invalid array length",
}
);
});
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,46 +1,50 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.of.length === 0); assert(Array.of.length === 0);
assert(typeof Array.of() === "object"); assert(typeof Array.of() === "object");
var a; var a;
a = Array.of(5); a = Array.of(5);
assert(a.length === 1); assert(a.length === 1);
assert(a[0] === 5); assert(a[0] === 5);
a = Array.of("5"); a = Array.of("5");
assert(a.length === 1); assert(a.length === 1);
assert(a[0] === "5"); assert(a[0] === "5");
a = Array.of(Infinity); a = Array.of(Infinity);
assert(a.length === 1); assert(a.length === 1);
assert(a[0] === Infinity); assert(a[0] === Infinity);
a = Array.of(1, 2, 3); a = Array.of(1, 2, 3);
assert(a.length === 3); assert(a.length === 3);
assert(a[0] === 1); assert(a[0] === 1);
assert(a[1] === 2); assert(a[1] === 2);
assert(a[2] === 3); assert(a[2] === 3);
a = Array.of([1, 2, 3]); a = Array.of([1, 2, 3]);
assert(a.length === 1); assert(a.length === 1);
assert(a[0][0] === 1); assert(a[0][0] === 1);
assert(a[0][1] === 2); assert(a[0][1] === 2);
assert(a[0][2] === 3); assert(a[0][2] === 3);
let t = [1, 2, 3]; let t = [1, 2, 3];
Object.defineProperty(t, 3, { get() { return 4; } }); Object.defineProperty(t, 3, {
a = Array.of(...t); get() {
assert(a.length === 4); return 4;
assert(a[0] === 1); },
assert(a[1] === 2); });
assert(a[2] === 3); a = Array.of(...t);
assert(a[3] === 4); assert(a.length === 4);
assert(a[0] === 1);
assert(a[1] === 2);
assert(a[2] === 3);
assert(a[3] === 4);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,134 +1,159 @@
load("test-common.js"); load("test-common.js");
try { try {
[undefined, "foo", -42, 0].forEach(length => { [undefined, "foo", -42, 0].forEach(length => {
const o = { length }; const o = { length };
assert(Array.prototype.push.call(o, "foo") === 1); assert(Array.prototype.push.call(o, "foo") === 1);
assert(o.length === 1); assert(o.length === 1);
assert(o[0] === "foo"); assert(o[0] === "foo");
assert(Array.prototype.push.call(o, "bar", "baz") === 3); assert(Array.prototype.push.call(o, "bar", "baz") === 3);
assert(o.length === 3); assert(o.length === 3);
assert(o[0] === "foo"); assert(o[0] === "foo");
assert(o[1] === "bar"); assert(o[1] === "bar");
assert(o[2] === "baz"); assert(o[2] === "baz");
assert(Array.prototype.pop.call(o) === "baz"); assert(Array.prototype.pop.call(o) === "baz");
assert(o.length === 2); assert(o.length === 2);
assert(Array.prototype.pop.call(o) === "bar"); assert(Array.prototype.pop.call(o) === "bar");
assert(o.length === 1); assert(o.length === 1);
assert(Array.prototype.pop.call(o) === "foo"); assert(Array.prototype.pop.call(o) === "foo");
assert(o.length === 0); assert(o.length === 0);
assert(Array.prototype.pop.call(o) === undefined); assert(Array.prototype.pop.call(o) === undefined);
assert(o.length === 0); assert(o.length === 0);
o.length = length; o.length = length;
assert(Array.prototype.pop.call(o) === undefined); assert(Array.prototype.pop.call(o) === undefined);
assert(o.length === 0); assert(o.length === 0);
}); });
{ {
const o = { length: 3, 0: "hello", 2: "serenity" }; const o = { length: 3, 0: "hello", 2: "serenity" };
const removed = Array.prototype.splice.call(o, 0, 2, "hello", "friends"); const removed = Array.prototype.splice.call(o, 0, 2, "hello", "friends");
assert(o.length === 3); assert(o.length === 3);
assert(o[0] === "hello"); assert(o[0] === "hello");
assert(o[1] === "friends"); assert(o[1] === "friends");
assert(o[2] === "serenity"); assert(o[2] === "serenity");
assert(removed.length === 2); assert(removed.length === 2);
assert(removed[0] === "hello"); assert(removed[0] === "hello");
assert(removed[1] === undefined); assert(removed[1] === undefined);
} }
{ {
assert(Array.prototype.join.call({}) === ""); assert(Array.prototype.join.call({}) === "");
assert(Array.prototype.join.call({ length: "foo" }) === ""); assert(Array.prototype.join.call({ length: "foo" }) === "");
assert(Array.prototype.join.call({ length: 3 }) === ",,"); assert(Array.prototype.join.call({ length: 3 }) === ",,");
assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" }) === "foo,bar"); assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" }) === "foo,bar");
assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" }) === "foo,bar"); assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" }) === "foo,bar");
assert(Array.prototype.join.call({ length: 3, 1: "bar" }, "~") === "~bar~"); assert(Array.prototype.join.call({ length: 3, 1: "bar" }, "~") === "~bar~");
assert(Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~") === "foo~bar~baz"); assert(
} Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~") === "foo~bar~baz"
);
}
{ {
assert(Array.prototype.toString.call({}) === "[object Object]"); assert(Array.prototype.toString.call({}) === "[object Object]");
assert(Array.prototype.toString.call({ join: "foo" }) === "[object Object]"); assert(Array.prototype.toString.call({ join: "foo" }) === "[object Object]");
assert(Array.prototype.toString.call({ join: () => "foo" }) === "foo"); assert(Array.prototype.toString.call({ join: () => "foo" }) === "foo");
} }
{ {
assert(Array.prototype.indexOf.call({}) === -1); assert(Array.prototype.indexOf.call({}) === -1);
assert(Array.prototype.indexOf.call({ 0: undefined }) === -1); assert(Array.prototype.indexOf.call({ 0: undefined }) === -1);
assert(Array.prototype.indexOf.call({ length: 1, 0: undefined }) === 0); assert(Array.prototype.indexOf.call({ length: 1, 0: undefined }) === 0);
assert(Array.prototype.indexOf.call({ length: 1, 2: "foo" }, "foo") === -1); assert(Array.prototype.indexOf.call({ length: 1, 2: "foo" }, "foo") === -1);
assert(Array.prototype.indexOf.call({ length: 5, 2: "foo" }, "foo") === 2); assert(Array.prototype.indexOf.call({ length: 5, 2: "foo" }, "foo") === 2);
assert(Array.prototype.indexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", 3) === 4); assert(Array.prototype.indexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", 3) === 4);
} }
{ {
assert(Array.prototype.lastIndexOf.call({}) === -1); assert(Array.prototype.lastIndexOf.call({}) === -1);
assert(Array.prototype.lastIndexOf.call({ 0: undefined }) === -1); assert(Array.prototype.lastIndexOf.call({ 0: undefined }) === -1);
assert(Array.prototype.lastIndexOf.call({ length: 1, 0: undefined }) === 0); assert(Array.prototype.lastIndexOf.call({ length: 1, 0: undefined }) === 0);
assert(Array.prototype.lastIndexOf.call({ length: 1, 2: "foo" }, "foo") === -1); assert(Array.prototype.lastIndexOf.call({ length: 1, 2: "foo" }, "foo") === -1);
assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo" }, "foo") === 2); assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo" }, "foo") === 2);
assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo") === 4); assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo") === 4);
assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", -2) === 2); assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", -2) === 2);
} }
{ {
assert(Array.prototype.includes.call({}) === false); assert(Array.prototype.includes.call({}) === false);
assert(Array.prototype.includes.call({ 0: undefined }) === false); assert(Array.prototype.includes.call({ 0: undefined }) === false);
assert(Array.prototype.includes.call({ length: 1, 0: undefined }) === true); assert(Array.prototype.includes.call({ length: 1, 0: undefined }) === true);
assert(Array.prototype.includes.call({ length: 1, 2: "foo" }, "foo") === false); assert(Array.prototype.includes.call({ length: 1, 2: "foo" }, "foo") === false);
assert(Array.prototype.includes.call({ length: 5, 2: "foo" }, "foo") === true); assert(Array.prototype.includes.call({ length: 5, 2: "foo" }, "foo") === true);
} }
const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" }; const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" };
{ {
assertVisitsAll(visit => { assertVisitsAll(
Array.prototype.every.call(o, function (value) { visit => {
visit(value); Array.prototype.every.call(o, function (value) {
return true; visit(value);
}); return true;
}, ["foo", "bar", "baz"]); });
} },
["foo", "bar", "baz"]
);
}
["find", "findIndex"].forEach(name => { ["find", "findIndex"].forEach(name => {
assertVisitsAll(visit => { assertVisitsAll(
Array.prototype[name].call(o, function (value) { visit => {
visit(value); Array.prototype[name].call(o, function (value) {
return false; visit(value);
}); return false;
}, ["foo", "bar", undefined, "baz", undefined]); });
}); },
["foo", "bar", undefined, "baz", undefined]
);
});
["filter", "forEach", "map", "some"].forEach(name => { ["filter", "forEach", "map", "some"].forEach(name => {
assertVisitsAll(visit => { assertVisitsAll(
Array.prototype[name].call(o, function (value) { visit => {
visit(value); Array.prototype[name].call(o, function (value) {
return false; visit(value);
}); return false;
}, ["foo", "bar", "baz"]); });
}); },
{ ["foo", "bar", "baz"]
assertVisitsAll(visit => { );
Array.prototype.reduce.call(o, function (_, value) { });
visit(value); {
return false; assertVisitsAll(
}, "initial"); visit => {
}, ["foo", "bar", "baz"]); Array.prototype.reduce.call(
} o,
function (_, value) {
visit(value);
return false;
},
"initial"
);
},
["foo", "bar", "baz"]
);
}
{ {
assertVisitsAll(visit => { assertVisitsAll(
Array.prototype.reduceRight.call(o, function (_, value) { visit => {
visit(value); Array.prototype.reduceRight.call(
return false; o,
}, "initial"); function (_, value) {
}, ["baz", "bar", "foo"]); visit(value);
} return false;
},
"initial"
);
},
["baz", "bar", "foo"]
);
}
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,37 +1,36 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.concat.length === 1); assert(Array.prototype.concat.length === 1);
var array = ["hello", "friends"]; var array = ["hello", "friends"];
var array_concat = array.concat(); var array_concat = array.concat();
assert(array_concat.length === array.length); assert(array_concat.length === array.length);
array_concat = array.concat(1) array_concat = array.concat(1);
assert(array_concat.length === 3); assert(array_concat.length === 3);
assert(array_concat[2] === 1); assert(array_concat[2] === 1);
array_concat = array.concat([1, 2, 3]) array_concat = array.concat([1, 2, 3]);
assert(array_concat.length === 5); assert(array_concat.length === 5);
assert(array_concat[2] === 1); assert(array_concat[2] === 1);
assert(array_concat[3] === 2); assert(array_concat[3] === 2);
assert(array_concat[4] === 3); assert(array_concat[4] === 3);
array_concat = array.concat(false, "serenity"); array_concat = array.concat(false, "serenity");
assert(array_concat.length === 4); assert(array_concat.length === 4);
assert(array_concat[2] === false); assert(array_concat[2] === false);
assert(array_concat[3] === "serenity"); assert(array_concat[3] === "serenity");
array_concat = array.concat({ name: "libjs" }, [1, [2, 3]]); array_concat = array.concat({ name: "libjs" }, [1, [2, 3]]);
assert(array_concat.length === 5); assert(array_concat.length === 5);
assert(array_concat[2].name === "libjs"); assert(array_concat[2].name === "libjs");
assert(array_concat[3] === 1); assert(array_concat[3] === 1);
assert(array_concat[4][0] === 2); assert(array_concat[4][0] === 2);
assert(array_concat[4][1] === 3); assert(array_concat[4][1] === 3);
console.log("PASS");
console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,44 +1,49 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.every.length === 1); assert(Array.prototype.every.length === 1);
assertThrowsError(() => { assertThrowsError(
[].every(undefined); () => {
}, { [].every(undefined);
error: TypeError, },
message: "undefined is not a function" {
}); error: TypeError,
message: "undefined is not a function",
}
);
var arrayOne = ["serenity", { test: "serenity"} ]; var arrayOne = ["serenity", { test: "serenity" }];
var arrayTwo = [true, false, 1, 2, 3, "3"]; var arrayTwo = [true, false, 1, 2, 3, "3"];
assert(arrayOne.every(value => value === "hello") === false); assert(arrayOne.every(value => value === "hello") === false);
assert(arrayOne.every(value => value === "serenity") === false); assert(arrayOne.every(value => value === "serenity") === false);
assert(arrayOne.every((value, index, arr) => index < 2) === true); assert(arrayOne.every((value, index, arr) => index < 2) === true);
assert(arrayOne.every(value => typeof(value) === "string") === false); assert(arrayOne.every(value => typeof value === "string") === false);
assert(arrayOne.every(value => arrayOne.pop()) === true); assert(arrayOne.every(value => arrayOne.pop()) === true);
assert(arrayTwo.every((value, index, arr) => index > 0) === false); assert(arrayTwo.every((value, index, arr) => index > 0) === false);
assert(arrayTwo.every((value, index, arr) => index >= 0) === true); assert(arrayTwo.every((value, index, arr) => index >= 0) === true);
assert(arrayTwo.every(value => typeof(value) !== "string") === false); assert(arrayTwo.every(value => typeof value !== "string") === false);
assert(arrayTwo.every(value => typeof(value) === "number") === false); assert(arrayTwo.every(value => typeof value === "number") === false);
assert(arrayTwo.every(value => value > 0) === false); assert(arrayTwo.every(value => value > 0) === false);
assert(arrayTwo.every(value => value >= 0 && value < 4) === true); assert(arrayTwo.every(value => value >= 0 && value < 4) === true);
assert(arrayTwo.every(value => arrayTwo.pop()) === true); assert(arrayTwo.every(value => arrayTwo.pop()) === true);
assert(["", "hello", "friends", "serenity"].every(value => value.length >= 0) === true); assert(["", "hello", "friends", "serenity"].every(value => value.length >= 0) === true);
assert([].every(value => value === 1) === true); assert([].every(value => value === 1) === true);
arrayTwo = [true, false, 1, 2, 3, "3"]; arrayTwo = [true, false, 1, 2, 3, "3"];
// Every only goes up to the original length. // Every only goes up to the original length.
assert(arrayTwo.every((value, index, arr) => { assert(
arr.push("serenity"); arrayTwo.every((value, index, arr) => {
return value < 4; arr.push("serenity");
}) === true); return value < 4;
}) === true
);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,24 +1,23 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.fill.length === 1); assert(Array.prototype.fill.length === 1);
var array = [1, 2, 3, 4]; var array = [1, 2, 3, 4];
assertArrayEquals(array.fill(0, 2, 4), [1, 2, 0, 0]); assertArrayEquals(array.fill(0, 2, 4), [1, 2, 0, 0]);
assertArrayEquals(array.fill(5, 1), [1, 5, 5, 5]); assertArrayEquals(array.fill(5, 1), [1, 5, 5, 5]);
assertArrayEquals(array.fill(6), [6, 6, 6, 6]); assertArrayEquals(array.fill(6), [6, 6, 6, 6]);
assertArrayEquals([1, 2, 3].fill(4), [4, 4, 4]); assertArrayEquals([1, 2, 3].fill(4), [4, 4, 4]);
assertArrayEquals([1, 2, 3].fill(4, 1), [1, 4, 4]); assertArrayEquals([1, 2, 3].fill(4, 1), [1, 4, 4]);
assertArrayEquals([1, 2, 3].fill(4, 1, 2), [1, 4, 3]); assertArrayEquals([1, 2, 3].fill(4, 1, 2), [1, 4, 3]);
assertArrayEquals([1, 2, 3].fill(4, 3, 3), [1, 2, 3]); assertArrayEquals([1, 2, 3].fill(4, 3, 3), [1, 2, 3]);
assertArrayEquals([1, 2, 3].fill(4, -3, -2), [4, 2, 3]); assertArrayEquals([1, 2, 3].fill(4, -3, -2), [4, 2, 3]);
assertArrayEquals([1, 2, 3].fill(4, NaN, NaN), [1, 2, 3]); assertArrayEquals([1, 2, 3].fill(4, NaN, NaN), [1, 2, 3]);
assertArrayEquals([1, 2, 3].fill(4, 3, 5), [1, 2, 3]); assertArrayEquals([1, 2, 3].fill(4, 3, 5), [1, 2, 3]);
assertArrayEquals(Array(3).fill(4), [4, 4, 4]); assertArrayEquals(Array(3).fill(4), [4, 4, 4]);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,59 +1,78 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.filter.length === 1); assert(Array.prototype.filter.length === 1);
assertThrowsError(() => { assertThrowsError(
[].filter(); () => {
}, { [].filter();
error: TypeError, },
message: "Array.prototype.filter() requires at least one argument" {
}); error: TypeError,
message: "Array.prototype.filter() requires at least one argument",
}
);
assertThrowsError(() => { assertThrowsError(
[].filter(undefined); () => {
}, { [].filter(undefined);
error: TypeError, },
message: "undefined is not a function" {
}); error: TypeError,
message: "undefined is not a function",
}
);
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; }; var callback = () => {
callbackCalled++;
};
assert([].filter(callback).length === 0); assert([].filter(callback).length === 0);
assert(callbackCalled === 0); assert(callbackCalled === 0);
assert([1, 2, 3].filter(callback).length === 0); assert([1, 2, 3].filter(callback).length === 0);
assert(callbackCalled === 3); assert(callbackCalled === 3);
var evenNumbers = [0, 1, 2, 3, 4, 5, 6, 7].filter(x => x % 2 === 0); var evenNumbers = [0, 1, 2, 3, 4, 5, 6, 7].filter(x => x % 2 === 0);
assert(evenNumbers.length === 4); assert(evenNumbers.length === 4);
assert(evenNumbers[0] === 0); assert(evenNumbers[0] === 0);
assert(evenNumbers[1] === 2); assert(evenNumbers[1] === 2);
assert(evenNumbers[2] === 4); assert(evenNumbers[2] === 4);
assert(evenNumbers[3] === 6); assert(evenNumbers[3] === 6);
var fruits = ["Apple", "Banana", "Blueberry", "Grape", "Mango", "Orange", "Peach", "Pineapple", "Raspberry", "Watermelon"]; var fruits = [
const filterItems = (arr, query) => { "Apple",
return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1) "Banana",
}; "Blueberry",
"Grape",
"Mango",
"Orange",
"Peach",
"Pineapple",
"Raspberry",
"Watermelon",
];
const filterItems = (arr, query) => {
return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1);
};
var results; var results;
results = filterItems(fruits, "Berry"); results = filterItems(fruits, "Berry");
assert(results.length === 2); assert(results.length === 2);
assert(results[0] === "Blueberry"); assert(results[0] === "Blueberry");
assert(results[1] === "Raspberry"); assert(results[1] === "Raspberry");
results = filterItems(fruits, "P"); results = filterItems(fruits, "P");
assert(results.length === 5); assert(results.length === 5);
assert(results[0] === "Apple"); assert(results[0] === "Apple");
assert(results[1] === "Grape"); assert(results[1] === "Grape");
assert(results[2] === "Peach"); assert(results[2] === "Peach");
assert(results[3] === "Pineapple"); assert(results[3] === "Pineapple");
assert(results[4] === "Raspberry"); assert(results[4] === "Raspberry");
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,49 +1,54 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.find.length === 1); assert(Array.prototype.find.length === 1);
assertThrowsError(() => { assertThrowsError(
[].find(undefined); () => {
}, { [].find(undefined);
error: TypeError, },
message: "undefined is not a function" {
}); error: TypeError,
message: "undefined is not a function",
}
);
var array = ["hello", "friends", 1, 2, false]; var array = ["hello", "friends", 1, 2, false];
assert(array.find(value => value === "hello") === "hello"); assert(array.find(value => value === "hello") === "hello");
assert(array.find((value, index, arr) => index === 1) === "friends"); assert(array.find((value, index, arr) => index === 1) === "friends");
assert(array.find(value => value == "1") === 1); assert(array.find(value => value == "1") === 1);
assert(array.find(value => value === 1) === 1); assert(array.find(value => value === 1) === 1);
assert(array.find(value => typeof(value) !== "string") === 1); assert(array.find(value => typeof value !== "string") === 1);
assert(array.find(value => typeof(value) === "boolean") === false); assert(array.find(value => typeof value === "boolean") === false);
assert(array.find(value => value > 1) === 2); assert(array.find(value => value > 1) === 2);
assert(array.find(value => value > 1 && value < 3) === 2); assert(array.find(value => value > 1 && value < 3) === 2);
assert(array.find(value => value > 100) === undefined); assert(array.find(value => value > 100) === undefined);
assert([].find(value => value === 1) === undefined); assert([].find(value => value === 1) === undefined);
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; }; var callback = () => {
callbackCalled++;
};
[].find(callback) [].find(callback);
assert(callbackCalled === 0); assert(callbackCalled === 0);
[1, 2, 3].find(callback); [1, 2, 3].find(callback);
assert(callbackCalled === 3); assert(callbackCalled === 3);
callbackCalled = 0; callbackCalled = 0;
[1, , , "foo", , undefined, , ,].find(callback); [1, , , "foo", , undefined, , ,].find(callback);
assert(callbackCalled === 8); assert(callbackCalled === 8);
callbackCalled = 0; callbackCalled = 0;
[1, , , "foo", , undefined, , ,].find(value => { [1, , , "foo", , undefined, , ,].find(value => {
callbackCalled++; callbackCalled++;
return value === undefined; return value === undefined;
}); });
assert(callbackCalled === 2); assert(callbackCalled === 2);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,49 +1,54 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.findIndex.length === 1); assert(Array.prototype.findIndex.length === 1);
assertThrowsError(() => { assertThrowsError(
[].findIndex(undefined); () => {
}, { [].findIndex(undefined);
error: TypeError, },
message: "undefined is not a function" {
}); error: TypeError,
message: "undefined is not a function",
}
);
var array = ["hello", "friends", 1, 2, false]; var array = ["hello", "friends", 1, 2, false];
assert(array.findIndex(value => value === "hello") === 0); assert(array.findIndex(value => value === "hello") === 0);
assert(array.findIndex((value, index, arr) => index === 1) === 1); assert(array.findIndex((value, index, arr) => index === 1) === 1);
assert(array.findIndex(value => value == "1") === 2); assert(array.findIndex(value => value == "1") === 2);
assert(array.findIndex(value => value === 1) === 2); assert(array.findIndex(value => value === 1) === 2);
assert(array.findIndex(value => typeof(value) !== "string") === 2); assert(array.findIndex(value => typeof value !== "string") === 2);
assert(array.findIndex(value => typeof(value) === "boolean") === 4); assert(array.findIndex(value => typeof value === "boolean") === 4);
assert(array.findIndex(value => value > 1) === 3); assert(array.findIndex(value => value > 1) === 3);
assert(array.findIndex(value => value > 1 && value < 3) === 3); assert(array.findIndex(value => value > 1 && value < 3) === 3);
assert(array.findIndex(value => value > 100) === -1); assert(array.findIndex(value => value > 100) === -1);
assert([].findIndex(value => value === 1) === -1); assert([].findIndex(value => value === 1) === -1);
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; }; var callback = () => {
callbackCalled++;
};
[].findIndex(callback) [].findIndex(callback);
assert(callbackCalled === 0); assert(callbackCalled === 0);
[1, 2, 3].findIndex(callback); [1, 2, 3].findIndex(callback);
assert(callbackCalled === 3); assert(callbackCalled === 3);
callbackCalled = 0; callbackCalled = 0;
[1, , , "foo", , undefined, , ,].findIndex(callback); [1, , , "foo", , undefined, , ,].findIndex(callback);
assert(callbackCalled === 8); assert(callbackCalled === 8);
callbackCalled = 0; callbackCalled = 0;
[1, , , "foo", , undefined, , ,].findIndex(value => { [1, , , "foo", , undefined, , ,].findIndex(value => {
callbackCalled++; callbackCalled++;
return value === undefined; return value === undefined;
}); });
assert(callbackCalled === 2); assert(callbackCalled === 2);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,62 +1,70 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.forEach.length === 1); assert(Array.prototype.forEach.length === 1);
assertThrowsError(() => { assertThrowsError(
[].forEach(); () => {
}, { [].forEach();
error: TypeError, },
message: "Array.prototype.forEach() requires at least one argument" {
}); error: TypeError,
message: "Array.prototype.forEach() requires at least one argument",
}
);
assertThrowsError(() => { assertThrowsError(
[].forEach(undefined); () => {
}, { [].forEach(undefined);
error: TypeError, },
message: "undefined is not a function" {
}); error: TypeError,
message: "undefined is not a function",
}
);
var a = [1, 2, 3]; var a = [1, 2, 3];
var o = {}; var o = {};
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; }; var callback = () => {
callbackCalled++;
};
assert([].forEach(callback) === undefined); assert([].forEach(callback) === undefined);
assert(callbackCalled === 0); assert(callbackCalled === 0);
assert(a.forEach(callback) === undefined); assert(a.forEach(callback) === undefined);
assert(callbackCalled === 3); assert(callbackCalled === 3);
callbackCalled = 0; callbackCalled = 0;
a.forEach(function(value, index) { a.forEach(function (value, index) {
assert(value === a[index]); assert(value === a[index]);
assert(index === a[index] - 1); assert(index === a[index] - 1);
}); });
callbackCalled = 0; callbackCalled = 0;
a.forEach(function(_, _, array) { a.forEach(function (_, _, array) {
callbackCalled++; callbackCalled++;
assert(a.length === array.length); assert(a.length === array.length);
a.push("test"); a.push("test");
}); });
assert(callbackCalled === 3); assert(callbackCalled === 3);
assert(a.length === 6); assert(a.length === 6);
callbackCalled = 0; callbackCalled = 0;
a.forEach(function(value, index) { a.forEach(function (value, index) {
callbackCalled++; callbackCalled++;
this[index] = value; this[index] = value;
}, o); }, o);
assert(callbackCalled === 6); assert(callbackCalled === 6);
assert(o[0] === 1); assert(o[0] === 1);
assert(o[1] === 2); assert(o[1] === 2);
assert(o[2] === 3); assert(o[2] === 3);
assert(o[3] === "test"); assert(o[3] === "test");
assert(o[4] === "test"); assert(o[4] === "test");
assert(o[5] === "test"); assert(o[5] === "test");
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,22 +1,22 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.includes.length === 1); assert(Array.prototype.includes.length === 1);
var array = ['hello', 'friends', 1, 2, false]; var array = ["hello", "friends", 1, 2, false];
assert([].includes() === false); assert([].includes() === false);
assert([undefined].includes() === true); assert([undefined].includes() === true);
assert(array.includes('hello') === true); assert(array.includes("hello") === true);
assert(array.includes(1) === true); assert(array.includes(1) === true);
assert(array.includes(1, -3) === true); assert(array.includes(1, -3) === true);
assert(array.includes('serenity') === false); assert(array.includes("serenity") === false);
assert(array.includes(false, -1) === true); assert(array.includes(false, -1) === true);
assert(array.includes(2, -1) === false); assert(array.includes(2, -1) === false);
assert(array.includes(2, -100) === true); assert(array.includes(2, -100) === true);
assert(array.includes('friends', 100) === false); assert(array.includes("friends", 100) === false);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,29 +1,29 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.indexOf.length === 1); assert(Array.prototype.indexOf.length === 1);
var array = ['hello', 'friends', 1, 2, false]; var array = ["hello", "friends", 1, 2, false];
assert(array.indexOf('hello') === 0); assert(array.indexOf("hello") === 0);
assert(array.indexOf('friends') === 1); assert(array.indexOf("friends") === 1);
assert(array.indexOf(false) === 4); assert(array.indexOf(false) === 4);
assert(array.indexOf(false, 2) === 4); assert(array.indexOf(false, 2) === 4);
assert(array.indexOf(false, -2) === 4); assert(array.indexOf(false, -2) === 4);
assert(array.indexOf(1) === 2); assert(array.indexOf(1) === 2);
assert(array.indexOf(1, 1000) === -1); assert(array.indexOf(1, 1000) === -1);
assert(array.indexOf(1, -1000) === 2); assert(array.indexOf(1, -1000) === 2);
assert(array.indexOf('serenity') === -1); assert(array.indexOf("serenity") === -1);
assert(array.indexOf(false, -1) === 4); assert(array.indexOf(false, -1) === 4);
assert(array.indexOf(2, -1) === -1); assert(array.indexOf(2, -1) === -1);
assert(array.indexOf(2, -2) === 3); assert(array.indexOf(2, -2) === 3);
assert([].indexOf('serenity') === -1); assert([].indexOf("serenity") === -1);
assert([].indexOf('serenity', 10) === -1); assert([].indexOf("serenity", 10) === -1);
assert([].indexOf('serenity', -10) === -1); assert([].indexOf("serenity", -10) === -1);
assert([].indexOf() === -1); assert([].indexOf() === -1);
assert([undefined].indexOf() === 0); assert([undefined].indexOf() === 0);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,19 +1,19 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.join.length === 1); assert(Array.prototype.join.length === 1);
assert(["hello", "friends"].join() === "hello,friends"); assert(["hello", "friends"].join() === "hello,friends");
assert(["hello", "friends"].join(" ") === "hello friends"); assert(["hello", "friends"].join(" ") === "hello friends");
assert(["hello", "friends", "foo"].join("~", "#") === "hello~friends~foo"); assert(["hello", "friends", "foo"].join("~", "#") === "hello~friends~foo");
assert([].join() === ""); assert([].join() === "");
assert([null].join() === ""); assert([null].join() === "");
assert([undefined].join() === ""); assert([undefined].join() === "");
assert([undefined, null, ""].join() === ",,"); assert([undefined, null, ""].join() === ",,");
assert([1, null, 2, undefined, 3].join() === "1,,2,,3"); assert([1, null, 2, undefined, 3].join() === "1,,2,,3");
assert(Array(3).join() === ",,"); assert(Array(3).join() === ",,");
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,26 +1,26 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.lastIndexOf.length === 1); assert(Array.prototype.lastIndexOf.length === 1);
var array = [1, 2, 3, 1, "hello"]; var array = [1, 2, 3, 1, "hello"];
assert(array.lastIndexOf("hello") === 4); assert(array.lastIndexOf("hello") === 4);
assert(array.lastIndexOf("hello", 1000) === 4); assert(array.lastIndexOf("hello", 1000) === 4);
assert(array.lastIndexOf(1) === 3); assert(array.lastIndexOf(1) === 3);
assert(array.lastIndexOf(1, -1) === 3); assert(array.lastIndexOf(1, -1) === 3);
assert(array.lastIndexOf(1, -2) === 3); assert(array.lastIndexOf(1, -2) === 3);
assert(array.lastIndexOf(2) === 1); assert(array.lastIndexOf(2) === 1);
assert(array.lastIndexOf(2, -3) === 1); assert(array.lastIndexOf(2, -3) === 1);
assert(array.lastIndexOf(2, -4) === 1); assert(array.lastIndexOf(2, -4) === 1);
assert([].lastIndexOf('hello') === -1); assert([].lastIndexOf("hello") === -1);
assert([].lastIndexOf('hello', 10) === -1); assert([].lastIndexOf("hello", 10) === -1);
assert([].lastIndexOf('hello', -10) === -1); assert([].lastIndexOf("hello", -10) === -1);
assert([].lastIndexOf() === -1); assert([].lastIndexOf() === -1);
assert([undefined].lastIndexOf() === 0); assert([undefined].lastIndexOf() === 0);
assert([undefined, undefined, undefined].lastIndexOf() === 2); assert([undefined, undefined, undefined].lastIndexOf() === 2);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,53 +1,63 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.map.length === 1); assert(Array.prototype.map.length === 1);
assertThrowsError(() => { assertThrowsError(
[].map(); () => {
}, { [].map();
error: TypeError, },
message: "Array.prototype.map() requires at least one argument" {
}); error: TypeError,
message: "Array.prototype.map() requires at least one argument",
}
);
assertThrowsError(() => { assertThrowsError(
[].map(undefined); () => {
}, { [].map(undefined);
error: TypeError, },
message: "undefined is not a function" {
}); error: TypeError,
message: "undefined is not a function",
}
);
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; }; var callback = () => {
callbackCalled++;
};
assert([].map(callback).length === 0); assert([].map(callback).length === 0);
assert(callbackCalled === 0); assert(callbackCalled === 0);
assert([1, 2, 3].map(callback).length === 3); assert([1, 2, 3].map(callback).length === 3);
assert(callbackCalled === 3); assert(callbackCalled === 3);
callbackCalled = 0; callbackCalled = 0;
assert([1, , , "foo", , undefined, , ,].map(callback).length === 8); assert([1, , , "foo", , undefined, , ,].map(callback).length === 8);
assert(callbackCalled === 3); assert(callbackCalled === 3);
var results = [undefined, null, true, "foo", 42, {}].map((value, index) => "" + index + " -> " + value); var results = [undefined, null, true, "foo", 42, {}].map(
assert(results.length === 6); (value, index) => "" + index + " -> " + value
assert(results[0] === "0 -> undefined"); );
assert(results[1] === "1 -> null"); assert(results.length === 6);
assert(results[2] === "2 -> true"); assert(results[0] === "0 -> undefined");
assert(results[3] === "3 -> foo"); assert(results[1] === "1 -> null");
assert(results[4] === "4 -> 42"); assert(results[2] === "2 -> true");
assert(results[5] === "5 -> [object Object]"); assert(results[3] === "3 -> foo");
assert(results[4] === "4 -> 42");
assert(results[5] === "5 -> [object Object]");
var squaredNumbers = [0, 1, 2, 3, 4].map(x => x ** 2); var squaredNumbers = [0, 1, 2, 3, 4].map(x => x ** 2);
assert(squaredNumbers.length === 5); assert(squaredNumbers.length === 5);
assert(squaredNumbers[0] === 0); assert(squaredNumbers[0] === 0);
assert(squaredNumbers[1] === 1); assert(squaredNumbers[1] === 1);
assert(squaredNumbers[2] === 4); assert(squaredNumbers[2] === 4);
assert(squaredNumbers[3] === 9); assert(squaredNumbers[3] === 9);
assert(squaredNumbers[4] === 16); assert(squaredNumbers[4] === 16);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,21 +1,21 @@
load("test-common.js"); load("test-common.js");
try { try {
var a = [1, 2, 3]; var a = [1, 2, 3];
var value = a.pop(); var value = a.pop();
assert(value === 3); assert(value === 3);
assert(a.length === 2); assert(a.length === 2);
assert(a[0] === 1); assert(a[0] === 1);
assert(a[1] === 2); assert(a[1] === 2);
var a = []; var a = [];
var value = a.pop(); var value = a.pop();
assert(value === undefined); assert(value === undefined);
assert(a.length === 0); assert(a.length === 0);
assert([,].pop() === undefined); assert([,].pop() === undefined);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,30 +1,30 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.push.length === 1); assert(Array.prototype.push.length === 1);
var a = ["hello"]; var a = ["hello"];
var length = a.push(); var length = a.push();
assert(length === 1); assert(length === 1);
assert(a.length === 1); assert(a.length === 1);
assert(a[0] === "hello"); assert(a[0] === "hello");
length = a.push("friends"); length = a.push("friends");
assert(length === 2); assert(length === 2);
assert(a.length === 2); assert(a.length === 2);
assert(a[0] === "hello"); assert(a[0] === "hello");
assert(a[1] === "friends"); assert(a[1] === "friends");
length = a.push(1, 2, 3); length = a.push(1, 2, 3);
assert(length === 5); assert(length === 5);
assert(a.length === 5); assert(a.length === 5);
assert(a[0] === "hello"); assert(a[0] === "hello");
assert(a[1] === "friends"); assert(a[1] === "friends");
assert(a[2] === 1); assert(a[2] === 1);
assert(a[3] === 2); assert(a[3] === 2);
assert(a[4] === 3); assert(a[4] === 3);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,104 +1,132 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.reduce.length === 1); assert(Array.prototype.reduce.length === 1);
assertThrowsError(() => { assertThrowsError(
[1].reduce(); () => {
}, { [1].reduce();
error: TypeError, },
message: "Array.prototype.reduce() requires at least one argument" {
}); error: TypeError,
message: "Array.prototype.reduce() requires at least one argument",
}
);
assertThrowsError(() => { assertThrowsError(
[1].reduce(undefined); () => {
}, { [1].reduce(undefined);
error: TypeError, },
message: "undefined is not a function" {
}); error: TypeError,
message: "undefined is not a function",
}
);
assertThrowsError(() => { assertThrowsError(
[].reduce((a, x) => x); () => {
}, { [].reduce((a, x) => x);
error: TypeError, },
message: "Reduce of empty array with no initial value" {
}); error: TypeError,
message: "Reduce of empty array with no initial value",
}
);
assertThrowsError(() => { assertThrowsError(
[, ,].reduce((a, x) => x); () => {
}, { [, ,].reduce((a, x) => x);
error: TypeError, },
message: "Reduce of empty array with no initial value" {
}); error: TypeError,
message: "Reduce of empty array with no initial value",
}
);
[1, 2].reduce(function () { assert(this === undefined) }); [1, 2].reduce(function () {
assert(this === undefined);
});
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; return true }; var callback = () => {
callbackCalled++;
return true;
};
assert([1].reduce(callback) === 1); assert([1].reduce(callback) === 1);
assert(callbackCalled === 0); assert(callbackCalled === 0);
assert([, 1].reduce(callback) === 1); assert([, 1].reduce(callback) === 1);
assert(callbackCalled === 0); assert(callbackCalled === 0);
callbackCalled = 0; callbackCalled = 0;
assert([1, 2, 3].reduce(callback) === true); assert([1, 2, 3].reduce(callback) === true);
assert(callbackCalled === 2); assert(callbackCalled === 2);
callbackCalled = 0; callbackCalled = 0;
assert([, , 1, 2, 3].reduce(callback) === true); assert([, , 1, 2, 3].reduce(callback) === true);
assert(callbackCalled === 2); assert(callbackCalled === 2);
callbackCalled = 0; callbackCalled = 0;
assert([1, , , 10, , 100, , ,].reduce(callback) === true); assert([1, , , 10, , 100, , ,].reduce(callback) === true);
assert(callbackCalled === 2); assert(callbackCalled === 2);
var constantlySad = () => ":^("; var constantlySad = () => ":^(";
var result = [].reduce(constantlySad, ":^)"); var result = [].reduce(constantlySad, ":^)");
assert(result === ":^)"); assert(result === ":^)");
result = [":^0"].reduce(constantlySad, ":^)"); result = [":^0"].reduce(constantlySad, ":^)");
assert(result === ":^("); assert(result === ":^(");
result = [":^0"].reduce(constantlySad); result = [":^0"].reduce(constantlySad);
assert(result === ":^0"); assert(result === ":^0");
result = [5, 4, 3, 2, 1].reduce((accum, elem) => accum + elem); result = [5, 4, 3, 2, 1].reduce((accum, elem) => accum + elem);
assert(result === 15); assert(result === 15);
result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100); result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100);
assert(result === 121); assert(result === 121);
result = [6, 5, 4, 3, 2, 1].reduce((accum, elem) => { return accum + elem }, 100); result = [6, 5, 4, 3, 2, 1].reduce((accum, elem) => {
assert(result === 121); return accum + elem;
}, 100);
assert(result === 121);
var indexes = []; var indexes = [];
result = ["foo", 1, true].reduce((a, v, i) => { indexes.push(i) }); result = ["foo", 1, true].reduce((a, v, i) => {
assert(result === undefined); indexes.push(i);
assert(indexes.length === 2); });
assert(indexes[0] === 1); assert(result === undefined);
assert(indexes[1] === 2); assert(indexes.length === 2);
assert(indexes[0] === 1);
assert(indexes[1] === 2);
indexes = []; indexes = [];
result = ["foo", 1, true].reduce((a, v, i) => { indexes.push(i) }, "foo"); result = ["foo", 1, true].reduce((a, v, i) => {
assert(result === undefined); indexes.push(i);
assert(indexes.length === 3); }, "foo");
assert(indexes[0] === 0); assert(result === undefined);
assert(indexes[1] === 1); assert(indexes.length === 3);
assert(indexes[2] === 2); assert(indexes[0] === 0);
assert(indexes[1] === 1);
assert(indexes[2] === 2);
var mutable = { prop: 0 }; var mutable = { prop: 0 };
result = ["foo", 1, true].reduce((a, v) => { a.prop = v; return a; }, mutable); result = ["foo", 1, true].reduce((a, v) => {
assert(result === mutable); a.prop = v;
assert(result.prop === true); return a;
}, mutable);
assert(result === mutable);
assert(result.prop === true);
var a1 = [1, 2]; var a1 = [1, 2];
var a2 = null; var a2 = null;
a1.reduce((a, v, i, t) => { a2 = t }); a1.reduce((a, v, i, t) => {
assert(a1 === a2); a2 = t;
});
assert(a1 === a2);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,31 +1,31 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.reverse.length === 0); assert(Array.prototype.reverse.length === 0);
var array = [1, 2, 3]; var array = [1, 2, 3];
assert(array[0] === 1);
assert(array[1] === 2);
assert(array[2] === 3);
array.reverse();
assert(array[0] === 3);
assert(array[1] === 2);
assert(array[2] === 1);
var array_ref = array.reverse();
assert(array_ref[0] === 1);
assert(array_ref[1] === 2);
assert(array_ref[2] === 3);
assert(array[0] === 1); assert(array[0] === 1);
assert(array[1] === 2); assert(array[1] === 2);
assert(array[2] === 3); assert(array[2] === 3);
console.log("PASS"); array.reverse();
assert(array[0] === 3);
assert(array[1] === 2);
assert(array[2] === 1);
var array_ref = array.reverse();
assert(array_ref[0] === 1);
assert(array_ref[1] === 2);
assert(array_ref[2] === 3);
assert(array[0] === 1);
assert(array[1] === 2);
assert(array[2] === 3);
console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,21 +1,21 @@
load("test-common.js"); load("test-common.js");
try { try {
var a = [1, 2, 3]; var a = [1, 2, 3];
var value = a.shift(); var value = a.shift();
assert(value === 1); assert(value === 1);
assert(a.length === 2); assert(a.length === 2);
assert(a[0] === 2); assert(a[0] === 2);
assert(a[1] === 3); assert(a[1] === 3);
var a = []; var a = [];
var value = a.shift(); var value = a.shift();
assert(value === undefined); assert(value === undefined);
assert(a.length === 0); assert(a.length === 0);
assert([,].shift() === undefined); assert([,].shift() === undefined);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,53 +1,53 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.slice.length === 2); assert(Array.prototype.slice.length === 2);
var array = ["hello", "friends", "serenity", 1]; var array = ["hello", "friends", "serenity", 1];
var array_slice = array.slice(); var array_slice = array.slice();
assert(array_slice.length === array.length); assert(array_slice.length === array.length);
assert(array_slice.length === 4); assert(array_slice.length === 4);
assert(array_slice[0] === "hello"); assert(array_slice[0] === "hello");
assert(array_slice[1] === "friends"); assert(array_slice[1] === "friends");
assert(array_slice[2] === "serenity"); assert(array_slice[2] === "serenity");
assert(array_slice[3] === 1); assert(array_slice[3] === 1);
array_slice = array.slice(1) array_slice = array.slice(1);
assert(array_slice.length === 3); assert(array_slice.length === 3);
assert(array_slice[0] === "friends"); assert(array_slice[0] === "friends");
assert(array_slice[1] === "serenity"); assert(array_slice[1] === "serenity");
assert(array_slice[2] === 1); assert(array_slice[2] === 1);
array_slice = array.slice(0, 2); array_slice = array.slice(0, 2);
assert(array_slice.length === 2); assert(array_slice.length === 2);
assert(array_slice[0] === "hello"); assert(array_slice[0] === "hello");
assert(array_slice[1] === "friends"); assert(array_slice[1] === "friends");
array_slice = array.slice(-1); array_slice = array.slice(-1);
assert(array_slice.length === 1); assert(array_slice.length === 1);
assert(array_slice[0] === 1); assert(array_slice[0] === 1);
array_slice = array.slice(1, 1); array_slice = array.slice(1, 1);
assert(array_slice.length === 0); assert(array_slice.length === 0);
array_slice = array.slice(1, -1);
assert(array_slice.length === 2);
assert(array_slice[0] === "friends");
assert(array_slice[1] === "serenity");
array_slice = array.slice(2, -1);
assert(array_slice.length === 1);
assert(array_slice[0] === "serenity");
array_slice = array.slice(0, 100); array_slice = array.slice(1, -1);
assert(array_slice.length === 4); assert(array_slice.length === 2);
assert(array_slice[0] === "hello"); assert(array_slice[0] === "friends");
assert(array_slice[1] === "friends"); assert(array_slice[1] === "serenity");
assert(array_slice[2] === "serenity");
assert(array_slice[3] === 1);
console.log("PASS"); array_slice = array.slice(2, -1);
assert(array_slice.length === 1);
assert(array_slice[0] === "serenity");
array_slice = array.slice(0, 100);
assert(array_slice.length === 4);
assert(array_slice[0] === "hello");
assert(array_slice[1] === "friends");
assert(array_slice[2] === "serenity");
assert(array_slice[3] === 1);
console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,34 +1,37 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.some.length === 1); assert(Array.prototype.some.length === 1);
assertThrowsError(() => { assertThrowsError(
[].some(undefined); () => {
}, { [].some(undefined);
error: TypeError, },
message: "undefined is not a function" {
}); error: TypeError,
message: "undefined is not a function",
}
);
var array = ["hello", "friends", 1, 2, false, -42, { name: "serenityos"}]; var array = ["hello", "friends", 1, 2, false, -42, { name: "serenityos" }];
assert(array.some(value => value === "hello") === true); assert(array.some(value => value === "hello") === true);
assert(array.some(value => value === "serenity") === false); assert(array.some(value => value === "serenity") === false);
assert(array.some((value, index, arr) => index === 1) === true); assert(array.some((value, index, arr) => index === 1) === true);
assert(array.some(value => value == "1") === true); assert(array.some(value => value == "1") === true);
assert(array.some(value => value === 1) === true); assert(array.some(value => value === 1) === true);
assert(array.some(value => value === 13) === false); assert(array.some(value => value === 13) === false);
assert(array.some(value => typeof(value) !== "string") === true); assert(array.some(value => typeof value !== "string") === true);
assert(array.some(value => typeof(value) === "boolean") === true); assert(array.some(value => typeof value === "boolean") === true);
assert(array.some(value => value > 1) === true); assert(array.some(value => value > 1) === true);
assert(array.some(value => value > 1 && value < 3) === true); assert(array.some(value => value > 1 && value < 3) === true);
assert(array.some(value => value > 100) === false); assert(array.some(value => value > 100) === false);
assert(array.some(value => value < 0) === true); assert(array.some(value => value < 0) === true);
assert(array.some(value => array.pop()) === true); assert(array.some(value => array.pop()) === true);
assert(["", "hello", "friends", "serenity"].some(value => value.length === 0) === true); assert(["", "hello", "friends", "serenity"].some(value => value.length === 0) === true);
assert([].some(value => value === 1) === false); assert([].some(value => value === 1) === false);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,87 +1,87 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.splice.length === 2); assert(Array.prototype.splice.length === 2);
var array = ["hello", "friends", "serenity", 1, 2]; var array = ["hello", "friends", "serenity", 1, 2];
var removed = array.splice(3); var removed = array.splice(3);
assert(array.length === 3); assert(array.length === 3);
assert(array[0] === "hello"); assert(array[0] === "hello");
assert(array[1] === "friends"); assert(array[1] === "friends");
assert(array[2] === "serenity"); assert(array[2] === "serenity");
assert(removed.length === 2); assert(removed.length === 2);
assert(removed[0] === 1); assert(removed[0] === 1);
assert(removed[1] === 2); assert(removed[1] === 2);
array = ["hello", "friends", "serenity", 1, 2]; array = ["hello", "friends", "serenity", 1, 2];
removed = array.splice(-2); removed = array.splice(-2);
assert(array.length === 3); assert(array.length === 3);
assert(array[0] === "hello"); assert(array[0] === "hello");
assert(array[1] === "friends"); assert(array[1] === "friends");
assert(array[2] === "serenity"); assert(array[2] === "serenity");
assert(removed.length === 2); assert(removed.length === 2);
assert(removed[0] === 1); assert(removed[0] === 1);
assert(removed[1] === 2); assert(removed[1] === 2);
array = ["hello", "friends", "serenity", 1, 2]; array = ["hello", "friends", "serenity", 1, 2];
removed = array.splice(-2, 1); removed = array.splice(-2, 1);
assert(array.length === 4); assert(array.length === 4);
assert(array[0] === "hello"); assert(array[0] === "hello");
assert(array[1] === "friends"); assert(array[1] === "friends");
assert(array[2] === "serenity"); assert(array[2] === "serenity");
assert(array[3] === 2); assert(array[3] === 2);
assert(removed.length === 1); assert(removed.length === 1);
assert(removed[0] === 1); assert(removed[0] === 1);
array = ["serenity"]; array = ["serenity"];
removed = array.splice(0, 0, "hello", "friends"); removed = array.splice(0, 0, "hello", "friends");
assert(array.length === 3); assert(array.length === 3);
assert(array[0] === "hello"); assert(array[0] === "hello");
assert(array[1] === "friends"); assert(array[1] === "friends");
assert(array[2] === "serenity"); assert(array[2] === "serenity");
assert(removed.length === 0); assert(removed.length === 0);
array = ["goodbye", "friends", "serenity"]; array = ["goodbye", "friends", "serenity"];
removed = array.splice(0, 1, "hello"); removed = array.splice(0, 1, "hello");
assert(array.length === 3); assert(array.length === 3);
assert(array[0] === "hello"); assert(array[0] === "hello");
assert(array[1] === "friends"); assert(array[1] === "friends");
assert(array[2] === "serenity"); assert(array[2] === "serenity");
assert(removed.length === 1); assert(removed.length === 1);
assert(removed[0] === "goodbye"); assert(removed[0] === "goodbye");
array = ["foo", "bar", "baz"]; array = ["foo", "bar", "baz"];
removed = array.splice(); removed = array.splice();
assert(array.length === 3); assert(array.length === 3);
assert(array[0] === "foo"); assert(array[0] === "foo");
assert(array[1] === "bar"); assert(array[1] === "bar");
assert(array[2] === "baz"); assert(array[2] === "baz");
assert(removed.length === 0); assert(removed.length === 0);
removed = array.splice(0, 123); removed = array.splice(0, 123);
assert(array.length === 0); assert(array.length === 0);
assert(removed.length === 3); assert(removed.length === 3);
assert(removed[0] === "foo"); assert(removed[0] === "foo");
assert(removed[1] === "bar"); assert(removed[1] === "bar");
assert(removed[2] === "baz"); assert(removed[2] === "baz");
array = ["foo", "bar", "baz"]; array = ["foo", "bar", "baz"];
removed = array.splice(123, 123); removed = array.splice(123, 123);
assert(array.length === 3); assert(array.length === 3);
assert(array[0] === "foo"); assert(array[0] === "foo");
assert(array[1] === "bar"); assert(array[1] === "bar");
assert(array[2] === "baz"); assert(array[2] === "baz");
assert(removed.length === 0); assert(removed.length === 0);
array = ["foo", "bar", "baz"]; array = ["foo", "bar", "baz"];
removed = array.splice(-123, 123); removed = array.splice(-123, 123);
assert(array.length === 0); assert(array.length === 0);
assert(removed.length === 3); assert(removed.length === 3);
assert(removed[0] === "foo"); assert(removed[0] === "foo");
assert(removed[1] === "bar"); assert(removed[1] === "bar");
assert(removed[2] === "baz"); assert(removed[2] === "baz");
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,24 +1,24 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.toLocaleString.length === 0); assert(Array.prototype.toLocaleString.length === 0);
assert([].toLocaleString() === ""); assert([].toLocaleString() === "");
assert(["foo"].toLocaleString() === "foo"); assert(["foo"].toLocaleString() === "foo");
assert(["foo", "bar"].toLocaleString() === "foo,bar"); assert(["foo", "bar"].toLocaleString() === "foo,bar");
assert(["foo", undefined, "bar", null, "baz"].toLocaleString() === "foo,,bar,,baz"); assert(["foo", undefined, "bar", null, "baz"].toLocaleString() === "foo,,bar,,baz");
var toStringCalled = 0; var toStringCalled = 0;
var o = { var o = {
toString: () => { toString: () => {
toStringCalled++; toStringCalled++;
return "o"; return "o";
} },
}; };
assert([o, undefined, o, null, o].toLocaleString() === "o,,o,,o"); assert([o, undefined, o, null, o].toLocaleString() === "o,,o,,o");
assert(toStringCalled === 3); assert(toStringCalled === 3);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,22 +1,22 @@
load("test-common.js"); load("test-common.js");
try { try {
var a = [1, 2, 3]; var a = [1, 2, 3];
assert(a.toString() === '1,2,3'); assert(a.toString() === "1,2,3");
assert([].toString() === ''); assert([].toString() === "");
assert([5].toString() === '5'); assert([5].toString() === "5");
assert("rgb(" + [10, 11, 12] + ")" === "rgb(10,11,12)"); assert("rgb(" + [10, 11, 12] + ")" === "rgb(10,11,12)");
assert([undefined, null].toString() === ","); assert([undefined, null].toString() === ",");
a = new Array(5); a = new Array(5);
assert(a.toString() === ",,,,"); assert(a.toString() === ",,,,");
a[2] = "foo"; a[2] = "foo";
a[4] = "bar"; a[4] = "bar";
assert(a.toString() === ",,foo,,bar"); assert(a.toString() === ",,foo,,bar");
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,30 +1,30 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.unshift.length === 1); assert(Array.prototype.unshift.length === 1);
var a = ["hello"]; var a = ["hello"];
var length = a.unshift(); var length = a.unshift();
assert(length === 1); assert(length === 1);
assert(a.length === 1); assert(a.length === 1);
assert(a[0] === "hello"); assert(a[0] === "hello");
length = a.unshift("friends"); length = a.unshift("friends");
assert(length === 2); assert(length === 2);
assert(a.length === 2); assert(a.length === 2);
assert(a[0] === "friends"); assert(a[0] === "friends");
assert(a[1] === "hello"); assert(a[1] === "hello");
length = a.unshift(1, 2, 3); length = a.unshift(1, 2, 3);
assert(length === 5); assert(length === 5);
assert(a.length === 5); assert(a.length === 5);
assert(a[0] === 1); assert(a[0] === 1);
assert(a[1] === 2); assert(a[1] === 2);
assert(a[2] === 3); assert(a[2] === 3);
assert(a[3] === "friends"); assert(a[3] === "friends");
assert(a[4] === "hello"); assert(a[4] === "hello");
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,63 +1,63 @@
load("test-common.js"); load("test-common.js");
try { try {
var a = [1, 2, 3]; var a = [1, 2, 3];
assert(typeof a === "object"); assert(typeof a === "object");
assert(a.length === 3); assert(a.length === 3);
assert(a[0] === 1); assert(a[0] === 1);
assert(a[1] === 2); assert(a[1] === 2);
assert(a[2] === 3); assert(a[2] === 3);
a[1] = 5; a[1] = 5;
assert(a[1] === 5); assert(a[1] === 5);
assert(a.length === 3); assert(a.length === 3);
a.push(7); a.push(7);
assert(a[3] === 7); assert(a[3] === 7);
assert(a.length === 4); assert(a.length === 4);
a = [,]; a = [,];
assert(a.length === 1); assert(a.length === 1);
assert(a.toString() === ""); assert(a.toString() === "");
assert(a[0] === undefined); assert(a[0] === undefined);
a = [,,,,]; a = [, , , ,];
assert(a.length === 4); assert(a.length === 4);
assert(a.toString() === ",,,"); assert(a.toString() === ",,,");
assert(a[0] === undefined); assert(a[0] === undefined);
assert(a[1] === undefined); assert(a[1] === undefined);
assert(a[2] === undefined); assert(a[2] === undefined);
assert(a[3] === undefined); assert(a[3] === undefined);
a = [1,,2,,,3,]; a = [1, , 2, , , 3];
assert(a.length === 6); assert(a.length === 6);
assert(a.toString() === "1,,2,,,3"); assert(a.toString() === "1,,2,,,3");
assert(a[0] === 1); assert(a[0] === 1);
assert(a[1] === undefined); assert(a[1] === undefined);
assert(a[2] === 2); assert(a[2] === 2);
assert(a[3] === undefined); assert(a[3] === undefined);
assert(a[4] === undefined); assert(a[4] === undefined);
assert(a[5] === 3); assert(a[5] === 3);
a = [1,,2,,,3,]; a = [1, , 2, , , 3];
Object.defineProperty(a, 1, { Object.defineProperty(a, 1, {
get() { get() {
return this.secret_prop; return this.secret_prop;
}, },
set(value) { set(value) {
this.secret_prop = value; this.secret_prop = value;
}, },
}); });
assert(a.length === 6); assert(a.length === 6);
assert(a.toString() === "1,,2,,,3"); assert(a.toString() === "1,,2,,,3");
assert(a.secret_prop === undefined); assert(a.secret_prop === undefined);
a[1] = 20; a[1] = 20;
assert(a.length === 6); assert(a.length === 6);
assert(a.toString() === "1,20,2,,,3"); assert(a.toString() === "1,20,2,,,3");
assert(a.secret_prop === 20); assert(a.secret_prop === 20);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,48 +1,51 @@
load("test-common.js"); load("test-common.js");
try { try {
var a = [1, 2, 3]; var a = [1, 2, 3];
assert(a.length === 3); assert(a.length === 3);
assert(a[0] === 1); assert(a[0] === 1);
assert(a[1] === 2); assert(a[1] === 2);
assert(a[2] === 3); assert(a[2] === 3);
a.length = 5; a.length = 5;
assert(a.length === 5); assert(a.length === 5);
assert(a[0] === 1); assert(a[0] === 1);
assert(a[1] === 2); assert(a[1] === 2);
assert(a[2] === 3); assert(a[2] === 3);
assert(a[3] === undefined); assert(a[3] === undefined);
assert(a[4] === undefined); assert(a[4] === undefined);
a.length = 1; a.length = 1;
assert(a.length === 1);
assert(a[0] === 1);
a.length = 0;
assert(a.length === 0);
a.length = "42";
assert(a.length === 42);
a.length = [];
assert(a.length === 0);
a.length = true;
assert(a.length === 1);
[undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => {
assertThrowsError(
() => {
a.length = value;
},
{
error: RangeError,
message: "Invalid array length",
}
);
assert(a.length === 1); assert(a.length === 1);
assert(a[0] === 1); });
a.length = 0; console.log("PASS");
assert(a.length === 0);
a.length = "42";
assert(a.length === 42);
a.length = [];
assert(a.length === 0);
a.length = true;
assert(a.length === 1);
[undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => {
assertThrowsError(() => {
a.length = value;
}, {
error: RangeError,
message: "Invalid array length"
});
assert(a.length === 1);
});
console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,25 +1,25 @@
load("test-common.js"); load("test-common.js");
try { try {
var a, callbackCalled; var a, callbackCalled;
callbackCalled = 0; callbackCalled = 0;
a = [1, 2, 3, 4, 5]; a = [1, 2, 3, 4, 5];
a.find(() => { a.find(() => {
callbackCalled++; callbackCalled++;
a.pop(); a.pop();
}); });
assert(callbackCalled === 5); assert(callbackCalled === 5);
callbackCalled = 0; callbackCalled = 0;
a = [1, 2, 3, 4, 5]; a = [1, 2, 3, 4, 5];
a.findIndex(() => { a.findIndex(() => {
callbackCalled++; callbackCalled++;
a.pop(); a.pop();
}); });
assert(callbackCalled === 5); assert(callbackCalled === 5);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,44 +1,45 @@
load("test-common.js"); load("test-common.js");
function testArray(arr) { function testArray(arr) {
return arr.length === 4 && return arr.length === 4 && arr[0] === 0 && arr[1] === 1 && arr[2] === 2 && arr[3] === 3;
arr[0] === 0 &&
arr[1] === 1 &&
arr[2] === 2 &&
arr[3] === 3;
} }
try { try {
let arr = [0, ...[1, 2], 3]; let arr = [0, ...[1, 2], 3];
assert(testArray(arr)); assert(testArray(arr));
let a = [1, 2]; let a = [1, 2];
arr = [0, ...a, 3]; arr = [0, ...a, 3];
assert(testArray(arr)); assert(testArray(arr));
let obj = { a: [1, 2] }; let obj = { a: [1, 2] };
arr = [0, ...obj.a, 3]; arr = [0, ...obj.a, 3];
assert(testArray(arr)); assert(testArray(arr));
arr = [...[], ...[...[0, 1, 2]], 3]; arr = [...[], ...[...[0, 1, 2]], 3];
assert(testArray(arr)); assert(testArray(arr));
assertThrowsError(() => { assertThrowsError(
[...1]; () => {
}, { [...1];
error: TypeError, },
message: "1 is not iterable", {
}); error: TypeError,
message: "1 is not iterable",
}
);
assertThrowsError(
() => {
[...{}];
},
{
error: TypeError,
message: "[object Object] is not iterable",
}
);
assertThrowsError(() => { console.log("PASS");
[...{}];
}, {
error: TypeError,
message: "[object Object] is not iterable",
});
console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,9 +1,9 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(BigInt.asIntN.length === 2); assert(BigInt.asIntN.length === 2);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,9 +1,9 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(BigInt.asUintN.length === 2); assert(BigInt.asUintN.length === 2);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,62 +1,78 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(BigInt.length === 1); assert(BigInt.length === 1);
assert(BigInt.name === "BigInt"); assert(BigInt.name === "BigInt");
assert(BigInt(0) === 0n); assert(BigInt(0) === 0n);
assert(BigInt(1) === 1n); assert(BigInt(1) === 1n);
assert(BigInt(+1) === 1n); assert(BigInt(+1) === 1n);
assert(BigInt(-1) === -1n); assert(BigInt(-1) === -1n);
assert(BigInt("") === 0n); assert(BigInt("") === 0n);
assert(BigInt("0") === 0n); assert(BigInt("0") === 0n);
assert(BigInt("1") === 1n); assert(BigInt("1") === 1n);
assert(BigInt("+1") === 1n); assert(BigInt("+1") === 1n);
assert(BigInt("-1") === -1n); assert(BigInt("-1") === -1n);
assert(BigInt("-1") === -1n); assert(BigInt("-1") === -1n);
assert(BigInt([]) === 0n); assert(BigInt([]) === 0n);
assert(BigInt("42") === 42n); assert(BigInt("42") === 42n);
assert(BigInt(" \n 00100 \n ") === 100n); assert(BigInt(" \n 00100 \n ") === 100n);
assert(BigInt(123n) === 123n); assert(BigInt(123n) === 123n);
assert(BigInt("3323214327642987348732109829832143298746432437532197321") === 3323214327642987348732109829832143298746432437532197321n); assert(
BigInt("3323214327642987348732109829832143298746432437532197321") ===
3323214327642987348732109829832143298746432437532197321n
);
assertThrowsError(() => { assertThrowsError(
new BigInt(); () => {
}, { new BigInt();
},
{
error: TypeError,
message: "BigInt is not a constructor",
}
);
[null, undefined, Symbol()].forEach(value => {
assertThrowsError(
() => {
BigInt(value);
},
{
error: TypeError, error: TypeError,
message: "BigInt is not a constructor" message:
}); typeof value === "symbol"
? "Cannot convert symbol to BigInt"
: `Cannot convert ${value} to BigInt`,
}
);
});
[null, undefined, Symbol()].forEach(value => { ["foo", "123n", "1+1", {}, function () {}].forEach(value => {
assertThrowsError(() => { assertThrowsError(
BigInt(value); () => {
}, { BigInt(value);
error: TypeError, },
message: typeof value === "symbol" {
? "Cannot convert symbol to BigInt" error: SyntaxError,
: `Cannot convert ${value} to BigInt` message: `Invalid value for BigInt: ${value}`,
}); }
}); );
});
["foo", "123n", "1+1", {}, function () { }].forEach(value => { [1.23, Infinity, -Infinity, NaN].forEach(value => {
assertThrowsError(() => { assertThrowsError(
BigInt(value); () => {
}, { BigInt(value);
error: SyntaxError, },
message: `Invalid value for BigInt: ${value}` {
}); error: RangeError,
}); message: "BigInt argument must be an integer",
}
);
});
[1.23, Infinity, -Infinity, NaN].forEach(value => { console.log("PASS");
assertThrowsError(() => {
BigInt(value);
}, {
error: RangeError,
message: "BigInt argument must be an integer"
});
});
console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,18 +1,21 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(BigInt.prototype.toLocaleString.length === 0); assert(BigInt.prototype.toLocaleString.length === 0);
assertThrowsError(() => { assertThrowsError(
BigInt.prototype.toLocaleString.call("foo"); () => {
}, { BigInt.prototype.toLocaleString.call("foo");
error: TypeError, },
message: "Not a BigInt object" {
}); error: TypeError,
message: "Not a BigInt object",
assert(BigInt(123).toLocaleString() === "123"); }
);
console.log("PASS"); assert(BigInt(123).toLocaleString() === "123");
console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,18 +1,21 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(BigInt.prototype.toString.length === 0); assert(BigInt.prototype.toString.length === 0);
assertThrowsError(() => { assertThrowsError(
BigInt.prototype.toString.call("foo"); () => {
}, { BigInt.prototype.toString.call("foo");
error: TypeError, },
message: "Not a BigInt object" {
}); error: TypeError,
message: "Not a BigInt object",
assert(BigInt(123).toString() === "123"); }
);
console.log("PASS"); assert(BigInt(123).toString() === "123");
console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,20 +1,23 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(BigInt.prototype.valueOf.length === 0); assert(BigInt.prototype.valueOf.length === 0);
assertThrowsError(() => { assertThrowsError(
BigInt.prototype.valueOf.call("foo"); () => {
}, { BigInt.prototype.valueOf.call("foo");
error: TypeError, },
message: "Not a BigInt object" {
}); error: TypeError,
message: "Not a BigInt object",
}
);
assert(typeof BigInt(123).valueOf() === "bigint"); assert(typeof BigInt(123).valueOf() === "bigint");
// FIXME: Uncomment once we support Object() with argument // FIXME: Uncomment once we support Object() with argument
// assert(typeof Object(123n).valueOf() === "bigint"); // assert(typeof Object(123n).valueOf() === "bigint");
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,68 +1,74 @@
load("test-common.js"); load("test-common.js");
try { try {
var bigint = 123n; var bigint = 123n;
assert(typeof bigint === "bigint"); assert(typeof bigint === "bigint");
assert(-bigint === -123n); assert(-bigint === -123n);
assert("" + bigint === "123") assert("" + bigint === "123");
assertThrowsError(() => { assertThrowsError(
+bigint; () => {
}, { +bigint;
error: TypeError, },
message: "Cannot convert BigInt to number" {
}); error: TypeError,
message: "Cannot convert BigInt to number",
}
);
assert(12n + 34n === 46n); assert(12n + 34n === 46n);
assert(12n - 34n === -22n); assert(12n - 34n === -22n);
assert(8n * 12n === 96n); assert(8n * 12n === 96n);
assert(123n / 10n === 12n); assert(123n / 10n === 12n);
assert(2n ** 3n === 8n); assert(2n ** 3n === 8n);
assert(5n % 3n === 2n); assert(5n % 3n === 2n);
assert(45977665298704210987n + 714320987142450987412098743217984576n / 4598741987421098765327980n * 987498743n === 199365500239020623962n); assert(
45977665298704210987n +
(714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n ===
199365500239020623962n
);
assert((12n & 5n) === 4n); assert((12n & 5n) === 4n);
assert((1n | 2n) === 3n); assert((1n | 2n) === 3n);
assert((5n ^ 3n) === 6n); assert((5n ^ 3n) === 6n);
assert(~1n === -2n); assert(~1n === -2n);
bigint = 1n; bigint = 1n;
assert(bigint++ === 1n); assert(bigint++ === 1n);
assert(bigint === 2n); assert(bigint === 2n);
assert(bigint-- === 2n); assert(bigint-- === 2n);
assert(bigint === 1n); assert(bigint === 1n);
assert(++bigint === 2n); assert(++bigint === 2n);
assert(bigint === 2n); assert(bigint === 2n);
assert(--bigint === 1n); assert(--bigint === 1n);
assert(bigint === 1n); assert(bigint === 1n);
assert((1n == 1n) === true);
assert((1n == 1) === true);
assert((1 == 1n) === true);
assert((1n == 1.23) === false);
assert((1.23 == 1n) === false);
assert((1n == 1n) === true); assert((1n != 1n) === false);
assert((1n == 1) === true); assert((1n != 1) === false);
assert((1 == 1n) === true); assert((1 != 1n) === false);
assert((1n == 1.23) === false); assert((1n != 1.23) === true);
assert((1.23 == 1n) === false); assert((1.23 != 1n) === true);
assert((1n != 1n) === false); assert((1n === 1n) === true);
assert((1n != 1) === false); assert((1n === 1) == false);
assert((1 != 1n) === false); assert((1 === 1n) === false);
assert((1n != 1.23) === true); assert((1n === 1.23) === false);
assert((1.23 != 1n) === true); assert((1.23 === 1n) === false);
assert((1n === 1n) === true); assert((1n !== 1n) === false);
assert((1n === 1) == false); assert((1n !== 1) === true);
assert((1 === 1n) === false); assert((1 !== 1n) === true);
assert((1n === 1.23) === false); assert((1n !== 1.23) === true);
assert((1.23 === 1n) === false); assert((1.23 !== 1n) === true);
assert((1n !== 1n) === false); console.log("PASS");
assert((1n !== 1) === true);
assert((1 !== 1n) === true);
assert((1n !== 1.23) === true);
assert((1.23 !== 1n) === true);
console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,82 +1,118 @@
load("test-common.js"); load("test-common.js");
try { try {
[1, null, undefined].forEach(value => { [1, null, undefined].forEach(value => {
assertThrowsError(() => { assertThrowsError(
1n + value; () => {
}, { 1n + value;
error: TypeError, },
message: "Cannot use addition operator with BigInt and other type" {
}); error: TypeError,
assertThrowsError(() => { message: "Cannot use addition operator with BigInt and other type",
1n - value; }
}, { );
error: TypeError, assertThrowsError(
message: "Cannot use subtraction operator with BigInt and other type" () => {
}); 1n - value;
assertThrowsError(() => { },
1n * value; {
}, { error: TypeError,
error: TypeError, message: "Cannot use subtraction operator with BigInt and other type",
message: "Cannot use multiplication operator with BigInt and other type" }
}); );
assertThrowsError(() => { assertThrowsError(
1n / value; () => {
}, { 1n * value;
error: TypeError, },
message: "Cannot use division operator with BigInt and other type" {
}); error: TypeError,
assertThrowsError(() => { message: "Cannot use multiplication operator with BigInt and other type",
1n % value; }
}, { );
error: TypeError, assertThrowsError(
message: "Cannot use modulo operator with BigInt and other type" () => {
}); 1n / value;
assertThrowsError(() => { },
1n ** value; {
}, { error: TypeError,
error: TypeError, message: "Cannot use division operator with BigInt and other type",
message: "Cannot use exponentiation operator with BigInt and other type" }
}); );
assertThrowsError(() => { assertThrowsError(
1n | value; () => {
}, { 1n % value;
error: TypeError, },
message: "Cannot use bitwise OR operator with BigInt and other type" {
}); error: TypeError,
assertThrowsError(() => { message: "Cannot use modulo operator with BigInt and other type",
1n & value; }
}, { );
error: TypeError, assertThrowsError(
message: "Cannot use bitwise AND operator with BigInt and other type" () => {
}); 1n ** value;
assertThrowsError(() => { },
1n ^ value; {
}, { error: TypeError,
error: TypeError, message: "Cannot use exponentiation operator with BigInt and other type",
message: "Cannot use bitwise XOR operator with BigInt and other type" }
}); );
assertThrowsError(() => { assertThrowsError(
1n << value; () => {
}, { 1n | value;
error: TypeError, },
message: "Cannot use left-shift operator with BigInt and other type" {
}); error: TypeError,
assertThrowsError(() => { message: "Cannot use bitwise OR operator with BigInt and other type",
1n >> value; }
}, { );
error: TypeError, assertThrowsError(
message: "Cannot use right-shift operator with BigInt and other type" () => {
}); 1n & value;
assertThrowsError(() => { },
1n >>> value; {
}, { error: TypeError,
error: TypeError, message: "Cannot use bitwise AND operator with BigInt and other type",
message: "Cannot use unsigned right-shift operator with BigInt" }
}); );
}); assertThrowsError(
() => {
1n ^ value;
},
{
error: TypeError,
message: "Cannot use bitwise XOR operator with BigInt and other type",
}
);
assertThrowsError(
() => {
1n << value;
},
{
error: TypeError,
message: "Cannot use left-shift operator with BigInt and other type",
}
);
assertThrowsError(
() => {
1n >> value;
},
{
error: TypeError,
message: "Cannot use right-shift operator with BigInt and other type",
}
);
assertThrowsError(
() => {
1n >>> value;
},
{
error: TypeError,
message: "Cannot use unsigned right-shift operator with BigInt",
}
);
});
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -1,32 +1,32 @@
test("constructor properties", () => { test("constructor properties", () => {
expect(Boolean).toHaveLength(1); expect(Boolean).toHaveLength(1);
expect(Boolean.name).toBe("Boolean"); expect(Boolean.name).toBe("Boolean");
}); });
test("typeof", () => { test("typeof", () => {
expect(typeof new Boolean()).toBe("object"); expect(typeof new Boolean()).toBe("object");
expect(typeof Boolean()).toBe("boolean"); expect(typeof Boolean()).toBe("boolean");
expect(typeof Boolean(true)).toBe("boolean"); expect(typeof Boolean(true)).toBe("boolean");
}) });
test("basic functionality", () => { test("basic functionality", () => {
var foo = new Boolean(true); var foo = new Boolean(true);
var bar = new Boolean(true); var bar = new Boolean(true);
expect(foo).not.toBe(bar); expect(foo).not.toBe(bar);
expect(foo.valueOf()).toBe(bar.valueOf()); expect(foo.valueOf()).toBe(bar.valueOf());
expect(Boolean()).toBeFalse(); expect(Boolean()).toBeFalse();
expect(Boolean(false)).toBeFalse(); expect(Boolean(false)).toBeFalse();
expect(Boolean(null)).toBeFalse(); expect(Boolean(null)).toBeFalse();
expect(Boolean(undefined)).toBeFalse(); expect(Boolean(undefined)).toBeFalse();
expect(Boolean(NaN)).toBeFalse(); expect(Boolean(NaN)).toBeFalse();
expect(Boolean("")).toBeFalse(); expect(Boolean("")).toBeFalse();
expect(Boolean(0.0)).toBeFalse(); expect(Boolean(0.0)).toBeFalse();
expect(Boolean(-0.0)).toBeFalse(); expect(Boolean(-0.0)).toBeFalse();
expect(Boolean(true)).toBeTrue(); expect(Boolean(true)).toBeTrue();
expect(Boolean("0")).toBeTrue(); expect(Boolean("0")).toBeTrue();
expect(Boolean({})).toBeTrue(); expect(Boolean({})).toBeTrue();
expect(Boolean([])).toBeTrue(); expect(Boolean([])).toBeTrue();
expect(Boolean(1)).toBeTrue(); expect(Boolean(1)).toBeTrue();
}); });

View file

@ -1,5 +1,5 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(typeof Boolean.prototype).toBe("object"); expect(typeof Boolean.prototype).toBe("object");
expect(Boolean.prototype.valueOf()).toBeFalse(); expect(Boolean.prototype.valueOf()).toBeFalse();
expect(Boolean.prototype.length).toBeUndefined(); expect(Boolean.prototype).not.toHaveProperty("length");
}); });

View file

@ -1,17 +1,17 @@
test("basic functionality", () => { test("basic functionality", () => {
var foo = true; var foo = true;
expect(foo.toString()).toBe("true"); expect(foo.toString()).toBe("true");
expect(true.toString()).toBe("true"); expect(true.toString()).toBe("true");
expect(Boolean.prototype.toString.call(true)).toBe("true"); expect(Boolean.prototype.toString.call(true)).toBe("true");
expect(Boolean.prototype.toString.call(false)).toBe("false"); expect(Boolean.prototype.toString.call(false)).toBe("false");
expect(new Boolean(true).toString()).toBe("true"); expect(new Boolean(true).toString()).toBe("true");
expect(new Boolean(false).toString()).toBe("false"); expect(new Boolean(false).toString()).toBe("false");
}); });
test("errors on non-boolean |this|", () => { test("errors on non-boolean |this|", () => {
expect(() => { expect(() => {
Boolean.prototype.toString.call("foo"); Boolean.prototype.toString.call("foo");
}).toThrowWithMessage(TypeError, "Not a Boolean object"); }).toThrowWithMessage(TypeError, "Not a Boolean object");
}); });

View file

@ -1,16 +1,16 @@
test("basic functionality", () => { test("basic functionality", () => {
var foo = true; var foo = true;
expect(foo.valueOf()).toBeTrue(); expect(foo.valueOf()).toBeTrue();
expect(true.valueOf()).toBeTrue(); expect(true.valueOf()).toBeTrue();
expect(Boolean.prototype.valueOf.call(true)).toBeTrue(); expect(Boolean.prototype.valueOf.call(true)).toBeTrue();
expect(Boolean.prototype.valueOf.call(false)).toBeFalse(); expect(Boolean.prototype.valueOf.call(false)).toBeFalse();
expect(new Boolean().valueOf()).toBeFalse(); expect(new Boolean().valueOf()).toBeFalse();
}); });
test("errors on non-boolean |this|", () => { test("errors on non-boolean |this|", () => {
expect(() => { expect(() => {
Boolean.prototype.valueOf.call("foo"); Boolean.prototype.valueOf.call("foo");
}).toThrowWithMessage(TypeError, "Not a Boolean object"); }).toThrowWithMessage(TypeError, "Not a Boolean object");
}); });

View file

@ -1,5 +1,5 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Date).toHaveLength(7); expect(Date).toHaveLength(7);
expect(Date.name === "Date"); expect(Date.name === "Date");
expect(Date.prototype).not.toHaveProperty("length"); expect(Date.prototype).not.toHaveProperty("length");
}); });

View file

@ -1,10 +1,10 @@
test("basic functionality", () => { test("basic functionality", () => {
var last = 0; var last = 0;
for (var i = 0; i < 100; ++i) { for (var i = 0; i < 100; ++i) {
var now = Date.now(); var now = Date.now();
expect(now).not.toBeNaN(); expect(now).not.toBeNaN();
expect(now).toBeGreaterThan(1580000000000); expect(now).toBeGreaterThan(1580000000000);
expect(now).toBeGreaterThanOrEqual(last); expect(now).toBeGreaterThanOrEqual(last);
last = now; last = now;
} }
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
let d = new Date(); let d = new Date();
expect(d.getDate()).toBe(d.getDate()); expect(d.getDate()).toBe(d.getDate());
expect(d.getDate()).not.toBeNaN(); expect(d.getDate()).not.toBeNaN();
expect(d.getDate()).toBeGreaterThanOrEqual(1); expect(d.getDate()).toBeGreaterThanOrEqual(1);
expect(d.getDate()).toBeLessThanOrEqual(31); expect(d.getDate()).toBeLessThanOrEqual(31);
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
var d = new Date(); var d = new Date();
expect(d.getDay()).toBe(d.getDay()); expect(d.getDay()).toBe(d.getDay());
expect(d.getDay()).not.toBeNaN(); expect(d.getDay()).not.toBeNaN();
expect(d.getDay()).toBeGreaterThanOrEqual(0); expect(d.getDay()).toBeGreaterThanOrEqual(0);
expect(d.getDay()).toBeLessThanOrEqual(6); expect(d.getDay()).toBeLessThanOrEqual(6);
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
var d = new Date(); var d = new Date();
expect(d.getFullYear()).toBe(d.getFullYear()); expect(d.getFullYear()).toBe(d.getFullYear());
expect(d.getFullYear()).not.toBeNaN(); expect(d.getFullYear()).not.toBeNaN();
expect(d.getFullYear()).toBe(d.getFullYear()); expect(d.getFullYear()).toBe(d.getFullYear());
expect(d.getFullYear()).toBeGreaterThanOrEqual(2020); expect(d.getFullYear()).toBeGreaterThanOrEqual(2020);
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
var d = new Date(); var d = new Date();
expect(d.getHours()).toBe(d.getHours()); expect(d.getHours()).toBe(d.getHours());
expect(d.getHours()).not.toBeNaN(); expect(d.getHours()).not.toBeNaN();
expect(d.getHours()).toBeGreaterThanOrEqual(0); expect(d.getHours()).toBeGreaterThanOrEqual(0);
expect(d.getHours()).toBeLessThanOrEqual(23); expect(d.getHours()).toBeLessThanOrEqual(23);
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
var d = new Date(); var d = new Date();
expect(d.getMilliseconds()).toBe(d.getMilliseconds()); expect(d.getMilliseconds()).toBe(d.getMilliseconds());
expect(d.getMilliseconds()).not.toBeNaN(); expect(d.getMilliseconds()).not.toBeNaN();
expect(d.getMilliseconds()).toBeGreaterThanOrEqual(0); expect(d.getMilliseconds()).toBeGreaterThanOrEqual(0);
expect(d.getMilliseconds()).toBeLessThanOrEqual(999); expect(d.getMilliseconds()).toBeLessThanOrEqual(999);
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
var d = new Date(); var d = new Date();
expect(d.getMinutes()).toBe(d.getMinutes()); expect(d.getMinutes()).toBe(d.getMinutes());
expect(d.getMinutes()).not.toBeNaN(); expect(d.getMinutes()).not.toBeNaN();
expect(d.getMinutes()).toBeGreaterThanOrEqual(0); expect(d.getMinutes()).toBeGreaterThanOrEqual(0);
expect(d.getMinutes()).toBeLessThanOrEqual(59); expect(d.getMinutes()).toBeLessThanOrEqual(59);
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
var d = new Date(); var d = new Date();
expect(d.getMonth()).toBe(d.getMonth()); expect(d.getMonth()).toBe(d.getMonth());
expect(d.getMonth()).not.toBeNaN(); expect(d.getMonth()).not.toBeNaN();
expect(d.getMonth()).toBeGreaterThanOrEqual(0); expect(d.getMonth()).toBeGreaterThanOrEqual(0);
expect(d.getMonth()).toBeLessThanOrEqual(11); expect(d.getMonth()).toBeLessThanOrEqual(11);
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
var d = new Date(); var d = new Date();
expect(d.getSeconds()).toBe(d.getSeconds()); expect(d.getSeconds()).toBe(d.getSeconds());
expect(d.getSeconds()).not.toBeNaN(); expect(d.getSeconds()).not.toBeNaN();
expect(d.getSeconds()).toBeGreaterThanOrEqual(0); expect(d.getSeconds()).toBeGreaterThanOrEqual(0);
expect(d.getSeconds()).toBeLessThanOrEqual(59); expect(d.getSeconds()).toBeLessThanOrEqual(59);
}); });

View file

@ -1,6 +1,6 @@
test("basic functionality", () => { test("basic functionality", () => {
var d = new Date(); var d = new Date();
expect(d.getTime()).toBe(d.getTime()); expect(d.getTime()).toBe(d.getTime());
expect(d.getTime()).not.toBeNaN(); expect(d.getTime()).not.toBeNaN();
expect(d.getTime()).toBeGreaterThanOrEqual(1580000000000); expect(d.getTime()).toBeGreaterThanOrEqual(1580000000000);
}); });

View file

@ -1,18 +1,18 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Error).toHaveLength(1); expect(Error).toHaveLength(1);
expect(Error.name).toBe("Error"); expect(Error.name).toBe("Error");
}); });
test("name", () => { test("name", () => {
[Error(), Error(undefined), Error("test"), Error(42), Error(null)].forEach(error => { [Error(), Error(undefined), Error("test"), Error(42), Error(null)].forEach(error => {
expect(error.name).toBe("Error"); expect(error.name).toBe("Error");
}); });
}); });
test("message", () => { test("message", () => {
expect(Error().message).toBe(""); expect(Error().message).toBe("");
expect(Error(undefined).message).toBe(""); expect(Error(undefined).message).toBe("");
expect(Error("test").message).toBe("test"); expect(Error("test").message).toBe("test");
expect(Error(42).message).toBe("42"); expect(Error(42).message).toBe("42");
expect(Error(null).message).toBe("null"); expect(Error(null).message).toBe("null");
}); });

View file

@ -1,10 +1,10 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Error.prototype).not.toHaveProperty("length"); expect(Error.prototype).not.toHaveProperty("length");
var changedInstance = new Error("");
changedInstance.name = "NewCustomError";
expect(changedInstance.name).toBe("NewCustomError");
var normalInstance = new Error(""); var changedInstance = new Error("");
expect(normalInstance.name).toBe("Error"); changedInstance.name = "NewCustomError";
expect(changedInstance.name).toBe("NewCustomError");
var normalInstance = new Error("");
expect(normalInstance.name).toBe("Error");
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Error().toString()).toBe("Error"); expect(Error().toString()).toBe("Error");
expect(Error(undefined).toString()).toBe("Error"); expect(Error(undefined).toString()).toBe("Error");
expect(Error(null).toString()).toBe("Error: null"); expect(Error(null).toString()).toBe("Error: null");
expect(Error("test").toString()).toBe("Error: test"); expect(Error("test").toString()).toBe("Error: test");
expect(Error(42).toString()).toBe("Error: 42"); expect(Error(42).toString()).toBe("Error: 42");
}); });

View file

@ -1,44 +1,49 @@
describe("correct behavior", () => { describe("correct behavior", () => {
test("constructor properties", () => { test("constructor properties", () => {
expect(Function).toHaveLength(1); expect(Function).toHaveLength(1);
expect(Function.name).toBe("Function"); expect(Function.name).toBe("Function");
expect(Function.prototype).toHaveLength(0); expect(Function.prototype).toHaveLength(0);
expect(Function.prototype.name).toBe(""); expect(Function.prototype.name).toBe("");
}); });
test("typeof", () => { test("typeof", () => {
expect(typeof Function()).toBe("function"); expect(typeof Function()).toBe("function");
expect(typeof new Function()).toBe("function"); expect(typeof new Function()).toBe("function");
}); });
test("basic functionality", () => { test("basic functionality", () => {
expect(Function()()).toBe(undefined); expect(Function()()).toBeUndefined();
expect(new Function()()).toBe(undefined); expect(new Function()()).toBeUndefined();
expect(Function("return 42")()).toBe(42); expect(Function("return 42")()).toBe(42);
expect(new 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", "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", "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", "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'; }")(true)).toBe(42);
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe("bar"); expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe(
expect(new Function("return typeof Function()")()).toBe("function"); "bar"
expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3); );
expect(new Function("return typeof Function()")()).toBe("function");
expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3);
expect(new Function().name).toBe("anonymous"); expect(new Function().name).toBe("anonymous");
expect(new Function().toString()).toBe("function anonymous() {\n ???\n}"); expect(new Function().toString()).toBe("function anonymous() {\n ???\n}");
}); });
}); });
describe("errors", () => { describe("errors", () => {
test("syntax error", () => { test("syntax error", () => {
expect(() => { expect(() => {
new Function("["); new Function("[");
}) })
// This might be confusing at first but keep in mind it's actually parsing // This might be confusing at first but keep in mind it's actually parsing
// function anonymous() { [ } // function anonymous() { [ }
// This is in line with what other engines are reporting. // This is in line with what other engines are reporting.
.toThrowWithMessage(SyntaxError, "Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)"); .toThrowWithMessage(
}); SyntaxError,
"Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)"
);
});
}); });

View file

@ -1,49 +1,51 @@
test("basic functionality", () => { test("basic functionality", () => {
function Foo(arg) { function Foo(arg) {
this.foo = arg; this.foo = arg;
} }
function Bar(arg) { function Bar(arg) {
this.bar = arg; this.bar = arg;
} }
function FooBar(arg) { function FooBar(arg) {
Foo.apply(this, [arg]); Foo.apply(this, [arg]);
Bar.apply(this, [arg]); Bar.apply(this, [arg]);
} }
function FooBarBaz(arg) { function FooBarBaz(arg) {
Foo.apply(this, [arg]); Foo.apply(this, [arg]);
Bar.apply(this, [arg]); Bar.apply(this, [arg]);
this.baz = arg; this.baz = arg;
} }
expect(Function.prototype.apply).toHaveLength(2); expect(Function.prototype.apply).toHaveLength(2);
var foo = new Foo("test"); var foo = new Foo("test");
expect(foo.foo).toBe("test"); expect(foo.foo).toBe("test");
expect(foo.bar).toBeUndefined(); expect(foo.bar).toBeUndefined();
expect(foo.baz).toBeUndefined(); expect(foo.baz).toBeUndefined();
var bar = new Bar("test"); var bar = new Bar("test");
expect(bar.foo).toBeUndefined(); expect(bar.foo).toBeUndefined();
expect(bar.bar).toBe("test"); expect(bar.bar).toBe("test");
expect(bar.baz).toBeUndefined(); expect(bar.baz).toBeUndefined();
var foobar = new FooBar("test"); var foobar = new FooBar("test");
expect(foobar.foo).toBe("test"); expect(foobar.foo).toBe("test");
expect(foobar.bar).toBe("test"); expect(foobar.bar).toBe("test");
expect(foobar.baz).toBeUndefined(); expect(foobar.baz).toBeUndefined();
var foobarbaz = new FooBarBaz("test"); var foobarbaz = new FooBarBaz("test");
expect(foobarbaz.foo).toBe("test"); expect(foobarbaz.foo).toBe("test");
expect(foobarbaz.bar).toBe("test"); expect(foobarbaz.bar).toBe("test");
expect(foobarbaz.baz).toBe("test"); expect(foobarbaz.baz).toBe("test");
expect(Math.abs.apply(null, [-1])).toBe(1); expect(Math.abs.apply(null, [-1])).toBe(1);
var add = (x, y) => x + y; var add = (x, y) => x + y;
expect(add.apply(null, [1, 2])).toBe(3); expect(add.apply(null, [1, 2])).toBe(3);
var multiply = function (x, y) { return x * y; }; var multiply = function (x, y) {
expect(multiply.apply(null, [3, 4])).toBe(12); return x * y;
};
expect(multiply.apply(null, [3, 4])).toBe(12);
expect((() => this).apply("foo")).toBe(globalThis); expect((() => this).apply("foo")).toBe(globalThis);
}); });

View file

@ -1,138 +1,149 @@
describe("basic behavior", () => { describe("basic behavior", () => {
test("basic binding", () => { test("basic binding", () => {
expect(Function.prototype.bind.length).toBe(1); expect(Function.prototype.bind).toHaveLength(1);
var charAt = String.prototype.charAt.bind("bar"); var charAt = String.prototype.charAt.bind("bar");
expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar"); expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar");
function getB() { function getB() {
return this.toUpperCase().charAt(0); return this.toUpperCase().charAt(0);
} }
expect(getB.bind("bar")()).toBe("B"); expect(getB.bind("bar")()).toBe("B");
}); });
test("bound functions work with array functions", () => { test("bound functions work with array functions", () => {
var Make3 = Number.bind(null, 3); var Make3 = Number.bind(null, 3);
expect([55].map(Make3)[0]).toBe(3); expect([55].map(Make3)[0]).toBe(3);
var MakeTrue = Boolean.bind(null, true); var MakeTrue = Boolean.bind(null, true);
expect([1, 2, 3].filter(MakeTrue).length).toBe(3); expect([1, 2, 3].filter(MakeTrue)).toHaveLength(3);
expect([1, 2, 3].reduce((function (acc, x) { return acc + x }).bind(null, 4, 5))).toBe(9); expect(
expect([1, 2, 3].reduce((function (acc, x) { return acc + x + this; }).bind(3))).toBe(12); [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", () => { describe("bound function arguments", () => {
function sum(a, b, c) { function sum(a, b, c) {
return a + b + c; return a + b + c;
} }
var boundSum = sum.bind(null, 10, 5); var boundSum = sum.bind(null, 10, 5);
test("arguments are bound to the function", () => { test("arguments are bound to the function", () => {
expect(boundSum()).toBeNaN(); expect(boundSum()).toBeNaN();
expect(boundSum(5)).toBe(20); expect(boundSum(5)).toBe(20);
expect(boundSum(5, 6, 7)).toBe(20); expect(boundSum(5, 6, 7)).toBe(20);
}); });
test("arguments are appended to a BoundFunction's bound arguments", () => { test("arguments are appended to a BoundFunction's bound arguments", () => {
expect(boundSum.bind(null, 5)()).toBe(20); expect(boundSum.bind(null, 5)()).toBe(20);
}); });
test("binding a constructor's arguments", () => { test("binding a constructor's arguments", () => {
var Make5 = Number.bind(null, 5); var Make5 = Number.bind(null, 5);
expect(Make5()).toBe(5); expect(Make5()).toBe(5);
expect(new Make5().valueOf()).toBe(5); expect(new Make5().valueOf()).toBe(5);
}); });
test("length property", () => { test("length property", () => {
expect(sum).toHaveLength(3); expect(sum).toHaveLength(3);
expect(boundSum).toHaveLength(1); expect(boundSum).toHaveLength(1);
expect(boundSum.bind(null, 5)).toHaveLength(0); expect(boundSum.bind(null, 5)).toHaveLength(0);
expect(boundSum.bind(null, 5, 6, 7, 8)).toHaveLength(0); expect(boundSum.bind(null, 5, 6, 7, 8)).toHaveLength(0);
}); });
}) });
describe("bound function |this|", () => { describe("bound function |this|", () => {
function identity() { function identity() {
return this; return this;
}
test("captures global object as |this| if |this| is null or undefined", () => {
expect(identity.bind()()).toBe(globalThis);
expect(identity.bind(null)()).toBe(globalThis);
expect(identity.bind(undefined)()).toBe(globalThis);
function Foo() {
expect(identity.bind()()).toBe(globalThis);
expect(identity.bind(this)()).toBe(this);
}
new Foo();
});
test("does not capture global object as |this| if |this| is null or undefined in strict mode", () => {
"use strict";
function strictIdentity() {
return this;
} }
test("captures global object as |this| if |this| is null or undefined", () => { expect(strictIdentity.bind()()).toBeUndefined();
expect(identity.bind()()).toBe(globalThis); expect(strictIdentity.bind(null)()).toBeNull();
expect(identity.bind(null)()).toBe(globalThis); expect(strictIdentity.bind(undefined)()).toBeUndefined();
expect(identity.bind(undefined)()).toBe(globalThis); });
function Foo() { test("primitive |this| values are converted to objects", () => {
expect(identity.bind()()).toBe(globalThis); expect(identity.bind("foo")()).toBeInstanceOf(String);
expect(identity.bind(this)()).toBe(this); expect(identity.bind(123)()).toBeInstanceOf(Number);
} expect(identity.bind(true)()).toBeInstanceOf(Boolean);
new Foo(); });
});
test("does not capture global object as |this| if |this| is null or undefined in strict mode", () => { test("bound functions retain |this| values passed to them", () => {
"use strict"; var obj = { foo: "bar" };
expect(identity.bind(obj)()).toBe(obj);
});
function strictIdentity() { test("bound |this| cannot be changed after being set", () => {
return this; expect(identity.bind("foo").bind(123)()).toBeInstanceOf(String);
} });
expect(strictIdentity.bind()()).toBeUndefined(); test("arrow functions cannot be bound", () => {
expect(strictIdentity.bind(null)()).toBeNull(); expect((() => this).bind("foo")()).toBe(globalThis);
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", () => { describe("bound function constructors", () => {
function Bar() { function Bar() {
this.x = 3; this.x = 3;
this.y = 4; this.y = 4;
} }
Bar.prototype.baz = "baz"; Bar.prototype.baz = "baz";
var BoundBar = Bar.bind({ u: 5, v: 6 }); var BoundBar = Bar.bind({ u: 5, v: 6 });
var bar = new BoundBar(); var bar = new BoundBar();
test("bound |this| value does not affect constructor", () => {
expect(bar.x).toBe(3);
expect(bar.y).toBe(4);
expect(typeof bar.u).toBe("undefined");
expect(typeof bar.v).toBe("undefined");
});
test("bound |this| value does not affect constructor", () => { test("bound functions retain original prototype", () => {
expect(bar.x).toBe(3); expect(bar.baz).toBe("baz");
expect(bar.y).toBe(4); });
expect(typeof bar.u).toBe("undefined");
expect(typeof bar.v).toBe("undefined");
});
test("bound functions retain original prototype", () => { test("bound functions do not have a prototype property", () => {
expect(bar.baz).toBe("baz"); expect(BoundBar).not.toHaveProperty("prototype");
}); });
test("bound functions do not have a prototype property", () => {
expect(BoundBar).not.toHaveProperty("prototype");
});
}); });
describe("errors", () => { describe("errors", () => {
test("does not accept non-function values", () => { test("does not accept non-function values", () => {
expect(() => { expect(() => {
Function.prototype.bind.call("foo"); Function.prototype.bind.call("foo");
}).toThrowWithMessage(TypeError, "Not a Function object"); }).toThrowWithMessage(TypeError, "Not a Function object");
}); });
}); });

View file

@ -1,51 +1,53 @@
test("length", () => { test("length", () => {
expect(Function.prototype.call).toHaveLength(1); expect(Function.prototype.call).toHaveLength(1);
}); });
test("basic functionality", () => { test("basic functionality", () => {
function Foo(arg) { function Foo(arg) {
this.foo = arg; this.foo = arg;
} }
function Bar(arg) { function Bar(arg) {
this.bar = arg; this.bar = arg;
} }
function FooBar(arg) { function FooBar(arg) {
Foo.call(this, arg); Foo.call(this, arg);
Bar.call(this, arg); Bar.call(this, arg);
} }
function FooBarBaz(arg) { function FooBarBaz(arg) {
Foo.call(this, arg); Foo.call(this, arg);
Bar.call(this, arg); Bar.call(this, arg);
this.baz = arg; this.baz = arg;
} }
var foo = new Foo("test"); var foo = new Foo("test");
expect(foo.foo).toBe("test"); expect(foo.foo).toBe("test");
expect(foo.bar).toBeUndefined(); expect(foo.bar).toBeUndefined();
expect(foo.baz).toBeUndefined(); expect(foo.baz).toBeUndefined();
var bar = new Bar("test"); var bar = new Bar("test");
expect(bar.foo).toBeUndefined(); expect(bar.foo).toBeUndefined();
expect(bar.bar).toBe("test"); expect(bar.bar).toBe("test");
expect(bar.baz).toBeUndefined(); expect(bar.baz).toBeUndefined();
var foobar = new FooBar("test"); var foobar = new FooBar("test");
expect(foobar.foo).toBe("test"); expect(foobar.foo).toBe("test");
expect(foobar.bar).toBe("test"); expect(foobar.bar).toBe("test");
expect(foobar.baz).toBeUndefined(); expect(foobar.baz).toBeUndefined();
var foobarbaz = new FooBarBaz("test"); var foobarbaz = new FooBarBaz("test");
expect(foobarbaz.foo).toBe("test"); expect(foobarbaz.foo).toBe("test");
expect(foobarbaz.bar).toBe("test"); expect(foobarbaz.bar).toBe("test");
expect(foobarbaz.baz).toBe("test"); expect(foobarbaz.baz).toBe("test");
expect(Math.abs.call(null, -1)).toBe(1); expect(Math.abs.call(null, -1)).toBe(1);
var add = (x, y) => x + y; var add = (x, y) => x + y;
expect(add.call(null, 1, 2)).toBe(3); expect(add.call(null, 1, 2)).toBe(3);
var multiply = function (x, y) { return x * y; }; var multiply = function (x, y) {
expect(multiply.call(null, 3, 4)).toBe(12); return x * y;
};
expect(multiply.call(null, 3, 4)).toBe(12);
expect((() => this).call("foo")).toBe(globalThis); expect((() => this).call("foo")).toBe(globalThis);
}); });

View file

@ -1,15 +1,17 @@
test("basic functionality", () => { test("basic functionality", () => {
expect((function() {}).toString()).toBe("function () {\n ???\n}"); expect(function () {}.toString()).toBe("function () {\n ???\n}");
expect((function(foo) {}).toString()).toBe("function (foo) {\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) {}.toString()).toBe("function (foo, bar, baz) {\n ???\n}");
expect((function(foo, bar, baz) { expect(
if (foo) { function (foo, bar, baz) {
return baz; if (foo) {
} else if (bar) { return baz;
return foo; } else if (bar) {
} return foo;
return bar + 42; }
}).toString()).toBe("function (foo, bar, baz) {\n ???\n}"); return bar + 42;
expect(console.debug.toString()).toBe("function debug() {\n [NativeFunction]\n}"); }.toString()
expect(Function.toString()).toBe("function Function() {\n [FunctionConstructor]\n}"); ).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}");
}); });

View file

@ -1,22 +1,22 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Infinity + "").toBe("Infinity"); expect(Infinity + "").toBe("Infinity");
expect(-Infinity + "").toBe("-Infinity"); expect(-Infinity + "").toBe("-Infinity");
expect(Infinity).toBe(Infinity); expect(Infinity).toBe(Infinity);
expect(Infinity - 1).toBe(Infinity); expect(Infinity - 1).toBe(Infinity);
expect(Infinity + 1).toBe(Infinity); expect(Infinity + 1).toBe(Infinity);
expect(-Infinity).toBe(-Infinity); expect(-Infinity).toBe(-Infinity);
expect(-Infinity - 1).toBe(-Infinity); expect(-Infinity - 1).toBe(-Infinity);
expect(-Infinity + 1).toBe(-Infinity); expect(-Infinity + 1).toBe(-Infinity);
expect(1 / Infinity).toBe(0); expect(1 / Infinity).toBe(0);
expect(1 / -Infinity).toBe(-0); expect(1 / -Infinity).toBe(-0);
expect(1 / 0).toBe(Infinity); expect(1 / 0).toBe(Infinity);
expect(-1 / 0).toBe(-Infinity); expect(-1 / 0).toBe(-Infinity);
expect(-100).toBeLessThan(Infinity); expect(-100).toBeLessThan(Infinity);
expect(0).toBeLessThan(Infinity); expect(0).toBeLessThan(Infinity);
expect(100).toBeLessThan(Infinity); expect(100).toBeLessThan(Infinity);
expect(-Infinity).toBeLessThan(Infinity); expect(-Infinity).toBeLessThan(Infinity);
expect(-100).toBeGreaterThan(-Infinity); expect(-100).toBeGreaterThan(-Infinity);
expect(0).toBeGreaterThan(-Infinity); expect(0).toBeGreaterThan(-Infinity);
expect(100).toBeGreaterThan(-Infinity); expect(100).toBeGreaterThan(-Infinity);
expect(Infinity).toBeGreaterThan(-Infinity); expect(Infinity).toBeGreaterThan(-Infinity);
}); });

View file

@ -1,9 +1,9 @@
test("basic functionality", () => { test("basic functionality", () => {
let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`; let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`;
let object = JSON.parse(string, (key, value) => typeof value === "number" ? value * 2 : value); let object = JSON.parse(string, (key, value) => (typeof value === "number" ? value * 2 : value));
expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } }); expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } });
object = JSON.parse(string, (key, value) => typeof value === "number" ? undefined : value); object = JSON.parse(string, (key, value) => (typeof value === "number" ? undefined : value));
expect(object).toEqual({ var2: "hello", var3: {} }); expect(object).toEqual({ var2: "hello", var3: {} });
}); });

View file

@ -1,37 +1,37 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(JSON.parse).toHaveLength(2); expect(JSON.parse).toHaveLength(2);
const properties = [ const properties = [
["5", 5], ["5", 5],
["null", null], ["null", null],
["true", true], ["true", true],
["false", false], ["false", false],
['"test"', "test"], ['"test"', "test"],
['[1,2,"foo"]', [1, 2, "foo"]], ['[1,2,"foo"]', [1, 2, "foo"]],
['{"foo":1,"bar":"baz"}', { foo: 1, bar: "baz" }], ['{"foo":1,"bar":"baz"}', { foo: 1, bar: "baz" }],
]; ];
properties.forEach(testCase => { properties.forEach(testCase => {
expect(JSON.parse(testCase[0])).toEqual(testCase[1]); expect(JSON.parse(testCase[0])).toEqual(testCase[1]);
}); });
}); });
test("syntax errors", () => { test("syntax errors", () => {
[ [
undefined, undefined,
NaN, NaN,
-NaN, -NaN,
Infinity, Infinity,
-Infinity, -Infinity,
'{ "foo" }', '{ "foo" }',
'{ foo: "bar" }', '{ foo: "bar" }',
"[1,2,3,]", "[1,2,3,]",
"[1,2,3, ]", "[1,2,3, ]",
'{ "foo": "bar",}', '{ "foo": "bar",}',
'{ "foo": "bar", }', '{ "foo": "bar", }',
].forEach(test => { ].forEach(test => {
expect(() => { expect(() => {
JSON.parse(test); JSON.parse(test);
}).toThrow(SyntaxError); }).toThrow(SyntaxError);
}); });
}); });

View file

@ -1,28 +1,30 @@
test("basic functionality", () => { test("basic functionality", () => {
let o = { let o = {
key1: "key1", key1: "key1",
key2: "key2", key2: "key2",
key3: "key3", key3: "key3",
}; };
Object.defineProperty(o, "defined", { Object.defineProperty(o, "defined", {
enumerable: true, enumerable: true,
get() { get() {
o.prop = "prop"; o.prop = "prop";
return "defined"; return "defined";
}, },
}); });
o.key4 = "key4"; o.key4 = "key4";
o[2] = 2; o[2] = 2;
o[0] = 0; o[0] = 0;
o[1] = 1; o[1] = 1;
delete o.key1; delete o.key1;
delete o.key3; delete o.key3;
o.key1 = "key1"; o.key1 = "key1";
expect(JSON.stringify(o)).toBe('{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}'); expect(JSON.stringify(o)).toBe(
'{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}'
);
}); });

View file

@ -1,12 +1,11 @@
test("basic functionality", () => { test("basic functionality", () => {
let p = new Proxy([], { let p = new Proxy([], {
get(_, key) { get(_, key) {
if (key === "length") if (key === "length") return 3;
return 3; return Number(key);
return Number(key); },
}, });
});
expect(JSON.stringify(p)).toBe("[0,1,2]"); expect(JSON.stringify(p)).toBe("[0,1,2]");
expect(JSON.stringify([[new Proxy(p, {})]])).toBe("[[[0,1,2]]]"); expect(JSON.stringify([[new Proxy(p, {})]])).toBe("[[[0,1,2]]]");
}); });

View file

@ -1,33 +1,38 @@
test("basic functionality", () => { test("basic functionality", () => {
let o = { let o = {
var1: "foo", var1: "foo",
var2: 42, var2: 42,
arr: [1, 2, { arr: [
nested: { 1,
hello: "world", 2,
}, {
get x() { return 10; } nested: {
}], hello: "world",
obj: {
subarr: [3],
}, },
}; get x() {
return 10;
},
},
],
obj: {
subarr: [3],
},
};
let string = JSON.stringify(o, (key, value) => { let string = JSON.stringify(o, (key, value) => {
if (key === "hello") if (key === "hello") return undefined;
return undefined; if (value === 10) return 20;
if (value === 10) if (key === "subarr") return [3, 4, 5];
return 20; return value;
if (key === "subarr") });
return [3, 4, 5];
return value;
});
expect(string).toBe('{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}'); expect(string).toBe(
'{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}'
);
string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]); string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]);
expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}'); expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}');
string = JSON.stringify(o, ["var1", "var1", "var2", "obj", "subarr"]); string = JSON.stringify(o, ["var1", "var1", "var2", "obj", "subarr"]);
expect(string).toBe('{"var1":"foo","var2":42,"obj":{"subarr":[3]}}'); expect(string).toBe('{"var1":"foo","var2":42,"obj":{"subarr":[3]}}');
}); });

View file

@ -1,17 +1,20 @@
test("basic functionality", () => { test("basic functionality", () => {
let o = { let o = {
foo: 1, foo: 1,
bar: "baz", bar: "baz",
qux: { qux: {
get x() { return 10; }, get x() {
y() { return 20; }, return 10;
arr: [1, 2, 3], },
} y() {
}; return 20;
},
arr: [1, 2, 3],
},
};
let string = JSON.stringify(o, null, 4); let string = JSON.stringify(o, null, 4);
let expected = let expected = `{
`{
"foo": 1, "foo": 1,
"bar": "baz", "bar": "baz",
"qux": { "qux": {
@ -24,11 +27,10 @@ test("basic functionality", () => {
} }
}`; }`;
expect(string).toBe(expected); expect(string).toBe(expected);
string = JSON.stringify(o, null, "abcd"); string = JSON.stringify(o, null, "abcd");
expected = expected = `{
`{
abcd"foo": 1, abcd"foo": 1,
abcd"bar": "baz", abcd"bar": "baz",
abcd"qux": { abcd"qux": {
@ -41,5 +43,5 @@ abcdabcd]
abcd} abcd}
}`; }`;
expect(string).toBe(expected); expect(string).toBe(expected);
}); });

View file

@ -1,71 +1,71 @@
describe("correct behavior", () => { describe("correct behavior", () => {
test("length", () => { test("length", () => {
expect(JSON.stringify).toHaveLength(3); expect(JSON.stringify).toHaveLength(3);
}); });
test("basic functionality", () => { test("basic functionality", () => {
[ [
[5, "5"], [5, "5"],
[undefined, undefined], [undefined, undefined],
[null, "null"], [null, "null"],
[NaN, "null"], [NaN, "null"],
[-NaN, "null"], [-NaN, "null"],
[Infinity, "null"], [Infinity, "null"],
[-Infinity, "null"], [-Infinity, "null"],
[true, "true"], [true, "true"],
[false, "false"], [false, "false"],
["test", '"test"'], ["test", '"test"'],
[new Number(5), "5"], [new Number(5), "5"],
[new Boolean(false), "false"], [new Boolean(false), "false"],
[new String("test"), '"test"'], [new String("test"), '"test"'],
[() => {}, undefined], [() => {}, undefined],
[[1, 2, "foo"], '[1,2,"foo"]'], [[1, 2, "foo"], '[1,2,"foo"]'],
[{ foo: 1, bar: "baz", qux() {} }, '{"foo":1,"bar":"baz"}'], [{ foo: 1, bar: "baz", qux() {} }, '{"foo":1,"bar":"baz"}'],
[ [
{ {
var1: 1, var1: 1,
var2: 2, var2: 2,
toJSON(key) { toJSON(key) {
let o = this; let o = this;
o.var2 = 10; o.var2 = 10;
return o; return o;
} },
}, },
'{"var1":1,"var2":10}', '{"var1":1,"var2":10}',
], ],
].forEach(testCase => { ].forEach(testCase => {
expect(JSON.stringify(testCase[0])).toEqual(testCase[1]); expect(JSON.stringify(testCase[0])).toEqual(testCase[1]);
});
}); });
});
test("ignores non-enumerable properties", () => { test("ignores non-enumerable properties", () => {
let o = { foo: "bar" }; let o = { foo: "bar" };
Object.defineProperty(o, "baz", { value: "qux", enumerable: false }); Object.defineProperty(o, "baz", { value: "qux", enumerable: false });
expect(JSON.stringify(o)).toBe('{"foo":"bar"}'); expect(JSON.stringify(o)).toBe('{"foo":"bar"}');
}); });
}); });
describe("errors", () => { describe("errors", () => {
test("cannot serialize BigInt", () => { test("cannot serialize BigInt", () => {
expect(() => { expect(() => {
JSON.stringify(5n); JSON.stringify(5n);
}).toThrow(TypeError, "Cannot serialize BigInt value to JSON"); }).toThrow(TypeError, "Cannot serialize BigInt value to JSON");
}); });
test("cannot serialize circular structures", () => { test("cannot serialize circular structures", () => {
let bad1 = {}; let bad1 = {};
bad1.foo = bad1; bad1.foo = bad1;
let bad2 = []; let bad2 = [];
bad2[5] = [[[bad2]]]; bad2[5] = [[[bad2]]];
let bad3a = { foo: "bar" }; let bad3a = { foo: "bar" };
let bad3b = [1, 2, bad3a]; let bad3b = [1, 2, bad3a];
bad3a.bad = bad3b; bad3a.bad = bad3b;
[bad1, bad2, bad3a].forEach(bad => { [bad1, bad2, bad3a].forEach(bad => {
expect(() => { expect(() => {
JSON.stringify(bad); JSON.stringify(bad);
}).toThrow(TypeError, "Cannot stringify circular object"); }).toThrow(TypeError, "Cannot stringify circular object");
});
}); });
});
}); });

View file

@ -1,10 +1,10 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.E).toBeCloseTo(2.718281); expect(Math.E).toBeCloseTo(2.718281);
expect(Math.LN2).toBeCloseTo(0.693147); expect(Math.LN2).toBeCloseTo(0.693147);
expect(Math.LN10).toBeCloseTo(2.302585); expect(Math.LN10).toBeCloseTo(2.302585);
expect(Math.LOG2E).toBeCloseTo(1.442695); expect(Math.LOG2E).toBeCloseTo(1.442695);
expect(Math.LOG10E).toBeCloseTo(0.434294); expect(Math.LOG10E).toBeCloseTo(0.434294);
expect(Math.PI).toBeCloseTo(3.1415926); expect(Math.PI).toBeCloseTo(3.1415926);
expect(Math.SQRT1_2).toBeCloseTo(0.707106); expect(Math.SQRT1_2).toBeCloseTo(0.707106);
expect(Math.SQRT2).toBeCloseTo(1.414213); expect(Math.SQRT2).toBeCloseTo(1.414213);
}); });

View file

@ -1,14 +1,14 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.abs).toHaveLength(1); expect(Math.abs).toHaveLength(1);
expect(Math.abs('-1')).toBe(1); expect(Math.abs("-1")).toBe(1);
expect(Math.abs(-2)).toBe(2); expect(Math.abs(-2)).toBe(2);
expect(Math.abs(null)).toBe(0); expect(Math.abs(null)).toBe(0);
expect(Math.abs('')).toBe(0); expect(Math.abs("")).toBe(0);
expect(Math.abs([])).toBe(0); expect(Math.abs([])).toBe(0);
expect(Math.abs([2])).toBe(2); expect(Math.abs([2])).toBe(2);
expect(Math.abs([1, 2])).toBeNaN(); expect(Math.abs([1, 2])).toBeNaN();
expect(Math.abs({})).toBeNaN(); expect(Math.abs({})).toBeNaN();
expect(Math.abs('string')).toBeNaN(); expect(Math.abs("string")).toBeNaN();
expect(Math.abs()).toBeNaN(); expect(Math.abs()).toBeNaN();
}); });

View file

@ -1,9 +1,9 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.acosh).toHaveLength(1); expect(Math.acosh).toHaveLength(1);
expect(Math.acosh(-1)).toBeNaN(); expect(Math.acosh(-1)).toBeNaN();
expect(Math.acosh(0)).toBeNaN(); expect(Math.acosh(0)).toBeNaN();
expect(Math.acosh(0.5)).toBeNaN(); expect(Math.acosh(0.5)).toBeNaN();
expect(Math.acosh(1)).toBeCloseTo(0); expect(Math.acosh(1)).toBeCloseTo(0);
// FIXME: expect(Math.acosh(2)).toBeCloseTo(1.316957); // FIXME: expect(Math.acosh(2)).toBeCloseTo(1.316957);
}); });

View file

@ -1,6 +1,6 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.asinh).toHaveLength(1); expect(Math.asinh).toHaveLength(1);
expect(Math.asinh(0)).toBeCloseTo(0); expect(Math.asinh(0)).toBeCloseTo(0);
// FIXME: expect(Math.asinh(1)).toBeCloseTo(0.881373); // FIXME: expect(Math.asinh(1)).toBeCloseTo(0.881373);
}); });

View file

@ -1,10 +1,10 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.atanh).toHaveLength(1); expect(Math.atanh).toHaveLength(1);
expect(Math.atanh(-2)).toBeNaN(); expect(Math.atanh(-2)).toBeNaN();
expect(Math.atanh(2)).toBeNaN(); expect(Math.atanh(2)).toBeNaN();
expect(Math.atanh(-1)).toBe(-Infinity); expect(Math.atanh(-1)).toBe(-Infinity);
// FIXME: expect(Math.atanh(0)).toBe(0); // FIXME: expect(Math.atanh(0)).toBe(0);
expect(Math.atanh(0.5)).toBeCloseTo(0.549306); expect(Math.atanh(0.5)).toBeCloseTo(0.549306);
// FIXME: expect(Math.atanh(1)).toBe(Infinity); // FIXME: expect(Math.atanh(1)).toBe(Infinity);
}); });

View file

@ -1,12 +1,12 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.cbrt).toHaveLength(1); expect(Math.cbrt).toHaveLength(1);
expect(Math.cbrt(NaN)).toBeNaN(); expect(Math.cbrt(NaN)).toBeNaN();
// FIXME: expect(Math.cbrt(-1)).toBe(-1); // FIXME: expect(Math.cbrt(-1)).toBe(-1);
expect(Math.cbrt(-0)).toBe(-0); expect(Math.cbrt(-0)).toBe(-0);
// FIXME: expect(Math.cbrt(-Infinity)).toBe(-Infinity); // FIXME: expect(Math.cbrt(-Infinity)).toBe(-Infinity);
// FIXME: expect(Math.cbrt(1)).toBe(1); // FIXME: expect(Math.cbrt(1)).toBe(1);
// FIXME: expect(Math.cbrt(Infinity)).toBe(Infinity); // FIXME: expect(Math.cbrt(Infinity)).toBe(Infinity);
expect(Math.cbrt(null)).toBe(0); expect(Math.cbrt(null)).toBe(0);
// FIXME: expect(Math.cbrt(2)).toBeCloseTo(1.259921)); // FIXME: expect(Math.cbrt(2)).toBeCloseTo(1.259921));
}); });

View file

@ -1,13 +1,13 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.ceil).toHaveLength(1); expect(Math.ceil).toHaveLength(1);
expect(Math.ceil(0.95)).toBe(1); expect(Math.ceil(0.95)).toBe(1);
expect(Math.ceil(4)).toBe(4); expect(Math.ceil(4)).toBe(4);
expect(Math.ceil(7.004)).toBe(8); expect(Math.ceil(7.004)).toBe(8);
expect(Math.ceil(-0.95)).toBe(-0); expect(Math.ceil(-0.95)).toBe(-0);
expect(Math.ceil(-4) ).toBe(-4); expect(Math.ceil(-4)).toBe(-4);
expect(Math.ceil(-7.004)).toBe(-7); expect(Math.ceil(-7.004)).toBe(-7);
expect(Math.ceil()).toBeNaN(); expect(Math.ceil()).toBeNaN();
expect(Math.ceil(NaN)).toBeNaN(); expect(Math.ceil(NaN)).toBeNaN();
}); });

View file

@ -1,44 +1,44 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.clz32).toHaveLength(1); expect(Math.clz32).toHaveLength(1);
expect(Math.clz32(0)).toBe(32); expect(Math.clz32(0)).toBe(32);
expect(Math.clz32(1)).toBe(31); expect(Math.clz32(1)).toBe(31);
expect(Math.clz32(2)).toBe(30); expect(Math.clz32(2)).toBe(30);
expect(Math.clz32(3)).toBe(30); expect(Math.clz32(3)).toBe(30);
expect(Math.clz32(4)).toBe(29); expect(Math.clz32(4)).toBe(29);
expect(Math.clz32(5)).toBe(29); expect(Math.clz32(5)).toBe(29);
expect(Math.clz32(-1)).toBe(0); expect(Math.clz32(-1)).toBe(0);
expect(Math.clz32(-10)).toBe(0); expect(Math.clz32(-10)).toBe(0);
expect(Math.clz32(-100)).toBe(0); expect(Math.clz32(-100)).toBe(0);
expect(Math.clz32(-1000)).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(0.123)).toBe(32); expect(Math.clz32(0.123)).toBe(32);
expect(Math.clz32(1.23)).toBe(31); expect(Math.clz32(1.23)).toBe(31);
expect(Math.clz32(12)).toBe(28); expect(Math.clz32(12)).toBe(28);
expect(Math.clz32(123)).toBe(25); expect(Math.clz32(123)).toBe(25);
expect(Math.clz32(1234)).toBe(21); expect(Math.clz32(1234)).toBe(21);
expect(Math.clz32(12345)).toBe(18); expect(Math.clz32(12345)).toBe(18);
expect(Math.clz32(123456)).toBe(15); expect(Math.clz32(123456)).toBe(15);
expect(Math.clz32(1234567)).toBe(11); expect(Math.clz32(1234567)).toBe(11);
expect(Math.clz32(12345678)).toBe(8); expect(Math.clz32(12345678)).toBe(8);
expect(Math.clz32(123456789)).toBe(5); expect(Math.clz32(123456789)).toBe(5);
expect(Math.clz32(999999999)).toBe(2); expect(Math.clz32(999999999)).toBe(2);
expect(Math.clz32(9999999999)).toBe(1); expect(Math.clz32(9999999999)).toBe(1);
expect(Math.clz32(99999999999)).toBe(1); expect(Math.clz32(99999999999)).toBe(1);
expect(Math.clz32(999999999999)).toBe(0); expect(Math.clz32(999999999999)).toBe(0);
expect(Math.clz32(9999999999999)).toBe(1); expect(Math.clz32(9999999999999)).toBe(1);
expect(Math.clz32(99999999999999)).toBe(3); expect(Math.clz32(99999999999999)).toBe(3);
expect(Math.clz32(999999999999999)).toBe(0); expect(Math.clz32(999999999999999)).toBe(0);
expect(Math.clz32()).toBe(32); expect(Math.clz32()).toBe(32);
expect(Math.clz32(NaN)).toBe(32); expect(Math.clz32(NaN)).toBe(32);
expect(Math.clz32(Infinity)).toBe(32); expect(Math.clz32(Infinity)).toBe(32);
expect(Math.clz32(-Infinity)).toBe(32); expect(Math.clz32(-Infinity)).toBe(32);
expect(Math.clz32(false)).toBe(32); expect(Math.clz32(false)).toBe(32);
expect(Math.clz32(true)).toBe(31); expect(Math.clz32(true)).toBe(31);
expect(Math.clz32(null)).toBe(32); expect(Math.clz32(null)).toBe(32);
expect(Math.clz32(undefined)).toBe(32); expect(Math.clz32(undefined)).toBe(32);
expect(Math.clz32([])).toBe(32); expect(Math.clz32([])).toBe(32);
expect(Math.clz32({})).toBe(32); expect(Math.clz32({})).toBe(32);
expect(Math.clz32("foo")).toBe(32); expect(Math.clz32("foo")).toBe(32);
}); });

View file

@ -1,14 +1,14 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.cos).toHaveLength(1); expect(Math.cos).toHaveLength(1);
expect(Math.cos(0)).toBe(1); expect(Math.cos(0)).toBe(1);
expect(Math.cos(null)).toBe(1); expect(Math.cos(null)).toBe(1);
expect(Math.cos('')).toBe(1); expect(Math.cos("")).toBe(1);
expect(Math.cos([])).toBe(1); expect(Math.cos([])).toBe(1);
expect(Math.cos(Math.PI)).toBe(-1); expect(Math.cos(Math.PI)).toBe(-1);
expect(Math.cos()).toBeNaN(); expect(Math.cos()).toBeNaN();
expect(Math.cos(undefined)).toBeNaN(); expect(Math.cos(undefined)).toBeNaN();
expect(Math.cos([1, 2, 3])).toBeNaN(); expect(Math.cos([1, 2, 3])).toBeNaN();
expect(Math.cos({})).toBeNaN(); expect(Math.cos({})).toBeNaN();
expect(Math.cos("foo")).toBeNaN(); expect(Math.cos("foo")).toBeNaN();
}); });

View file

@ -1,13 +1,13 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.exp).toHaveLength(1); expect(Math.exp).toHaveLength(1);
expect(Math.exp(0)).toBe(1); expect(Math.exp(0)).toBe(1);
expect(Math.exp(-2)).toBeCloseTo(0.135335); expect(Math.exp(-2)).toBeCloseTo(0.135335);
expect(Math.exp(-1)).toBeCloseTo(0.367879); expect(Math.exp(-1)).toBeCloseTo(0.367879);
expect(Math.exp(1)).toBeCloseTo(2.718281); expect(Math.exp(1)).toBeCloseTo(2.718281);
expect(Math.exp(2)).toBeCloseTo(7.389056); expect(Math.exp(2)).toBeCloseTo(7.389056);
expect(Math.exp()).toBeNaN(); expect(Math.exp()).toBeNaN();
expect(Math.exp(undefined)).toBeNaN(); expect(Math.exp(undefined)).toBeNaN();
expect(Math.exp("foo")).toBeNaN(); expect(Math.exp("foo")).toBeNaN();
}); });

View file

@ -1,13 +1,13 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.expm1).toHaveLength(1); expect(Math.expm1).toHaveLength(1);
expect(Math.expm1(0)).toBe(0); expect(Math.expm1(0)).toBe(0);
expect(Math.expm1(-2)).toBeCloseTo(-0.864664); expect(Math.expm1(-2)).toBeCloseTo(-0.864664);
expect(Math.expm1(-1)).toBeCloseTo(-0.632120); expect(Math.expm1(-1)).toBeCloseTo(-0.63212);
expect(Math.expm1(1)).toBeCloseTo(1.718281); expect(Math.expm1(1)).toBeCloseTo(1.718281);
expect(Math.expm1(2)).toBeCloseTo(6.389056); expect(Math.expm1(2)).toBeCloseTo(6.389056);
expect(Math.expm1()).toBeNaN(); expect(Math.expm1()).toBeNaN();
expect(Math.expm1(undefined)).toBeNaN(); expect(Math.expm1(undefined)).toBeNaN();
expect(Math.expm1("foo")).toBeNaN(); expect(Math.expm1("foo")).toBeNaN();
}); });

View file

@ -1,13 +1,13 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.floor).toHaveLength(1); expect(Math.floor).toHaveLength(1);
expect(Math.floor(0.95)).toBe(0); expect(Math.floor(0.95)).toBe(0);
expect(Math.floor(4)).toBe(4); expect(Math.floor(4)).toBe(4);
expect(Math.floor(7.004)).toBe(7); expect(Math.floor(7.004)).toBe(7);
expect(Math.floor(-0.95)).toBe(-1); expect(Math.floor(-0.95)).toBe(-1);
expect(Math.floor(-4)).toBe(-4); expect(Math.floor(-4)).toBe(-4);
expect(Math.floor(-7.004)).toBe(-8); expect(Math.floor(-7.004)).toBe(-8);
expect(Math.floor()).toBeNaN(); expect(Math.floor()).toBeNaN();
expect(Math.floor(NaN)).toBeNaN(); expect(Math.floor(NaN)).toBeNaN();
}); });

View file

@ -1,8 +1,8 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.log1p).toHaveLength(1); expect(Math.log1p).toHaveLength(1);
expect(Math.log1p(-2)).toBeNaN(); expect(Math.log1p(-2)).toBeNaN();
expect(Math.log1p(-1)).toBe(-Infinity); expect(Math.log1p(-1)).toBe(-Infinity);
// FIXME: expect(Math.log1p(0)).toBe(0); // FIXME: expect(Math.log1p(0)).toBe(0);
// FIXME: expect(Math.log1p(1)).toBeCloseTo(0.693147); // FIXME: expect(Math.log1p(1)).toBeCloseTo(0.693147);
}); });

View file

@ -1,10 +1,10 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.max).toHaveLength(2); expect(Math.max).toHaveLength(2);
expect(Math.max()).toBe(-Infinity); expect(Math.max()).toBe(-Infinity);
expect(Math.max(1)).toBe(1); expect(Math.max(1)).toBe(1);
expect(Math.max(2, 1)).toBe(2); expect(Math.max(2, 1)).toBe(2);
expect(Math.max(1, 2, 3)).toBe(3); expect(Math.max(1, 2, 3)).toBe(3);
expect(Math.max(NaN)).toBeNaN(); expect(Math.max(NaN)).toBeNaN();
expect(Math.max("String", 1)).toBeNaN(); expect(Math.max("String", 1)).toBeNaN();
}); });

View file

@ -1,9 +1,9 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.min).toHaveLength(2); expect(Math.min).toHaveLength(2);
expect(Math.min(1)).toBe(1); expect(Math.min(1)).toBe(1);
expect(Math.min(2, 1)).toBe(1); expect(Math.min(2, 1)).toBe(1);
expect(Math.min(1, 2, 3)).toBe(1); expect(Math.min(1, 2, 3)).toBe(1);
expect(Math.min(NaN)).toBeNaN(); expect(Math.min(NaN)).toBeNaN();
expect(Math.min("String", 1)).toBeNaN(); expect(Math.min("String", 1)).toBeNaN();
}); });

View file

@ -1,25 +1,25 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.pow).toHaveLength(2); expect(Math.pow).toHaveLength(2);
expect(Math.pow(2, 0)).toBe(1); expect(Math.pow(2, 0)).toBe(1);
expect(Math.pow(2, 1)).toBe(2); expect(Math.pow(2, 1)).toBe(2);
expect(Math.pow(2, 2)).toBe(4); expect(Math.pow(2, 2)).toBe(4);
expect(Math.pow(2, 3)).toBe(8); expect(Math.pow(2, 3)).toBe(8);
expect(Math.pow(2, -3)).toBe(0.125); expect(Math.pow(2, -3)).toBe(0.125);
expect(Math.pow(3, 2)).toBe(9); expect(Math.pow(3, 2)).toBe(9);
expect(Math.pow(0, 0)).toBe(1); expect(Math.pow(0, 0)).toBe(1);
expect(Math.pow(2, Math.pow(3, 2))).toBe(512); expect(Math.pow(2, Math.pow(3, 2))).toBe(512);
expect(Math.pow(Math.pow(2, 3), 2)).toBe(64); expect(Math.pow(Math.pow(2, 3), 2)).toBe(64);
expect(Math.pow("2", "3")).toBe(8); expect(Math.pow("2", "3")).toBe(8);
expect(Math.pow("", [])).toBe(1); expect(Math.pow("", [])).toBe(1);
expect(Math.pow([], null)).toBe(1); expect(Math.pow([], null)).toBe(1);
expect(Math.pow(null, null)).toBe(1); expect(Math.pow(null, null)).toBe(1);
expect(Math.pow(undefined, null)).toBe(1); expect(Math.pow(undefined, null)).toBe(1);
expect(Math.pow(NaN, 2)).toBeNaN(); expect(Math.pow(NaN, 2)).toBeNaN();
expect(Math.pow(2, NaN)).toBeNaN(); expect(Math.pow(2, NaN)).toBeNaN();
expect(Math.pow(undefined, 2)).toBeNaN(); expect(Math.pow(undefined, 2)).toBeNaN();
expect(Math.pow(2, undefined)).toBeNaN(); expect(Math.pow(2, undefined)).toBeNaN();
expect(Math.pow(null, undefined)).toBeNaN(); expect(Math.pow(null, undefined)).toBeNaN();
expect(Math.pow(2, "foo")).toBeNaN(); expect(Math.pow(2, "foo")).toBeNaN();
expect(Math.pow("foo", 2)).toBeNaN(); expect(Math.pow("foo", 2)).toBeNaN();
}); });

View file

@ -1,38 +1,36 @@
function isPositiveZero(value) { function isPositiveZero(value) {
return value === 0 && 1 / value === Infinity; return value === 0 && 1 / value === Infinity;
} }
function isNegativeZero(value) { function isNegativeZero(value) {
return value === 0 && 1 / value === -Infinity; return value === 0 && 1 / value === -Infinity;
} }
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.sign).toHaveLength(1); expect(Math.sign).toHaveLength(1);
expect(Math.sign.length).toBe(1); expect(Math.sign(0.0001)).toBe(1);
expect(Math.sign(1)).toBe(1);
expect(Math.sign(42)).toBe(1);
expect(Math.sign(Infinity)).toBe(1);
expect(isPositiveZero(Math.sign(0))).toBeTrue();
expect(isPositiveZero(Math.sign(null))).toBeTrue();
expect(isPositiveZero(Math.sign(""))).toBeTrue();
expect(isPositiveZero(Math.sign([]))).toBeTrue();
expect(Math.sign(0.0001)).toBe(1); expect(Math.sign(-0.0001)).toBe(-1);
expect(Math.sign(1)).toBe(1); expect(Math.sign(-1)).toBe(-1);
expect(Math.sign(42)).toBe(1); expect(Math.sign(-42)).toBe(-1);
expect(Math.sign(Infinity)).toBe(1); expect(Math.sign(-Infinity)).toBe(-1);
expect(isPositiveZero(Math.sign(0))).toBeTrue(); expect(isNegativeZero(Math.sign(-0))).toBeTrue();
expect(isPositiveZero(Math.sign(null))).toBeTrue(); expect(isNegativeZero(Math.sign(-null))).toBeTrue();
expect(isPositiveZero(Math.sign(''))).toBeTrue(); expect(isNegativeZero(Math.sign(-""))).toBeTrue();
expect(isPositiveZero(Math.sign([]))).toBeTrue(); expect(isNegativeZero(Math.sign(-[]))).toBeTrue();
expect(Math.sign(-0.0001)).toBe(-1); expect(Math.sign()).toBeNaN();
expect(Math.sign(-1)).toBe(-1); expect(Math.sign(undefined)).toBeNaN();
expect(Math.sign(-42)).toBe(-1); expect(Math.sign([1, 2, 3])).toBeNaN();
expect(Math.sign(-Infinity)).toBe(-1); expect(Math.sign({})).toBeNaN();
expect(isNegativeZero(Math.sign(-0))).toBeTrue(); expect(Math.sign(NaN)).toBeNaN();
expect(isNegativeZero(Math.sign(-null))).toBeTrue(); expect(Math.sign("foo")).toBeNaN();
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();
}); });

View file

@ -1,15 +1,15 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.sin).toHaveLength(1); expect(Math.sin).toHaveLength(1);
expect(Math.sin(0)).toBe(0); expect(Math.sin(0)).toBe(0);
expect(Math.sin(null)).toBe(0); expect(Math.sin(null)).toBe(0);
expect(Math.sin('')).toBe(0); expect(Math.sin("")).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 * 3) / 2)).toBe(-1);
expect(Math.sin(Math.PI / 2)).toBe(1); expect(Math.sin(Math.PI / 2)).toBe(1);
expect(Math.sin()).toBeNaN(); expect(Math.sin()).toBeNaN();
expect(Math.sin(undefined)).toBeNaN(); expect(Math.sin(undefined)).toBeNaN();
expect(Math.sin([1, 2, 3])).toBeNaN(); expect(Math.sin([1, 2, 3])).toBeNaN();
expect(Math.sin({})).toBeNaN(); expect(Math.sin({})).toBeNaN();
expect(Math.sin("foo")).toBeNaN(); expect(Math.sin("foo")).toBeNaN();
}); });

View file

@ -1,4 +1,4 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.sqrt).toHaveLength(1); expect(Math.sqrt).toHaveLength(1);
expect(Math.sqrt(9)).toBe(3); expect(Math.sqrt(9)).toBe(3);
}); });

View file

@ -1,14 +1,14 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.tan).toHaveLength(1); expect(Math.tan).toHaveLength(1);
expect(Math.tan(0)).toBe(0); expect(Math.tan(0)).toBe(0);
expect(Math.tan(null)).toBe(0); expect(Math.tan(null)).toBe(0);
expect(Math.tan('')).toBe(0); expect(Math.tan("")).toBe(0);
expect(Math.tan([])).toBe(0); expect(Math.tan([])).toBe(0);
expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1); expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1);
expect(Math.tan()).toBeNaN(); expect(Math.tan()).toBeNaN();
expect(Math.tan(undefined)).toBeNaN(); expect(Math.tan(undefined)).toBeNaN();
expect(Math.tan([1, 2, 3])).toBeNaN(); expect(Math.tan([1, 2, 3])).toBeNaN();
expect(Math.tan({})).toBeNaN(); expect(Math.tan({})).toBeNaN();
expect(Math.tan("foo")).toBeNaN(); expect(Math.tan("foo")).toBeNaN();
}); });

View file

@ -1,12 +1,12 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.trunc).toHaveLength(1); expect(Math.trunc).toHaveLength(1);
expect(Math.trunc(13.37)).toBe(13); expect(Math.trunc(13.37)).toBe(13);
expect(Math.trunc(42.84)).toBe(42); expect(Math.trunc(42.84)).toBe(42);
expect(Math.trunc(0.123)).toBe( 0); expect(Math.trunc(0.123)).toBe(0);
expect(Math.trunc(-0.123)).toBe(-0); expect(Math.trunc(-0.123)).toBe(-0);
expect(Math.trunc(NaN)).toBeNaN(); expect(Math.trunc(NaN)).toBeNaN();
expect(Math.trunc('foo')).toBeNaN(); expect(Math.trunc("foo")).toBeNaN();
expect(Math.trunc()).toBeNaN(); expect(Math.trunc()).toBeNaN();
}); });

View file

@ -1,13 +1,13 @@
test("basic functionality", () => { test("basic functionality", () => {
const nan = undefined + 1; const nan = undefined + 1;
expect(nan + "").toBe("NaN"); expect(nan + "").toBe("NaN");
expect(NaN + "").toBe("NaN"); expect(NaN + "").toBe("NaN");
expect(nan !== nan).toBeTrue(); expect(nan !== nan).toBeTrue();
expect(NaN !== NaN).toBeTrue(); expect(NaN !== NaN).toBeTrue();
expect(nan).toBeNaN(); expect(nan).toBeNaN();
expect(NaN).toBeNaN(); expect(NaN).toBeNaN();
expect(0).not.toBeNaN(); expect(0).not.toBeNaN();
expect(!!nan).toBeFalse(); expect(!!nan).toBeFalse();
expect(!!NaN).toBeFalse(); expect(!!NaN).toBeFalse();
}); });

View file

@ -1,11 +1,11 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Number.EPSILON).toBe(2 ** -52); expect(Number.EPSILON).toBe(2 ** -52);
expect(Number.EPSILON).toBeGreaterThan(0); expect(Number.EPSILON).toBeGreaterThan(0);
expect(Number.MAX_SAFE_INTEGER).toBe(2 ** 53 - 1); expect(Number.MAX_SAFE_INTEGER).toBe(2 ** 53 - 1);
expect(Number.MAX_SAFE_INTEGER + 1).toBe(Number.MAX_SAFE_INTEGER + 2); 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).toBe(-(2 ** 53 - 1));
expect(Number.MIN_SAFE_INTEGER - 1).toBe(Number.MIN_SAFE_INTEGER - 2); expect(Number.MIN_SAFE_INTEGER - 1).toBe(Number.MIN_SAFE_INTEGER - 2);
expect(Number.POSITIVE_INFINITY).toBe(Infinity); expect(Number.POSITIVE_INFINITY).toBe(Infinity);
expect(Number.NEGATIVE_INFINITY).toBe(-Infinity); expect(Number.NEGATIVE_INFINITY).toBe(-Infinity);
expect(Number.NaN).toBeNaN(); expect(Number.NaN).toBeNaN();
}); });

View file

@ -1,24 +1,24 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Number.isFinite).toHaveLength(1); expect(Number.isFinite).toHaveLength(1);
expect(Number.isFinite).not.toBe(isFinite); expect(Number.isFinite).not.toBe(isFinite);
expect(Number.isFinite(0)).toBeTrue(); expect(Number.isFinite(0)).toBeTrue();
expect(Number.isFinite(1.23)).toBeTrue(); expect(Number.isFinite(1.23)).toBeTrue();
expect(Number.isFinite(42)).toBeTrue(); expect(Number.isFinite(42)).toBeTrue();
expect(Number.isFinite("")).toBeFalse(); expect(Number.isFinite("")).toBeFalse();
expect(Number.isFinite("0")).toBeFalse(); expect(Number.isFinite("0")).toBeFalse();
expect(Number.isFinite("42")).toBeFalse(); expect(Number.isFinite("42")).toBeFalse();
expect(Number.isFinite(true)).toBeFalse(); expect(Number.isFinite(true)).toBeFalse();
expect(Number.isFinite(false)).toBeFalse(); expect(Number.isFinite(false)).toBeFalse();
expect(Number.isFinite(null)).toBeFalse(); expect(Number.isFinite(null)).toBeFalse();
expect(Number.isFinite([])).toBeFalse(); expect(Number.isFinite([])).toBeFalse();
expect(Number.isFinite()).toBeFalse(); expect(Number.isFinite()).toBeFalse();
expect(Number.isFinite(NaN)).toBeFalse(); expect(Number.isFinite(NaN)).toBeFalse();
expect(Number.isFinite(undefined)).toBeFalse(); expect(Number.isFinite(undefined)).toBeFalse();
expect(Number.isFinite(Infinity)).toBeFalse(); expect(Number.isFinite(Infinity)).toBeFalse();
expect(Number.isFinite(-Infinity)).toBeFalse(); expect(Number.isFinite(-Infinity)).toBeFalse();
expect(Number.isFinite("foo")).toBeFalse(); expect(Number.isFinite("foo")).toBeFalse();
expect(Number.isFinite({})).toBeFalse(); expect(Number.isFinite({})).toBeFalse();
expect(Number.isFinite([1, 2, 3])).toBeFalse(); expect(Number.isFinite([1, 2, 3])).toBeFalse();
}); });

View file

@ -1,32 +1,32 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Number.isInteger).toHaveLength(1); expect(Number.isInteger).toHaveLength(1);
expect(Number.isInteger(0)).toBeTrue(); expect(Number.isInteger(0)).toBeTrue();
expect(Number.isInteger(42)).toBeTrue(); expect(Number.isInteger(42)).toBeTrue();
expect(Number.isInteger(-10000)).toBeTrue(); expect(Number.isInteger(-10000)).toBeTrue();
expect(Number.isInteger(5)).toBeTrue(); expect(Number.isInteger(5)).toBeTrue();
expect(Number.isInteger(5.0)).toBeTrue(); expect(Number.isInteger(5.0)).toBeTrue();
expect(Number.isInteger(5 + 1/10000000000000000)).toBeTrue(); expect(Number.isInteger(5 + 1 / 10000000000000000)).toBeTrue();
// FIXME: values outside of i32's range should still return true // FIXME: values outside of i32's range should still return true
// expect(Number.isInteger(+2147483647 + 1)).toBeTrue(); // expect(Number.isInteger(+2147483647 + 1)).toBeTrue();
// expect(Number.isInteger(-2147483648 - 1)).toBeTrue(); // expect(Number.isInteger(-2147483648 - 1)).toBeTrue();
// expect(Number.isInteger(99999999999999999999999999999999999)).toBeTrue(); // expect(Number.isInteger(99999999999999999999999999999999999)).toBeTrue();
expect(Number.isInteger(5 + 1/1000000000000000)).toBeFalse(); expect(Number.isInteger(5 + 1 / 1000000000000000)).toBeFalse();
expect(Number.isInteger(1.23)).toBeFalse(); expect(Number.isInteger(1.23)).toBeFalse();
expect(Number.isInteger("")).toBeFalse(); expect(Number.isInteger("")).toBeFalse();
expect(Number.isInteger("0")).toBeFalse(); expect(Number.isInteger("0")).toBeFalse();
expect(Number.isInteger("42")).toBeFalse(); expect(Number.isInteger("42")).toBeFalse();
expect(Number.isInteger(true)).toBeFalse(); expect(Number.isInteger(true)).toBeFalse();
expect(Number.isInteger(false)).toBeFalse(); expect(Number.isInteger(false)).toBeFalse();
expect(Number.isInteger(null)).toBeFalse(); expect(Number.isInteger(null)).toBeFalse();
expect(Number.isInteger([])).toBeFalse(); expect(Number.isInteger([])).toBeFalse();
expect(Number.isInteger(Infinity)).toBeFalse(); expect(Number.isInteger(Infinity)).toBeFalse();
expect(Number.isInteger(-Infinity)).toBeFalse(); expect(Number.isInteger(-Infinity)).toBeFalse();
expect(Number.isInteger(NaN)).toBeFalse(); expect(Number.isInteger(NaN)).toBeFalse();
expect(Number.isInteger()).toBeFalse(); expect(Number.isInteger()).toBeFalse();
expect(Number.isInteger(undefined)).toBeFalse(); expect(Number.isInteger(undefined)).toBeFalse();
expect(Number.isInteger("foo")).toBeFalse(); expect(Number.isInteger("foo")).toBeFalse();
expect(Number.isInteger({})).toBeFalse(); expect(Number.isInteger({})).toBeFalse();
expect(Number.isInteger([1, 2, 3])).toBeFalse(); expect(Number.isInteger([1, 2, 3])).toBeFalse();
}); });

View file

@ -1,25 +1,25 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Number.isNaN).toHaveLength(1); expect(Number.isNaN).toHaveLength(1);
expect(Number.isNaN).not.toBe(isNaN); expect(Number.isNaN).not.toBe(isNaN);
expect(Number.isNaN(0)).toBeFalse(); expect(Number.isNaN(0)).toBeFalse();
expect(Number.isNaN(42)).toBeFalse(); expect(Number.isNaN(42)).toBeFalse();
expect(Number.isNaN("")).toBeFalse(); expect(Number.isNaN("")).toBeFalse();
expect(Number.isNaN("0")).toBeFalse(); expect(Number.isNaN("0")).toBeFalse();
expect(Number.isNaN("42")).toBeFalse(); expect(Number.isNaN("42")).toBeFalse();
expect(Number.isNaN(true)).toBeFalse(); expect(Number.isNaN(true)).toBeFalse();
expect(Number.isNaN(false)).toBeFalse(); expect(Number.isNaN(false)).toBeFalse();
expect(Number.isNaN(null)).toBeFalse(); expect(Number.isNaN(null)).toBeFalse();
expect(Number.isNaN([])).toBeFalse(); expect(Number.isNaN([])).toBeFalse();
expect(Number.isNaN(Infinity)).toBeFalse(); expect(Number.isNaN(Infinity)).toBeFalse();
expect(Number.isNaN(-Infinity)).toBeFalse(); expect(Number.isNaN(-Infinity)).toBeFalse();
expect(Number.isNaN()).toBeFalse(); expect(Number.isNaN()).toBeFalse();
expect(Number.isNaN(undefined)).toBeFalse(); expect(Number.isNaN(undefined)).toBeFalse();
expect(Number.isNaN("foo")).toBeFalse(); expect(Number.isNaN("foo")).toBeFalse();
expect(Number.isNaN({})).toBeFalse(); expect(Number.isNaN({})).toBeFalse();
expect(Number.isNaN([1, 2, 3])).toBeFalse(); expect(Number.isNaN([1, 2, 3])).toBeFalse();
expect(Number.isNaN(NaN)).toBeTrue(); expect(Number.isNaN(NaN)).toBeTrue();
expect(Number.isNaN(Number.NaN)).toBeTrue(); expect(Number.isNaN(Number.NaN)).toBeTrue();
expect(Number.isNaN(0 / 0)).toBeTrue(); expect(Number.isNaN(0 / 0)).toBeTrue();
}); });

View file

@ -1,24 +1,24 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Number.isSafeInteger).toHaveLength(1); expect(Number.isSafeInteger).toHaveLength(1);
expect(Number.isSafeInteger(0)).toBeTrue(); expect(Number.isSafeInteger(0)).toBeTrue();
expect(Number.isSafeInteger(1)).toBeTrue(); expect(Number.isSafeInteger(1)).toBeTrue();
expect(Number.isSafeInteger(2.0)).toBeTrue(); expect(Number.isSafeInteger(2.0)).toBeTrue();
expect(Number.isSafeInteger(42)).toBeTrue(); expect(Number.isSafeInteger(42)).toBeTrue();
expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER)).toBeTrue(); expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER)).toBeTrue();
expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER)).toBeTrue(); expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER)).toBeTrue();
expect(Number.isSafeInteger()).toBeFalse(); expect(Number.isSafeInteger()).toBeFalse();
expect(Number.isSafeInteger("1")).toBeFalse(); expect(Number.isSafeInteger("1")).toBeFalse();
expect(Number.isSafeInteger(2.1)).toBeFalse(); expect(Number.isSafeInteger(2.1)).toBeFalse();
expect(Number.isSafeInteger(42.42)).toBeFalse(); expect(Number.isSafeInteger(42.42)).toBeFalse();
expect(Number.isSafeInteger("")).toBeFalse(); expect(Number.isSafeInteger("")).toBeFalse();
expect(Number.isSafeInteger([])).toBeFalse(); expect(Number.isSafeInteger([])).toBeFalse();
expect(Number.isSafeInteger(null)).toBeFalse(); expect(Number.isSafeInteger(null)).toBeFalse();
expect(Number.isSafeInteger(undefined)).toBeFalse(); expect(Number.isSafeInteger(undefined)).toBeFalse();
expect(Number.isSafeInteger(NaN)).toBeFalse(); expect(Number.isSafeInteger(NaN)).toBeFalse();
expect(Number.isSafeInteger(Infinity)).toBeFalse(); expect(Number.isSafeInteger(Infinity)).toBeFalse();
expect(Number.isSafeInteger(-Infinity)).toBeFalse(); expect(Number.isSafeInteger(-Infinity)).toBeFalse();
expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1)).toBeFalse(); expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1)).toBeFalse();
expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1)).toBeFalse(); expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1)).toBeFalse();
}); });

Some files were not shown because too many files have changed in this diff Show more