mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibJS: Indent tests with 4 spaces instead of 2
This commit is contained in:
parent
15de2eda2b
commit
1ef573eb30
Notes:
sideshowbarker
2024-07-19 05:03:50 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/1ef573eb308 Pull-request: https://github.com/SerenityOS/serenity/pull/2689 Reviewed-by: https://github.com/linusg
261 changed files with 8536 additions and 8497 deletions
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"arrowParens": "avoid",
|
||||
"bracketSpacing": true,
|
||||
"endOfLine": "lf",
|
||||
"insertPragma": false,
|
||||
"printWidth": 100,
|
||||
"quoteProps": "as-needed",
|
||||
"semi": true,
|
||||
"singleQuote": false,
|
||||
"tabWidth": 2,
|
||||
"trailingComma": "es5",
|
||||
"useTabs": false
|
||||
"arrowParens": "avoid",
|
||||
"bracketSpacing": true,
|
||||
"endOfLine": "lf",
|
||||
"insertPragma": false,
|
||||
"printWidth": 100,
|
||||
"quoteProps": "as-needed",
|
||||
"semi": true,
|
||||
"singleQuote": false,
|
||||
"tabWidth": 4,
|
||||
"trailingComma": "es5",
|
||||
"useTabs": false
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
test("adding objects", () => {
|
||||
expect([] + []).toBe("");
|
||||
expect([] + {}).toBe("[object Object]");
|
||||
expect({} + {}).toBe("[object Object][object Object]");
|
||||
expect({} + []).toBe("[object Object]");
|
||||
expect([] + []).toBe("");
|
||||
expect([] + {}).toBe("[object Object]");
|
||||
expect({} + {}).toBe("[object Object][object Object]");
|
||||
expect({} + []).toBe("[object Object]");
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
test("Issue #1829, if-else without braces or semicolons", () => {
|
||||
const source = `if (1)
|
||||
const source = `if (1)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
|
@ -14,11 +14,11 @@ if (1)
|
|||
else
|
||||
return 0;`;
|
||||
|
||||
expect(source).toEval();
|
||||
expect(source).toEval();
|
||||
});
|
||||
|
||||
test("break/continue, variable declaration, do-while, and return asi", () => {
|
||||
const source = `function foo() {
|
||||
const source = `function foo() {
|
||||
label:
|
||||
for (var i = 0; i < 4; i++) {
|
||||
break // semicolon inserted here
|
||||
|
@ -39,11 +39,11 @@ var curly/* semicolon inserted here */}
|
|||
|
||||
return foo();`;
|
||||
|
||||
expect(source).toEvalTo(undefined);
|
||||
expect(source).toEvalTo(undefined);
|
||||
});
|
||||
|
||||
test("more break and continue asi", () => {
|
||||
const source = `let counter = 0;
|
||||
const source = `let counter = 0;
|
||||
let outer;
|
||||
|
||||
outer:
|
||||
|
@ -57,9 +57,9 @@ for (let i = 0; i < 5; ++i) {
|
|||
|
||||
return counter;`;
|
||||
|
||||
expect(source).toEvalTo(5);
|
||||
expect(source).toEvalTo(5);
|
||||
});
|
||||
|
||||
test("eof with no semicolon", () => {
|
||||
expect("var eof").toEval();
|
||||
expect("var eof").toEval();
|
||||
});
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.isArray.length === 1);
|
||||
assert(Array.isArray.length === 1);
|
||||
|
||||
assert(Array.isArray() === false);
|
||||
assert(Array.isArray("1") === false);
|
||||
assert(Array.isArray("foo") === false);
|
||||
assert(Array.isArray(1) === false);
|
||||
assert(Array.isArray(1, 2, 3) === false);
|
||||
assert(Array.isArray(undefined) === false);
|
||||
assert(Array.isArray(null) === false);
|
||||
assert(Array.isArray(Infinity) === false);
|
||||
assert(Array.isArray({}) === false);
|
||||
assert(Array.isArray() === false);
|
||||
assert(Array.isArray("1") === false);
|
||||
assert(Array.isArray("foo") === false);
|
||||
assert(Array.isArray(1) === false);
|
||||
assert(Array.isArray(1, 2, 3) === false);
|
||||
assert(Array.isArray(undefined) === false);
|
||||
assert(Array.isArray(null) === false);
|
||||
assert(Array.isArray(Infinity) === false);
|
||||
assert(Array.isArray({}) === false);
|
||||
|
||||
assert(Array.isArray([]) === true);
|
||||
assert(Array.isArray([1]) === true);
|
||||
assert(Array.isArray([1, 2, 3]) === true);
|
||||
assert(Array.isArray(new Array()) === true);
|
||||
assert(Array.isArray(new Array(10)) === true);
|
||||
assert(Array.isArray(new Array("a", "b", "c")) === true);
|
||||
// FIXME: Array.prototype is supposed to be an array!
|
||||
// assert(Array.isArray(Array.prototype) === true);
|
||||
assert(Array.isArray([]) === true);
|
||||
assert(Array.isArray([1]) === true);
|
||||
assert(Array.isArray([1, 2, 3]) === true);
|
||||
assert(Array.isArray(new Array()) === true);
|
||||
assert(Array.isArray(new Array(10)) === true);
|
||||
assert(Array.isArray(new Array("a", "b", "c")) === true);
|
||||
// FIXME: Array.prototype is supposed to be an array!
|
||||
// assert(Array.isArray(Array.prototype) === true);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.length === 1);
|
||||
assert(Array.name === "Array");
|
||||
assert(Array.prototype.length === 0);
|
||||
assert(Array.length === 1);
|
||||
assert(Array.name === "Array");
|
||||
assert(Array.prototype.length === 0);
|
||||
|
||||
assert(typeof Array() === "object");
|
||||
assert(typeof new Array() === "object");
|
||||
assert(typeof Array() === "object");
|
||||
assert(typeof new Array() === "object");
|
||||
|
||||
var a;
|
||||
var a;
|
||||
|
||||
a = new Array(5);
|
||||
assert(a.length === 5);
|
||||
a = new Array(5);
|
||||
assert(a.length === 5);
|
||||
|
||||
a = new Array("5");
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === "5");
|
||||
a = new Array("5");
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === "5");
|
||||
|
||||
a = new Array(1, 2, 3);
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
a = new Array(1, 2, 3);
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
|
||||
a = new Array([1, 2, 3]);
|
||||
assert(a.length === 1);
|
||||
assert(a[0][0] === 1);
|
||||
assert(a[0][1] === 2);
|
||||
assert(a[0][2] === 3);
|
||||
a = new Array([1, 2, 3]);
|
||||
assert(a.length === 1);
|
||||
assert(a[0][0] === 1);
|
||||
assert(a[0][1] === 2);
|
||||
assert(a[0][2] === 3);
|
||||
|
||||
a = new Array(1, 2, 3);
|
||||
Object.defineProperty(a, 3, {
|
||||
get() {
|
||||
return 10;
|
||||
},
|
||||
});
|
||||
assert(a.toString() === "1,2,3,10");
|
||||
a = new Array(1, 2, 3);
|
||||
Object.defineProperty(a, 3, {
|
||||
get() {
|
||||
return 10;
|
||||
},
|
||||
});
|
||||
assert(a.toString() === "1,2,3,10");
|
||||
|
||||
[-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
new Array(value);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Invalid array length",
|
||||
}
|
||||
);
|
||||
});
|
||||
[-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
new Array(value);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Invalid array length",
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,50 +1,50 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.of.length === 0);
|
||||
assert(Array.of.length === 0);
|
||||
|
||||
assert(typeof Array.of() === "object");
|
||||
assert(typeof Array.of() === "object");
|
||||
|
||||
var a;
|
||||
var a;
|
||||
|
||||
a = Array.of(5);
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === 5);
|
||||
a = Array.of(5);
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === 5);
|
||||
|
||||
a = Array.of("5");
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === "5");
|
||||
a = Array.of("5");
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === "5");
|
||||
|
||||
a = Array.of(Infinity);
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === Infinity);
|
||||
a = Array.of(Infinity);
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === Infinity);
|
||||
|
||||
a = Array.of(1, 2, 3);
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
a = Array.of(1, 2, 3);
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
|
||||
a = Array.of([1, 2, 3]);
|
||||
assert(a.length === 1);
|
||||
assert(a[0][0] === 1);
|
||||
assert(a[0][1] === 2);
|
||||
assert(a[0][2] === 3);
|
||||
a = Array.of([1, 2, 3]);
|
||||
assert(a.length === 1);
|
||||
assert(a[0][0] === 1);
|
||||
assert(a[0][1] === 2);
|
||||
assert(a[0][2] === 3);
|
||||
|
||||
let t = [1, 2, 3];
|
||||
Object.defineProperty(t, 3, {
|
||||
get() {
|
||||
return 4;
|
||||
},
|
||||
});
|
||||
a = Array.of(...t);
|
||||
assert(a.length === 4);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
assert(a[3] === 4);
|
||||
let t = [1, 2, 3];
|
||||
Object.defineProperty(t, 3, {
|
||||
get() {
|
||||
return 4;
|
||||
},
|
||||
});
|
||||
a = Array.of(...t);
|
||||
assert(a.length === 4);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
assert(a[3] === 4);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,159 +1,164 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
[undefined, "foo", -42, 0].forEach(length => {
|
||||
const o = { length };
|
||||
[undefined, "foo", -42, 0].forEach(length => {
|
||||
const o = { length };
|
||||
|
||||
assert(Array.prototype.push.call(o, "foo") === 1);
|
||||
assert(o.length === 1);
|
||||
assert(o[0] === "foo");
|
||||
assert(Array.prototype.push.call(o, "bar", "baz") === 3);
|
||||
assert(o.length === 3);
|
||||
assert(o[0] === "foo");
|
||||
assert(o[1] === "bar");
|
||||
assert(o[2] === "baz");
|
||||
assert(Array.prototype.push.call(o, "foo") === 1);
|
||||
assert(o.length === 1);
|
||||
assert(o[0] === "foo");
|
||||
assert(Array.prototype.push.call(o, "bar", "baz") === 3);
|
||||
assert(o.length === 3);
|
||||
assert(o[0] === "foo");
|
||||
assert(o[1] === "bar");
|
||||
assert(o[2] === "baz");
|
||||
|
||||
assert(Array.prototype.pop.call(o) === "baz");
|
||||
assert(o.length === 2);
|
||||
assert(Array.prototype.pop.call(o) === "bar");
|
||||
assert(o.length === 1);
|
||||
assert(Array.prototype.pop.call(o) === "foo");
|
||||
assert(o.length === 0);
|
||||
assert(Array.prototype.pop.call(o) === undefined);
|
||||
assert(o.length === 0);
|
||||
assert(Array.prototype.pop.call(o) === "baz");
|
||||
assert(o.length === 2);
|
||||
assert(Array.prototype.pop.call(o) === "bar");
|
||||
assert(o.length === 1);
|
||||
assert(Array.prototype.pop.call(o) === "foo");
|
||||
assert(o.length === 0);
|
||||
assert(Array.prototype.pop.call(o) === undefined);
|
||||
assert(o.length === 0);
|
||||
|
||||
o.length = length;
|
||||
assert(Array.prototype.pop.call(o) === undefined);
|
||||
assert(o.length === 0);
|
||||
});
|
||||
o.length = length;
|
||||
assert(Array.prototype.pop.call(o) === undefined);
|
||||
assert(o.length === 0);
|
||||
});
|
||||
|
||||
{
|
||||
const o = { length: 3, 0: "hello", 2: "serenity" };
|
||||
const removed = Array.prototype.splice.call(o, 0, 2, "hello", "friends");
|
||||
assert(o.length === 3);
|
||||
assert(o[0] === "hello");
|
||||
assert(o[1] === "friends");
|
||||
assert(o[2] === "serenity");
|
||||
assert(removed.length === 2);
|
||||
assert(removed[0] === "hello");
|
||||
assert(removed[1] === undefined);
|
||||
}
|
||||
{
|
||||
const o = { length: 3, 0: "hello", 2: "serenity" };
|
||||
const removed = Array.prototype.splice.call(o, 0, 2, "hello", "friends");
|
||||
assert(o.length === 3);
|
||||
assert(o[0] === "hello");
|
||||
assert(o[1] === "friends");
|
||||
assert(o[2] === "serenity");
|
||||
assert(removed.length === 2);
|
||||
assert(removed[0] === "hello");
|
||||
assert(removed[1] === undefined);
|
||||
}
|
||||
|
||||
{
|
||||
assert(Array.prototype.join.call({}) === "");
|
||||
assert(Array.prototype.join.call({ length: "foo" }) === "");
|
||||
assert(Array.prototype.join.call({ length: 3 }) === ",,");
|
||||
assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" }) === "foo,bar");
|
||||
assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" }) === "foo,bar");
|
||||
assert(Array.prototype.join.call({ length: 3, 1: "bar" }, "~") === "~bar~");
|
||||
assert(
|
||||
Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~") === "foo~bar~baz"
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
assert(Array.prototype.toString.call({}) === "[object Object]");
|
||||
assert(Array.prototype.toString.call({ join: "foo" }) === "[object Object]");
|
||||
assert(Array.prototype.toString.call({ join: () => "foo" }) === "foo");
|
||||
}
|
||||
|
||||
{
|
||||
assert(Array.prototype.indexOf.call({}) === -1);
|
||||
assert(Array.prototype.indexOf.call({ 0: undefined }) === -1);
|
||||
assert(Array.prototype.indexOf.call({ length: 1, 0: undefined }) === 0);
|
||||
assert(Array.prototype.indexOf.call({ length: 1, 2: "foo" }, "foo") === -1);
|
||||
assert(Array.prototype.indexOf.call({ length: 5, 2: "foo" }, "foo") === 2);
|
||||
assert(Array.prototype.indexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", 3) === 4);
|
||||
}
|
||||
|
||||
{
|
||||
assert(Array.prototype.lastIndexOf.call({}) === -1);
|
||||
assert(Array.prototype.lastIndexOf.call({ 0: undefined }) === -1);
|
||||
assert(Array.prototype.lastIndexOf.call({ length: 1, 0: undefined }) === 0);
|
||||
assert(Array.prototype.lastIndexOf.call({ length: 1, 2: "foo" }, "foo") === -1);
|
||||
assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo" }, "foo") === 2);
|
||||
assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo") === 4);
|
||||
assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", -2) === 2);
|
||||
}
|
||||
|
||||
{
|
||||
assert(Array.prototype.includes.call({}) === false);
|
||||
assert(Array.prototype.includes.call({ 0: undefined }) === false);
|
||||
assert(Array.prototype.includes.call({ length: 1, 0: undefined }) === true);
|
||||
assert(Array.prototype.includes.call({ length: 1, 2: "foo" }, "foo") === false);
|
||||
assert(Array.prototype.includes.call({ length: 5, 2: "foo" }, "foo") === true);
|
||||
}
|
||||
|
||||
const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" };
|
||||
|
||||
{
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype.every.call(o, function (value) {
|
||||
visit(value);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
["foo", "bar", "baz"]
|
||||
);
|
||||
}
|
||||
|
||||
["find", "findIndex"].forEach(name => {
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype[name].call(o, function (value) {
|
||||
visit(value);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
["foo", "bar", undefined, "baz", undefined]
|
||||
);
|
||||
});
|
||||
|
||||
["filter", "forEach", "map", "some"].forEach(name => {
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype[name].call(o, function (value) {
|
||||
visit(value);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
["foo", "bar", "baz"]
|
||||
);
|
||||
});
|
||||
{
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype.reduce.call(
|
||||
o,
|
||||
function (_, value) {
|
||||
visit(value);
|
||||
return false;
|
||||
},
|
||||
"initial"
|
||||
{
|
||||
assert(Array.prototype.join.call({}) === "");
|
||||
assert(Array.prototype.join.call({ length: "foo" }) === "");
|
||||
assert(Array.prototype.join.call({ length: 3 }) === ",,");
|
||||
assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" }) === "foo,bar");
|
||||
assert(
|
||||
Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" }) === "foo,bar"
|
||||
);
|
||||
},
|
||||
["foo", "bar", "baz"]
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype.reduceRight.call(
|
||||
o,
|
||||
function (_, value) {
|
||||
visit(value);
|
||||
return false;
|
||||
},
|
||||
"initial"
|
||||
assert(Array.prototype.join.call({ length: 3, 1: "bar" }, "~") === "~bar~");
|
||||
assert(
|
||||
Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~") ===
|
||||
"foo~bar~baz"
|
||||
);
|
||||
},
|
||||
["baz", "bar", "foo"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("PASS");
|
||||
{
|
||||
assert(Array.prototype.toString.call({}) === "[object Object]");
|
||||
assert(Array.prototype.toString.call({ join: "foo" }) === "[object Object]");
|
||||
assert(Array.prototype.toString.call({ join: () => "foo" }) === "foo");
|
||||
}
|
||||
|
||||
{
|
||||
assert(Array.prototype.indexOf.call({}) === -1);
|
||||
assert(Array.prototype.indexOf.call({ 0: undefined }) === -1);
|
||||
assert(Array.prototype.indexOf.call({ length: 1, 0: undefined }) === 0);
|
||||
assert(Array.prototype.indexOf.call({ length: 1, 2: "foo" }, "foo") === -1);
|
||||
assert(Array.prototype.indexOf.call({ length: 5, 2: "foo" }, "foo") === 2);
|
||||
assert(Array.prototype.indexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", 3) === 4);
|
||||
}
|
||||
|
||||
{
|
||||
assert(Array.prototype.lastIndexOf.call({}) === -1);
|
||||
assert(Array.prototype.lastIndexOf.call({ 0: undefined }) === -1);
|
||||
assert(Array.prototype.lastIndexOf.call({ length: 1, 0: undefined }) === 0);
|
||||
assert(Array.prototype.lastIndexOf.call({ length: 1, 2: "foo" }, "foo") === -1);
|
||||
assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo" }, "foo") === 2);
|
||||
assert(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo") === 4);
|
||||
assert(
|
||||
Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", -2) === 2
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
assert(Array.prototype.includes.call({}) === false);
|
||||
assert(Array.prototype.includes.call({ 0: undefined }) === false);
|
||||
assert(Array.prototype.includes.call({ length: 1, 0: undefined }) === true);
|
||||
assert(Array.prototype.includes.call({ length: 1, 2: "foo" }, "foo") === false);
|
||||
assert(Array.prototype.includes.call({ length: 5, 2: "foo" }, "foo") === true);
|
||||
}
|
||||
|
||||
const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" };
|
||||
|
||||
{
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype.every.call(o, function (value) {
|
||||
visit(value);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
["foo", "bar", "baz"]
|
||||
);
|
||||
}
|
||||
|
||||
["find", "findIndex"].forEach(name => {
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype[name].call(o, function (value) {
|
||||
visit(value);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
["foo", "bar", undefined, "baz", undefined]
|
||||
);
|
||||
});
|
||||
|
||||
["filter", "forEach", "map", "some"].forEach(name => {
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype[name].call(o, function (value) {
|
||||
visit(value);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
["foo", "bar", "baz"]
|
||||
);
|
||||
});
|
||||
{
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype.reduce.call(
|
||||
o,
|
||||
function (_, value) {
|
||||
visit(value);
|
||||
return false;
|
||||
},
|
||||
"initial"
|
||||
);
|
||||
},
|
||||
["foo", "bar", "baz"]
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype.reduceRight.call(
|
||||
o,
|
||||
function (_, value) {
|
||||
visit(value);
|
||||
return false;
|
||||
},
|
||||
"initial"
|
||||
);
|
||||
},
|
||||
["baz", "bar", "foo"]
|
||||
);
|
||||
}
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.concat.length === 1);
|
||||
assert(Array.prototype.concat.length === 1);
|
||||
|
||||
var array = ["hello", "friends"];
|
||||
var array = ["hello", "friends"];
|
||||
|
||||
var array_concat = array.concat();
|
||||
assert(array_concat.length === array.length);
|
||||
var array_concat = array.concat();
|
||||
assert(array_concat.length === array.length);
|
||||
|
||||
array_concat = array.concat(1);
|
||||
assert(array_concat.length === 3);
|
||||
assert(array_concat[2] === 1);
|
||||
array_concat = array.concat(1);
|
||||
assert(array_concat.length === 3);
|
||||
assert(array_concat[2] === 1);
|
||||
|
||||
array_concat = array.concat([1, 2, 3]);
|
||||
assert(array_concat.length === 5);
|
||||
assert(array_concat[2] === 1);
|
||||
assert(array_concat[3] === 2);
|
||||
assert(array_concat[4] === 3);
|
||||
array_concat = array.concat([1, 2, 3]);
|
||||
assert(array_concat.length === 5);
|
||||
assert(array_concat[2] === 1);
|
||||
assert(array_concat[3] === 2);
|
||||
assert(array_concat[4] === 3);
|
||||
|
||||
array_concat = array.concat(false, "serenity");
|
||||
assert(array_concat.length === 4);
|
||||
assert(array_concat[2] === false);
|
||||
assert(array_concat[3] === "serenity");
|
||||
array_concat = array.concat(false, "serenity");
|
||||
assert(array_concat.length === 4);
|
||||
assert(array_concat[2] === false);
|
||||
assert(array_concat[3] === "serenity");
|
||||
|
||||
array_concat = array.concat({ name: "libjs" }, [1, [2, 3]]);
|
||||
assert(array_concat.length === 5);
|
||||
assert(array_concat[2].name === "libjs");
|
||||
assert(array_concat[3] === 1);
|
||||
assert(array_concat[4][0] === 2);
|
||||
assert(array_concat[4][1] === 3);
|
||||
array_concat = array.concat({ name: "libjs" }, [1, [2, 3]]);
|
||||
assert(array_concat.length === 5);
|
||||
assert(array_concat[2].name === "libjs");
|
||||
assert(array_concat[3] === 1);
|
||||
assert(array_concat[4][0] === 2);
|
||||
assert(array_concat[4][1] === 3);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.every.length === 1);
|
||||
assert(Array.prototype.every.length === 1);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].every(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].every(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var arrayOne = ["serenity", { test: "serenity" }];
|
||||
var arrayTwo = [true, false, 1, 2, 3, "3"];
|
||||
var arrayOne = ["serenity", { test: "serenity" }];
|
||||
var arrayTwo = [true, false, 1, 2, 3, "3"];
|
||||
|
||||
assert(arrayOne.every(value => value === "hello") === false);
|
||||
assert(arrayOne.every(value => value === "serenity") === false);
|
||||
assert(arrayOne.every((value, index, arr) => index < 2) === true);
|
||||
assert(arrayOne.every(value => typeof value === "string") === false);
|
||||
assert(arrayOne.every(value => arrayOne.pop()) === true);
|
||||
assert(arrayOne.every(value => value === "hello") === false);
|
||||
assert(arrayOne.every(value => value === "serenity") === false);
|
||||
assert(arrayOne.every((value, index, arr) => index < 2) === true);
|
||||
assert(arrayOne.every(value => typeof value === "string") === false);
|
||||
assert(arrayOne.every(value => arrayOne.pop()) === true);
|
||||
|
||||
assert(arrayTwo.every((value, index, arr) => index > 0) === false);
|
||||
assert(arrayTwo.every((value, index, arr) => index >= 0) === true);
|
||||
assert(arrayTwo.every(value => typeof value !== "string") === false);
|
||||
assert(arrayTwo.every(value => typeof value === "number") === false);
|
||||
assert(arrayTwo.every(value => value > 0) === false);
|
||||
assert(arrayTwo.every(value => value >= 0 && value < 4) === true);
|
||||
assert(arrayTwo.every(value => arrayTwo.pop()) === true);
|
||||
assert(arrayTwo.every((value, index, arr) => index > 0) === false);
|
||||
assert(arrayTwo.every((value, index, arr) => index >= 0) === true);
|
||||
assert(arrayTwo.every(value => typeof value !== "string") === false);
|
||||
assert(arrayTwo.every(value => typeof value === "number") === false);
|
||||
assert(arrayTwo.every(value => value > 0) === false);
|
||||
assert(arrayTwo.every(value => value >= 0 && value < 4) === true);
|
||||
assert(arrayTwo.every(value => arrayTwo.pop()) === true);
|
||||
|
||||
assert(["", "hello", "friends", "serenity"].every(value => value.length >= 0) === true);
|
||||
assert([].every(value => value === 1) === true);
|
||||
assert(["", "hello", "friends", "serenity"].every(value => value.length >= 0) === true);
|
||||
assert([].every(value => value === 1) === true);
|
||||
|
||||
arrayTwo = [true, false, 1, 2, 3, "3"];
|
||||
arrayTwo = [true, false, 1, 2, 3, "3"];
|
||||
|
||||
// Every only goes up to the original length.
|
||||
assert(
|
||||
arrayTwo.every((value, index, arr) => {
|
||||
arr.push("serenity");
|
||||
return value < 4;
|
||||
}) === true
|
||||
);
|
||||
// Every only goes up to the original length.
|
||||
assert(
|
||||
arrayTwo.every((value, index, arr) => {
|
||||
arr.push("serenity");
|
||||
return value < 4;
|
||||
}) === true
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.fill.length === 1);
|
||||
assert(Array.prototype.fill.length === 1);
|
||||
|
||||
var array = [1, 2, 3, 4];
|
||||
assertArrayEquals(array.fill(0, 2, 4), [1, 2, 0, 0]);
|
||||
assertArrayEquals(array.fill(5, 1), [1, 5, 5, 5]);
|
||||
assertArrayEquals(array.fill(6), [6, 6, 6, 6]);
|
||||
var array = [1, 2, 3, 4];
|
||||
assertArrayEquals(array.fill(0, 2, 4), [1, 2, 0, 0]);
|
||||
assertArrayEquals(array.fill(5, 1), [1, 5, 5, 5]);
|
||||
assertArrayEquals(array.fill(6), [6, 6, 6, 6]);
|
||||
|
||||
assertArrayEquals([1, 2, 3].fill(4), [4, 4, 4]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, 1), [1, 4, 4]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, 1, 2), [1, 4, 3]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, 3, 3), [1, 2, 3]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, -3, -2), [4, 2, 3]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, NaN, NaN), [1, 2, 3]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, 3, 5), [1, 2, 3]);
|
||||
assertArrayEquals(Array(3).fill(4), [4, 4, 4]);
|
||||
assertArrayEquals([1, 2, 3].fill(4), [4, 4, 4]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, 1), [1, 4, 4]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, 1, 2), [1, 4, 3]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, 3, 3), [1, 2, 3]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, -3, -2), [4, 2, 3]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, NaN, NaN), [1, 2, 3]);
|
||||
assertArrayEquals([1, 2, 3].fill(4, 3, 5), [1, 2, 3]);
|
||||
assertArrayEquals(Array(3).fill(4), [4, 4, 4]);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,78 +1,78 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.filter.length === 1);
|
||||
assert(Array.prototype.filter.length === 1);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].filter();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.filter() requires at least one argument",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].filter();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.filter() requires at least one argument",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].filter(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].filter(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
|
||||
assert([].filter(callback).length === 0);
|
||||
assert(callbackCalled === 0);
|
||||
assert([].filter(callback).length === 0);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
assert([1, 2, 3].filter(callback).length === 0);
|
||||
assert(callbackCalled === 3);
|
||||
assert([1, 2, 3].filter(callback).length === 0);
|
||||
assert(callbackCalled === 3);
|
||||
|
||||
var evenNumbers = [0, 1, 2, 3, 4, 5, 6, 7].filter(x => x % 2 === 0);
|
||||
assert(evenNumbers.length === 4);
|
||||
assert(evenNumbers[0] === 0);
|
||||
assert(evenNumbers[1] === 2);
|
||||
assert(evenNumbers[2] === 4);
|
||||
assert(evenNumbers[3] === 6);
|
||||
var evenNumbers = [0, 1, 2, 3, 4, 5, 6, 7].filter(x => x % 2 === 0);
|
||||
assert(evenNumbers.length === 4);
|
||||
assert(evenNumbers[0] === 0);
|
||||
assert(evenNumbers[1] === 2);
|
||||
assert(evenNumbers[2] === 4);
|
||||
assert(evenNumbers[3] === 6);
|
||||
|
||||
var fruits = [
|
||||
"Apple",
|
||||
"Banana",
|
||||
"Blueberry",
|
||||
"Grape",
|
||||
"Mango",
|
||||
"Orange",
|
||||
"Peach",
|
||||
"Pineapple",
|
||||
"Raspberry",
|
||||
"Watermelon",
|
||||
];
|
||||
const filterItems = (arr, query) => {
|
||||
return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1);
|
||||
};
|
||||
var fruits = [
|
||||
"Apple",
|
||||
"Banana",
|
||||
"Blueberry",
|
||||
"Grape",
|
||||
"Mango",
|
||||
"Orange",
|
||||
"Peach",
|
||||
"Pineapple",
|
||||
"Raspberry",
|
||||
"Watermelon",
|
||||
];
|
||||
const filterItems = (arr, query) => {
|
||||
return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1);
|
||||
};
|
||||
|
||||
var results;
|
||||
var results;
|
||||
|
||||
results = filterItems(fruits, "Berry");
|
||||
assert(results.length === 2);
|
||||
assert(results[0] === "Blueberry");
|
||||
assert(results[1] === "Raspberry");
|
||||
results = filterItems(fruits, "Berry");
|
||||
assert(results.length === 2);
|
||||
assert(results[0] === "Blueberry");
|
||||
assert(results[1] === "Raspberry");
|
||||
|
||||
results = filterItems(fruits, "P");
|
||||
assert(results.length === 5);
|
||||
assert(results[0] === "Apple");
|
||||
assert(results[1] === "Grape");
|
||||
assert(results[2] === "Peach");
|
||||
assert(results[3] === "Pineapple");
|
||||
assert(results[4] === "Raspberry");
|
||||
results = filterItems(fruits, "P");
|
||||
assert(results.length === 5);
|
||||
assert(results[0] === "Apple");
|
||||
assert(results[1] === "Grape");
|
||||
assert(results[2] === "Peach");
|
||||
assert(results[3] === "Pineapple");
|
||||
assert(results[4] === "Raspberry");
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.find.length === 1);
|
||||
assert(Array.prototype.find.length === 1);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].find(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].find(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var array = ["hello", "friends", 1, 2, false];
|
||||
var array = ["hello", "friends", 1, 2, false];
|
||||
|
||||
assert(array.find(value => value === "hello") === "hello");
|
||||
assert(array.find((value, index, arr) => index === 1) === "friends");
|
||||
assert(array.find(value => value == "1") === 1);
|
||||
assert(array.find(value => value === 1) === 1);
|
||||
assert(array.find(value => typeof value !== "string") === 1);
|
||||
assert(array.find(value => typeof value === "boolean") === false);
|
||||
assert(array.find(value => value > 1) === 2);
|
||||
assert(array.find(value => value > 1 && value < 3) === 2);
|
||||
assert(array.find(value => value > 100) === undefined);
|
||||
assert([].find(value => value === 1) === undefined);
|
||||
assert(array.find(value => value === "hello") === "hello");
|
||||
assert(array.find((value, index, arr) => index === 1) === "friends");
|
||||
assert(array.find(value => value == "1") === 1);
|
||||
assert(array.find(value => value === 1) === 1);
|
||||
assert(array.find(value => typeof value !== "string") === 1);
|
||||
assert(array.find(value => typeof value === "boolean") === false);
|
||||
assert(array.find(value => value > 1) === 2);
|
||||
assert(array.find(value => value > 1 && value < 3) === 2);
|
||||
assert(array.find(value => value > 100) === undefined);
|
||||
assert([].find(value => value === 1) === undefined);
|
||||
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
|
||||
[].find(callback);
|
||||
assert(callbackCalled === 0);
|
||||
[].find(callback);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
[1, 2, 3].find(callback);
|
||||
assert(callbackCalled === 3);
|
||||
[1, 2, 3].find(callback);
|
||||
assert(callbackCalled === 3);
|
||||
|
||||
callbackCalled = 0;
|
||||
[1, , , "foo", , undefined, , ,].find(callback);
|
||||
assert(callbackCalled === 8);
|
||||
callbackCalled = 0;
|
||||
[1, , , "foo", , undefined, , ,].find(callback);
|
||||
assert(callbackCalled === 8);
|
||||
|
||||
callbackCalled = 0;
|
||||
[1, , , "foo", , undefined, , ,].find(value => {
|
||||
callbackCalled++;
|
||||
return value === undefined;
|
||||
});
|
||||
assert(callbackCalled === 2);
|
||||
callbackCalled = 0;
|
||||
[1, , , "foo", , undefined, , ,].find(value => {
|
||||
callbackCalled++;
|
||||
return value === undefined;
|
||||
});
|
||||
assert(callbackCalled === 2);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.findIndex.length === 1);
|
||||
assert(Array.prototype.findIndex.length === 1);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].findIndex(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].findIndex(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var array = ["hello", "friends", 1, 2, false];
|
||||
var array = ["hello", "friends", 1, 2, false];
|
||||
|
||||
assert(array.findIndex(value => value === "hello") === 0);
|
||||
assert(array.findIndex((value, index, arr) => index === 1) === 1);
|
||||
assert(array.findIndex(value => value == "1") === 2);
|
||||
assert(array.findIndex(value => value === 1) === 2);
|
||||
assert(array.findIndex(value => typeof value !== "string") === 2);
|
||||
assert(array.findIndex(value => typeof value === "boolean") === 4);
|
||||
assert(array.findIndex(value => value > 1) === 3);
|
||||
assert(array.findIndex(value => value > 1 && value < 3) === 3);
|
||||
assert(array.findIndex(value => value > 100) === -1);
|
||||
assert([].findIndex(value => value === 1) === -1);
|
||||
assert(array.findIndex(value => value === "hello") === 0);
|
||||
assert(array.findIndex((value, index, arr) => index === 1) === 1);
|
||||
assert(array.findIndex(value => value == "1") === 2);
|
||||
assert(array.findIndex(value => value === 1) === 2);
|
||||
assert(array.findIndex(value => typeof value !== "string") === 2);
|
||||
assert(array.findIndex(value => typeof value === "boolean") === 4);
|
||||
assert(array.findIndex(value => value > 1) === 3);
|
||||
assert(array.findIndex(value => value > 1 && value < 3) === 3);
|
||||
assert(array.findIndex(value => value > 100) === -1);
|
||||
assert([].findIndex(value => value === 1) === -1);
|
||||
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
|
||||
[].findIndex(callback);
|
||||
assert(callbackCalled === 0);
|
||||
[].findIndex(callback);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
[1, 2, 3].findIndex(callback);
|
||||
assert(callbackCalled === 3);
|
||||
[1, 2, 3].findIndex(callback);
|
||||
assert(callbackCalled === 3);
|
||||
|
||||
callbackCalled = 0;
|
||||
[1, , , "foo", , undefined, , ,].findIndex(callback);
|
||||
assert(callbackCalled === 8);
|
||||
callbackCalled = 0;
|
||||
[1, , , "foo", , undefined, , ,].findIndex(callback);
|
||||
assert(callbackCalled === 8);
|
||||
|
||||
callbackCalled = 0;
|
||||
[1, , , "foo", , undefined, , ,].findIndex(value => {
|
||||
callbackCalled++;
|
||||
return value === undefined;
|
||||
});
|
||||
assert(callbackCalled === 2);
|
||||
callbackCalled = 0;
|
||||
[1, , , "foo", , undefined, , ,].findIndex(value => {
|
||||
callbackCalled++;
|
||||
return value === undefined;
|
||||
});
|
||||
assert(callbackCalled === 2);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,70 +1,70 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.forEach.length === 1);
|
||||
assert(Array.prototype.forEach.length === 1);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].forEach();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.forEach() requires at least one argument",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].forEach();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.forEach() requires at least one argument",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].forEach(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].forEach(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var a = [1, 2, 3];
|
||||
var o = {};
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
var a = [1, 2, 3];
|
||||
var o = {};
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
|
||||
assert([].forEach(callback) === undefined);
|
||||
assert(callbackCalled === 0);
|
||||
assert([].forEach(callback) === undefined);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
assert(a.forEach(callback) === undefined);
|
||||
assert(callbackCalled === 3);
|
||||
assert(a.forEach(callback) === undefined);
|
||||
assert(callbackCalled === 3);
|
||||
|
||||
callbackCalled = 0;
|
||||
a.forEach(function (value, index) {
|
||||
assert(value === a[index]);
|
||||
assert(index === a[index] - 1);
|
||||
});
|
||||
callbackCalled = 0;
|
||||
a.forEach(function (value, index) {
|
||||
assert(value === a[index]);
|
||||
assert(index === a[index] - 1);
|
||||
});
|
||||
|
||||
callbackCalled = 0;
|
||||
a.forEach(function (_, _, array) {
|
||||
callbackCalled++;
|
||||
assert(a.length === array.length);
|
||||
a.push("test");
|
||||
});
|
||||
assert(callbackCalled === 3);
|
||||
assert(a.length === 6);
|
||||
callbackCalled = 0;
|
||||
a.forEach(function (_, _, array) {
|
||||
callbackCalled++;
|
||||
assert(a.length === array.length);
|
||||
a.push("test");
|
||||
});
|
||||
assert(callbackCalled === 3);
|
||||
assert(a.length === 6);
|
||||
|
||||
callbackCalled = 0;
|
||||
a.forEach(function (value, index) {
|
||||
callbackCalled++;
|
||||
this[index] = value;
|
||||
}, o);
|
||||
assert(callbackCalled === 6);
|
||||
assert(o[0] === 1);
|
||||
assert(o[1] === 2);
|
||||
assert(o[2] === 3);
|
||||
assert(o[3] === "test");
|
||||
assert(o[4] === "test");
|
||||
assert(o[5] === "test");
|
||||
callbackCalled = 0;
|
||||
a.forEach(function (value, index) {
|
||||
callbackCalled++;
|
||||
this[index] = value;
|
||||
}, o);
|
||||
assert(callbackCalled === 6);
|
||||
assert(o[0] === 1);
|
||||
assert(o[1] === 2);
|
||||
assert(o[2] === 3);
|
||||
assert(o[3] === "test");
|
||||
assert(o[4] === "test");
|
||||
assert(o[5] === "test");
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.includes.length === 1);
|
||||
assert(Array.prototype.includes.length === 1);
|
||||
|
||||
var array = ["hello", "friends", 1, 2, false];
|
||||
var array = ["hello", "friends", 1, 2, false];
|
||||
|
||||
assert([].includes() === false);
|
||||
assert([undefined].includes() === true);
|
||||
assert(array.includes("hello") === true);
|
||||
assert(array.includes(1) === true);
|
||||
assert(array.includes(1, -3) === true);
|
||||
assert(array.includes("serenity") === false);
|
||||
assert(array.includes(false, -1) === true);
|
||||
assert(array.includes(2, -1) === false);
|
||||
assert(array.includes(2, -100) === true);
|
||||
assert(array.includes("friends", 100) === false);
|
||||
assert([].includes() === false);
|
||||
assert([undefined].includes() === true);
|
||||
assert(array.includes("hello") === true);
|
||||
assert(array.includes(1) === true);
|
||||
assert(array.includes(1, -3) === true);
|
||||
assert(array.includes("serenity") === false);
|
||||
assert(array.includes(false, -1) === true);
|
||||
assert(array.includes(2, -1) === false);
|
||||
assert(array.includes(2, -100) === true);
|
||||
assert(array.includes("friends", 100) === false);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.indexOf.length === 1);
|
||||
assert(Array.prototype.indexOf.length === 1);
|
||||
|
||||
var array = ["hello", "friends", 1, 2, false];
|
||||
var array = ["hello", "friends", 1, 2, false];
|
||||
|
||||
assert(array.indexOf("hello") === 0);
|
||||
assert(array.indexOf("friends") === 1);
|
||||
assert(array.indexOf(false) === 4);
|
||||
assert(array.indexOf(false, 2) === 4);
|
||||
assert(array.indexOf(false, -2) === 4);
|
||||
assert(array.indexOf(1) === 2);
|
||||
assert(array.indexOf(1, 1000) === -1);
|
||||
assert(array.indexOf(1, -1000) === 2);
|
||||
assert(array.indexOf("serenity") === -1);
|
||||
assert(array.indexOf(false, -1) === 4);
|
||||
assert(array.indexOf(2, -1) === -1);
|
||||
assert(array.indexOf(2, -2) === 3);
|
||||
assert([].indexOf("serenity") === -1);
|
||||
assert([].indexOf("serenity", 10) === -1);
|
||||
assert([].indexOf("serenity", -10) === -1);
|
||||
assert([].indexOf() === -1);
|
||||
assert([undefined].indexOf() === 0);
|
||||
assert(array.indexOf("hello") === 0);
|
||||
assert(array.indexOf("friends") === 1);
|
||||
assert(array.indexOf(false) === 4);
|
||||
assert(array.indexOf(false, 2) === 4);
|
||||
assert(array.indexOf(false, -2) === 4);
|
||||
assert(array.indexOf(1) === 2);
|
||||
assert(array.indexOf(1, 1000) === -1);
|
||||
assert(array.indexOf(1, -1000) === 2);
|
||||
assert(array.indexOf("serenity") === -1);
|
||||
assert(array.indexOf(false, -1) === 4);
|
||||
assert(array.indexOf(2, -1) === -1);
|
||||
assert(array.indexOf(2, -2) === 3);
|
||||
assert([].indexOf("serenity") === -1);
|
||||
assert([].indexOf("serenity", 10) === -1);
|
||||
assert([].indexOf("serenity", -10) === -1);
|
||||
assert([].indexOf() === -1);
|
||||
assert([undefined].indexOf() === 0);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.join.length === 1);
|
||||
assert(Array.prototype.join.length === 1);
|
||||
|
||||
assert(["hello", "friends"].join() === "hello,friends");
|
||||
assert(["hello", "friends"].join(" ") === "hello friends");
|
||||
assert(["hello", "friends", "foo"].join("~", "#") === "hello~friends~foo");
|
||||
assert([].join() === "");
|
||||
assert([null].join() === "");
|
||||
assert([undefined].join() === "");
|
||||
assert([undefined, null, ""].join() === ",,");
|
||||
assert([1, null, 2, undefined, 3].join() === "1,,2,,3");
|
||||
assert(Array(3).join() === ",,");
|
||||
assert(["hello", "friends"].join() === "hello,friends");
|
||||
assert(["hello", "friends"].join(" ") === "hello friends");
|
||||
assert(["hello", "friends", "foo"].join("~", "#") === "hello~friends~foo");
|
||||
assert([].join() === "");
|
||||
assert([null].join() === "");
|
||||
assert([undefined].join() === "");
|
||||
assert([undefined, null, ""].join() === ",,");
|
||||
assert([1, null, 2, undefined, 3].join() === "1,,2,,3");
|
||||
assert(Array(3).join() === ",,");
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.lastIndexOf.length === 1);
|
||||
assert(Array.prototype.lastIndexOf.length === 1);
|
||||
|
||||
var array = [1, 2, 3, 1, "hello"];
|
||||
var array = [1, 2, 3, 1, "hello"];
|
||||
|
||||
assert(array.lastIndexOf("hello") === 4);
|
||||
assert(array.lastIndexOf("hello", 1000) === 4);
|
||||
assert(array.lastIndexOf(1) === 3);
|
||||
assert(array.lastIndexOf(1, -1) === 3);
|
||||
assert(array.lastIndexOf(1, -2) === 3);
|
||||
assert(array.lastIndexOf(2) === 1);
|
||||
assert(array.lastIndexOf(2, -3) === 1);
|
||||
assert(array.lastIndexOf(2, -4) === 1);
|
||||
assert([].lastIndexOf("hello") === -1);
|
||||
assert([].lastIndexOf("hello", 10) === -1);
|
||||
assert([].lastIndexOf("hello", -10) === -1);
|
||||
assert([].lastIndexOf() === -1);
|
||||
assert([undefined].lastIndexOf() === 0);
|
||||
assert([undefined, undefined, undefined].lastIndexOf() === 2);
|
||||
assert(array.lastIndexOf("hello") === 4);
|
||||
assert(array.lastIndexOf("hello", 1000) === 4);
|
||||
assert(array.lastIndexOf(1) === 3);
|
||||
assert(array.lastIndexOf(1, -1) === 3);
|
||||
assert(array.lastIndexOf(1, -2) === 3);
|
||||
assert(array.lastIndexOf(2) === 1);
|
||||
assert(array.lastIndexOf(2, -3) === 1);
|
||||
assert(array.lastIndexOf(2, -4) === 1);
|
||||
assert([].lastIndexOf("hello") === -1);
|
||||
assert([].lastIndexOf("hello", 10) === -1);
|
||||
assert([].lastIndexOf("hello", -10) === -1);
|
||||
assert([].lastIndexOf() === -1);
|
||||
assert([undefined].lastIndexOf() === 0);
|
||||
assert([undefined, undefined, undefined].lastIndexOf() === 2);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,63 +1,63 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.map.length === 1);
|
||||
assert(Array.prototype.map.length === 1);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].map();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.map() requires at least one argument",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].map();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.map() requires at least one argument",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].map(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].map(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
|
||||
assert([].map(callback).length === 0);
|
||||
assert(callbackCalled === 0);
|
||||
assert([].map(callback).length === 0);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
assert([1, 2, 3].map(callback).length === 3);
|
||||
assert(callbackCalled === 3);
|
||||
assert([1, 2, 3].map(callback).length === 3);
|
||||
assert(callbackCalled === 3);
|
||||
|
||||
callbackCalled = 0;
|
||||
assert([1, , , "foo", , undefined, , ,].map(callback).length === 8);
|
||||
assert(callbackCalled === 3);
|
||||
callbackCalled = 0;
|
||||
assert([1, , , "foo", , undefined, , ,].map(callback).length === 8);
|
||||
assert(callbackCalled === 3);
|
||||
|
||||
var results = [undefined, null, true, "foo", 42, {}].map(
|
||||
(value, index) => "" + index + " -> " + value
|
||||
);
|
||||
assert(results.length === 6);
|
||||
assert(results[0] === "0 -> undefined");
|
||||
assert(results[1] === "1 -> null");
|
||||
assert(results[2] === "2 -> true");
|
||||
assert(results[3] === "3 -> foo");
|
||||
assert(results[4] === "4 -> 42");
|
||||
assert(results[5] === "5 -> [object Object]");
|
||||
var results = [undefined, null, true, "foo", 42, {}].map(
|
||||
(value, index) => "" + index + " -> " + value
|
||||
);
|
||||
assert(results.length === 6);
|
||||
assert(results[0] === "0 -> undefined");
|
||||
assert(results[1] === "1 -> null");
|
||||
assert(results[2] === "2 -> true");
|
||||
assert(results[3] === "3 -> foo");
|
||||
assert(results[4] === "4 -> 42");
|
||||
assert(results[5] === "5 -> [object Object]");
|
||||
|
||||
var squaredNumbers = [0, 1, 2, 3, 4].map(x => x ** 2);
|
||||
assert(squaredNumbers.length === 5);
|
||||
assert(squaredNumbers[0] === 0);
|
||||
assert(squaredNumbers[1] === 1);
|
||||
assert(squaredNumbers[2] === 4);
|
||||
assert(squaredNumbers[3] === 9);
|
||||
assert(squaredNumbers[4] === 16);
|
||||
var squaredNumbers = [0, 1, 2, 3, 4].map(x => x ** 2);
|
||||
assert(squaredNumbers.length === 5);
|
||||
assert(squaredNumbers[0] === 0);
|
||||
assert(squaredNumbers[1] === 1);
|
||||
assert(squaredNumbers[2] === 4);
|
||||
assert(squaredNumbers[3] === 9);
|
||||
assert(squaredNumbers[4] === 16);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
var a = [1, 2, 3];
|
||||
var value = a.pop();
|
||||
assert(value === 3);
|
||||
assert(a.length === 2);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
var a = [1, 2, 3];
|
||||
var value = a.pop();
|
||||
assert(value === 3);
|
||||
assert(a.length === 2);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
|
||||
var a = [];
|
||||
var value = a.pop();
|
||||
assert(value === undefined);
|
||||
assert(a.length === 0);
|
||||
var a = [];
|
||||
var value = a.pop();
|
||||
assert(value === undefined);
|
||||
assert(a.length === 0);
|
||||
|
||||
assert([,].pop() === undefined);
|
||||
assert([,].pop() === undefined);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.push.length === 1);
|
||||
assert(Array.prototype.push.length === 1);
|
||||
|
||||
var a = ["hello"];
|
||||
var length = a.push();
|
||||
assert(length === 1);
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === "hello");
|
||||
var a = ["hello"];
|
||||
var length = a.push();
|
||||
assert(length === 1);
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === "hello");
|
||||
|
||||
length = a.push("friends");
|
||||
assert(length === 2);
|
||||
assert(a.length === 2);
|
||||
assert(a[0] === "hello");
|
||||
assert(a[1] === "friends");
|
||||
length = a.push("friends");
|
||||
assert(length === 2);
|
||||
assert(a.length === 2);
|
||||
assert(a[0] === "hello");
|
||||
assert(a[1] === "friends");
|
||||
|
||||
length = a.push(1, 2, 3);
|
||||
assert(length === 5);
|
||||
assert(a.length === 5);
|
||||
assert(a[0] === "hello");
|
||||
assert(a[1] === "friends");
|
||||
assert(a[2] === 1);
|
||||
assert(a[3] === 2);
|
||||
assert(a[4] === 3);
|
||||
length = a.push(1, 2, 3);
|
||||
assert(length === 5);
|
||||
assert(a.length === 5);
|
||||
assert(a[0] === "hello");
|
||||
assert(a[1] === "friends");
|
||||
assert(a[2] === 1);
|
||||
assert(a[3] === 2);
|
||||
assert(a[4] === 3);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,132 +1,132 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.reduce.length === 1);
|
||||
assert(Array.prototype.reduce.length === 1);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[1].reduce();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.reduce() requires at least one argument",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[1].reduce();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.reduce() requires at least one argument",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[1].reduce(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[1].reduce(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].reduce((a, x) => x);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Reduce of empty array with no initial value",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].reduce((a, x) => x);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Reduce of empty array with no initial value",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[, ,].reduce((a, x) => x);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Reduce of empty array with no initial value",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[, ,].reduce((a, x) => x);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Reduce of empty array with no initial value",
|
||||
}
|
||||
);
|
||||
|
||||
[1, 2].reduce(function () {
|
||||
assert(this === undefined);
|
||||
});
|
||||
[1, 2].reduce(function () {
|
||||
assert(this === undefined);
|
||||
});
|
||||
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
return true;
|
||||
};
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
return true;
|
||||
};
|
||||
|
||||
assert([1].reduce(callback) === 1);
|
||||
assert(callbackCalled === 0);
|
||||
assert([1].reduce(callback) === 1);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
assert([, 1].reduce(callback) === 1);
|
||||
assert(callbackCalled === 0);
|
||||
assert([, 1].reduce(callback) === 1);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
callbackCalled = 0;
|
||||
assert([1, 2, 3].reduce(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
callbackCalled = 0;
|
||||
assert([1, 2, 3].reduce(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
|
||||
callbackCalled = 0;
|
||||
assert([, , 1, 2, 3].reduce(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
callbackCalled = 0;
|
||||
assert([, , 1, 2, 3].reduce(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
|
||||
callbackCalled = 0;
|
||||
assert([1, , , 10, , 100, , ,].reduce(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
callbackCalled = 0;
|
||||
assert([1, , , 10, , 100, , ,].reduce(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
|
||||
var constantlySad = () => ":^(";
|
||||
var result = [].reduce(constantlySad, ":^)");
|
||||
assert(result === ":^)");
|
||||
var constantlySad = () => ":^(";
|
||||
var result = [].reduce(constantlySad, ":^)");
|
||||
assert(result === ":^)");
|
||||
|
||||
result = [":^0"].reduce(constantlySad, ":^)");
|
||||
assert(result === ":^(");
|
||||
result = [":^0"].reduce(constantlySad, ":^)");
|
||||
assert(result === ":^(");
|
||||
|
||||
result = [":^0"].reduce(constantlySad);
|
||||
assert(result === ":^0");
|
||||
result = [":^0"].reduce(constantlySad);
|
||||
assert(result === ":^0");
|
||||
|
||||
result = [5, 4, 3, 2, 1].reduce((accum, elem) => accum + elem);
|
||||
assert(result === 15);
|
||||
result = [5, 4, 3, 2, 1].reduce((accum, elem) => accum + elem);
|
||||
assert(result === 15);
|
||||
|
||||
result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100);
|
||||
assert(result === 121);
|
||||
result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100);
|
||||
assert(result === 121);
|
||||
|
||||
result = [6, 5, 4, 3, 2, 1].reduce((accum, elem) => {
|
||||
return accum + elem;
|
||||
}, 100);
|
||||
assert(result === 121);
|
||||
result = [6, 5, 4, 3, 2, 1].reduce((accum, elem) => {
|
||||
return accum + elem;
|
||||
}, 100);
|
||||
assert(result === 121);
|
||||
|
||||
var indexes = [];
|
||||
result = ["foo", 1, true].reduce((a, v, i) => {
|
||||
indexes.push(i);
|
||||
});
|
||||
assert(result === undefined);
|
||||
assert(indexes.length === 2);
|
||||
assert(indexes[0] === 1);
|
||||
assert(indexes[1] === 2);
|
||||
var indexes = [];
|
||||
result = ["foo", 1, true].reduce((a, v, i) => {
|
||||
indexes.push(i);
|
||||
});
|
||||
assert(result === undefined);
|
||||
assert(indexes.length === 2);
|
||||
assert(indexes[0] === 1);
|
||||
assert(indexes[1] === 2);
|
||||
|
||||
indexes = [];
|
||||
result = ["foo", 1, true].reduce((a, v, i) => {
|
||||
indexes.push(i);
|
||||
}, "foo");
|
||||
assert(result === undefined);
|
||||
assert(indexes.length === 3);
|
||||
assert(indexes[0] === 0);
|
||||
assert(indexes[1] === 1);
|
||||
assert(indexes[2] === 2);
|
||||
indexes = [];
|
||||
result = ["foo", 1, true].reduce((a, v, i) => {
|
||||
indexes.push(i);
|
||||
}, "foo");
|
||||
assert(result === undefined);
|
||||
assert(indexes.length === 3);
|
||||
assert(indexes[0] === 0);
|
||||
assert(indexes[1] === 1);
|
||||
assert(indexes[2] === 2);
|
||||
|
||||
var mutable = { prop: 0 };
|
||||
result = ["foo", 1, true].reduce((a, v) => {
|
||||
a.prop = v;
|
||||
return a;
|
||||
}, mutable);
|
||||
assert(result === mutable);
|
||||
assert(result.prop === true);
|
||||
var mutable = { prop: 0 };
|
||||
result = ["foo", 1, true].reduce((a, v) => {
|
||||
a.prop = v;
|
||||
return a;
|
||||
}, mutable);
|
||||
assert(result === mutable);
|
||||
assert(result.prop === true);
|
||||
|
||||
var a1 = [1, 2];
|
||||
var a2 = null;
|
||||
a1.reduce((a, v, i, t) => {
|
||||
a2 = t;
|
||||
});
|
||||
assert(a1 === a2);
|
||||
var a1 = [1, 2];
|
||||
var a2 = null;
|
||||
a1.reduce((a, v, i, t) => {
|
||||
a2 = t;
|
||||
});
|
||||
assert(a1 === a2);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,134 +1,134 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.reduceRight.length === 1);
|
||||
assert(Array.prototype.reduceRight.length === 1);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[1].reduceRight();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.reduceRight() requires at least one argument",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[1].reduceRight();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.reduceRight() requires at least one argument",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[1].reduceRight(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[1].reduceRight(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].reduceRight((a, x) => x);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Reduce of empty array with no initial value",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].reduceRight((a, x) => x);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Reduce of empty array with no initial value",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[, ,].reduceRight((a, x) => x);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Reduce of empty array with no initial value",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[, ,].reduceRight((a, x) => x);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Reduce of empty array with no initial value",
|
||||
}
|
||||
);
|
||||
|
||||
[1, 2].reduceRight(function () {
|
||||
assert(this === undefined);
|
||||
});
|
||||
[1, 2].reduceRight(function () {
|
||||
assert(this === undefined);
|
||||
});
|
||||
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
return true;
|
||||
};
|
||||
var callbackCalled = 0;
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
return true;
|
||||
};
|
||||
|
||||
assert([1].reduceRight(callback) === 1);
|
||||
assert(callbackCalled === 0);
|
||||
assert([1].reduceRight(callback) === 1);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
assert([1].reduceRight(callback) === 1);
|
||||
assert(callbackCalled === 0);
|
||||
assert([1].reduceRight(callback) === 1);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
callbackCalled = 0;
|
||||
assert([1, 2, 3].reduceRight(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
callbackCalled = 0;
|
||||
assert([1, 2, 3].reduceRight(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
|
||||
callbackCalled = 0;
|
||||
assert([1, 2, 3, ,].reduceRight(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
callbackCalled = 0;
|
||||
assert([1, 2, 3, ,].reduceRight(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
|
||||
callbackCalled = 0;
|
||||
assert([, , , 1, , , 10, , 100, , ,].reduceRight(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
callbackCalled = 0;
|
||||
assert([, , , 1, , , 10, , 100, , ,].reduceRight(callback) === true);
|
||||
assert(callbackCalled === 2);
|
||||
|
||||
var constantlySad = () => ":^(";
|
||||
var result = [].reduceRight(constantlySad, ":^)");
|
||||
assert(result === ":^)");
|
||||
var constantlySad = () => ":^(";
|
||||
var result = [].reduceRight(constantlySad, ":^)");
|
||||
assert(result === ":^)");
|
||||
|
||||
result = [":^0"].reduceRight(constantlySad, ":^)");
|
||||
assert(result === ":^(");
|
||||
result = [":^0"].reduceRight(constantlySad, ":^)");
|
||||
assert(result === ":^(");
|
||||
|
||||
result = [":^0"].reduceRight(constantlySad);
|
||||
assert(result === ":^0");
|
||||
result = [":^0"].reduceRight(constantlySad);
|
||||
assert(result === ":^0");
|
||||
|
||||
result = [5, 4, 3, 2, 1].reduceRight((accum, elem) => "" + accum + elem);
|
||||
assert(result === "12345");
|
||||
result = [5, 4, 3, 2, 1].reduceRight((accum, elem) => "" + accum + elem);
|
||||
assert(result === "12345");
|
||||
|
||||
result = [1, 2, 3, 4, 5, 6].reduceRight((accum, elem) => {
|
||||
return "" + accum + elem;
|
||||
}, 100);
|
||||
assert(result === "100654321");
|
||||
result = [1, 2, 3, 4, 5, 6].reduceRight((accum, elem) => {
|
||||
return "" + accum + elem;
|
||||
}, 100);
|
||||
assert(result === "100654321");
|
||||
|
||||
result = [6, 5, 4, 3, 2, 1].reduceRight((accum, elem) => {
|
||||
return "" + accum + elem;
|
||||
}, 100);
|
||||
assert(result === "100123456");
|
||||
result = [6, 5, 4, 3, 2, 1].reduceRight((accum, elem) => {
|
||||
return "" + accum + elem;
|
||||
}, 100);
|
||||
assert(result === "100123456");
|
||||
|
||||
var indexes = [];
|
||||
result = ["foo", 1, true].reduceRight((a, v, i) => {
|
||||
indexes.push(i);
|
||||
});
|
||||
assert(result === undefined);
|
||||
assert(indexes.length === 2);
|
||||
assert(indexes[0] === 1);
|
||||
assert(indexes[1] === 0);
|
||||
var indexes = [];
|
||||
result = ["foo", 1, true].reduceRight((a, v, i) => {
|
||||
indexes.push(i);
|
||||
});
|
||||
assert(result === undefined);
|
||||
assert(indexes.length === 2);
|
||||
assert(indexes[0] === 1);
|
||||
assert(indexes[1] === 0);
|
||||
|
||||
indexes = [];
|
||||
result = ["foo", 1, true].reduceRight((a, v, i) => {
|
||||
indexes.push(i);
|
||||
}, "foo");
|
||||
assert(result === undefined);
|
||||
assert(indexes.length === 3);
|
||||
assert(indexes[0] === 2);
|
||||
assert(indexes[1] === 1);
|
||||
assert(indexes[2] === 0);
|
||||
indexes = [];
|
||||
result = ["foo", 1, true].reduceRight((a, v, i) => {
|
||||
indexes.push(i);
|
||||
}, "foo");
|
||||
assert(result === undefined);
|
||||
assert(indexes.length === 3);
|
||||
assert(indexes[0] === 2);
|
||||
assert(indexes[1] === 1);
|
||||
assert(indexes[2] === 0);
|
||||
|
||||
var mutable = { prop: 0 };
|
||||
result = ["foo", 1, true].reduceRight((a, v) => {
|
||||
a.prop = v;
|
||||
return a;
|
||||
}, mutable);
|
||||
assert(result === mutable);
|
||||
assert(result.prop === "foo");
|
||||
var mutable = { prop: 0 };
|
||||
result = ["foo", 1, true].reduceRight((a, v) => {
|
||||
a.prop = v;
|
||||
return a;
|
||||
}, mutable);
|
||||
assert(result === mutable);
|
||||
assert(result.prop === "foo");
|
||||
|
||||
var a1 = [1, 2];
|
||||
var a2 = null;
|
||||
a1.reduceRight((a, v, i, t) => {
|
||||
a2 = t;
|
||||
});
|
||||
assert(a1 === a2);
|
||||
var a1 = [1, 2];
|
||||
var a2 = null;
|
||||
a1.reduceRight((a, v, i, t) => {
|
||||
a2 = t;
|
||||
});
|
||||
assert(a1 === a2);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.reverse.length === 0);
|
||||
assert(Array.prototype.reverse.length === 0);
|
||||
|
||||
var array = [1, 2, 3];
|
||||
var array = [1, 2, 3];
|
||||
|
||||
assert(array[0] === 1);
|
||||
assert(array[1] === 2);
|
||||
assert(array[2] === 3);
|
||||
assert(array[0] === 1);
|
||||
assert(array[1] === 2);
|
||||
assert(array[2] === 3);
|
||||
|
||||
array.reverse();
|
||||
array.reverse();
|
||||
|
||||
assert(array[0] === 3);
|
||||
assert(array[1] === 2);
|
||||
assert(array[2] === 1);
|
||||
assert(array[0] === 3);
|
||||
assert(array[1] === 2);
|
||||
assert(array[2] === 1);
|
||||
|
||||
var array_ref = array.reverse();
|
||||
var array_ref = array.reverse();
|
||||
|
||||
assert(array_ref[0] === 1);
|
||||
assert(array_ref[1] === 2);
|
||||
assert(array_ref[2] === 3);
|
||||
assert(array_ref[0] === 1);
|
||||
assert(array_ref[1] === 2);
|
||||
assert(array_ref[2] === 3);
|
||||
|
||||
assert(array[0] === 1);
|
||||
assert(array[1] === 2);
|
||||
assert(array[2] === 3);
|
||||
assert(array[0] === 1);
|
||||
assert(array[1] === 2);
|
||||
assert(array[2] === 3);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
var a = [1, 2, 3];
|
||||
var value = a.shift();
|
||||
assert(value === 1);
|
||||
assert(a.length === 2);
|
||||
assert(a[0] === 2);
|
||||
assert(a[1] === 3);
|
||||
var a = [1, 2, 3];
|
||||
var value = a.shift();
|
||||
assert(value === 1);
|
||||
assert(a.length === 2);
|
||||
assert(a[0] === 2);
|
||||
assert(a[1] === 3);
|
||||
|
||||
var a = [];
|
||||
var value = a.shift();
|
||||
assert(value === undefined);
|
||||
assert(a.length === 0);
|
||||
var a = [];
|
||||
var value = a.shift();
|
||||
assert(value === undefined);
|
||||
assert(a.length === 0);
|
||||
|
||||
assert([,].shift() === undefined);
|
||||
assert([,].shift() === undefined);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,53 +1,53 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.slice.length === 2);
|
||||
assert(Array.prototype.slice.length === 2);
|
||||
|
||||
var array = ["hello", "friends", "serenity", 1];
|
||||
var array = ["hello", "friends", "serenity", 1];
|
||||
|
||||
var array_slice = array.slice();
|
||||
assert(array_slice.length === array.length);
|
||||
assert(array_slice.length === 4);
|
||||
assert(array_slice[0] === "hello");
|
||||
assert(array_slice[1] === "friends");
|
||||
assert(array_slice[2] === "serenity");
|
||||
assert(array_slice[3] === 1);
|
||||
var array_slice = array.slice();
|
||||
assert(array_slice.length === array.length);
|
||||
assert(array_slice.length === 4);
|
||||
assert(array_slice[0] === "hello");
|
||||
assert(array_slice[1] === "friends");
|
||||
assert(array_slice[2] === "serenity");
|
||||
assert(array_slice[3] === 1);
|
||||
|
||||
array_slice = array.slice(1);
|
||||
assert(array_slice.length === 3);
|
||||
assert(array_slice[0] === "friends");
|
||||
assert(array_slice[1] === "serenity");
|
||||
assert(array_slice[2] === 1);
|
||||
array_slice = array.slice(1);
|
||||
assert(array_slice.length === 3);
|
||||
assert(array_slice[0] === "friends");
|
||||
assert(array_slice[1] === "serenity");
|
||||
assert(array_slice[2] === 1);
|
||||
|
||||
array_slice = array.slice(0, 2);
|
||||
assert(array_slice.length === 2);
|
||||
assert(array_slice[0] === "hello");
|
||||
assert(array_slice[1] === "friends");
|
||||
array_slice = array.slice(0, 2);
|
||||
assert(array_slice.length === 2);
|
||||
assert(array_slice[0] === "hello");
|
||||
assert(array_slice[1] === "friends");
|
||||
|
||||
array_slice = array.slice(-1);
|
||||
assert(array_slice.length === 1);
|
||||
assert(array_slice[0] === 1);
|
||||
array_slice = array.slice(-1);
|
||||
assert(array_slice.length === 1);
|
||||
assert(array_slice[0] === 1);
|
||||
|
||||
array_slice = array.slice(1, 1);
|
||||
assert(array_slice.length === 0);
|
||||
array_slice = array.slice(1, 1);
|
||||
assert(array_slice.length === 0);
|
||||
|
||||
array_slice = array.slice(1, -1);
|
||||
assert(array_slice.length === 2);
|
||||
assert(array_slice[0] === "friends");
|
||||
assert(array_slice[1] === "serenity");
|
||||
array_slice = array.slice(1, -1);
|
||||
assert(array_slice.length === 2);
|
||||
assert(array_slice[0] === "friends");
|
||||
assert(array_slice[1] === "serenity");
|
||||
|
||||
array_slice = array.slice(2, -1);
|
||||
assert(array_slice.length === 1);
|
||||
assert(array_slice[0] === "serenity");
|
||||
array_slice = array.slice(2, -1);
|
||||
assert(array_slice.length === 1);
|
||||
assert(array_slice[0] === "serenity");
|
||||
|
||||
array_slice = array.slice(0, 100);
|
||||
assert(array_slice.length === 4);
|
||||
assert(array_slice[0] === "hello");
|
||||
assert(array_slice[1] === "friends");
|
||||
assert(array_slice[2] === "serenity");
|
||||
assert(array_slice[3] === 1);
|
||||
array_slice = array.slice(0, 100);
|
||||
assert(array_slice.length === 4);
|
||||
assert(array_slice[0] === "hello");
|
||||
assert(array_slice[1] === "friends");
|
||||
assert(array_slice[2] === "serenity");
|
||||
assert(array_slice[3] === 1);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.some.length === 1);
|
||||
assert(Array.prototype.some.length === 1);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].some(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].some(undefined);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var array = ["hello", "friends", 1, 2, false, -42, { name: "serenityos" }];
|
||||
var array = ["hello", "friends", 1, 2, false, -42, { name: "serenityos" }];
|
||||
|
||||
assert(array.some(value => value === "hello") === true);
|
||||
assert(array.some(value => value === "serenity") === false);
|
||||
assert(array.some((value, index, arr) => index === 1) === true);
|
||||
assert(array.some(value => value == "1") === true);
|
||||
assert(array.some(value => value === 1) === true);
|
||||
assert(array.some(value => value === 13) === false);
|
||||
assert(array.some(value => typeof value !== "string") === true);
|
||||
assert(array.some(value => typeof value === "boolean") === true);
|
||||
assert(array.some(value => value > 1) === true);
|
||||
assert(array.some(value => value > 1 && value < 3) === true);
|
||||
assert(array.some(value => value > 100) === false);
|
||||
assert(array.some(value => value < 0) === true);
|
||||
assert(array.some(value => array.pop()) === true);
|
||||
assert(["", "hello", "friends", "serenity"].some(value => value.length === 0) === true);
|
||||
assert([].some(value => value === 1) === false);
|
||||
assert(array.some(value => value === "hello") === true);
|
||||
assert(array.some(value => value === "serenity") === false);
|
||||
assert(array.some((value, index, arr) => index === 1) === true);
|
||||
assert(array.some(value => value == "1") === true);
|
||||
assert(array.some(value => value === 1) === true);
|
||||
assert(array.some(value => value === 13) === false);
|
||||
assert(array.some(value => typeof value !== "string") === true);
|
||||
assert(array.some(value => typeof value === "boolean") === true);
|
||||
assert(array.some(value => value > 1) === true);
|
||||
assert(array.some(value => value > 1 && value < 3) === true);
|
||||
assert(array.some(value => value > 100) === false);
|
||||
assert(array.some(value => value < 0) === true);
|
||||
assert(array.some(value => array.pop()) === true);
|
||||
assert(["", "hello", "friends", "serenity"].some(value => value.length === 0) === true);
|
||||
assert([].some(value => value === 1) === false);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,87 +1,87 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.splice.length === 2);
|
||||
assert(Array.prototype.splice.length === 2);
|
||||
|
||||
var array = ["hello", "friends", "serenity", 1, 2];
|
||||
var removed = array.splice(3);
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "hello");
|
||||
assert(array[1] === "friends");
|
||||
assert(array[2] === "serenity");
|
||||
assert(removed.length === 2);
|
||||
assert(removed[0] === 1);
|
||||
assert(removed[1] === 2);
|
||||
var array = ["hello", "friends", "serenity", 1, 2];
|
||||
var removed = array.splice(3);
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "hello");
|
||||
assert(array[1] === "friends");
|
||||
assert(array[2] === "serenity");
|
||||
assert(removed.length === 2);
|
||||
assert(removed[0] === 1);
|
||||
assert(removed[1] === 2);
|
||||
|
||||
array = ["hello", "friends", "serenity", 1, 2];
|
||||
removed = array.splice(-2);
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "hello");
|
||||
assert(array[1] === "friends");
|
||||
assert(array[2] === "serenity");
|
||||
assert(removed.length === 2);
|
||||
assert(removed[0] === 1);
|
||||
assert(removed[1] === 2);
|
||||
array = ["hello", "friends", "serenity", 1, 2];
|
||||
removed = array.splice(-2);
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "hello");
|
||||
assert(array[1] === "friends");
|
||||
assert(array[2] === "serenity");
|
||||
assert(removed.length === 2);
|
||||
assert(removed[0] === 1);
|
||||
assert(removed[1] === 2);
|
||||
|
||||
array = ["hello", "friends", "serenity", 1, 2];
|
||||
removed = array.splice(-2, 1);
|
||||
assert(array.length === 4);
|
||||
assert(array[0] === "hello");
|
||||
assert(array[1] === "friends");
|
||||
assert(array[2] === "serenity");
|
||||
assert(array[3] === 2);
|
||||
assert(removed.length === 1);
|
||||
assert(removed[0] === 1);
|
||||
array = ["hello", "friends", "serenity", 1, 2];
|
||||
removed = array.splice(-2, 1);
|
||||
assert(array.length === 4);
|
||||
assert(array[0] === "hello");
|
||||
assert(array[1] === "friends");
|
||||
assert(array[2] === "serenity");
|
||||
assert(array[3] === 2);
|
||||
assert(removed.length === 1);
|
||||
assert(removed[0] === 1);
|
||||
|
||||
array = ["serenity"];
|
||||
removed = array.splice(0, 0, "hello", "friends");
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "hello");
|
||||
assert(array[1] === "friends");
|
||||
assert(array[2] === "serenity");
|
||||
assert(removed.length === 0);
|
||||
array = ["serenity"];
|
||||
removed = array.splice(0, 0, "hello", "friends");
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "hello");
|
||||
assert(array[1] === "friends");
|
||||
assert(array[2] === "serenity");
|
||||
assert(removed.length === 0);
|
||||
|
||||
array = ["goodbye", "friends", "serenity"];
|
||||
removed = array.splice(0, 1, "hello");
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "hello");
|
||||
assert(array[1] === "friends");
|
||||
assert(array[2] === "serenity");
|
||||
assert(removed.length === 1);
|
||||
assert(removed[0] === "goodbye");
|
||||
array = ["goodbye", "friends", "serenity"];
|
||||
removed = array.splice(0, 1, "hello");
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "hello");
|
||||
assert(array[1] === "friends");
|
||||
assert(array[2] === "serenity");
|
||||
assert(removed.length === 1);
|
||||
assert(removed[0] === "goodbye");
|
||||
|
||||
array = ["foo", "bar", "baz"];
|
||||
removed = array.splice();
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "foo");
|
||||
assert(array[1] === "bar");
|
||||
assert(array[2] === "baz");
|
||||
assert(removed.length === 0);
|
||||
array = ["foo", "bar", "baz"];
|
||||
removed = array.splice();
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "foo");
|
||||
assert(array[1] === "bar");
|
||||
assert(array[2] === "baz");
|
||||
assert(removed.length === 0);
|
||||
|
||||
removed = array.splice(0, 123);
|
||||
assert(array.length === 0);
|
||||
assert(removed.length === 3);
|
||||
assert(removed[0] === "foo");
|
||||
assert(removed[1] === "bar");
|
||||
assert(removed[2] === "baz");
|
||||
removed = array.splice(0, 123);
|
||||
assert(array.length === 0);
|
||||
assert(removed.length === 3);
|
||||
assert(removed[0] === "foo");
|
||||
assert(removed[1] === "bar");
|
||||
assert(removed[2] === "baz");
|
||||
|
||||
array = ["foo", "bar", "baz"];
|
||||
removed = array.splice(123, 123);
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "foo");
|
||||
assert(array[1] === "bar");
|
||||
assert(array[2] === "baz");
|
||||
assert(removed.length === 0);
|
||||
array = ["foo", "bar", "baz"];
|
||||
removed = array.splice(123, 123);
|
||||
assert(array.length === 3);
|
||||
assert(array[0] === "foo");
|
||||
assert(array[1] === "bar");
|
||||
assert(array[2] === "baz");
|
||||
assert(removed.length === 0);
|
||||
|
||||
array = ["foo", "bar", "baz"];
|
||||
removed = array.splice(-123, 123);
|
||||
assert(array.length === 0);
|
||||
assert(removed.length === 3);
|
||||
assert(removed[0] === "foo");
|
||||
assert(removed[1] === "bar");
|
||||
assert(removed[2] === "baz");
|
||||
array = ["foo", "bar", "baz"];
|
||||
removed = array.splice(-123, 123);
|
||||
assert(array.length === 0);
|
||||
assert(removed.length === 3);
|
||||
assert(removed[0] === "foo");
|
||||
assert(removed[1] === "bar");
|
||||
assert(removed[2] === "baz");
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.toLocaleString.length === 0);
|
||||
assert(Array.prototype.toLocaleString.length === 0);
|
||||
|
||||
assert([].toLocaleString() === "");
|
||||
assert(["foo"].toLocaleString() === "foo");
|
||||
assert(["foo", "bar"].toLocaleString() === "foo,bar");
|
||||
assert(["foo", undefined, "bar", null, "baz"].toLocaleString() === "foo,,bar,,baz");
|
||||
assert([].toLocaleString() === "");
|
||||
assert(["foo"].toLocaleString() === "foo");
|
||||
assert(["foo", "bar"].toLocaleString() === "foo,bar");
|
||||
assert(["foo", undefined, "bar", null, "baz"].toLocaleString() === "foo,,bar,,baz");
|
||||
|
||||
var toStringCalled = 0;
|
||||
var o = {
|
||||
toString: () => {
|
||||
toStringCalled++;
|
||||
return "o";
|
||||
},
|
||||
};
|
||||
assert([o, undefined, o, null, o].toLocaleString() === "o,,o,,o");
|
||||
assert(toStringCalled === 3);
|
||||
var toStringCalled = 0;
|
||||
var o = {
|
||||
toString: () => {
|
||||
toStringCalled++;
|
||||
return "o";
|
||||
},
|
||||
};
|
||||
assert([o, undefined, o, null, o].toLocaleString() === "o,,o,,o");
|
||||
assert(toStringCalled === 3);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
var a = [1, 2, 3];
|
||||
assert(a.toString() === "1,2,3");
|
||||
assert([].toString() === "");
|
||||
assert([5].toString() === "5");
|
||||
var a = [1, 2, 3];
|
||||
assert(a.toString() === "1,2,3");
|
||||
assert([].toString() === "");
|
||||
assert([5].toString() === "5");
|
||||
|
||||
assert("rgb(" + [10, 11, 12] + ")" === "rgb(10,11,12)");
|
||||
assert("rgb(" + [10, 11, 12] + ")" === "rgb(10,11,12)");
|
||||
|
||||
assert([undefined, null].toString() === ",");
|
||||
assert([undefined, null].toString() === ",");
|
||||
|
||||
a = new Array(5);
|
||||
assert(a.toString() === ",,,,");
|
||||
a[2] = "foo";
|
||||
a[4] = "bar";
|
||||
assert(a.toString() === ",,foo,,bar");
|
||||
a = new Array(5);
|
||||
assert(a.toString() === ",,,,");
|
||||
a[2] = "foo";
|
||||
a[4] = "bar";
|
||||
assert(a.toString() === ",,foo,,bar");
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.unshift.length === 1);
|
||||
assert(Array.prototype.unshift.length === 1);
|
||||
|
||||
var a = ["hello"];
|
||||
var length = a.unshift();
|
||||
assert(length === 1);
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === "hello");
|
||||
var a = ["hello"];
|
||||
var length = a.unshift();
|
||||
assert(length === 1);
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === "hello");
|
||||
|
||||
length = a.unshift("friends");
|
||||
assert(length === 2);
|
||||
assert(a.length === 2);
|
||||
assert(a[0] === "friends");
|
||||
assert(a[1] === "hello");
|
||||
length = a.unshift("friends");
|
||||
assert(length === 2);
|
||||
assert(a.length === 2);
|
||||
assert(a[0] === "friends");
|
||||
assert(a[1] === "hello");
|
||||
|
||||
length = a.unshift(1, 2, 3);
|
||||
assert(length === 5);
|
||||
assert(a.length === 5);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
assert(a[3] === "friends");
|
||||
assert(a[4] === "hello");
|
||||
length = a.unshift(1, 2, 3);
|
||||
assert(length === 5);
|
||||
assert(a.length === 5);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
assert(a[3] === "friends");
|
||||
assert(a[4] === "hello");
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,63 +1,63 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
var a = [1, 2, 3];
|
||||
var a = [1, 2, 3];
|
||||
|
||||
assert(typeof a === "object");
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
assert(typeof a === "object");
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
|
||||
a[1] = 5;
|
||||
assert(a[1] === 5);
|
||||
assert(a.length === 3);
|
||||
a[1] = 5;
|
||||
assert(a[1] === 5);
|
||||
assert(a.length === 3);
|
||||
|
||||
a.push(7);
|
||||
assert(a[3] === 7);
|
||||
assert(a.length === 4);
|
||||
a.push(7);
|
||||
assert(a[3] === 7);
|
||||
assert(a.length === 4);
|
||||
|
||||
a = [,];
|
||||
assert(a.length === 1);
|
||||
assert(a.toString() === "");
|
||||
assert(a[0] === undefined);
|
||||
a = [,];
|
||||
assert(a.length === 1);
|
||||
assert(a.toString() === "");
|
||||
assert(a[0] === undefined);
|
||||
|
||||
a = [, , , ,];
|
||||
assert(a.length === 4);
|
||||
assert(a.toString() === ",,,");
|
||||
assert(a[0] === undefined);
|
||||
assert(a[1] === undefined);
|
||||
assert(a[2] === undefined);
|
||||
assert(a[3] === undefined);
|
||||
a = [, , , ,];
|
||||
assert(a.length === 4);
|
||||
assert(a.toString() === ",,,");
|
||||
assert(a[0] === undefined);
|
||||
assert(a[1] === undefined);
|
||||
assert(a[2] === undefined);
|
||||
assert(a[3] === undefined);
|
||||
|
||||
a = [1, , 2, , , 3];
|
||||
assert(a.length === 6);
|
||||
assert(a.toString() === "1,,2,,,3");
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === undefined);
|
||||
assert(a[2] === 2);
|
||||
assert(a[3] === undefined);
|
||||
assert(a[4] === undefined);
|
||||
assert(a[5] === 3);
|
||||
a = [1, , 2, , , 3];
|
||||
assert(a.length === 6);
|
||||
assert(a.toString() === "1,,2,,,3");
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === undefined);
|
||||
assert(a[2] === 2);
|
||||
assert(a[3] === undefined);
|
||||
assert(a[4] === undefined);
|
||||
assert(a[5] === 3);
|
||||
|
||||
a = [1, , 2, , , 3];
|
||||
Object.defineProperty(a, 1, {
|
||||
get() {
|
||||
return this.secret_prop;
|
||||
},
|
||||
set(value) {
|
||||
this.secret_prop = value;
|
||||
},
|
||||
});
|
||||
assert(a.length === 6);
|
||||
assert(a.toString() === "1,,2,,,3");
|
||||
assert(a.secret_prop === undefined);
|
||||
a[1] = 20;
|
||||
assert(a.length === 6);
|
||||
assert(a.toString() === "1,20,2,,,3");
|
||||
assert(a.secret_prop === 20);
|
||||
a = [1, , 2, , , 3];
|
||||
Object.defineProperty(a, 1, {
|
||||
get() {
|
||||
return this.secret_prop;
|
||||
},
|
||||
set(value) {
|
||||
this.secret_prop = value;
|
||||
},
|
||||
});
|
||||
assert(a.length === 6);
|
||||
assert(a.toString() === "1,,2,,,3");
|
||||
assert(a.secret_prop === undefined);
|
||||
a[1] = 20;
|
||||
assert(a.length === 6);
|
||||
assert(a.toString() === "1,20,2,,,3");
|
||||
assert(a.secret_prop === 20);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,51 +1,51 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
var a = [1, 2, 3];
|
||||
var a = [1, 2, 3];
|
||||
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
|
||||
a.length = 5;
|
||||
assert(a.length === 5);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
assert(a[3] === undefined);
|
||||
assert(a[4] === undefined);
|
||||
a.length = 5;
|
||||
assert(a.length === 5);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
assert(a[3] === undefined);
|
||||
assert(a[4] === undefined);
|
||||
|
||||
a.length = 1;
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === 1);
|
||||
|
||||
a.length = 0;
|
||||
assert(a.length === 0);
|
||||
|
||||
a.length = "42";
|
||||
assert(a.length === 42);
|
||||
|
||||
a.length = [];
|
||||
assert(a.length === 0);
|
||||
|
||||
a.length = true;
|
||||
assert(a.length === 1);
|
||||
|
||||
[undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
a.length = value;
|
||||
},
|
||||
{
|
||||
error: RangeError,
|
||||
message: "Invalid array length",
|
||||
}
|
||||
);
|
||||
a.length = 1;
|
||||
assert(a.length === 1);
|
||||
});
|
||||
assert(a[0] === 1);
|
||||
|
||||
console.log("PASS");
|
||||
a.length = 0;
|
||||
assert(a.length === 0);
|
||||
|
||||
a.length = "42";
|
||||
assert(a.length === 42);
|
||||
|
||||
a.length = [];
|
||||
assert(a.length === 0);
|
||||
|
||||
a.length = true;
|
||||
assert(a.length === 1);
|
||||
|
||||
[undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
a.length = value;
|
||||
},
|
||||
{
|
||||
error: RangeError,
|
||||
message: "Invalid array length",
|
||||
}
|
||||
);
|
||||
assert(a.length === 1);
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
var a, callbackCalled;
|
||||
var a, callbackCalled;
|
||||
|
||||
callbackCalled = 0;
|
||||
a = [1, 2, 3, 4, 5];
|
||||
a.find(() => {
|
||||
callbackCalled++;
|
||||
a.pop();
|
||||
});
|
||||
assert(callbackCalled === 5);
|
||||
callbackCalled = 0;
|
||||
a = [1, 2, 3, 4, 5];
|
||||
a.find(() => {
|
||||
callbackCalled++;
|
||||
a.pop();
|
||||
});
|
||||
assert(callbackCalled === 5);
|
||||
|
||||
callbackCalled = 0;
|
||||
a = [1, 2, 3, 4, 5];
|
||||
a.findIndex(() => {
|
||||
callbackCalled++;
|
||||
a.pop();
|
||||
});
|
||||
assert(callbackCalled === 5);
|
||||
callbackCalled = 0;
|
||||
a = [1, 2, 3, 4, 5];
|
||||
a.findIndex(() => {
|
||||
callbackCalled++;
|
||||
a.pop();
|
||||
});
|
||||
assert(callbackCalled === 5);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,45 +1,45 @@
|
|||
load("test-common.js");
|
||||
|
||||
function testArray(arr) {
|
||||
return arr.length === 4 && arr[0] === 0 && arr[1] === 1 && arr[2] === 2 && arr[3] === 3;
|
||||
return arr.length === 4 && arr[0] === 0 && arr[1] === 1 && arr[2] === 2 && arr[3] === 3;
|
||||
}
|
||||
|
||||
try {
|
||||
let arr = [0, ...[1, 2], 3];
|
||||
assert(testArray(arr));
|
||||
let arr = [0, ...[1, 2], 3];
|
||||
assert(testArray(arr));
|
||||
|
||||
let a = [1, 2];
|
||||
arr = [0, ...a, 3];
|
||||
assert(testArray(arr));
|
||||
let a = [1, 2];
|
||||
arr = [0, ...a, 3];
|
||||
assert(testArray(arr));
|
||||
|
||||
let obj = { a: [1, 2] };
|
||||
arr = [0, ...obj.a, 3];
|
||||
assert(testArray(arr));
|
||||
let obj = { a: [1, 2] };
|
||||
arr = [0, ...obj.a, 3];
|
||||
assert(testArray(arr));
|
||||
|
||||
arr = [...[], ...[...[0, 1, 2]], 3];
|
||||
assert(testArray(arr));
|
||||
arr = [...[], ...[...[0, 1, 2]], 3];
|
||||
assert(testArray(arr));
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[...1];
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "1 is not iterable",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[...1];
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "1 is not iterable",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[...{}];
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "[object Object] is not iterable",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[...{}];
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "[object Object] is not iterable",
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,68 +1,68 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
expect(BigInt).toHaveLength(1);
|
||||
expect(BigInt.name).toBe("BigInt");
|
||||
});
|
||||
test("basic functionality", () => {
|
||||
expect(BigInt).toHaveLength(1);
|
||||
expect(BigInt.name).toBe("BigInt");
|
||||
});
|
||||
|
||||
test("constructor with numbers", () => {
|
||||
expect(BigInt(0)).toBe(0n);
|
||||
expect(BigInt(1)).toBe(1n);
|
||||
expect(BigInt(+1)).toBe(1n);
|
||||
expect(BigInt(-1)).toBe(-1n);
|
||||
expect(BigInt(123n)).toBe(123n);
|
||||
});
|
||||
test("constructor with numbers", () => {
|
||||
expect(BigInt(0)).toBe(0n);
|
||||
expect(BigInt(1)).toBe(1n);
|
||||
expect(BigInt(+1)).toBe(1n);
|
||||
expect(BigInt(-1)).toBe(-1n);
|
||||
expect(BigInt(123n)).toBe(123n);
|
||||
});
|
||||
|
||||
test("constructor with strings", () => {
|
||||
expect(BigInt("")).toBe(0n);
|
||||
expect(BigInt("0")).toBe(0n);
|
||||
expect(BigInt("1")).toBe(1n);
|
||||
expect(BigInt("+1")).toBe(1n);
|
||||
expect(BigInt("-1")).toBe(-1n);
|
||||
expect(BigInt("-1")).toBe(-1n);
|
||||
expect(BigInt("42")).toBe(42n);
|
||||
expect(BigInt(" \n 00100 \n ")).toBe(100n);
|
||||
expect(BigInt("3323214327642987348732109829832143298746432437532197321")).toBe(
|
||||
3323214327642987348732109829832143298746432437532197321n
|
||||
);
|
||||
});
|
||||
test("constructor with strings", () => {
|
||||
expect(BigInt("")).toBe(0n);
|
||||
expect(BigInt("0")).toBe(0n);
|
||||
expect(BigInt("1")).toBe(1n);
|
||||
expect(BigInt("+1")).toBe(1n);
|
||||
expect(BigInt("-1")).toBe(-1n);
|
||||
expect(BigInt("-1")).toBe(-1n);
|
||||
expect(BigInt("42")).toBe(42n);
|
||||
expect(BigInt(" \n 00100 \n ")).toBe(100n);
|
||||
expect(BigInt("3323214327642987348732109829832143298746432437532197321")).toBe(
|
||||
3323214327642987348732109829832143298746432437532197321n
|
||||
);
|
||||
});
|
||||
|
||||
test("constructor with objects", () => {
|
||||
expect(BigInt([])).toBe(0n);
|
||||
});
|
||||
test("constructor with objects", () => {
|
||||
expect(BigInt([])).toBe(0n);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test('cannot be constructed with "new"', () => {
|
||||
expect(() => {
|
||||
new BigInt();
|
||||
}).toThrowWithMessage(TypeError, "BigInt is not a constructor");
|
||||
});
|
||||
|
||||
test("invalid arguments", () => {
|
||||
expect(() => {
|
||||
BigInt(null);
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert null to BigInt");
|
||||
|
||||
expect(() => {
|
||||
BigInt(undefined);
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert undefined to BigInt");
|
||||
|
||||
expect(() => {
|
||||
BigInt(Symbol());
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert symbol to BigInt");
|
||||
|
||||
["foo", "123n", "1+1", {}, function () {}].forEach(value => {
|
||||
expect(() => {
|
||||
BigInt(value);
|
||||
}).toThrowWithMessage(SyntaxError, `Invalid value for BigInt: ${value}`);
|
||||
test('cannot be constructed with "new"', () => {
|
||||
expect(() => {
|
||||
new BigInt();
|
||||
}).toThrowWithMessage(TypeError, "BigInt is not a constructor");
|
||||
});
|
||||
});
|
||||
|
||||
test("invalid numeric arguments", () => {
|
||||
[1.23, Infinity, -Infinity, NaN].forEach(value => {
|
||||
expect(() => {
|
||||
BigInt(value);
|
||||
}).toThrowWithMessage(RangeError, "BigInt argument must be an integer");
|
||||
test("invalid arguments", () => {
|
||||
expect(() => {
|
||||
BigInt(null);
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert null to BigInt");
|
||||
|
||||
expect(() => {
|
||||
BigInt(undefined);
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert undefined to BigInt");
|
||||
|
||||
expect(() => {
|
||||
BigInt(Symbol());
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert symbol to BigInt");
|
||||
|
||||
["foo", "123n", "1+1", {}, function () {}].forEach(value => {
|
||||
expect(() => {
|
||||
BigInt(value);
|
||||
}).toThrowWithMessage(SyntaxError, `Invalid value for BigInt: ${value}`);
|
||||
});
|
||||
});
|
||||
|
||||
test("invalid numeric arguments", () => {
|
||||
[1.23, Infinity, -Infinity, NaN].forEach(value => {
|
||||
expect(() => {
|
||||
BigInt(value);
|
||||
}).toThrowWithMessage(RangeError, "BigInt argument must be an integer");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
test("basic functionality", () => {
|
||||
expect(BigInt.prototype.toLocaleString).toHaveLength(0);
|
||||
expect(BigInt(123).toLocaleString()).toBe("123");
|
||||
expect(BigInt.prototype.toLocaleString).toHaveLength(0);
|
||||
expect(BigInt(123).toLocaleString()).toBe("123");
|
||||
});
|
||||
|
||||
test("calling with non-BigInt |this|", () => {
|
||||
expect(() => {
|
||||
BigInt.prototype.toLocaleString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a BigInt object");
|
||||
expect(() => {
|
||||
BigInt.prototype.toLocaleString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a BigInt object");
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
test("basic functionality", () => {
|
||||
expect(BigInt.prototype.toString).toHaveLength(0);
|
||||
expect(BigInt(123).toString()).toBe("123");
|
||||
expect(BigInt.prototype.toString).toHaveLength(0);
|
||||
expect(BigInt(123).toString()).toBe("123");
|
||||
});
|
||||
|
||||
test("calling with non-BigInt |this|", () => {
|
||||
expect(() => {
|
||||
BigInt.prototype.toString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a BigInt object");
|
||||
expect(() => {
|
||||
BigInt.prototype.toString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a BigInt object");
|
||||
});
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
test("basic functionality", () => {
|
||||
expect(BigInt.prototype.valueOf).toHaveLength(0);
|
||||
expect(typeof BigInt(123).valueOf()).toBe("bigint");
|
||||
// FIXME: Uncomment once we support Object() with argument
|
||||
// expect(typeof Object(123n).valueOf()).toBe("bigint");
|
||||
expect(BigInt.prototype.valueOf).toHaveLength(0);
|
||||
expect(typeof BigInt(123).valueOf()).toBe("bigint");
|
||||
// FIXME: Uncomment once we support Object() with argument
|
||||
// expect(typeof Object(123n).valueOf()).toBe("bigint");
|
||||
});
|
||||
|
||||
test("calling with non-BigInt |this|", () => {
|
||||
expect(() => {
|
||||
BigInt.prototype.valueOf.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a BigInt object");
|
||||
expect(() => {
|
||||
BigInt.prototype.valueOf.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a BigInt object");
|
||||
});
|
||||
|
|
|
@ -1,80 +1,80 @@
|
|||
describe("correct behavior", () => {
|
||||
test("typeof bigint", () => {
|
||||
expect(typeof 1n).toBe("bigint");
|
||||
});
|
||||
test("typeof bigint", () => {
|
||||
expect(typeof 1n).toBe("bigint");
|
||||
});
|
||||
|
||||
test("bigint string coersion", () => {
|
||||
expect("" + 123n).toBe("123");
|
||||
});
|
||||
test("bigint string coersion", () => {
|
||||
expect("" + 123n).toBe("123");
|
||||
});
|
||||
|
||||
test("arithmetic operators", () => {
|
||||
let bigint = 123n;
|
||||
expect(-bigint).toBe(-123n);
|
||||
test("arithmetic operators", () => {
|
||||
let bigint = 123n;
|
||||
expect(-bigint).toBe(-123n);
|
||||
|
||||
expect(12n + 34n).toBe(46n);
|
||||
expect(12n - 34n).toBe(-22n);
|
||||
expect(8n * 12n).toBe(96n);
|
||||
expect(123n / 10n).toBe(12n);
|
||||
expect(2n ** 3n).toBe(8n);
|
||||
expect(5n % 3n).toBe(2n);
|
||||
expect(
|
||||
45977665298704210987n +
|
||||
(714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n
|
||||
).toBe(199365500239020623962n);
|
||||
});
|
||||
expect(12n + 34n).toBe(46n);
|
||||
expect(12n - 34n).toBe(-22n);
|
||||
expect(8n * 12n).toBe(96n);
|
||||
expect(123n / 10n).toBe(12n);
|
||||
expect(2n ** 3n).toBe(8n);
|
||||
expect(5n % 3n).toBe(2n);
|
||||
expect(
|
||||
45977665298704210987n +
|
||||
(714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n
|
||||
).toBe(199365500239020623962n);
|
||||
});
|
||||
|
||||
test("bitwise operators", () => {
|
||||
expect(12n & 5n).toBe(4n);
|
||||
expect(1n | 2n).toBe(3n);
|
||||
expect(5n ^ 3n).toBe(6n);
|
||||
expect(~1n).toBe(-2n);
|
||||
});
|
||||
test("bitwise operators", () => {
|
||||
expect(12n & 5n).toBe(4n);
|
||||
expect(1n | 2n).toBe(3n);
|
||||
expect(5n ^ 3n).toBe(6n);
|
||||
expect(~1n).toBe(-2n);
|
||||
});
|
||||
|
||||
test("increment operators", () => {
|
||||
let bigint = 1n;
|
||||
expect(bigint++).toBe(1n);
|
||||
expect(bigint).toBe(2n);
|
||||
expect(bigint--).toBe(2n);
|
||||
expect(bigint).toBe(1n);
|
||||
expect(++bigint).toBe(2n);
|
||||
expect(bigint).toBe(2n);
|
||||
expect(--bigint).toBe(1n);
|
||||
expect(bigint).toBe(1n);
|
||||
});
|
||||
test("increment operators", () => {
|
||||
let bigint = 1n;
|
||||
expect(bigint++).toBe(1n);
|
||||
expect(bigint).toBe(2n);
|
||||
expect(bigint--).toBe(2n);
|
||||
expect(bigint).toBe(1n);
|
||||
expect(++bigint).toBe(2n);
|
||||
expect(bigint).toBe(2n);
|
||||
expect(--bigint).toBe(1n);
|
||||
expect(bigint).toBe(1n);
|
||||
});
|
||||
|
||||
test("weak equality operators", () => {
|
||||
expect(1n == 1n).toBeTrue();
|
||||
expect(1n == 1).toBeTrue();
|
||||
expect(1 == 1n).toBeTrue();
|
||||
expect(1n == 1.23).toBeFalse();
|
||||
expect(1.23 == 1n).toBeFalse();
|
||||
test("weak equality operators", () => {
|
||||
expect(1n == 1n).toBeTrue();
|
||||
expect(1n == 1).toBeTrue();
|
||||
expect(1 == 1n).toBeTrue();
|
||||
expect(1n == 1.23).toBeFalse();
|
||||
expect(1.23 == 1n).toBeFalse();
|
||||
|
||||
expect(1n != 1n).toBeFalse();
|
||||
expect(1n != 1).toBeFalse();
|
||||
expect(1 != 1n).toBeFalse();
|
||||
expect(1n != 1.23).toBeTrue();
|
||||
expect(1.23 != 1n).toBeTrue();
|
||||
});
|
||||
expect(1n != 1n).toBeFalse();
|
||||
expect(1n != 1).toBeFalse();
|
||||
expect(1 != 1n).toBeFalse();
|
||||
expect(1n != 1.23).toBeTrue();
|
||||
expect(1.23 != 1n).toBeTrue();
|
||||
});
|
||||
|
||||
test("strong equality operators", () => {
|
||||
expect(1n === 1n).toBeTrue();
|
||||
expect(1n === 1).toBeFalse();
|
||||
expect(1 === 1n).toBeFalse();
|
||||
expect(1n === 1.23).toBeFalse();
|
||||
expect(1.23 === 1n).toBeFalse();
|
||||
test("strong equality operators", () => {
|
||||
expect(1n === 1n).toBeTrue();
|
||||
expect(1n === 1).toBeFalse();
|
||||
expect(1 === 1n).toBeFalse();
|
||||
expect(1n === 1.23).toBeFalse();
|
||||
expect(1.23 === 1n).toBeFalse();
|
||||
|
||||
expect(1n !== 1n).toBeFalse();
|
||||
expect(1n !== 1).toBeTrue();
|
||||
expect(1 !== 1n).toBeTrue();
|
||||
expect(1n !== 1.23).toBeTrue();
|
||||
expect(1.23 !== 1n).toBeTrue();
|
||||
});
|
||||
expect(1n !== 1n).toBeFalse();
|
||||
expect(1n !== 1).toBeTrue();
|
||||
expect(1 !== 1n).toBeTrue();
|
||||
expect(1n !== 1.23).toBeTrue();
|
||||
expect(1.23 !== 1n).toBeTrue();
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("conversion to number", () => {
|
||||
expect(() => {
|
||||
+123n;
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert BigInt to number");
|
||||
});
|
||||
test("conversion to number", () => {
|
||||
expect(() => {
|
||||
+123n;
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert BigInt to number");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
const doTest = (operatorName, executeOperation) => {
|
||||
[1, null, undefined].forEach(value => {
|
||||
const messageSuffix = operatorName === "unsigned right-shift" ? "" : " and other type";
|
||||
[1, null, undefined].forEach(value => {
|
||||
const messageSuffix = operatorName === "unsigned right-shift" ? "" : " and other type";
|
||||
|
||||
expect(() => {
|
||||
executeOperation(1n, value);
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
`Cannot use ${operatorName} operator with BigInt${messageSuffix}`
|
||||
);
|
||||
});
|
||||
expect(() => {
|
||||
executeOperation(1n, value);
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
`Cannot use ${operatorName} operator with BigInt${messageSuffix}`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
[
|
||||
["addition", (a, b) => a + b],
|
||||
["subtraction", (a, b) => a - b],
|
||||
["multiplication", (a, b) => a * b],
|
||||
["division", (a, b) => a / b],
|
||||
["modulo", (a, b) => a % b],
|
||||
["exponentiation", (a, b) => a ** b],
|
||||
["bitwise OR", (a, b) => a | b],
|
||||
["bitwise AND", (a, b) => a & b],
|
||||
["bitwise XOR", (a, b) => a ^ b],
|
||||
["left-shift", (a, b) => a << b],
|
||||
["right-shift", (a, b) => a >> b],
|
||||
["unsigned right-shift", (a, b) => a >>> b],
|
||||
["addition", (a, b) => a + b],
|
||||
["subtraction", (a, b) => a - b],
|
||||
["multiplication", (a, b) => a * b],
|
||||
["division", (a, b) => a / b],
|
||||
["modulo", (a, b) => a % b],
|
||||
["exponentiation", (a, b) => a ** b],
|
||||
["bitwise OR", (a, b) => a | b],
|
||||
["bitwise AND", (a, b) => a & b],
|
||||
["bitwise XOR", (a, b) => a ^ b],
|
||||
["left-shift", (a, b) => a << b],
|
||||
["right-shift", (a, b) => a >> b],
|
||||
["unsigned right-shift", (a, b) => a >>> b],
|
||||
].forEach(testCase => {
|
||||
test(`using ${testCase[0]} operator with BigInt and other type`, () => {
|
||||
doTest(testCase[0], testCase[1]);
|
||||
});
|
||||
test(`using ${testCase[0]} operator with BigInt and other type`, () => {
|
||||
doTest(testCase[0], testCase[1]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
test("constructor properties", () => {
|
||||
expect(Boolean).toHaveLength(1);
|
||||
expect(Boolean.name).toBe("Boolean");
|
||||
expect(Boolean).toHaveLength(1);
|
||||
expect(Boolean.name).toBe("Boolean");
|
||||
});
|
||||
|
||||
test("typeof", () => {
|
||||
expect(typeof new Boolean()).toBe("object");
|
||||
expect(typeof Boolean()).toBe("boolean");
|
||||
expect(typeof Boolean(true)).toBe("boolean");
|
||||
expect(typeof new Boolean()).toBe("object");
|
||||
expect(typeof Boolean()).toBe("boolean");
|
||||
expect(typeof Boolean(true)).toBe("boolean");
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
var foo = new Boolean(true);
|
||||
var bar = new Boolean(true);
|
||||
var foo = new Boolean(true);
|
||||
var bar = new Boolean(true);
|
||||
|
||||
expect(foo).not.toBe(bar);
|
||||
expect(foo.valueOf()).toBe(bar.valueOf());
|
||||
expect(foo).not.toBe(bar);
|
||||
expect(foo.valueOf()).toBe(bar.valueOf());
|
||||
|
||||
expect(Boolean()).toBeFalse();
|
||||
expect(Boolean(false)).toBeFalse();
|
||||
expect(Boolean(null)).toBeFalse();
|
||||
expect(Boolean(undefined)).toBeFalse();
|
||||
expect(Boolean(NaN)).toBeFalse();
|
||||
expect(Boolean("")).toBeFalse();
|
||||
expect(Boolean(0.0)).toBeFalse();
|
||||
expect(Boolean(-0.0)).toBeFalse();
|
||||
expect(Boolean(true)).toBeTrue();
|
||||
expect(Boolean("0")).toBeTrue();
|
||||
expect(Boolean({})).toBeTrue();
|
||||
expect(Boolean([])).toBeTrue();
|
||||
expect(Boolean(1)).toBeTrue();
|
||||
expect(Boolean()).toBeFalse();
|
||||
expect(Boolean(false)).toBeFalse();
|
||||
expect(Boolean(null)).toBeFalse();
|
||||
expect(Boolean(undefined)).toBeFalse();
|
||||
expect(Boolean(NaN)).toBeFalse();
|
||||
expect(Boolean("")).toBeFalse();
|
||||
expect(Boolean(0.0)).toBeFalse();
|
||||
expect(Boolean(-0.0)).toBeFalse();
|
||||
expect(Boolean(true)).toBeTrue();
|
||||
expect(Boolean("0")).toBeTrue();
|
||||
expect(Boolean({})).toBeTrue();
|
||||
expect(Boolean([])).toBeTrue();
|
||||
expect(Boolean(1)).toBeTrue();
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
test("basic functionality", () => {
|
||||
expect(typeof Boolean.prototype).toBe("object");
|
||||
expect(Boolean.prototype.valueOf()).toBeFalse();
|
||||
expect(Boolean.prototype).not.toHaveProperty("length");
|
||||
expect(typeof Boolean.prototype).toBe("object");
|
||||
expect(Boolean.prototype.valueOf()).toBeFalse();
|
||||
expect(Boolean.prototype).not.toHaveProperty("length");
|
||||
});
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
test("basic functionality", () => {
|
||||
var foo = true;
|
||||
expect(foo.toString()).toBe("true");
|
||||
expect(true.toString()).toBe("true");
|
||||
var foo = true;
|
||||
expect(foo.toString()).toBe("true");
|
||||
expect(true.toString()).toBe("true");
|
||||
|
||||
expect(Boolean.prototype.toString.call(true)).toBe("true");
|
||||
expect(Boolean.prototype.toString.call(false)).toBe("false");
|
||||
expect(Boolean.prototype.toString.call(true)).toBe("true");
|
||||
expect(Boolean.prototype.toString.call(false)).toBe("false");
|
||||
|
||||
expect(new Boolean(true).toString()).toBe("true");
|
||||
expect(new Boolean(false).toString()).toBe("false");
|
||||
expect(new Boolean(true).toString()).toBe("true");
|
||||
expect(new Boolean(false).toString()).toBe("false");
|
||||
});
|
||||
|
||||
test("errors on non-boolean |this|", () => {
|
||||
expect(() => {
|
||||
Boolean.prototype.toString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Boolean object");
|
||||
expect(() => {
|
||||
Boolean.prototype.toString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Boolean object");
|
||||
});
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
test("basic functionality", () => {
|
||||
var foo = true;
|
||||
expect(foo.valueOf()).toBeTrue();
|
||||
expect(true.valueOf()).toBeTrue();
|
||||
var foo = true;
|
||||
expect(foo.valueOf()).toBeTrue();
|
||||
expect(true.valueOf()).toBeTrue();
|
||||
|
||||
expect(Boolean.prototype.valueOf.call(true)).toBeTrue();
|
||||
expect(Boolean.prototype.valueOf.call(false)).toBeFalse();
|
||||
expect(Boolean.prototype.valueOf.call(true)).toBeTrue();
|
||||
expect(Boolean.prototype.valueOf.call(false)).toBeFalse();
|
||||
|
||||
expect(new Boolean().valueOf()).toBeFalse();
|
||||
expect(new Boolean().valueOf()).toBeFalse();
|
||||
});
|
||||
|
||||
test("errors on non-boolean |this|", () => {
|
||||
expect(() => {
|
||||
Boolean.prototype.valueOf.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Boolean object");
|
||||
expect(() => {
|
||||
Boolean.prototype.valueOf.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Boolean object");
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Date).toHaveLength(7);
|
||||
expect(Date.name === "Date");
|
||||
expect(Date.prototype).not.toHaveProperty("length");
|
||||
expect(Date).toHaveLength(7);
|
||||
expect(Date.name === "Date");
|
||||
expect(Date.prototype).not.toHaveProperty("length");
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
test("basic functionality", () => {
|
||||
var last = 0;
|
||||
for (var i = 0; i < 100; ++i) {
|
||||
var now = Date.now();
|
||||
expect(now).not.toBeNaN();
|
||||
expect(now).toBeGreaterThan(1580000000000);
|
||||
expect(now).toBeGreaterThanOrEqual(last);
|
||||
last = now;
|
||||
}
|
||||
var last = 0;
|
||||
for (var i = 0; i < 100; ++i) {
|
||||
var now = Date.now();
|
||||
expect(now).not.toBeNaN();
|
||||
expect(now).toBeGreaterThan(1580000000000);
|
||||
expect(now).toBeGreaterThanOrEqual(last);
|
||||
last = now;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
let d = new Date();
|
||||
expect(d.getDate()).toBe(d.getDate());
|
||||
expect(d.getDate()).not.toBeNaN();
|
||||
expect(d.getDate()).toBeGreaterThanOrEqual(1);
|
||||
expect(d.getDate()).toBeLessThanOrEqual(31);
|
||||
let d = new Date();
|
||||
expect(d.getDate()).toBe(d.getDate());
|
||||
expect(d.getDate()).not.toBeNaN();
|
||||
expect(d.getDate()).toBeGreaterThanOrEqual(1);
|
||||
expect(d.getDate()).toBeLessThanOrEqual(31);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
var d = new Date();
|
||||
expect(d.getDay()).toBe(d.getDay());
|
||||
expect(d.getDay()).not.toBeNaN();
|
||||
expect(d.getDay()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getDay()).toBeLessThanOrEqual(6);
|
||||
var d = new Date();
|
||||
expect(d.getDay()).toBe(d.getDay());
|
||||
expect(d.getDay()).not.toBeNaN();
|
||||
expect(d.getDay()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getDay()).toBeLessThanOrEqual(6);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
var d = new Date();
|
||||
expect(d.getFullYear()).toBe(d.getFullYear());
|
||||
expect(d.getFullYear()).not.toBeNaN();
|
||||
expect(d.getFullYear()).toBe(d.getFullYear());
|
||||
expect(d.getFullYear()).toBeGreaterThanOrEqual(2020);
|
||||
var d = new Date();
|
||||
expect(d.getFullYear()).toBe(d.getFullYear());
|
||||
expect(d.getFullYear()).not.toBeNaN();
|
||||
expect(d.getFullYear()).toBe(d.getFullYear());
|
||||
expect(d.getFullYear()).toBeGreaterThanOrEqual(2020);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
var d = new Date();
|
||||
expect(d.getHours()).toBe(d.getHours());
|
||||
expect(d.getHours()).not.toBeNaN();
|
||||
expect(d.getHours()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getHours()).toBeLessThanOrEqual(23);
|
||||
var d = new Date();
|
||||
expect(d.getHours()).toBe(d.getHours());
|
||||
expect(d.getHours()).not.toBeNaN();
|
||||
expect(d.getHours()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getHours()).toBeLessThanOrEqual(23);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
var d = new Date();
|
||||
expect(d.getMilliseconds()).toBe(d.getMilliseconds());
|
||||
expect(d.getMilliseconds()).not.toBeNaN();
|
||||
expect(d.getMilliseconds()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getMilliseconds()).toBeLessThanOrEqual(999);
|
||||
var d = new Date();
|
||||
expect(d.getMilliseconds()).toBe(d.getMilliseconds());
|
||||
expect(d.getMilliseconds()).not.toBeNaN();
|
||||
expect(d.getMilliseconds()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getMilliseconds()).toBeLessThanOrEqual(999);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
var d = new Date();
|
||||
expect(d.getMinutes()).toBe(d.getMinutes());
|
||||
expect(d.getMinutes()).not.toBeNaN();
|
||||
expect(d.getMinutes()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getMinutes()).toBeLessThanOrEqual(59);
|
||||
var d = new Date();
|
||||
expect(d.getMinutes()).toBe(d.getMinutes());
|
||||
expect(d.getMinutes()).not.toBeNaN();
|
||||
expect(d.getMinutes()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getMinutes()).toBeLessThanOrEqual(59);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
var d = new Date();
|
||||
expect(d.getMonth()).toBe(d.getMonth());
|
||||
expect(d.getMonth()).not.toBeNaN();
|
||||
expect(d.getMonth()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getMonth()).toBeLessThanOrEqual(11);
|
||||
var d = new Date();
|
||||
expect(d.getMonth()).toBe(d.getMonth());
|
||||
expect(d.getMonth()).not.toBeNaN();
|
||||
expect(d.getMonth()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getMonth()).toBeLessThanOrEqual(11);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
var d = new Date();
|
||||
expect(d.getSeconds()).toBe(d.getSeconds());
|
||||
expect(d.getSeconds()).not.toBeNaN();
|
||||
expect(d.getSeconds()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getSeconds()).toBeLessThanOrEqual(59);
|
||||
var d = new Date();
|
||||
expect(d.getSeconds()).toBe(d.getSeconds());
|
||||
expect(d.getSeconds()).not.toBeNaN();
|
||||
expect(d.getSeconds()).toBeGreaterThanOrEqual(0);
|
||||
expect(d.getSeconds()).toBeLessThanOrEqual(59);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
test("basic functionality", () => {
|
||||
var d = new Date();
|
||||
expect(d.getTime()).toBe(d.getTime());
|
||||
expect(d.getTime()).not.toBeNaN();
|
||||
expect(d.getTime()).toBeGreaterThanOrEqual(1580000000000);
|
||||
var d = new Date();
|
||||
expect(d.getTime()).toBe(d.getTime());
|
||||
expect(d.getTime()).not.toBeNaN();
|
||||
expect(d.getTime()).toBeGreaterThanOrEqual(1580000000000);
|
||||
});
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Error).toHaveLength(1);
|
||||
expect(Error.name).toBe("Error");
|
||||
expect(Error).toHaveLength(1);
|
||||
expect(Error.name).toBe("Error");
|
||||
});
|
||||
|
||||
test("name", () => {
|
||||
[Error(), Error(undefined), Error("test"), Error(42), Error(null)].forEach(error => {
|
||||
expect(error.name).toBe("Error");
|
||||
});
|
||||
[Error(), Error(undefined), Error("test"), Error(42), Error(null)].forEach(error => {
|
||||
expect(error.name).toBe("Error");
|
||||
});
|
||||
});
|
||||
|
||||
test("message", () => {
|
||||
expect(Error().message).toBe("");
|
||||
expect(Error(undefined).message).toBe("");
|
||||
expect(Error("test").message).toBe("test");
|
||||
expect(Error(42).message).toBe("42");
|
||||
expect(Error(null).message).toBe("null");
|
||||
expect(Error().message).toBe("");
|
||||
expect(Error(undefined).message).toBe("");
|
||||
expect(Error("test").message).toBe("test");
|
||||
expect(Error(42).message).toBe("42");
|
||||
expect(Error(null).message).toBe("null");
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Error.prototype).not.toHaveProperty("length");
|
||||
expect(Error.prototype).not.toHaveProperty("length");
|
||||
|
||||
var changedInstance = new Error("");
|
||||
changedInstance.name = "NewCustomError";
|
||||
expect(changedInstance.name).toBe("NewCustomError");
|
||||
var changedInstance = new Error("");
|
||||
changedInstance.name = "NewCustomError";
|
||||
expect(changedInstance.name).toBe("NewCustomError");
|
||||
|
||||
var normalInstance = new Error("");
|
||||
expect(normalInstance.name).toBe("Error");
|
||||
var normalInstance = new Error("");
|
||||
expect(normalInstance.name).toBe("Error");
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Error().toString()).toBe("Error");
|
||||
expect(Error(undefined).toString()).toBe("Error");
|
||||
expect(Error(null).toString()).toBe("Error: null");
|
||||
expect(Error("test").toString()).toBe("Error: test");
|
||||
expect(Error(42).toString()).toBe("Error: 42");
|
||||
expect(Error().toString()).toBe("Error");
|
||||
expect(Error(undefined).toString()).toBe("Error");
|
||||
expect(Error(null).toString()).toBe("Error: null");
|
||||
expect(Error("test").toString()).toBe("Error: test");
|
||||
expect(Error(42).toString()).toBe("Error: 42");
|
||||
});
|
||||
|
|
|
@ -1,49 +1,51 @@
|
|||
describe("correct behavior", () => {
|
||||
test("constructor properties", () => {
|
||||
expect(Function).toHaveLength(1);
|
||||
expect(Function.name).toBe("Function");
|
||||
expect(Function.prototype).toHaveLength(0);
|
||||
expect(Function.prototype.name).toBe("");
|
||||
});
|
||||
test("constructor properties", () => {
|
||||
expect(Function).toHaveLength(1);
|
||||
expect(Function.name).toBe("Function");
|
||||
expect(Function.prototype).toHaveLength(0);
|
||||
expect(Function.prototype.name).toBe("");
|
||||
});
|
||||
|
||||
test("typeof", () => {
|
||||
expect(typeof Function()).toBe("function");
|
||||
expect(typeof new Function()).toBe("function");
|
||||
});
|
||||
test("typeof", () => {
|
||||
expect(typeof Function()).toBe("function");
|
||||
expect(typeof new Function()).toBe("function");
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
expect(Function()()).toBeUndefined();
|
||||
expect(new Function()()).toBeUndefined();
|
||||
expect(Function("return 42")()).toBe(42);
|
||||
expect(new Function("return 42")()).toBe(42);
|
||||
expect(new Function("foo", "return foo")(42)).toBe(42);
|
||||
expect(new Function("foo,bar", "return foo + bar")(1, 2)).toBe(3);
|
||||
expect(new Function("foo", "bar", "return foo + bar")(1, 2)).toBe(3);
|
||||
expect(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
|
||||
expect(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
|
||||
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true)).toBe(42);
|
||||
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe(
|
||||
"bar"
|
||||
);
|
||||
expect(new Function("return typeof Function()")()).toBe("function");
|
||||
expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3);
|
||||
test("basic functionality", () => {
|
||||
expect(Function()()).toBeUndefined();
|
||||
expect(new Function()()).toBeUndefined();
|
||||
expect(Function("return 42")()).toBe(42);
|
||||
expect(new Function("return 42")()).toBe(42);
|
||||
expect(new Function("foo", "return foo")(42)).toBe(42);
|
||||
expect(new Function("foo,bar", "return foo + bar")(1, 2)).toBe(3);
|
||||
expect(new Function("foo", "bar", "return foo + bar")(1, 2)).toBe(3);
|
||||
expect(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
|
||||
expect(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
|
||||
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true)).toBe(
|
||||
42
|
||||
);
|
||||
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe(
|
||||
"bar"
|
||||
);
|
||||
expect(new Function("return typeof Function()")()).toBe("function");
|
||||
expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3);
|
||||
|
||||
expect(new Function().name).toBe("anonymous");
|
||||
expect(new Function().toString()).toBe("function anonymous() {\n ???\n}");
|
||||
});
|
||||
expect(new Function().name).toBe("anonymous");
|
||||
expect(new Function().toString()).toBe("function anonymous() {\n ???\n}");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("syntax error", () => {
|
||||
expect(() => {
|
||||
new Function("[");
|
||||
})
|
||||
// This might be confusing at first but keep in mind it's actually parsing
|
||||
// function anonymous() { [ }
|
||||
// This is in line with what other engines are reporting.
|
||||
.toThrowWithMessage(
|
||||
SyntaxError,
|
||||
"Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)"
|
||||
);
|
||||
});
|
||||
test("syntax error", () => {
|
||||
expect(() => {
|
||||
new Function("[");
|
||||
})
|
||||
// This might be confusing at first but keep in mind it's actually parsing
|
||||
// function anonymous() { [ }
|
||||
// This is in line with what other engines are reporting.
|
||||
.toThrowWithMessage(
|
||||
SyntaxError,
|
||||
"Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,51 +1,51 @@
|
|||
test("basic functionality", () => {
|
||||
function Foo(arg) {
|
||||
this.foo = arg;
|
||||
}
|
||||
function Bar(arg) {
|
||||
this.bar = arg;
|
||||
}
|
||||
function FooBar(arg) {
|
||||
Foo.apply(this, [arg]);
|
||||
Bar.apply(this, [arg]);
|
||||
}
|
||||
function FooBarBaz(arg) {
|
||||
Foo.apply(this, [arg]);
|
||||
Bar.apply(this, [arg]);
|
||||
this.baz = arg;
|
||||
}
|
||||
function Foo(arg) {
|
||||
this.foo = arg;
|
||||
}
|
||||
function Bar(arg) {
|
||||
this.bar = arg;
|
||||
}
|
||||
function FooBar(arg) {
|
||||
Foo.apply(this, [arg]);
|
||||
Bar.apply(this, [arg]);
|
||||
}
|
||||
function FooBarBaz(arg) {
|
||||
Foo.apply(this, [arg]);
|
||||
Bar.apply(this, [arg]);
|
||||
this.baz = arg;
|
||||
}
|
||||
|
||||
expect(Function.prototype.apply).toHaveLength(2);
|
||||
expect(Function.prototype.apply).toHaveLength(2);
|
||||
|
||||
var foo = new Foo("test");
|
||||
expect(foo.foo).toBe("test");
|
||||
expect(foo.bar).toBeUndefined();
|
||||
expect(foo.baz).toBeUndefined();
|
||||
var foo = new Foo("test");
|
||||
expect(foo.foo).toBe("test");
|
||||
expect(foo.bar).toBeUndefined();
|
||||
expect(foo.baz).toBeUndefined();
|
||||
|
||||
var bar = new Bar("test");
|
||||
expect(bar.foo).toBeUndefined();
|
||||
expect(bar.bar).toBe("test");
|
||||
expect(bar.baz).toBeUndefined();
|
||||
var bar = new Bar("test");
|
||||
expect(bar.foo).toBeUndefined();
|
||||
expect(bar.bar).toBe("test");
|
||||
expect(bar.baz).toBeUndefined();
|
||||
|
||||
var foobar = new FooBar("test");
|
||||
expect(foobar.foo).toBe("test");
|
||||
expect(foobar.bar).toBe("test");
|
||||
expect(foobar.baz).toBeUndefined();
|
||||
var foobar = new FooBar("test");
|
||||
expect(foobar.foo).toBe("test");
|
||||
expect(foobar.bar).toBe("test");
|
||||
expect(foobar.baz).toBeUndefined();
|
||||
|
||||
var foobarbaz = new FooBarBaz("test");
|
||||
expect(foobarbaz.foo).toBe("test");
|
||||
expect(foobarbaz.bar).toBe("test");
|
||||
expect(foobarbaz.baz).toBe("test");
|
||||
var foobarbaz = new FooBarBaz("test");
|
||||
expect(foobarbaz.foo).toBe("test");
|
||||
expect(foobarbaz.bar).toBe("test");
|
||||
expect(foobarbaz.baz).toBe("test");
|
||||
|
||||
expect(Math.abs.apply(null, [-1])).toBe(1);
|
||||
expect(Math.abs.apply(null, [-1])).toBe(1);
|
||||
|
||||
var add = (x, y) => x + y;
|
||||
expect(add.apply(null, [1, 2])).toBe(3);
|
||||
var add = (x, y) => x + y;
|
||||
expect(add.apply(null, [1, 2])).toBe(3);
|
||||
|
||||
var multiply = function (x, y) {
|
||||
return x * y;
|
||||
};
|
||||
expect(multiply.apply(null, [3, 4])).toBe(12);
|
||||
var multiply = function (x, y) {
|
||||
return x * y;
|
||||
};
|
||||
expect(multiply.apply(null, [3, 4])).toBe(12);
|
||||
|
||||
expect((() => this).apply("foo")).toBe(globalThis);
|
||||
expect((() => this).apply("foo")).toBe(globalThis);
|
||||
});
|
||||
|
|
|
@ -1,149 +1,149 @@
|
|||
describe("basic behavior", () => {
|
||||
test("basic binding", () => {
|
||||
expect(Function.prototype.bind).toHaveLength(1);
|
||||
test("basic binding", () => {
|
||||
expect(Function.prototype.bind).toHaveLength(1);
|
||||
|
||||
var charAt = String.prototype.charAt.bind("bar");
|
||||
expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar");
|
||||
var charAt = String.prototype.charAt.bind("bar");
|
||||
expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar");
|
||||
|
||||
function getB() {
|
||||
return this.toUpperCase().charAt(0);
|
||||
}
|
||||
expect(getB.bind("bar")()).toBe("B");
|
||||
});
|
||||
function getB() {
|
||||
return this.toUpperCase().charAt(0);
|
||||
}
|
||||
expect(getB.bind("bar")()).toBe("B");
|
||||
});
|
||||
|
||||
test("bound functions work with array functions", () => {
|
||||
var Make3 = Number.bind(null, 3);
|
||||
expect([55].map(Make3)[0]).toBe(3);
|
||||
test("bound functions work with array functions", () => {
|
||||
var Make3 = Number.bind(null, 3);
|
||||
expect([55].map(Make3)[0]).toBe(3);
|
||||
|
||||
var MakeTrue = Boolean.bind(null, true);
|
||||
var MakeTrue = Boolean.bind(null, true);
|
||||
|
||||
expect([1, 2, 3].filter(MakeTrue)).toHaveLength(3);
|
||||
expect(
|
||||
[1, 2, 3].reduce(
|
||||
function (acc, x) {
|
||||
return acc + x;
|
||||
}.bind(null, 4, 5)
|
||||
)
|
||||
).toBe(9);
|
||||
expect(
|
||||
[1, 2, 3].reduce(
|
||||
function (acc, x) {
|
||||
return acc + x + this;
|
||||
}.bind(3)
|
||||
)
|
||||
).toBe(12);
|
||||
});
|
||||
expect([1, 2, 3].filter(MakeTrue)).toHaveLength(3);
|
||||
expect(
|
||||
[1, 2, 3].reduce(
|
||||
function (acc, x) {
|
||||
return acc + x;
|
||||
}.bind(null, 4, 5)
|
||||
)
|
||||
).toBe(9);
|
||||
expect(
|
||||
[1, 2, 3].reduce(
|
||||
function (acc, x) {
|
||||
return acc + x + this;
|
||||
}.bind(3)
|
||||
)
|
||||
).toBe(12);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bound function arguments", () => {
|
||||
function sum(a, b, c) {
|
||||
return a + b + c;
|
||||
}
|
||||
var boundSum = sum.bind(null, 10, 5);
|
||||
function sum(a, b, c) {
|
||||
return a + b + c;
|
||||
}
|
||||
var boundSum = sum.bind(null, 10, 5);
|
||||
|
||||
test("arguments are bound to the function", () => {
|
||||
expect(boundSum()).toBeNaN();
|
||||
expect(boundSum(5)).toBe(20);
|
||||
expect(boundSum(5, 6, 7)).toBe(20);
|
||||
});
|
||||
test("arguments are bound to the function", () => {
|
||||
expect(boundSum()).toBeNaN();
|
||||
expect(boundSum(5)).toBe(20);
|
||||
expect(boundSum(5, 6, 7)).toBe(20);
|
||||
});
|
||||
|
||||
test("arguments are appended to a BoundFunction's bound arguments", () => {
|
||||
expect(boundSum.bind(null, 5)()).toBe(20);
|
||||
});
|
||||
test("arguments are appended to a BoundFunction's bound arguments", () => {
|
||||
expect(boundSum.bind(null, 5)()).toBe(20);
|
||||
});
|
||||
|
||||
test("binding a constructor's arguments", () => {
|
||||
var Make5 = Number.bind(null, 5);
|
||||
expect(Make5()).toBe(5);
|
||||
expect(new Make5().valueOf()).toBe(5);
|
||||
});
|
||||
test("binding a constructor's arguments", () => {
|
||||
var Make5 = Number.bind(null, 5);
|
||||
expect(Make5()).toBe(5);
|
||||
expect(new Make5().valueOf()).toBe(5);
|
||||
});
|
||||
|
||||
test("length property", () => {
|
||||
expect(sum).toHaveLength(3);
|
||||
expect(boundSum).toHaveLength(1);
|
||||
expect(boundSum.bind(null, 5)).toHaveLength(0);
|
||||
expect(boundSum.bind(null, 5, 6, 7, 8)).toHaveLength(0);
|
||||
});
|
||||
test("length property", () => {
|
||||
expect(sum).toHaveLength(3);
|
||||
expect(boundSum).toHaveLength(1);
|
||||
expect(boundSum.bind(null, 5)).toHaveLength(0);
|
||||
expect(boundSum.bind(null, 5, 6, 7, 8)).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bound function |this|", () => {
|
||||
function identity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
test("captures global object as |this| if |this| is null or undefined", () => {
|
||||
expect(identity.bind()()).toBe(globalThis);
|
||||
expect(identity.bind(null)()).toBe(globalThis);
|
||||
expect(identity.bind(undefined)()).toBe(globalThis);
|
||||
|
||||
function Foo() {
|
||||
expect(identity.bind()()).toBe(globalThis);
|
||||
expect(identity.bind(this)()).toBe(this);
|
||||
}
|
||||
new Foo();
|
||||
});
|
||||
|
||||
test("does not capture global object as |this| if |this| is null or undefined in strict mode", () => {
|
||||
"use strict";
|
||||
|
||||
function strictIdentity() {
|
||||
return this;
|
||||
function identity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
expect(strictIdentity.bind()()).toBeUndefined();
|
||||
expect(strictIdentity.bind(null)()).toBeNull();
|
||||
expect(strictIdentity.bind(undefined)()).toBeUndefined();
|
||||
});
|
||||
test("captures global object as |this| if |this| is null or undefined", () => {
|
||||
expect(identity.bind()()).toBe(globalThis);
|
||||
expect(identity.bind(null)()).toBe(globalThis);
|
||||
expect(identity.bind(undefined)()).toBe(globalThis);
|
||||
|
||||
test("primitive |this| values are converted to objects", () => {
|
||||
expect(identity.bind("foo")()).toBeInstanceOf(String);
|
||||
expect(identity.bind(123)()).toBeInstanceOf(Number);
|
||||
expect(identity.bind(true)()).toBeInstanceOf(Boolean);
|
||||
});
|
||||
function Foo() {
|
||||
expect(identity.bind()()).toBe(globalThis);
|
||||
expect(identity.bind(this)()).toBe(this);
|
||||
}
|
||||
new Foo();
|
||||
});
|
||||
|
||||
test("bound functions retain |this| values passed to them", () => {
|
||||
var obj = { foo: "bar" };
|
||||
expect(identity.bind(obj)()).toBe(obj);
|
||||
});
|
||||
test("does not capture global object as |this| if |this| is null or undefined in strict mode", () => {
|
||||
"use strict";
|
||||
|
||||
test("bound |this| cannot be changed after being set", () => {
|
||||
expect(identity.bind("foo").bind(123)()).toBeInstanceOf(String);
|
||||
});
|
||||
function strictIdentity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
test("arrow functions cannot be bound", () => {
|
||||
expect((() => this).bind("foo")()).toBe(globalThis);
|
||||
});
|
||||
expect(strictIdentity.bind()()).toBeUndefined();
|
||||
expect(strictIdentity.bind(null)()).toBeNull();
|
||||
expect(strictIdentity.bind(undefined)()).toBeUndefined();
|
||||
});
|
||||
|
||||
test("primitive |this| values are converted to objects", () => {
|
||||
expect(identity.bind("foo")()).toBeInstanceOf(String);
|
||||
expect(identity.bind(123)()).toBeInstanceOf(Number);
|
||||
expect(identity.bind(true)()).toBeInstanceOf(Boolean);
|
||||
});
|
||||
|
||||
test("bound functions retain |this| values passed to them", () => {
|
||||
var obj = { foo: "bar" };
|
||||
expect(identity.bind(obj)()).toBe(obj);
|
||||
});
|
||||
|
||||
test("bound |this| cannot be changed after being set", () => {
|
||||
expect(identity.bind("foo").bind(123)()).toBeInstanceOf(String);
|
||||
});
|
||||
|
||||
test("arrow functions cannot be bound", () => {
|
||||
expect((() => this).bind("foo")()).toBe(globalThis);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bound function constructors", () => {
|
||||
function Bar() {
|
||||
this.x = 3;
|
||||
this.y = 4;
|
||||
}
|
||||
function Bar() {
|
||||
this.x = 3;
|
||||
this.y = 4;
|
||||
}
|
||||
|
||||
Bar.prototype.baz = "baz";
|
||||
var BoundBar = Bar.bind({ u: 5, v: 6 });
|
||||
var bar = new BoundBar();
|
||||
Bar.prototype.baz = "baz";
|
||||
var BoundBar = Bar.bind({ u: 5, v: 6 });
|
||||
var bar = new BoundBar();
|
||||
|
||||
test("bound |this| value does not affect constructor", () => {
|
||||
expect(bar.x).toBe(3);
|
||||
expect(bar.y).toBe(4);
|
||||
expect(typeof bar.u).toBe("undefined");
|
||||
expect(typeof bar.v).toBe("undefined");
|
||||
});
|
||||
test("bound |this| value does not affect constructor", () => {
|
||||
expect(bar.x).toBe(3);
|
||||
expect(bar.y).toBe(4);
|
||||
expect(typeof bar.u).toBe("undefined");
|
||||
expect(typeof bar.v).toBe("undefined");
|
||||
});
|
||||
|
||||
test("bound functions retain original prototype", () => {
|
||||
expect(bar.baz).toBe("baz");
|
||||
});
|
||||
test("bound functions retain original prototype", () => {
|
||||
expect(bar.baz).toBe("baz");
|
||||
});
|
||||
|
||||
test("bound functions do not have a prototype property", () => {
|
||||
expect(BoundBar).not.toHaveProperty("prototype");
|
||||
});
|
||||
test("bound functions do not have a prototype property", () => {
|
||||
expect(BoundBar).not.toHaveProperty("prototype");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("does not accept non-function values", () => {
|
||||
expect(() => {
|
||||
Function.prototype.bind.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Function object");
|
||||
});
|
||||
test("does not accept non-function values", () => {
|
||||
expect(() => {
|
||||
Function.prototype.bind.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Function object");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,53 +1,53 @@
|
|||
test("length", () => {
|
||||
expect(Function.prototype.call).toHaveLength(1);
|
||||
expect(Function.prototype.call).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
function Foo(arg) {
|
||||
this.foo = arg;
|
||||
}
|
||||
function Bar(arg) {
|
||||
this.bar = arg;
|
||||
}
|
||||
function FooBar(arg) {
|
||||
Foo.call(this, arg);
|
||||
Bar.call(this, arg);
|
||||
}
|
||||
function FooBarBaz(arg) {
|
||||
Foo.call(this, arg);
|
||||
Bar.call(this, arg);
|
||||
this.baz = arg;
|
||||
}
|
||||
function Foo(arg) {
|
||||
this.foo = arg;
|
||||
}
|
||||
function Bar(arg) {
|
||||
this.bar = arg;
|
||||
}
|
||||
function FooBar(arg) {
|
||||
Foo.call(this, arg);
|
||||
Bar.call(this, arg);
|
||||
}
|
||||
function FooBarBaz(arg) {
|
||||
Foo.call(this, arg);
|
||||
Bar.call(this, arg);
|
||||
this.baz = arg;
|
||||
}
|
||||
|
||||
var foo = new Foo("test");
|
||||
expect(foo.foo).toBe("test");
|
||||
expect(foo.bar).toBeUndefined();
|
||||
expect(foo.baz).toBeUndefined();
|
||||
var foo = new Foo("test");
|
||||
expect(foo.foo).toBe("test");
|
||||
expect(foo.bar).toBeUndefined();
|
||||
expect(foo.baz).toBeUndefined();
|
||||
|
||||
var bar = new Bar("test");
|
||||
expect(bar.foo).toBeUndefined();
|
||||
expect(bar.bar).toBe("test");
|
||||
expect(bar.baz).toBeUndefined();
|
||||
var bar = new Bar("test");
|
||||
expect(bar.foo).toBeUndefined();
|
||||
expect(bar.bar).toBe("test");
|
||||
expect(bar.baz).toBeUndefined();
|
||||
|
||||
var foobar = new FooBar("test");
|
||||
expect(foobar.foo).toBe("test");
|
||||
expect(foobar.bar).toBe("test");
|
||||
expect(foobar.baz).toBeUndefined();
|
||||
var foobar = new FooBar("test");
|
||||
expect(foobar.foo).toBe("test");
|
||||
expect(foobar.bar).toBe("test");
|
||||
expect(foobar.baz).toBeUndefined();
|
||||
|
||||
var foobarbaz = new FooBarBaz("test");
|
||||
expect(foobarbaz.foo).toBe("test");
|
||||
expect(foobarbaz.bar).toBe("test");
|
||||
expect(foobarbaz.baz).toBe("test");
|
||||
var foobarbaz = new FooBarBaz("test");
|
||||
expect(foobarbaz.foo).toBe("test");
|
||||
expect(foobarbaz.bar).toBe("test");
|
||||
expect(foobarbaz.baz).toBe("test");
|
||||
|
||||
expect(Math.abs.call(null, -1)).toBe(1);
|
||||
expect(Math.abs.call(null, -1)).toBe(1);
|
||||
|
||||
var add = (x, y) => x + y;
|
||||
expect(add.call(null, 1, 2)).toBe(3);
|
||||
var add = (x, y) => x + y;
|
||||
expect(add.call(null, 1, 2)).toBe(3);
|
||||
|
||||
var multiply = function (x, y) {
|
||||
return x * y;
|
||||
};
|
||||
expect(multiply.call(null, 3, 4)).toBe(12);
|
||||
var multiply = function (x, y) {
|
||||
return x * y;
|
||||
};
|
||||
expect(multiply.call(null, 3, 4)).toBe(12);
|
||||
|
||||
expect((() => this).call("foo")).toBe(globalThis);
|
||||
expect((() => this).call("foo")).toBe(globalThis);
|
||||
});
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
test("basic functionality", () => {
|
||||
expect(function () {}.toString()).toBe("function () {\n ???\n}");
|
||||
expect(function (foo) {}.toString()).toBe("function (foo) {\n ???\n}");
|
||||
expect(function (foo, bar, baz) {}.toString()).toBe("function (foo, bar, baz) {\n ???\n}");
|
||||
expect(
|
||||
function (foo, bar, baz) {
|
||||
if (foo) {
|
||||
return baz;
|
||||
} else if (bar) {
|
||||
return foo;
|
||||
}
|
||||
return bar + 42;
|
||||
}.toString()
|
||||
).toBe("function (foo, bar, baz) {\n ???\n}");
|
||||
expect(console.debug.toString()).toBe("function debug() {\n [NativeFunction]\n}");
|
||||
expect(Function.toString()).toBe("function Function() {\n [FunctionConstructor]\n}");
|
||||
expect(function () {}.toString()).toBe("function () {\n ???\n}");
|
||||
expect(function (foo) {}.toString()).toBe("function (foo) {\n ???\n}");
|
||||
expect(function (foo, bar, baz) {}.toString()).toBe("function (foo, bar, baz) {\n ???\n}");
|
||||
expect(
|
||||
function (foo, bar, baz) {
|
||||
if (foo) {
|
||||
return baz;
|
||||
} else if (bar) {
|
||||
return foo;
|
||||
}
|
||||
return bar + 42;
|
||||
}.toString()
|
||||
).toBe("function (foo, bar, baz) {\n ???\n}");
|
||||
expect(console.debug.toString()).toBe("function debug() {\n [NativeFunction]\n}");
|
||||
expect(Function.toString()).toBe("function Function() {\n [FunctionConstructor]\n}");
|
||||
});
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Infinity + "").toBe("Infinity");
|
||||
expect(-Infinity + "").toBe("-Infinity");
|
||||
expect(Infinity).toBe(Infinity);
|
||||
expect(Infinity - 1).toBe(Infinity);
|
||||
expect(Infinity + 1).toBe(Infinity);
|
||||
expect(-Infinity).toBe(-Infinity);
|
||||
expect(-Infinity - 1).toBe(-Infinity);
|
||||
expect(-Infinity + 1).toBe(-Infinity);
|
||||
expect(1 / Infinity).toBe(0);
|
||||
expect(1 / -Infinity).toBe(-0);
|
||||
expect(1 / 0).toBe(Infinity);
|
||||
expect(-1 / 0).toBe(-Infinity);
|
||||
expect(-100).toBeLessThan(Infinity);
|
||||
expect(0).toBeLessThan(Infinity);
|
||||
expect(100).toBeLessThan(Infinity);
|
||||
expect(-Infinity).toBeLessThan(Infinity);
|
||||
expect(-100).toBeGreaterThan(-Infinity);
|
||||
expect(0).toBeGreaterThan(-Infinity);
|
||||
expect(100).toBeGreaterThan(-Infinity);
|
||||
expect(Infinity).toBeGreaterThan(-Infinity);
|
||||
expect(Infinity + "").toBe("Infinity");
|
||||
expect(-Infinity + "").toBe("-Infinity");
|
||||
expect(Infinity).toBe(Infinity);
|
||||
expect(Infinity - 1).toBe(Infinity);
|
||||
expect(Infinity + 1).toBe(Infinity);
|
||||
expect(-Infinity).toBe(-Infinity);
|
||||
expect(-Infinity - 1).toBe(-Infinity);
|
||||
expect(-Infinity + 1).toBe(-Infinity);
|
||||
expect(1 / Infinity).toBe(0);
|
||||
expect(1 / -Infinity).toBe(-0);
|
||||
expect(1 / 0).toBe(Infinity);
|
||||
expect(-1 / 0).toBe(-Infinity);
|
||||
expect(-100).toBeLessThan(Infinity);
|
||||
expect(0).toBeLessThan(Infinity);
|
||||
expect(100).toBeLessThan(Infinity);
|
||||
expect(-Infinity).toBeLessThan(Infinity);
|
||||
expect(-100).toBeGreaterThan(-Infinity);
|
||||
expect(0).toBeGreaterThan(-Infinity);
|
||||
expect(100).toBeGreaterThan(-Infinity);
|
||||
expect(Infinity).toBeGreaterThan(-Infinity);
|
||||
});
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
test("basic functionality", () => {
|
||||
let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`;
|
||||
let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`;
|
||||
|
||||
let object = JSON.parse(string, (key, value) => (typeof value === "number" ? value * 2 : value));
|
||||
expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } });
|
||||
let object = JSON.parse(string, (key, value) =>
|
||||
typeof value === "number" ? value * 2 : value
|
||||
);
|
||||
expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } });
|
||||
|
||||
object = JSON.parse(string, (key, value) => (typeof value === "number" ? undefined : value));
|
||||
expect(object).toEqual({ var2: "hello", var3: {} });
|
||||
object = JSON.parse(string, (key, value) => (typeof value === "number" ? undefined : value));
|
||||
expect(object).toEqual({ var2: "hello", var3: {} });
|
||||
});
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
test("basic functionality", () => {
|
||||
expect(JSON.parse).toHaveLength(2);
|
||||
expect(JSON.parse).toHaveLength(2);
|
||||
|
||||
const properties = [
|
||||
["5", 5],
|
||||
["null", null],
|
||||
["true", true],
|
||||
["false", false],
|
||||
['"test"', "test"],
|
||||
['[1,2,"foo"]', [1, 2, "foo"]],
|
||||
['{"foo":1,"bar":"baz"}', { foo: 1, bar: "baz" }],
|
||||
];
|
||||
const properties = [
|
||||
["5", 5],
|
||||
["null", null],
|
||||
["true", true],
|
||||
["false", false],
|
||||
['"test"', "test"],
|
||||
['[1,2,"foo"]', [1, 2, "foo"]],
|
||||
['{"foo":1,"bar":"baz"}', { foo: 1, bar: "baz" }],
|
||||
];
|
||||
|
||||
properties.forEach(testCase => {
|
||||
expect(JSON.parse(testCase[0])).toEqual(testCase[1]);
|
||||
});
|
||||
properties.forEach(testCase => {
|
||||
expect(JSON.parse(testCase[0])).toEqual(testCase[1]);
|
||||
});
|
||||
});
|
||||
|
||||
test("syntax errors", () => {
|
||||
[
|
||||
undefined,
|
||||
NaN,
|
||||
-NaN,
|
||||
Infinity,
|
||||
-Infinity,
|
||||
'{ "foo" }',
|
||||
'{ foo: "bar" }',
|
||||
"[1,2,3,]",
|
||||
"[1,2,3, ]",
|
||||
'{ "foo": "bar",}',
|
||||
'{ "foo": "bar", }',
|
||||
].forEach(test => {
|
||||
expect(() => {
|
||||
JSON.parse(test);
|
||||
}).toThrow(SyntaxError);
|
||||
});
|
||||
[
|
||||
undefined,
|
||||
NaN,
|
||||
-NaN,
|
||||
Infinity,
|
||||
-Infinity,
|
||||
'{ "foo" }',
|
||||
'{ foo: "bar" }',
|
||||
"[1,2,3,]",
|
||||
"[1,2,3, ]",
|
||||
'{ "foo": "bar",}',
|
||||
'{ "foo": "bar", }',
|
||||
].forEach(test => {
|
||||
expect(() => {
|
||||
JSON.parse(test);
|
||||
}).toThrow(SyntaxError);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
test("basic functionality", () => {
|
||||
let o = {
|
||||
key1: "key1",
|
||||
key2: "key2",
|
||||
key3: "key3",
|
||||
};
|
||||
let o = {
|
||||
key1: "key1",
|
||||
key2: "key2",
|
||||
key3: "key3",
|
||||
};
|
||||
|
||||
Object.defineProperty(o, "defined", {
|
||||
enumerable: true,
|
||||
get() {
|
||||
o.prop = "prop";
|
||||
return "defined";
|
||||
},
|
||||
});
|
||||
Object.defineProperty(o, "defined", {
|
||||
enumerable: true,
|
||||
get() {
|
||||
o.prop = "prop";
|
||||
return "defined";
|
||||
},
|
||||
});
|
||||
|
||||
o.key4 = "key4";
|
||||
o.key4 = "key4";
|
||||
|
||||
o[2] = 2;
|
||||
o[0] = 0;
|
||||
o[1] = 1;
|
||||
o[2] = 2;
|
||||
o[0] = 0;
|
||||
o[1] = 1;
|
||||
|
||||
delete o.key1;
|
||||
delete o.key3;
|
||||
delete o.key1;
|
||||
delete o.key3;
|
||||
|
||||
o.key1 = "key1";
|
||||
o.key1 = "key1";
|
||||
|
||||
expect(JSON.stringify(o)).toBe(
|
||||
'{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}'
|
||||
);
|
||||
expect(JSON.stringify(o)).toBe(
|
||||
'{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}'
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
test("basic functionality", () => {
|
||||
let p = new Proxy([], {
|
||||
get(_, key) {
|
||||
if (key === "length") return 3;
|
||||
return Number(key);
|
||||
},
|
||||
});
|
||||
let p = new Proxy([], {
|
||||
get(_, key) {
|
||||
if (key === "length") return 3;
|
||||
return Number(key);
|
||||
},
|
||||
});
|
||||
|
||||
expect(JSON.stringify(p)).toBe("[0,1,2]");
|
||||
expect(JSON.stringify([[new Proxy(p, {})]])).toBe("[[[0,1,2]]]");
|
||||
expect(JSON.stringify(p)).toBe("[0,1,2]");
|
||||
expect(JSON.stringify([[new Proxy(p, {})]])).toBe("[[[0,1,2]]]");
|
||||
});
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
test("basic functionality", () => {
|
||||
let o = {
|
||||
var1: "foo",
|
||||
var2: 42,
|
||||
arr: [
|
||||
1,
|
||||
2,
|
||||
{
|
||||
nested: {
|
||||
hello: "world",
|
||||
let o = {
|
||||
var1: "foo",
|
||||
var2: 42,
|
||||
arr: [
|
||||
1,
|
||||
2,
|
||||
{
|
||||
nested: {
|
||||
hello: "world",
|
||||
},
|
||||
get x() {
|
||||
return 10;
|
||||
},
|
||||
},
|
||||
],
|
||||
obj: {
|
||||
subarr: [3],
|
||||
},
|
||||
get x() {
|
||||
return 10;
|
||||
},
|
||||
},
|
||||
],
|
||||
obj: {
|
||||
subarr: [3],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
let string = JSON.stringify(o, (key, value) => {
|
||||
if (key === "hello") return undefined;
|
||||
if (value === 10) return 20;
|
||||
if (key === "subarr") return [3, 4, 5];
|
||||
return value;
|
||||
});
|
||||
let string = JSON.stringify(o, (key, value) => {
|
||||
if (key === "hello") return undefined;
|
||||
if (value === 10) return 20;
|
||||
if (key === "subarr") return [3, 4, 5];
|
||||
return value;
|
||||
});
|
||||
|
||||
expect(string).toBe(
|
||||
'{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}'
|
||||
);
|
||||
expect(string).toBe(
|
||||
'{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}'
|
||||
);
|
||||
|
||||
string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]);
|
||||
expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}');
|
||||
string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]);
|
||||
expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}');
|
||||
|
||||
string = JSON.stringify(o, ["var1", "var1", "var2", "obj", "subarr"]);
|
||||
expect(string).toBe('{"var1":"foo","var2":42,"obj":{"subarr":[3]}}');
|
||||
string = JSON.stringify(o, ["var1", "var1", "var2", "obj", "subarr"]);
|
||||
expect(string).toBe('{"var1":"foo","var2":42,"obj":{"subarr":[3]}}');
|
||||
});
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
test("basic functionality", () => {
|
||||
let o = {
|
||||
foo: 1,
|
||||
bar: "baz",
|
||||
qux: {
|
||||
get x() {
|
||||
return 10;
|
||||
},
|
||||
y() {
|
||||
return 20;
|
||||
},
|
||||
arr: [1, 2, 3],
|
||||
},
|
||||
};
|
||||
let o = {
|
||||
foo: 1,
|
||||
bar: "baz",
|
||||
qux: {
|
||||
get x() {
|
||||
return 10;
|
||||
},
|
||||
y() {
|
||||
return 20;
|
||||
},
|
||||
arr: [1, 2, 3],
|
||||
},
|
||||
};
|
||||
|
||||
let string = JSON.stringify(o, null, 4);
|
||||
let expected = `{
|
||||
let string = JSON.stringify(o, null, 4);
|
||||
let expected = `{
|
||||
"foo": 1,
|
||||
"bar": "baz",
|
||||
"qux": {
|
||||
|
@ -27,10 +27,10 @@ test("basic functionality", () => {
|
|||
}
|
||||
}`;
|
||||
|
||||
expect(string).toBe(expected);
|
||||
expect(string).toBe(expected);
|
||||
|
||||
string = JSON.stringify(o, null, "abcd");
|
||||
expected = `{
|
||||
string = JSON.stringify(o, null, "abcd");
|
||||
expected = `{
|
||||
abcd"foo": 1,
|
||||
abcd"bar": "baz",
|
||||
abcd"qux": {
|
||||
|
@ -43,5 +43,5 @@ abcdabcd]
|
|||
abcd}
|
||||
}`;
|
||||
|
||||
expect(string).toBe(expected);
|
||||
expect(string).toBe(expected);
|
||||
});
|
||||
|
|
|
@ -1,71 +1,71 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length", () => {
|
||||
expect(JSON.stringify).toHaveLength(3);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
[
|
||||
[5, "5"],
|
||||
[undefined, undefined],
|
||||
[null, "null"],
|
||||
[NaN, "null"],
|
||||
[-NaN, "null"],
|
||||
[Infinity, "null"],
|
||||
[-Infinity, "null"],
|
||||
[true, "true"],
|
||||
[false, "false"],
|
||||
["test", '"test"'],
|
||||
[new Number(5), "5"],
|
||||
[new Boolean(false), "false"],
|
||||
[new String("test"), '"test"'],
|
||||
[() => {}, undefined],
|
||||
[[1, 2, "foo"], '[1,2,"foo"]'],
|
||||
[{ foo: 1, bar: "baz", qux() {} }, '{"foo":1,"bar":"baz"}'],
|
||||
[
|
||||
{
|
||||
var1: 1,
|
||||
var2: 2,
|
||||
toJSON(key) {
|
||||
let o = this;
|
||||
o.var2 = 10;
|
||||
return o;
|
||||
},
|
||||
},
|
||||
'{"var1":1,"var2":10}',
|
||||
],
|
||||
].forEach(testCase => {
|
||||
expect(JSON.stringify(testCase[0])).toEqual(testCase[1]);
|
||||
test("length", () => {
|
||||
expect(JSON.stringify).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
|
||||
test("ignores non-enumerable properties", () => {
|
||||
let o = { foo: "bar" };
|
||||
Object.defineProperty(o, "baz", { value: "qux", enumerable: false });
|
||||
expect(JSON.stringify(o)).toBe('{"foo":"bar"}');
|
||||
});
|
||||
test("basic functionality", () => {
|
||||
[
|
||||
[5, "5"],
|
||||
[undefined, undefined],
|
||||
[null, "null"],
|
||||
[NaN, "null"],
|
||||
[-NaN, "null"],
|
||||
[Infinity, "null"],
|
||||
[-Infinity, "null"],
|
||||
[true, "true"],
|
||||
[false, "false"],
|
||||
["test", '"test"'],
|
||||
[new Number(5), "5"],
|
||||
[new Boolean(false), "false"],
|
||||
[new String("test"), '"test"'],
|
||||
[() => {}, undefined],
|
||||
[[1, 2, "foo"], '[1,2,"foo"]'],
|
||||
[{ foo: 1, bar: "baz", qux() {} }, '{"foo":1,"bar":"baz"}'],
|
||||
[
|
||||
{
|
||||
var1: 1,
|
||||
var2: 2,
|
||||
toJSON(key) {
|
||||
let o = this;
|
||||
o.var2 = 10;
|
||||
return o;
|
||||
},
|
||||
},
|
||||
'{"var1":1,"var2":10}',
|
||||
],
|
||||
].forEach(testCase => {
|
||||
expect(JSON.stringify(testCase[0])).toEqual(testCase[1]);
|
||||
});
|
||||
});
|
||||
|
||||
test("ignores non-enumerable properties", () => {
|
||||
let o = { foo: "bar" };
|
||||
Object.defineProperty(o, "baz", { value: "qux", enumerable: false });
|
||||
expect(JSON.stringify(o)).toBe('{"foo":"bar"}');
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("cannot serialize BigInt", () => {
|
||||
expect(() => {
|
||||
JSON.stringify(5n);
|
||||
}).toThrow(TypeError, "Cannot serialize BigInt value to JSON");
|
||||
});
|
||||
|
||||
test("cannot serialize circular structures", () => {
|
||||
let bad1 = {};
|
||||
bad1.foo = bad1;
|
||||
let bad2 = [];
|
||||
bad2[5] = [[[bad2]]];
|
||||
|
||||
let bad3a = { foo: "bar" };
|
||||
let bad3b = [1, 2, bad3a];
|
||||
bad3a.bad = bad3b;
|
||||
|
||||
[bad1, bad2, bad3a].forEach(bad => {
|
||||
expect(() => {
|
||||
JSON.stringify(bad);
|
||||
}).toThrow(TypeError, "Cannot stringify circular object");
|
||||
test("cannot serialize BigInt", () => {
|
||||
expect(() => {
|
||||
JSON.stringify(5n);
|
||||
}).toThrow(TypeError, "Cannot serialize BigInt value to JSON");
|
||||
});
|
||||
|
||||
test("cannot serialize circular structures", () => {
|
||||
let bad1 = {};
|
||||
bad1.foo = bad1;
|
||||
let bad2 = [];
|
||||
bad2[5] = [[[bad2]]];
|
||||
|
||||
let bad3a = { foo: "bar" };
|
||||
let bad3b = [1, 2, bad3a];
|
||||
bad3a.bad = bad3b;
|
||||
|
||||
[bad1, bad2, bad3a].forEach(bad => {
|
||||
expect(() => {
|
||||
JSON.stringify(bad);
|
||||
}).toThrow(TypeError, "Cannot stringify circular object");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.E).toBeCloseTo(2.718281);
|
||||
expect(Math.LN2).toBeCloseTo(0.693147);
|
||||
expect(Math.LN10).toBeCloseTo(2.302585);
|
||||
expect(Math.LOG2E).toBeCloseTo(1.442695);
|
||||
expect(Math.LOG10E).toBeCloseTo(0.434294);
|
||||
expect(Math.PI).toBeCloseTo(3.1415926);
|
||||
expect(Math.SQRT1_2).toBeCloseTo(0.707106);
|
||||
expect(Math.SQRT2).toBeCloseTo(1.414213);
|
||||
expect(Math.E).toBeCloseTo(2.718281);
|
||||
expect(Math.LN2).toBeCloseTo(0.693147);
|
||||
expect(Math.LN10).toBeCloseTo(2.302585);
|
||||
expect(Math.LOG2E).toBeCloseTo(1.442695);
|
||||
expect(Math.LOG10E).toBeCloseTo(0.434294);
|
||||
expect(Math.PI).toBeCloseTo(3.1415926);
|
||||
expect(Math.SQRT1_2).toBeCloseTo(0.707106);
|
||||
expect(Math.SQRT2).toBeCloseTo(1.414213);
|
||||
});
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.abs).toHaveLength(1);
|
||||
expect(Math.abs).toHaveLength(1);
|
||||
|
||||
expect(Math.abs("-1")).toBe(1);
|
||||
expect(Math.abs(-2)).toBe(2);
|
||||
expect(Math.abs(null)).toBe(0);
|
||||
expect(Math.abs("")).toBe(0);
|
||||
expect(Math.abs([])).toBe(0);
|
||||
expect(Math.abs([2])).toBe(2);
|
||||
expect(Math.abs([1, 2])).toBeNaN();
|
||||
expect(Math.abs({})).toBeNaN();
|
||||
expect(Math.abs("string")).toBeNaN();
|
||||
expect(Math.abs()).toBeNaN();
|
||||
expect(Math.abs("-1")).toBe(1);
|
||||
expect(Math.abs(-2)).toBe(2);
|
||||
expect(Math.abs(null)).toBe(0);
|
||||
expect(Math.abs("")).toBe(0);
|
||||
expect(Math.abs([])).toBe(0);
|
||||
expect(Math.abs([2])).toBe(2);
|
||||
expect(Math.abs([1, 2])).toBeNaN();
|
||||
expect(Math.abs({})).toBeNaN();
|
||||
expect(Math.abs("string")).toBeNaN();
|
||||
expect(Math.abs()).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.acosh).toHaveLength(1);
|
||||
expect(Math.acosh).toHaveLength(1);
|
||||
|
||||
expect(Math.acosh(-1)).toBeNaN();
|
||||
expect(Math.acosh(0)).toBeNaN();
|
||||
expect(Math.acosh(0.5)).toBeNaN();
|
||||
expect(Math.acosh(1)).toBeCloseTo(0);
|
||||
// FIXME: expect(Math.acosh(2)).toBeCloseTo(1.316957);
|
||||
expect(Math.acosh(-1)).toBeNaN();
|
||||
expect(Math.acosh(0)).toBeNaN();
|
||||
expect(Math.acosh(0.5)).toBeNaN();
|
||||
expect(Math.acosh(1)).toBeCloseTo(0);
|
||||
// FIXME: expect(Math.acosh(2)).toBeCloseTo(1.316957);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.asinh).toHaveLength(1);
|
||||
expect(Math.asinh).toHaveLength(1);
|
||||
|
||||
expect(Math.asinh(0)).toBeCloseTo(0);
|
||||
// FIXME: expect(Math.asinh(1)).toBeCloseTo(0.881373);
|
||||
expect(Math.asinh(0)).toBeCloseTo(0);
|
||||
// FIXME: expect(Math.asinh(1)).toBeCloseTo(0.881373);
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.atanh).toHaveLength(1);
|
||||
expect(Math.atanh).toHaveLength(1);
|
||||
|
||||
expect(Math.atanh(-2)).toBeNaN();
|
||||
expect(Math.atanh(2)).toBeNaN();
|
||||
expect(Math.atanh(-1)).toBe(-Infinity);
|
||||
// FIXME: expect(Math.atanh(0)).toBe(0);
|
||||
expect(Math.atanh(0.5)).toBeCloseTo(0.549306);
|
||||
// FIXME: expect(Math.atanh(1)).toBe(Infinity);
|
||||
expect(Math.atanh(-2)).toBeNaN();
|
||||
expect(Math.atanh(2)).toBeNaN();
|
||||
expect(Math.atanh(-1)).toBe(-Infinity);
|
||||
// FIXME: expect(Math.atanh(0)).toBe(0);
|
||||
expect(Math.atanh(0.5)).toBeCloseTo(0.549306);
|
||||
// FIXME: expect(Math.atanh(1)).toBe(Infinity);
|
||||
});
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.cbrt).toHaveLength(1);
|
||||
expect(Math.cbrt).toHaveLength(1);
|
||||
|
||||
expect(Math.cbrt(NaN)).toBeNaN();
|
||||
// FIXME: expect(Math.cbrt(-1)).toBe(-1);
|
||||
expect(Math.cbrt(-0)).toBe(-0);
|
||||
// FIXME: expect(Math.cbrt(-Infinity)).toBe(-Infinity);
|
||||
// FIXME: expect(Math.cbrt(1)).toBe(1);
|
||||
// FIXME: expect(Math.cbrt(Infinity)).toBe(Infinity);
|
||||
expect(Math.cbrt(null)).toBe(0);
|
||||
// FIXME: expect(Math.cbrt(2)).toBeCloseTo(1.259921));
|
||||
expect(Math.cbrt(NaN)).toBeNaN();
|
||||
// FIXME: expect(Math.cbrt(-1)).toBe(-1);
|
||||
expect(Math.cbrt(-0)).toBe(-0);
|
||||
// FIXME: expect(Math.cbrt(-Infinity)).toBe(-Infinity);
|
||||
// FIXME: expect(Math.cbrt(1)).toBe(1);
|
||||
// FIXME: expect(Math.cbrt(Infinity)).toBe(Infinity);
|
||||
expect(Math.cbrt(null)).toBe(0);
|
||||
// FIXME: expect(Math.cbrt(2)).toBeCloseTo(1.259921));
|
||||
});
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.ceil).toHaveLength(1);
|
||||
expect(Math.ceil).toHaveLength(1);
|
||||
|
||||
expect(Math.ceil(0.95)).toBe(1);
|
||||
expect(Math.ceil(4)).toBe(4);
|
||||
expect(Math.ceil(7.004)).toBe(8);
|
||||
expect(Math.ceil(-0.95)).toBe(-0);
|
||||
expect(Math.ceil(-4)).toBe(-4);
|
||||
expect(Math.ceil(-7.004)).toBe(-7);
|
||||
expect(Math.ceil(0.95)).toBe(1);
|
||||
expect(Math.ceil(4)).toBe(4);
|
||||
expect(Math.ceil(7.004)).toBe(8);
|
||||
expect(Math.ceil(-0.95)).toBe(-0);
|
||||
expect(Math.ceil(-4)).toBe(-4);
|
||||
expect(Math.ceil(-7.004)).toBe(-7);
|
||||
|
||||
expect(Math.ceil()).toBeNaN();
|
||||
expect(Math.ceil(NaN)).toBeNaN();
|
||||
expect(Math.ceil()).toBeNaN();
|
||||
expect(Math.ceil(NaN)).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.clz32).toHaveLength(1);
|
||||
expect(Math.clz32).toHaveLength(1);
|
||||
|
||||
expect(Math.clz32(0)).toBe(32);
|
||||
expect(Math.clz32(1)).toBe(31);
|
||||
expect(Math.clz32(2)).toBe(30);
|
||||
expect(Math.clz32(3)).toBe(30);
|
||||
expect(Math.clz32(4)).toBe(29);
|
||||
expect(Math.clz32(5)).toBe(29);
|
||||
expect(Math.clz32(-1)).toBe(0);
|
||||
expect(Math.clz32(-10)).toBe(0);
|
||||
expect(Math.clz32(-100)).toBe(0);
|
||||
expect(Math.clz32(-1000)).toBe(0);
|
||||
expect(Math.clz32(-0.123)).toBe(32);
|
||||
expect(Math.clz32(0.123)).toBe(32);
|
||||
expect(Math.clz32(1.23)).toBe(31);
|
||||
expect(Math.clz32(12)).toBe(28);
|
||||
expect(Math.clz32(123)).toBe(25);
|
||||
expect(Math.clz32(1234)).toBe(21);
|
||||
expect(Math.clz32(12345)).toBe(18);
|
||||
expect(Math.clz32(123456)).toBe(15);
|
||||
expect(Math.clz32(1234567)).toBe(11);
|
||||
expect(Math.clz32(12345678)).toBe(8);
|
||||
expect(Math.clz32(123456789)).toBe(5);
|
||||
expect(Math.clz32(999999999)).toBe(2);
|
||||
expect(Math.clz32(9999999999)).toBe(1);
|
||||
expect(Math.clz32(99999999999)).toBe(1);
|
||||
expect(Math.clz32(999999999999)).toBe(0);
|
||||
expect(Math.clz32(9999999999999)).toBe(1);
|
||||
expect(Math.clz32(99999999999999)).toBe(3);
|
||||
expect(Math.clz32(999999999999999)).toBe(0);
|
||||
expect(Math.clz32(0)).toBe(32);
|
||||
expect(Math.clz32(1)).toBe(31);
|
||||
expect(Math.clz32(2)).toBe(30);
|
||||
expect(Math.clz32(3)).toBe(30);
|
||||
expect(Math.clz32(4)).toBe(29);
|
||||
expect(Math.clz32(5)).toBe(29);
|
||||
expect(Math.clz32(-1)).toBe(0);
|
||||
expect(Math.clz32(-10)).toBe(0);
|
||||
expect(Math.clz32(-100)).toBe(0);
|
||||
expect(Math.clz32(-1000)).toBe(0);
|
||||
expect(Math.clz32(-0.123)).toBe(32);
|
||||
expect(Math.clz32(0.123)).toBe(32);
|
||||
expect(Math.clz32(1.23)).toBe(31);
|
||||
expect(Math.clz32(12)).toBe(28);
|
||||
expect(Math.clz32(123)).toBe(25);
|
||||
expect(Math.clz32(1234)).toBe(21);
|
||||
expect(Math.clz32(12345)).toBe(18);
|
||||
expect(Math.clz32(123456)).toBe(15);
|
||||
expect(Math.clz32(1234567)).toBe(11);
|
||||
expect(Math.clz32(12345678)).toBe(8);
|
||||
expect(Math.clz32(123456789)).toBe(5);
|
||||
expect(Math.clz32(999999999)).toBe(2);
|
||||
expect(Math.clz32(9999999999)).toBe(1);
|
||||
expect(Math.clz32(99999999999)).toBe(1);
|
||||
expect(Math.clz32(999999999999)).toBe(0);
|
||||
expect(Math.clz32(9999999999999)).toBe(1);
|
||||
expect(Math.clz32(99999999999999)).toBe(3);
|
||||
expect(Math.clz32(999999999999999)).toBe(0);
|
||||
|
||||
expect(Math.clz32()).toBe(32);
|
||||
expect(Math.clz32(NaN)).toBe(32);
|
||||
expect(Math.clz32(Infinity)).toBe(32);
|
||||
expect(Math.clz32(-Infinity)).toBe(32);
|
||||
expect(Math.clz32(false)).toBe(32);
|
||||
expect(Math.clz32(true)).toBe(31);
|
||||
expect(Math.clz32(null)).toBe(32);
|
||||
expect(Math.clz32(undefined)).toBe(32);
|
||||
expect(Math.clz32([])).toBe(32);
|
||||
expect(Math.clz32({})).toBe(32);
|
||||
expect(Math.clz32("foo")).toBe(32);
|
||||
expect(Math.clz32()).toBe(32);
|
||||
expect(Math.clz32(NaN)).toBe(32);
|
||||
expect(Math.clz32(Infinity)).toBe(32);
|
||||
expect(Math.clz32(-Infinity)).toBe(32);
|
||||
expect(Math.clz32(false)).toBe(32);
|
||||
expect(Math.clz32(true)).toBe(31);
|
||||
expect(Math.clz32(null)).toBe(32);
|
||||
expect(Math.clz32(undefined)).toBe(32);
|
||||
expect(Math.clz32([])).toBe(32);
|
||||
expect(Math.clz32({})).toBe(32);
|
||||
expect(Math.clz32("foo")).toBe(32);
|
||||
});
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.cos).toHaveLength(1);
|
||||
expect(Math.cos).toHaveLength(1);
|
||||
|
||||
expect(Math.cos(0)).toBe(1);
|
||||
expect(Math.cos(null)).toBe(1);
|
||||
expect(Math.cos("")).toBe(1);
|
||||
expect(Math.cos([])).toBe(1);
|
||||
expect(Math.cos(Math.PI)).toBe(-1);
|
||||
expect(Math.cos()).toBeNaN();
|
||||
expect(Math.cos(undefined)).toBeNaN();
|
||||
expect(Math.cos([1, 2, 3])).toBeNaN();
|
||||
expect(Math.cos({})).toBeNaN();
|
||||
expect(Math.cos("foo")).toBeNaN();
|
||||
expect(Math.cos(0)).toBe(1);
|
||||
expect(Math.cos(null)).toBe(1);
|
||||
expect(Math.cos("")).toBe(1);
|
||||
expect(Math.cos([])).toBe(1);
|
||||
expect(Math.cos(Math.PI)).toBe(-1);
|
||||
expect(Math.cos()).toBeNaN();
|
||||
expect(Math.cos(undefined)).toBeNaN();
|
||||
expect(Math.cos([1, 2, 3])).toBeNaN();
|
||||
expect(Math.cos({})).toBeNaN();
|
||||
expect(Math.cos("foo")).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.exp).toHaveLength(1);
|
||||
expect(Math.exp).toHaveLength(1);
|
||||
|
||||
expect(Math.exp(0)).toBe(1);
|
||||
expect(Math.exp(-2)).toBeCloseTo(0.135335);
|
||||
expect(Math.exp(-1)).toBeCloseTo(0.367879);
|
||||
expect(Math.exp(1)).toBeCloseTo(2.718281);
|
||||
expect(Math.exp(2)).toBeCloseTo(7.389056);
|
||||
expect(Math.exp(0)).toBe(1);
|
||||
expect(Math.exp(-2)).toBeCloseTo(0.135335);
|
||||
expect(Math.exp(-1)).toBeCloseTo(0.367879);
|
||||
expect(Math.exp(1)).toBeCloseTo(2.718281);
|
||||
expect(Math.exp(2)).toBeCloseTo(7.389056);
|
||||
|
||||
expect(Math.exp()).toBeNaN();
|
||||
expect(Math.exp(undefined)).toBeNaN();
|
||||
expect(Math.exp("foo")).toBeNaN();
|
||||
expect(Math.exp()).toBeNaN();
|
||||
expect(Math.exp(undefined)).toBeNaN();
|
||||
expect(Math.exp("foo")).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.expm1).toHaveLength(1);
|
||||
expect(Math.expm1).toHaveLength(1);
|
||||
|
||||
expect(Math.expm1(0)).toBe(0);
|
||||
expect(Math.expm1(-2)).toBeCloseTo(-0.864664);
|
||||
expect(Math.expm1(-1)).toBeCloseTo(-0.63212);
|
||||
expect(Math.expm1(1)).toBeCloseTo(1.718281);
|
||||
expect(Math.expm1(2)).toBeCloseTo(6.389056);
|
||||
expect(Math.expm1(0)).toBe(0);
|
||||
expect(Math.expm1(-2)).toBeCloseTo(-0.864664);
|
||||
expect(Math.expm1(-1)).toBeCloseTo(-0.63212);
|
||||
expect(Math.expm1(1)).toBeCloseTo(1.718281);
|
||||
expect(Math.expm1(2)).toBeCloseTo(6.389056);
|
||||
|
||||
expect(Math.expm1()).toBeNaN();
|
||||
expect(Math.expm1(undefined)).toBeNaN();
|
||||
expect(Math.expm1("foo")).toBeNaN();
|
||||
expect(Math.expm1()).toBeNaN();
|
||||
expect(Math.expm1(undefined)).toBeNaN();
|
||||
expect(Math.expm1("foo")).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.floor).toHaveLength(1);
|
||||
expect(Math.floor).toHaveLength(1);
|
||||
|
||||
expect(Math.floor(0.95)).toBe(0);
|
||||
expect(Math.floor(4)).toBe(4);
|
||||
expect(Math.floor(7.004)).toBe(7);
|
||||
expect(Math.floor(-0.95)).toBe(-1);
|
||||
expect(Math.floor(-4)).toBe(-4);
|
||||
expect(Math.floor(-7.004)).toBe(-8);
|
||||
expect(Math.floor(0.95)).toBe(0);
|
||||
expect(Math.floor(4)).toBe(4);
|
||||
expect(Math.floor(7.004)).toBe(7);
|
||||
expect(Math.floor(-0.95)).toBe(-1);
|
||||
expect(Math.floor(-4)).toBe(-4);
|
||||
expect(Math.floor(-7.004)).toBe(-8);
|
||||
|
||||
expect(Math.floor()).toBeNaN();
|
||||
expect(Math.floor(NaN)).toBeNaN();
|
||||
expect(Math.floor()).toBeNaN();
|
||||
expect(Math.floor(NaN)).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.log1p).toHaveLength(1);
|
||||
expect(Math.log1p).toHaveLength(1);
|
||||
|
||||
expect(Math.log1p(-2)).toBeNaN();
|
||||
expect(Math.log1p(-1)).toBe(-Infinity);
|
||||
// FIXME: expect(Math.log1p(0)).toBe(0);
|
||||
// FIXME: expect(Math.log1p(1)).toBeCloseTo(0.693147);
|
||||
expect(Math.log1p(-2)).toBeNaN();
|
||||
expect(Math.log1p(-1)).toBe(-Infinity);
|
||||
// FIXME: expect(Math.log1p(0)).toBe(0);
|
||||
// FIXME: expect(Math.log1p(1)).toBeCloseTo(0.693147);
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.max).toHaveLength(2);
|
||||
expect(Math.max).toHaveLength(2);
|
||||
|
||||
expect(Math.max()).toBe(-Infinity);
|
||||
expect(Math.max(1)).toBe(1);
|
||||
expect(Math.max(2, 1)).toBe(2);
|
||||
expect(Math.max(1, 2, 3)).toBe(3);
|
||||
expect(Math.max(NaN)).toBeNaN();
|
||||
expect(Math.max("String", 1)).toBeNaN();
|
||||
expect(Math.max()).toBe(-Infinity);
|
||||
expect(Math.max(1)).toBe(1);
|
||||
expect(Math.max(2, 1)).toBe(2);
|
||||
expect(Math.max(1, 2, 3)).toBe(3);
|
||||
expect(Math.max(NaN)).toBeNaN();
|
||||
expect(Math.max("String", 1)).toBeNaN();
|
||||
});
|
||||
|
|
12
Libraries/LibJS/Tests/builtins/Math/Math.min.js
vendored
12
Libraries/LibJS/Tests/builtins/Math/Math.min.js
vendored
|
@ -1,9 +1,9 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.min).toHaveLength(2);
|
||||
expect(Math.min).toHaveLength(2);
|
||||
|
||||
expect(Math.min(1)).toBe(1);
|
||||
expect(Math.min(2, 1)).toBe(1);
|
||||
expect(Math.min(1, 2, 3)).toBe(1);
|
||||
expect(Math.min(NaN)).toBeNaN();
|
||||
expect(Math.min("String", 1)).toBeNaN();
|
||||
expect(Math.min(1)).toBe(1);
|
||||
expect(Math.min(2, 1)).toBe(1);
|
||||
expect(Math.min(1, 2, 3)).toBe(1);
|
||||
expect(Math.min(NaN)).toBeNaN();
|
||||
expect(Math.min("String", 1)).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.pow).toHaveLength(2);
|
||||
expect(Math.pow).toHaveLength(2);
|
||||
|
||||
expect(Math.pow(2, 0)).toBe(1);
|
||||
expect(Math.pow(2, 1)).toBe(2);
|
||||
expect(Math.pow(2, 2)).toBe(4);
|
||||
expect(Math.pow(2, 3)).toBe(8);
|
||||
expect(Math.pow(2, -3)).toBe(0.125);
|
||||
expect(Math.pow(3, 2)).toBe(9);
|
||||
expect(Math.pow(0, 0)).toBe(1);
|
||||
expect(Math.pow(2, Math.pow(3, 2))).toBe(512);
|
||||
expect(Math.pow(Math.pow(2, 3), 2)).toBe(64);
|
||||
expect(Math.pow("2", "3")).toBe(8);
|
||||
expect(Math.pow("", [])).toBe(1);
|
||||
expect(Math.pow([], null)).toBe(1);
|
||||
expect(Math.pow(null, null)).toBe(1);
|
||||
expect(Math.pow(undefined, null)).toBe(1);
|
||||
expect(Math.pow(NaN, 2)).toBeNaN();
|
||||
expect(Math.pow(2, NaN)).toBeNaN();
|
||||
expect(Math.pow(undefined, 2)).toBeNaN();
|
||||
expect(Math.pow(2, undefined)).toBeNaN();
|
||||
expect(Math.pow(null, undefined)).toBeNaN();
|
||||
expect(Math.pow(2, "foo")).toBeNaN();
|
||||
expect(Math.pow("foo", 2)).toBeNaN();
|
||||
expect(Math.pow(2, 0)).toBe(1);
|
||||
expect(Math.pow(2, 1)).toBe(2);
|
||||
expect(Math.pow(2, 2)).toBe(4);
|
||||
expect(Math.pow(2, 3)).toBe(8);
|
||||
expect(Math.pow(2, -3)).toBe(0.125);
|
||||
expect(Math.pow(3, 2)).toBe(9);
|
||||
expect(Math.pow(0, 0)).toBe(1);
|
||||
expect(Math.pow(2, Math.pow(3, 2))).toBe(512);
|
||||
expect(Math.pow(Math.pow(2, 3), 2)).toBe(64);
|
||||
expect(Math.pow("2", "3")).toBe(8);
|
||||
expect(Math.pow("", [])).toBe(1);
|
||||
expect(Math.pow([], null)).toBe(1);
|
||||
expect(Math.pow(null, null)).toBe(1);
|
||||
expect(Math.pow(undefined, null)).toBe(1);
|
||||
expect(Math.pow(NaN, 2)).toBeNaN();
|
||||
expect(Math.pow(2, NaN)).toBeNaN();
|
||||
expect(Math.pow(undefined, 2)).toBeNaN();
|
||||
expect(Math.pow(2, undefined)).toBeNaN();
|
||||
expect(Math.pow(null, undefined)).toBeNaN();
|
||||
expect(Math.pow(2, "foo")).toBeNaN();
|
||||
expect(Math.pow("foo", 2)).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
function isPositiveZero(value) {
|
||||
return value === 0 && 1 / value === Infinity;
|
||||
return value === 0 && 1 / value === Infinity;
|
||||
}
|
||||
|
||||
function isNegativeZero(value) {
|
||||
return value === 0 && 1 / value === -Infinity;
|
||||
return value === 0 && 1 / value === -Infinity;
|
||||
}
|
||||
|
||||
test("basic functionality", () => {
|
||||
expect(Math.sign).toHaveLength(1);
|
||||
expect(Math.sign).toHaveLength(1);
|
||||
|
||||
expect(Math.sign(0.0001)).toBe(1);
|
||||
expect(Math.sign(1)).toBe(1);
|
||||
expect(Math.sign(42)).toBe(1);
|
||||
expect(Math.sign(Infinity)).toBe(1);
|
||||
expect(isPositiveZero(Math.sign(0))).toBeTrue();
|
||||
expect(isPositiveZero(Math.sign(null))).toBeTrue();
|
||||
expect(isPositiveZero(Math.sign(""))).toBeTrue();
|
||||
expect(isPositiveZero(Math.sign([]))).toBeTrue();
|
||||
expect(Math.sign(0.0001)).toBe(1);
|
||||
expect(Math.sign(1)).toBe(1);
|
||||
expect(Math.sign(42)).toBe(1);
|
||||
expect(Math.sign(Infinity)).toBe(1);
|
||||
expect(isPositiveZero(Math.sign(0))).toBeTrue();
|
||||
expect(isPositiveZero(Math.sign(null))).toBeTrue();
|
||||
expect(isPositiveZero(Math.sign(""))).toBeTrue();
|
||||
expect(isPositiveZero(Math.sign([]))).toBeTrue();
|
||||
|
||||
expect(Math.sign(-0.0001)).toBe(-1);
|
||||
expect(Math.sign(-1)).toBe(-1);
|
||||
expect(Math.sign(-42)).toBe(-1);
|
||||
expect(Math.sign(-Infinity)).toBe(-1);
|
||||
expect(isNegativeZero(Math.sign(-0))).toBeTrue();
|
||||
expect(isNegativeZero(Math.sign(-null))).toBeTrue();
|
||||
expect(isNegativeZero(Math.sign(-""))).toBeTrue();
|
||||
expect(isNegativeZero(Math.sign(-[]))).toBeTrue();
|
||||
expect(Math.sign(-0.0001)).toBe(-1);
|
||||
expect(Math.sign(-1)).toBe(-1);
|
||||
expect(Math.sign(-42)).toBe(-1);
|
||||
expect(Math.sign(-Infinity)).toBe(-1);
|
||||
expect(isNegativeZero(Math.sign(-0))).toBeTrue();
|
||||
expect(isNegativeZero(Math.sign(-null))).toBeTrue();
|
||||
expect(isNegativeZero(Math.sign(-""))).toBeTrue();
|
||||
expect(isNegativeZero(Math.sign(-[]))).toBeTrue();
|
||||
|
||||
expect(Math.sign()).toBeNaN();
|
||||
expect(Math.sign(undefined)).toBeNaN();
|
||||
expect(Math.sign([1, 2, 3])).toBeNaN();
|
||||
expect(Math.sign({})).toBeNaN();
|
||||
expect(Math.sign(NaN)).toBeNaN();
|
||||
expect(Math.sign("foo")).toBeNaN();
|
||||
expect(Math.sign()).toBeNaN();
|
||||
expect(Math.sign(undefined)).toBeNaN();
|
||||
expect(Math.sign([1, 2, 3])).toBeNaN();
|
||||
expect(Math.sign({})).toBeNaN();
|
||||
expect(Math.sign(NaN)).toBeNaN();
|
||||
expect(Math.sign("foo")).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.sin).toHaveLength(1);
|
||||
expect(Math.sin).toHaveLength(1);
|
||||
|
||||
expect(Math.sin(0)).toBe(0);
|
||||
expect(Math.sin(null)).toBe(0);
|
||||
expect(Math.sin("")).toBe(0);
|
||||
expect(Math.sin([])).toBe(0);
|
||||
expect(Math.sin((Math.PI * 3) / 2)).toBe(-1);
|
||||
expect(Math.sin(Math.PI / 2)).toBe(1);
|
||||
expect(Math.sin()).toBeNaN();
|
||||
expect(Math.sin(undefined)).toBeNaN();
|
||||
expect(Math.sin([1, 2, 3])).toBeNaN();
|
||||
expect(Math.sin({})).toBeNaN();
|
||||
expect(Math.sin("foo")).toBeNaN();
|
||||
expect(Math.sin(0)).toBe(0);
|
||||
expect(Math.sin(null)).toBe(0);
|
||||
expect(Math.sin("")).toBe(0);
|
||||
expect(Math.sin([])).toBe(0);
|
||||
expect(Math.sin((Math.PI * 3) / 2)).toBe(-1);
|
||||
expect(Math.sin(Math.PI / 2)).toBe(1);
|
||||
expect(Math.sin()).toBeNaN();
|
||||
expect(Math.sin(undefined)).toBeNaN();
|
||||
expect(Math.sin([1, 2, 3])).toBeNaN();
|
||||
expect(Math.sin({})).toBeNaN();
|
||||
expect(Math.sin("foo")).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.sqrt).toHaveLength(1);
|
||||
expect(Math.sqrt(9)).toBe(3);
|
||||
expect(Math.sqrt).toHaveLength(1);
|
||||
expect(Math.sqrt(9)).toBe(3);
|
||||
});
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.tan).toHaveLength(1);
|
||||
expect(Math.tan).toHaveLength(1);
|
||||
|
||||
expect(Math.tan(0)).toBe(0);
|
||||
expect(Math.tan(null)).toBe(0);
|
||||
expect(Math.tan("")).toBe(0);
|
||||
expect(Math.tan([])).toBe(0);
|
||||
expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1);
|
||||
expect(Math.tan()).toBeNaN();
|
||||
expect(Math.tan(undefined)).toBeNaN();
|
||||
expect(Math.tan([1, 2, 3])).toBeNaN();
|
||||
expect(Math.tan({})).toBeNaN();
|
||||
expect(Math.tan("foo")).toBeNaN();
|
||||
expect(Math.tan(0)).toBe(0);
|
||||
expect(Math.tan(null)).toBe(0);
|
||||
expect(Math.tan("")).toBe(0);
|
||||
expect(Math.tan([])).toBe(0);
|
||||
expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1);
|
||||
expect(Math.tan()).toBeNaN();
|
||||
expect(Math.tan(undefined)).toBeNaN();
|
||||
expect(Math.tan([1, 2, 3])).toBeNaN();
|
||||
expect(Math.tan({})).toBeNaN();
|
||||
expect(Math.tan("foo")).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.trunc).toHaveLength(1);
|
||||
expect(Math.trunc).toHaveLength(1);
|
||||
|
||||
expect(Math.trunc(13.37)).toBe(13);
|
||||
expect(Math.trunc(42.84)).toBe(42);
|
||||
expect(Math.trunc(0.123)).toBe(0);
|
||||
expect(Math.trunc(-0.123)).toBe(-0);
|
||||
expect(Math.trunc(13.37)).toBe(13);
|
||||
expect(Math.trunc(42.84)).toBe(42);
|
||||
expect(Math.trunc(0.123)).toBe(0);
|
||||
expect(Math.trunc(-0.123)).toBe(-0);
|
||||
|
||||
expect(Math.trunc(NaN)).toBeNaN();
|
||||
expect(Math.trunc("foo")).toBeNaN();
|
||||
expect(Math.trunc()).toBeNaN();
|
||||
expect(Math.trunc(NaN)).toBeNaN();
|
||||
expect(Math.trunc("foo")).toBeNaN();
|
||||
expect(Math.trunc()).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
test("basic functionality", () => {
|
||||
const nan = undefined + 1;
|
||||
const nan = undefined + 1;
|
||||
|
||||
expect(nan + "").toBe("NaN");
|
||||
expect(NaN + "").toBe("NaN");
|
||||
expect(nan !== nan).toBeTrue();
|
||||
expect(NaN !== NaN).toBeTrue();
|
||||
expect(nan).toBeNaN();
|
||||
expect(NaN).toBeNaN();
|
||||
expect(0).not.toBeNaN();
|
||||
expect(!!nan).toBeFalse();
|
||||
expect(!!NaN).toBeFalse();
|
||||
expect(nan + "").toBe("NaN");
|
||||
expect(NaN + "").toBe("NaN");
|
||||
expect(nan !== nan).toBeTrue();
|
||||
expect(NaN !== NaN).toBeTrue();
|
||||
expect(nan).toBeNaN();
|
||||
expect(NaN).toBeNaN();
|
||||
expect(0).not.toBeNaN();
|
||||
expect(!!nan).toBeFalse();
|
||||
expect(!!NaN).toBeFalse();
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Number.EPSILON).toBe(2 ** -52);
|
||||
expect(Number.EPSILON).toBeGreaterThan(0);
|
||||
expect(Number.MAX_SAFE_INTEGER).toBe(2 ** 53 - 1);
|
||||
expect(Number.MAX_SAFE_INTEGER + 1).toBe(Number.MAX_SAFE_INTEGER + 2);
|
||||
expect(Number.MIN_SAFE_INTEGER).toBe(-(2 ** 53 - 1));
|
||||
expect(Number.MIN_SAFE_INTEGER - 1).toBe(Number.MIN_SAFE_INTEGER - 2);
|
||||
expect(Number.POSITIVE_INFINITY).toBe(Infinity);
|
||||
expect(Number.NEGATIVE_INFINITY).toBe(-Infinity);
|
||||
expect(Number.NaN).toBeNaN();
|
||||
expect(Number.EPSILON).toBe(2 ** -52);
|
||||
expect(Number.EPSILON).toBeGreaterThan(0);
|
||||
expect(Number.MAX_SAFE_INTEGER).toBe(2 ** 53 - 1);
|
||||
expect(Number.MAX_SAFE_INTEGER + 1).toBe(Number.MAX_SAFE_INTEGER + 2);
|
||||
expect(Number.MIN_SAFE_INTEGER).toBe(-(2 ** 53 - 1));
|
||||
expect(Number.MIN_SAFE_INTEGER - 1).toBe(Number.MIN_SAFE_INTEGER - 2);
|
||||
expect(Number.POSITIVE_INFINITY).toBe(Infinity);
|
||||
expect(Number.NEGATIVE_INFINITY).toBe(-Infinity);
|
||||
expect(Number.NaN).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Number.isFinite).toHaveLength(1);
|
||||
expect(Number.isFinite).not.toBe(isFinite);
|
||||
expect(Number.isFinite).toHaveLength(1);
|
||||
expect(Number.isFinite).not.toBe(isFinite);
|
||||
|
||||
expect(Number.isFinite(0)).toBeTrue();
|
||||
expect(Number.isFinite(1.23)).toBeTrue();
|
||||
expect(Number.isFinite(42)).toBeTrue();
|
||||
expect(Number.isFinite(0)).toBeTrue();
|
||||
expect(Number.isFinite(1.23)).toBeTrue();
|
||||
expect(Number.isFinite(42)).toBeTrue();
|
||||
|
||||
expect(Number.isFinite("")).toBeFalse();
|
||||
expect(Number.isFinite("0")).toBeFalse();
|
||||
expect(Number.isFinite("42")).toBeFalse();
|
||||
expect(Number.isFinite(true)).toBeFalse();
|
||||
expect(Number.isFinite(false)).toBeFalse();
|
||||
expect(Number.isFinite(null)).toBeFalse();
|
||||
expect(Number.isFinite([])).toBeFalse();
|
||||
expect(Number.isFinite()).toBeFalse();
|
||||
expect(Number.isFinite(NaN)).toBeFalse();
|
||||
expect(Number.isFinite(undefined)).toBeFalse();
|
||||
expect(Number.isFinite(Infinity)).toBeFalse();
|
||||
expect(Number.isFinite(-Infinity)).toBeFalse();
|
||||
expect(Number.isFinite("foo")).toBeFalse();
|
||||
expect(Number.isFinite({})).toBeFalse();
|
||||
expect(Number.isFinite([1, 2, 3])).toBeFalse();
|
||||
expect(Number.isFinite("")).toBeFalse();
|
||||
expect(Number.isFinite("0")).toBeFalse();
|
||||
expect(Number.isFinite("42")).toBeFalse();
|
||||
expect(Number.isFinite(true)).toBeFalse();
|
||||
expect(Number.isFinite(false)).toBeFalse();
|
||||
expect(Number.isFinite(null)).toBeFalse();
|
||||
expect(Number.isFinite([])).toBeFalse();
|
||||
expect(Number.isFinite()).toBeFalse();
|
||||
expect(Number.isFinite(NaN)).toBeFalse();
|
||||
expect(Number.isFinite(undefined)).toBeFalse();
|
||||
expect(Number.isFinite(Infinity)).toBeFalse();
|
||||
expect(Number.isFinite(-Infinity)).toBeFalse();
|
||||
expect(Number.isFinite("foo")).toBeFalse();
|
||||
expect(Number.isFinite({})).toBeFalse();
|
||||
expect(Number.isFinite([1, 2, 3])).toBeFalse();
|
||||
});
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Number.isInteger).toHaveLength(1);
|
||||
expect(Number.isInteger).toHaveLength(1);
|
||||
|
||||
expect(Number.isInteger(0)).toBeTrue();
|
||||
expect(Number.isInteger(42)).toBeTrue();
|
||||
expect(Number.isInteger(-10000)).toBeTrue();
|
||||
expect(Number.isInteger(5)).toBeTrue();
|
||||
expect(Number.isInteger(5.0)).toBeTrue();
|
||||
expect(Number.isInteger(5 + 1 / 10000000000000000)).toBeTrue();
|
||||
// FIXME: values outside of i32's range should still return true
|
||||
// expect(Number.isInteger(+2147483647 + 1)).toBeTrue();
|
||||
// expect(Number.isInteger(-2147483648 - 1)).toBeTrue();
|
||||
// expect(Number.isInteger(99999999999999999999999999999999999)).toBeTrue();
|
||||
expect(Number.isInteger(0)).toBeTrue();
|
||||
expect(Number.isInteger(42)).toBeTrue();
|
||||
expect(Number.isInteger(-10000)).toBeTrue();
|
||||
expect(Number.isInteger(5)).toBeTrue();
|
||||
expect(Number.isInteger(5.0)).toBeTrue();
|
||||
expect(Number.isInteger(5 + 1 / 10000000000000000)).toBeTrue();
|
||||
// FIXME: values outside of i32's range should still return true
|
||||
// expect(Number.isInteger(+2147483647 + 1)).toBeTrue();
|
||||
// expect(Number.isInteger(-2147483648 - 1)).toBeTrue();
|
||||
// expect(Number.isInteger(99999999999999999999999999999999999)).toBeTrue();
|
||||
|
||||
expect(Number.isInteger(5 + 1 / 1000000000000000)).toBeFalse();
|
||||
expect(Number.isInteger(1.23)).toBeFalse();
|
||||
expect(Number.isInteger("")).toBeFalse();
|
||||
expect(Number.isInteger("0")).toBeFalse();
|
||||
expect(Number.isInteger("42")).toBeFalse();
|
||||
expect(Number.isInteger(true)).toBeFalse();
|
||||
expect(Number.isInteger(false)).toBeFalse();
|
||||
expect(Number.isInteger(null)).toBeFalse();
|
||||
expect(Number.isInteger([])).toBeFalse();
|
||||
expect(Number.isInteger(Infinity)).toBeFalse();
|
||||
expect(Number.isInteger(-Infinity)).toBeFalse();
|
||||
expect(Number.isInteger(NaN)).toBeFalse();
|
||||
expect(Number.isInteger()).toBeFalse();
|
||||
expect(Number.isInteger(undefined)).toBeFalse();
|
||||
expect(Number.isInteger("foo")).toBeFalse();
|
||||
expect(Number.isInteger({})).toBeFalse();
|
||||
expect(Number.isInteger([1, 2, 3])).toBeFalse();
|
||||
expect(Number.isInteger(5 + 1 / 1000000000000000)).toBeFalse();
|
||||
expect(Number.isInteger(1.23)).toBeFalse();
|
||||
expect(Number.isInteger("")).toBeFalse();
|
||||
expect(Number.isInteger("0")).toBeFalse();
|
||||
expect(Number.isInteger("42")).toBeFalse();
|
||||
expect(Number.isInteger(true)).toBeFalse();
|
||||
expect(Number.isInteger(false)).toBeFalse();
|
||||
expect(Number.isInteger(null)).toBeFalse();
|
||||
expect(Number.isInteger([])).toBeFalse();
|
||||
expect(Number.isInteger(Infinity)).toBeFalse();
|
||||
expect(Number.isInteger(-Infinity)).toBeFalse();
|
||||
expect(Number.isInteger(NaN)).toBeFalse();
|
||||
expect(Number.isInteger()).toBeFalse();
|
||||
expect(Number.isInteger(undefined)).toBeFalse();
|
||||
expect(Number.isInteger("foo")).toBeFalse();
|
||||
expect(Number.isInteger({})).toBeFalse();
|
||||
expect(Number.isInteger([1, 2, 3])).toBeFalse();
|
||||
});
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Number.isNaN).toHaveLength(1);
|
||||
expect(Number.isNaN).not.toBe(isNaN);
|
||||
expect(Number.isNaN).toHaveLength(1);
|
||||
expect(Number.isNaN).not.toBe(isNaN);
|
||||
|
||||
expect(Number.isNaN(0)).toBeFalse();
|
||||
expect(Number.isNaN(42)).toBeFalse();
|
||||
expect(Number.isNaN("")).toBeFalse();
|
||||
expect(Number.isNaN("0")).toBeFalse();
|
||||
expect(Number.isNaN("42")).toBeFalse();
|
||||
expect(Number.isNaN(true)).toBeFalse();
|
||||
expect(Number.isNaN(false)).toBeFalse();
|
||||
expect(Number.isNaN(null)).toBeFalse();
|
||||
expect(Number.isNaN([])).toBeFalse();
|
||||
expect(Number.isNaN(Infinity)).toBeFalse();
|
||||
expect(Number.isNaN(-Infinity)).toBeFalse();
|
||||
expect(Number.isNaN()).toBeFalse();
|
||||
expect(Number.isNaN(undefined)).toBeFalse();
|
||||
expect(Number.isNaN("foo")).toBeFalse();
|
||||
expect(Number.isNaN({})).toBeFalse();
|
||||
expect(Number.isNaN([1, 2, 3])).toBeFalse();
|
||||
expect(Number.isNaN(0)).toBeFalse();
|
||||
expect(Number.isNaN(42)).toBeFalse();
|
||||
expect(Number.isNaN("")).toBeFalse();
|
||||
expect(Number.isNaN("0")).toBeFalse();
|
||||
expect(Number.isNaN("42")).toBeFalse();
|
||||
expect(Number.isNaN(true)).toBeFalse();
|
||||
expect(Number.isNaN(false)).toBeFalse();
|
||||
expect(Number.isNaN(null)).toBeFalse();
|
||||
expect(Number.isNaN([])).toBeFalse();
|
||||
expect(Number.isNaN(Infinity)).toBeFalse();
|
||||
expect(Number.isNaN(-Infinity)).toBeFalse();
|
||||
expect(Number.isNaN()).toBeFalse();
|
||||
expect(Number.isNaN(undefined)).toBeFalse();
|
||||
expect(Number.isNaN("foo")).toBeFalse();
|
||||
expect(Number.isNaN({})).toBeFalse();
|
||||
expect(Number.isNaN([1, 2, 3])).toBeFalse();
|
||||
|
||||
expect(Number.isNaN(NaN)).toBeTrue();
|
||||
expect(Number.isNaN(Number.NaN)).toBeTrue();
|
||||
expect(Number.isNaN(0 / 0)).toBeTrue();
|
||||
expect(Number.isNaN(NaN)).toBeTrue();
|
||||
expect(Number.isNaN(Number.NaN)).toBeTrue();
|
||||
expect(Number.isNaN(0 / 0)).toBeTrue();
|
||||
});
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Number.isSafeInteger).toHaveLength(1);
|
||||
expect(Number.isSafeInteger).toHaveLength(1);
|
||||
|
||||
expect(Number.isSafeInteger(0)).toBeTrue();
|
||||
expect(Number.isSafeInteger(1)).toBeTrue();
|
||||
expect(Number.isSafeInteger(2.0)).toBeTrue();
|
||||
expect(Number.isSafeInteger(42)).toBeTrue();
|
||||
expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER)).toBeTrue();
|
||||
expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER)).toBeTrue();
|
||||
expect(Number.isSafeInteger(0)).toBeTrue();
|
||||
expect(Number.isSafeInteger(1)).toBeTrue();
|
||||
expect(Number.isSafeInteger(2.0)).toBeTrue();
|
||||
expect(Number.isSafeInteger(42)).toBeTrue();
|
||||
expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER)).toBeTrue();
|
||||
expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER)).toBeTrue();
|
||||
|
||||
expect(Number.isSafeInteger()).toBeFalse();
|
||||
expect(Number.isSafeInteger("1")).toBeFalse();
|
||||
expect(Number.isSafeInteger(2.1)).toBeFalse();
|
||||
expect(Number.isSafeInteger(42.42)).toBeFalse();
|
||||
expect(Number.isSafeInteger("")).toBeFalse();
|
||||
expect(Number.isSafeInteger([])).toBeFalse();
|
||||
expect(Number.isSafeInteger(null)).toBeFalse();
|
||||
expect(Number.isSafeInteger(undefined)).toBeFalse();
|
||||
expect(Number.isSafeInteger(NaN)).toBeFalse();
|
||||
expect(Number.isSafeInteger(Infinity)).toBeFalse();
|
||||
expect(Number.isSafeInteger(-Infinity)).toBeFalse();
|
||||
expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1)).toBeFalse();
|
||||
expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1)).toBeFalse();
|
||||
expect(Number.isSafeInteger()).toBeFalse();
|
||||
expect(Number.isSafeInteger("1")).toBeFalse();
|
||||
expect(Number.isSafeInteger(2.1)).toBeFalse();
|
||||
expect(Number.isSafeInteger(42.42)).toBeFalse();
|
||||
expect(Number.isSafeInteger("")).toBeFalse();
|
||||
expect(Number.isSafeInteger([])).toBeFalse();
|
||||
expect(Number.isSafeInteger(null)).toBeFalse();
|
||||
expect(Number.isSafeInteger(undefined)).toBeFalse();
|
||||
expect(Number.isSafeInteger(NaN)).toBeFalse();
|
||||
expect(Number.isSafeInteger(Infinity)).toBeFalse();
|
||||
expect(Number.isSafeInteger(-Infinity)).toBeFalse();
|
||||
expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1)).toBeFalse();
|
||||
expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1)).toBeFalse();
|
||||
});
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Number).toHaveLength(1);
|
||||
expect(Number.name).toBe("Number");
|
||||
expect(Number.prototype).not.toHaveProperty("length");
|
||||
expect(Number).toHaveLength(1);
|
||||
expect(Number.name).toBe("Number");
|
||||
expect(Number.prototype).not.toHaveProperty("length");
|
||||
|
||||
expect(typeof Number()).toBe("number");
|
||||
expect(typeof new Number()).toBe("object");
|
||||
expect(typeof Number()).toBe("number");
|
||||
expect(typeof new Number()).toBe("object");
|
||||
|
||||
expect(Number()).toBe(0);
|
||||
expect(new Number().valueOf()).toBe(0);
|
||||
expect(Number("42")).toBe(42);
|
||||
expect(new Number("42").valueOf()).toBe(42);
|
||||
expect(Number(null)).toBe(0);
|
||||
expect(new Number(null).valueOf()).toBe(0);
|
||||
expect(Number(true)).toBe(1);
|
||||
expect(new Number(true).valueOf()).toBe(1);
|
||||
expect(Number("Infinity")).toBe(Infinity);
|
||||
expect(new Number("Infinity").valueOf()).toBe(Infinity);
|
||||
expect(Number("+Infinity")).toBe(Infinity);
|
||||
expect(new Number("+Infinity").valueOf()).toBe(Infinity);
|
||||
expect(Number("-Infinity")).toBe(-Infinity);
|
||||
expect(new Number("-Infinity").valueOf()).toBe(-Infinity);
|
||||
expect(Number(undefined)).toBeNaN();
|
||||
expect(new Number(undefined).valueOf()).toBeNaN();
|
||||
expect(Number({})).toBeNaN();
|
||||
expect(new Number({}).valueOf()).toBeNaN();
|
||||
expect(Number({ a: 1 })).toBeNaN();
|
||||
expect(new Number({ a: 1 }).valueOf()).toBeNaN();
|
||||
expect(Number([1, 2, 3])).toBeNaN();
|
||||
expect(new Number([1, 2, 3]).valueOf()).toBeNaN();
|
||||
expect(Number("foo")).toBeNaN();
|
||||
expect(new Number("foo").valueOf()).toBeNaN();
|
||||
expect(Number()).toBe(0);
|
||||
expect(new Number().valueOf()).toBe(0);
|
||||
expect(Number("42")).toBe(42);
|
||||
expect(new Number("42").valueOf()).toBe(42);
|
||||
expect(Number(null)).toBe(0);
|
||||
expect(new Number(null).valueOf()).toBe(0);
|
||||
expect(Number(true)).toBe(1);
|
||||
expect(new Number(true).valueOf()).toBe(1);
|
||||
expect(Number("Infinity")).toBe(Infinity);
|
||||
expect(new Number("Infinity").valueOf()).toBe(Infinity);
|
||||
expect(Number("+Infinity")).toBe(Infinity);
|
||||
expect(new Number("+Infinity").valueOf()).toBe(Infinity);
|
||||
expect(Number("-Infinity")).toBe(-Infinity);
|
||||
expect(new Number("-Infinity").valueOf()).toBe(-Infinity);
|
||||
expect(Number(undefined)).toBeNaN();
|
||||
expect(new Number(undefined).valueOf()).toBeNaN();
|
||||
expect(Number({})).toBeNaN();
|
||||
expect(new Number({}).valueOf()).toBeNaN();
|
||||
expect(Number({ a: 1 })).toBeNaN();
|
||||
expect(new Number({ a: 1 }).valueOf()).toBeNaN();
|
||||
expect(Number([1, 2, 3])).toBeNaN();
|
||||
expect(new Number([1, 2, 3]).valueOf()).toBeNaN();
|
||||
expect(Number("foo")).toBeNaN();
|
||||
expect(new Number("foo").valueOf()).toBeNaN();
|
||||
});
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue