1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 10:37:41 +00:00

LibJS: Convert most builtin tests to new system

This commit is contained in:
Matthew Olsson 2020-07-04 10:09:48 -07:00 committed by Andreas Kling
parent 46581773c1
commit 3f97d75778
107 changed files with 2031 additions and 2243 deletions

View file

@ -1,40 +1,32 @@
load("test-common.js"); test("constructor properties", () => {
expect(Boolean).toHaveLength(1);
expect(Boolean.name).toBe("Boolean");
});
try { test("typeof", () => {
assert(Boolean.length === 1); expect(typeof new Boolean()).toBe("object");
assert(Boolean.name === "Boolean"); expect(typeof Boolean()).toBe("boolean");
assert(Boolean.prototype.length === undefined); expect(typeof Boolean(true)).toBe("boolean");
})
assert(typeof new Boolean() === "object");
assert(new Boolean().valueOf() === false);
test("basic functionality", () => {
var foo = new Boolean(true); var foo = new Boolean(true);
var bar = new Boolean(true); var bar = new Boolean(true);
assert(foo !== bar); expect(foo).not.toBe(bar);
assert(foo.valueOf() === bar.valueOf()); expect(foo.valueOf()).toBe(bar.valueOf());
assert(new Boolean(true).toString() === "true"); expect(Boolean()).toBeFalse();
assert(new Boolean(false).toString() === "false"); expect(Boolean(false)).toBeFalse();
expect(Boolean(null)).toBeFalse();
assert(typeof Boolean() === "boolean"); expect(Boolean(undefined)).toBeFalse();
assert(typeof Boolean(true) === "boolean"); expect(Boolean(NaN)).toBeFalse();
expect(Boolean("")).toBeFalse();
assert(Boolean() === false); expect(Boolean(0.0)).toBeFalse();
assert(Boolean(false) === false); expect(Boolean(-0.0)).toBeFalse();
assert(Boolean(null) === false); expect(Boolean(true)).toBeTrue();
assert(Boolean(undefined) === false); expect(Boolean("0")).toBeTrue();
assert(Boolean(NaN) === false); expect(Boolean({})).toBeTrue();
assert(Boolean("") === false); expect(Boolean([])).toBeTrue();
assert(Boolean(0.0) === false); expect(Boolean(1)).toBeTrue();
assert(Boolean(-0.0) === false); });
assert(Boolean(true) === true);
assert(Boolean("0") === true);
assert(Boolean({}) === true);
assert(Boolean([]) === true);
assert(Boolean(1)) === true;
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,10 +1,5 @@
load("test-common.js"); test("basic functionality", () => {
expect(typeof Boolean.prototype).toBe("object");
try { expect(Boolean.prototype.valueOf()).toBeFalse();
assert(typeof Boolean.prototype === "object"); expect(Boolean.prototype.length).toBeUndefined();
assert(Boolean.prototype.valueOf() === false); });
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,21 +1,17 @@
load("test-common.js"); test("basic functionality", () => {
try {
var foo = true; var foo = true;
assert(foo.toString() === "true"); expect(foo.toString()).toBe("true");
assert(true.toString() === "true"); expect(true.toString()).toBe("true");
assert(Boolean.prototype.toString.call(true) === "true"); expect(Boolean.prototype.toString.call(true)).toBe("true");
assert(Boolean.prototype.toString.call(false) === "false"); expect(Boolean.prototype.toString.call(false)).toBe("false");
assertThrowsError(() => { 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"); Boolean.prototype.toString.call("foo");
}, { }).toThrowWithMessage(TypeError, "Not a Boolean object");
error: TypeError, });
message: "Not a Boolean object"
});
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,21 +1,16 @@
load("test-common.js"); test("basic functionality", () => {
try {
var foo = true; var foo = true;
assert(foo.valueOf() === true); expect(foo.valueOf()).toBeTrue();
assert(true.valueOf() === true); expect(true.valueOf()).toBeTrue();
assert(Boolean.prototype.valueOf.call(true) === true); expect(Boolean.prototype.valueOf.call(true)).toBeTrue();
assert(Boolean.prototype.valueOf.call(false) === false); expect(Boolean.prototype.valueOf.call(false)).toBeFalse();
assertThrowsError(() => { expect(new Boolean().valueOf()).toBeFalse();
});
test("errors on non-boolean |this|", () => {
expect(() => {
Boolean.prototype.valueOf.call("foo"); Boolean.prototype.valueOf.call("foo");
}, { }).toThrowWithMessage(TypeError, "Not a Boolean object");
error: TypeError, });
message: "Not a Boolean object"
});
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,11 +1,5 @@
load("test-common.js"); test("basic functionality", () => {
expect(Date).toHaveLength(7);
try { expect(Date.name === "Date");
assert(Date.length === 7); expect(Date.prototype).not.toHaveProperty("length");
assert(Date.name === "Date"); });
assert(Date.prototype.length === undefined);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,15 +1,10 @@
load("test-common.js"); test("basic functionality", () => {
try {
var last = 0; var last = 0;
for (var i = 0; i < 100; ++i) { for (var i = 0; i < 100; ++i) {
var now = Date.now(); var now = Date.now();
assert(!isNaN(now)) expect(now).not.toBeNaN();
assert(now > 1580000000000); expect(now).toBeGreaterThan(1580000000000);
assert(now >= last); expect(now).toBeGreaterThanOrEqual(last);
last = now; last = now;
} }
console.log("PASS"); });
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,7 @@
load("test-common.js"); test("basic functionality", () => {
let d = new Date();
try { expect(d.getDate()).toBe(d.getDate());
var d = new Date(); expect(d.getDate()).not.toBeNaN();
assert(!isNaN(d.getDate())); expect(d.getDate()).toBeGreaterThanOrEqual(1);
assert(1 <= d.getDate() <= 31); expect(d.getDate()).toBeLessThanOrEqual(31);
assert(d.getDate() === d.getDate()); });
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,7 @@
load("test-common.js"); test("basic functionality", () => {
try {
var d = new Date(); var d = new Date();
assert(!isNaN(d.getDay())); expect(d.getDay()).toBe(d.getDay());
assert(0 <= d.getDay() <= 6); expect(d.getDay()).not.toBeNaN();
assert(d.getDay() === d.getDay()); expect(d.getDay()).toBeGreaterThanOrEqual(0);
console.log("PASS"); expect(d.getDay()).toBeLessThanOrEqual(6);
} catch (e) { });
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,7 @@
load("test-common.js"); test("basic functionality", () => {
try {
var d = new Date(); var d = new Date();
assert(!isNaN(d.getFullYear())); expect(d.getFullYear()).toBe(d.getFullYear());
assert(d.getFullYear() >= 2020); expect(d.getFullYear()).not.toBeNaN();
assert(d.getFullYear() === d.getFullYear()); expect(d.getFullYear()).toBe(d.getFullYear());
console.log("PASS"); expect(d.getFullYear()).toBeGreaterThanOrEqual(2020);
} catch (e) { });
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,7 @@
load("test-common.js"); test("basic functionality", () => {
try {
var d = new Date(); var d = new Date();
assert(!isNaN(d.getHours())); expect(d.getHours()).toBe(d.getHours());
assert(0 <= d.getHours() <= 23); expect(d.getHours()).not.toBeNaN();
assert(d.getHours() === d.getHours()); expect(d.getHours()).toBeGreaterThanOrEqual(0);
console.log("PASS"); expect(d.getHours()).toBeLessThanOrEqual(23);
} catch (e) { });
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,7 @@
load("test-common.js"); test("basic functionality", () => {
try {
var d = new Date(); var d = new Date();
assert(!isNaN(d.getMilliseconds())); expect(d.getMilliseconds()).toBe(d.getMilliseconds());
assert(0 <= d.getMilliseconds() <= 999); expect(d.getMilliseconds()).not.toBeNaN();
assert(d.getMilliseconds() === d.getMilliseconds()); expect(d.getMilliseconds()).toBeGreaterThanOrEqual(0);
console.log("PASS"); expect(d.getMilliseconds()).toBeLessThanOrEqual(999);
} catch (e) { });
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,7 @@
load("test-common.js"); test("basic functionality", () => {
try {
var d = new Date(); var d = new Date();
assert(!isNaN(d.getMinutes())); expect(d.getMinutes()).toBe(d.getMinutes());
assert(0 <= d.getMinutes() <= 59); expect(d.getMinutes()).not.toBeNaN();
assert(d.getMinutes() === d.getMinutes()); expect(d.getMinutes()).toBeGreaterThanOrEqual(0);
console.log("PASS"); expect(d.getMinutes()).toBeLessThanOrEqual(59);
} catch (e) { });
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,7 @@
load("test-common.js"); test("basic functionality", () => {
try {
var d = new Date(); var d = new Date();
assert(!isNaN(d.getMonth())); expect(d.getMonth()).toBe(d.getMonth());
assert(0 <= d.getMonth() <= 11); expect(d.getMonth()).not.toBeNaN();
assert(d.getMonth() === d.getMonth()); expect(d.getMonth()).toBeGreaterThanOrEqual(0);
console.log("PASS"); expect(d.getMonth()).toBeLessThanOrEqual(11);
} catch (e) { });
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,7 @@
load("test-common.js"); test("basic functionality", () => {
try {
var d = new Date(); var d = new Date();
assert(!isNaN(d.getSeconds())); expect(d.getSeconds()).toBe(d.getSeconds());
assert(0 <= d.getSeconds() <= 59); expect(d.getSeconds()).not.toBeNaN();
assert(d.getSeconds() === d.getSeconds()); expect(d.getSeconds()).toBeGreaterThanOrEqual(0);
console.log("PASS"); expect(d.getSeconds()).toBeLessThanOrEqual(59);
} catch (e) { });
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,6 @@
load("test-common.js"); test("basic functionality", () => {
try {
var d = new Date(); var d = new Date();
assert(!isNaN(d.getTime())); expect(d.getTime()).toBe(d.getTime());
assert(d.getTime() > 1580000000000); expect(d.getTime()).not.toBeNaN();
assert(d.getTime() === d.getTime()); expect(d.getTime()).toBeGreaterThanOrEqual(1580000000000);
console.log("PASS"); });
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,33 +1,18 @@
load("test-common.js"); test("basic functionality", () => {
expect(Error).toHaveLength(1);
expect(Error.name).toBe("Error");
});
try { test("name", () => {
assert(Error.length === 1); [Error(), Error(undefined), Error("test"), Error(42), Error(null)].forEach(error => {
assert(Error.name === "Error"); expect(error.name).toBe("Error");
assert(Error.prototype.length === undefined); });
});
var e; test("message", () => {
expect(Error().message).toBe("");
e = Error(); expect(Error(undefined).message).toBe("");
assert(e.name === "Error"); expect(Error("test").message).toBe("test");
assert(e.message === ""); expect(Error(42).message).toBe("42");
expect(Error(null).message).toBe("null");
e = Error(undefined); });
assert(e.name === "Error");
assert(e.message === "");
e = Error("test");
assert(e.name === "Error");
assert(e.message === "test");
e = Error(42);
assert(e.name === "Error");
assert(e.message === "42");
e = Error(null);
assert(e.name === "Error");
assert(e.message === "null");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,14 +1,10 @@
load("test-common.js"); test("basic functionality", () => {
expect(Error.prototype).not.toHaveProperty("length");
try {
var changedInstance = new Error(""); var changedInstance = new Error("");
changedInstance.name = 'NewCustomError'; changedInstance.name = "NewCustomError";
assert(changedInstance.name === "NewCustomError"); expect(changedInstance.name).toBe("NewCustomError");
var normalInstance = new Error(""); var normalInstance = new Error("");
assert(normalInstance.name === "Error"); expect(normalInstance.name).toBe("Error");
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e.message);
}

View file

@ -1,13 +1,7 @@
load("test-common.js"); test("basic functionality", () => {
expect(Error().toString()).toBe("Error");
try { expect(Error(undefined).toString()).toBe("Error");
assert(Error().toString() === "Error"); expect(Error(null).toString()).toBe("Error: null");
assert(Error(undefined).toString() === "Error"); expect(Error("test").toString()).toBe("Error: test");
assert(Error(null).toString() === "Error: null"); expect(Error(42).toString()).toBe("Error: 42");
assert(Error("test").toString() === "Error: test"); });
assert(Error(42).toString() === "Error: 42");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,42 +1,44 @@
load("test-common.js"); describe("correct behavior", () => {
test("constructor properties", () => {
try { expect(Function).toHaveLength(1);
assert(Function.length === 1); expect(Function.name).toBe("Function");
assert(Function.name === "Function"); expect(Function.prototype).toHaveLength(0);
assert(Function.prototype.length === 0); expect(Function.prototype.name).toBe("");
assert(Function.prototype.name === "");
assert(typeof Function() === "function");
assert(typeof new Function() === "function");
assert(Function()() === undefined);
assert(new Function()() === undefined);
assert(Function("return 42")() === 42);
assert(new Function("return 42")() === 42);
assert(new Function("foo", "return foo")(42) === 42);
assert(new Function("foo,bar", "return foo + bar")(1, 2) === 3);
assert(new Function("foo", "bar", "return foo + bar")(1, 2) === 3);
assert(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3) === 6);
assert(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3) === 6);
assert(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true) === 42);
assert(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false) === "bar");
assert(new Function("return typeof Function()")() === "function");
assert(new Function("x", "return function (y) { return x + y };")(1)(2) === 3);
assert(new Function().name === "anonymous");
assert(new Function().toString() === "function anonymous() {\n ???\n}");
assertThrowsError(() => {
new Function("[");
}, {
error: SyntaxError,
// 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.
message: "Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)"
}); });
console.log("PASS"); test("typeof", () => {
} catch (e) { expect(typeof Function()).toBe("function");
console.log("FAIL: " + e.message); expect(typeof new Function()).toBe("function");
} });
test("basic functionality", () => {
expect(Function()()).toBe(undefined);
expect(new Function()()).toBe(undefined);
expect(Function("return 42")()).toBe(42);
expect(new Function("return 42")()).toBe(42);
expect(new Function("foo", "return foo")(42)).toBe(42);
expect(new Function("foo,bar", "return foo + bar")(1, 2)).toBe(3);
expect(new Function("foo", "bar", "return foo + bar")(1, 2)).toBe(3);
expect(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
expect(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true)).toBe(42);
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe("bar");
expect(new Function("return typeof Function()")()).toBe("function");
expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3);
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)");
});
});

View file

@ -1,6 +1,4 @@
load("test-common.js"); test("basic functionality", () => {
try {
function Foo(arg) { function Foo(arg) {
this.foo = arg; this.foo = arg;
} }
@ -17,39 +15,35 @@ try {
this.baz = arg; this.baz = arg;
} }
assert(Function.prototype.apply.length === 2); expect(Function.prototype.apply).toHaveLength(2);
var foo = new Foo("test"); var foo = new Foo("test");
assert(foo.foo === "test"); expect(foo.foo).toBe("test");
assert(foo.bar === undefined); expect(foo.bar).toBeUndefined();
assert(foo.baz === undefined); expect(foo.baz).toBeUndefined();
var bar = new Bar("test"); var bar = new Bar("test");
assert(bar.foo === undefined); expect(bar.foo).toBeUndefined();
assert(bar.bar === "test"); expect(bar.bar).toBe("test");
assert(bar.baz === undefined); expect(bar.baz).toBeUndefined();
var foobar = new FooBar("test"); var foobar = new FooBar("test");
assert(foobar.foo === "test"); expect(foobar.foo).toBe("test");
assert(foobar.bar === "test"); expect(foobar.bar).toBe("test");
assert(foobar.baz === undefined); expect(foobar.baz).toBeUndefined();
var foobarbaz = new FooBarBaz("test"); var foobarbaz = new FooBarBaz("test");
assert(foobarbaz.foo === "test"); expect(foobarbaz.foo).toBe("test");
assert(foobarbaz.bar === "test"); expect(foobarbaz.bar).toBe("test");
assert(foobarbaz.baz === "test"); expect(foobarbaz.baz).toBe("test");
assert(Math.abs.apply(null, [-1]) === 1); expect(Math.abs.apply(null, [-1])).toBe(1);
var add = (x, y) => x + y; var add = (x, y) => x + y;
assert(add.apply(null, [1, 2]) === 3); expect(add.apply(null, [1, 2])).toBe(3);
var multiply = function (x, y) { return x * y; }; var multiply = function (x, y) { return x * y; };
assert(multiply.apply(null, [3, 4]) === 12); expect(multiply.apply(null, [3, 4])).toBe(12);
assert((() => this).apply("foo") === globalThis); expect((() => this).apply("foo")).toBe(globalThis);
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,124 +1,138 @@
load("test-common.js"); describe("basic behavior", () => {
test("basic binding", () => {
expect(Function.prototype.bind.length).toBe(1);
try { var charAt = String.prototype.charAt.bind("bar");
assert(Function.prototype.bind.length === 1); expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar");
var charAt = String.prototype.charAt.bind("bar"); function getB() {
assert(charAt(0) + charAt(1) + charAt(2) === "bar"); return this.toUpperCase().charAt(0);
}
expect(getB.bind("bar")()).toBe("B");
});
function getB() { test("bound functions work with array functions", () => {
return this.toUpperCase().charAt(0); var Make3 = Number.bind(null, 3);
} expect([55].map(Make3)[0]).toBe(3);
assert(getB.bind("bar")() === "B");
// Bound functions should work with array functions var MakeTrue = Boolean.bind(null, true);
var Make3 = Number.bind(null, 3);
assert([55].map(Make3)[0] === 3);
var MakeTrue = Boolean.bind(null, true); expect([1, 2, 3].filter(MakeTrue).length).toBe(3);
assert([1, 2, 3].filter(MakeTrue).length === 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);
assert([1, 2, 3].reduce((function (acc, x) { return acc + x }).bind(null, 4, 5)) === 9); });
});
assert([1, 2, 3].reduce((function (acc, x) { return acc + x + this; }).bind(3)) === 12);
describe("bound function arguments", () => {
function sum(a, b, c) { function sum(a, b, c) {
return a + b + c; return a + b + c;
} }
// Arguments should be able to be bound to a function.
var boundSum = sum.bind(null, 10, 5); var boundSum = sum.bind(null, 10, 5);
assert(isNaN(boundSum()));
assert(boundSum(5) === 20); test("arguments are bound to the function", () => {
assert(boundSum(5, 6, 7) === 20); expect(boundSum()).toBeNaN();
expect(boundSum(5)).toBe(20);
expect(boundSum(5, 6, 7)).toBe(20);
});
// Arguments should be appended to a BoundFunction's bound arguments. test("arguments are appended to a BoundFunction's bound arguments", () => {
assert(boundSum.bind(null, 5)() === 20); expect(boundSum.bind(null, 5)()).toBe(20);
});
// A BoundFunction's length property should be adjusted based on the number test("binding a constructor's arguments", () => {
// of bound arguments. var Make5 = Number.bind(null, 5);
assert(sum.length === 3); expect(Make5()).toBe(5);
assert(boundSum.length === 1); expect(new Make5().valueOf()).toBe(5);
assert(boundSum.bind(null, 5).length === 0); });
assert(boundSum.bind(null, 5, 6, 7, 8).length === 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() { function identity() {
return this; return this;
} }
// It should capture the global object if the |this| value is null or undefined. test("captures global object as |this| if |this| is null or undefined", () => {
assert(identity.bind()() === globalThis); expect(identity.bind()()).toBe(globalThis);
assert(identity.bind(null)() === globalThis); expect(identity.bind(null)()).toBe(globalThis);
assert(identity.bind(undefined)() === globalThis); expect(identity.bind(undefined)()).toBe(globalThis);
function Foo() { function Foo() {
assert(identity.bind()() === globalThis); expect(identity.bind()()).toBe(globalThis);
assert(identity.bind(this)() === this); expect(identity.bind(this)()).toBe(this);
} }
new Foo(); new Foo();
});
// Primitive |this| values should be converted to objects. test("does not capture global object as |this| if |this| is null or undefined in strict mode", () => {
assert(identity.bind("foo")() instanceof String); "use strict";
assert(identity.bind(123)() instanceof Number);
assert(identity.bind(true)() instanceof Boolean);
// It should retain |this| values passed to it. function strictIdentity() {
var obj = { foo: "bar" }; return this;
}
assert(identity.bind(obj)() === obj); expect(strictIdentity.bind()()).toBeUndefined();
expect(strictIdentity.bind(null)()).toBeNull();
expect(strictIdentity.bind(undefined)()).toBeUndefined();
});
// The bound |this| can not be changed once set test("primitive |this| values are converted to objects", () => {
assert(identity.bind("foo").bind(123)() instanceof String); expect(identity.bind("foo")()).toBeInstanceOf(String);
expect(identity.bind(123)()).toBeInstanceOf(Number);
expect(identity.bind(true)()).toBeInstanceOf(Boolean);
});
// The bound |this| value should have no effect on a constructor. 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() { function Bar() {
this.x = 3; this.x = 3;
this.y = 4; this.y = 4;
} }
Bar.prototype.baz = "baz"; Bar.prototype.baz = "baz";
var BoundBar = Bar.bind({ u: 5, v: 6 }); var BoundBar = Bar.bind({ u: 5, v: 6 });
var bar = new BoundBar(); var bar = new BoundBar();
assert(bar.x === 3);
assert(bar.y === 4);
assert(typeof bar.u === "undefined");
assert(typeof bar.v === "undefined");
// Objects constructed from BoundFunctions should retain the prototype of the original function.
assert(bar.baz === "baz");
// BoundFunctions should not have a prototype property.
assert(typeof BoundBar.prototype === "undefined");
// Function.prototype.bind should not accept non-function values.
assertThrowsError(() => { test("bound |this| value does not affect constructor", () => {
Function.prototype.bind.call("foo"); expect(bar.x).toBe(3);
}, { expect(bar.y).toBe(4);
error: TypeError, expect(typeof bar.u).toBe("undefined");
message: "Not a Function object" expect(typeof bar.v).toBe("undefined");
}); });
// A constructor's arguments should be able to be bound. test("bound functions retain original prototype", () => {
var Make5 = Number.bind(null, 5); expect(bar.baz).toBe("baz");
assert(Make5() === 5); });
assert(new Make5().valueOf() === 5);
// Null or undefined should be passed through as a |this| value in strict mode. test("bound functions do not have a prototype property", () => {
(() => { expect(BoundBar).not.toHaveProperty("prototype");
"use strict"; });
function strictIdentity() { });
return this;
}
assert(strictIdentity.bind()() === undefined); describe("errors", () => {
assert(strictIdentity.bind(null)() === null); test("does not accept non-function values", () => {
assert(strictIdentity.bind(undefined)() === undefined); expect(() => {
})(); Function.prototype.bind.call("foo");
}).toThrowWithMessage(TypeError, "Not a Function object");
// Arrow functions can not have their |this| value set. });
assert((() => this).bind("foo")() === globalThis) });
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,6 +1,8 @@
load("test-common.js"); test("length", () => {
expect(Function.prototype.call).toHaveLength(1);
});
try { test("basic functionality", () => {
function Foo(arg) { function Foo(arg) {
this.foo = arg; this.foo = arg;
} }
@ -17,39 +19,33 @@ try {
this.baz = arg; this.baz = arg;
} }
assert(Function.prototype.call.length === 1);
var foo = new Foo("test"); var foo = new Foo("test");
assert(foo.foo === "test"); expect(foo.foo).toBe("test");
assert(foo.bar === undefined); expect(foo.bar).toBeUndefined();
assert(foo.baz === undefined); expect(foo.baz).toBeUndefined();
var bar = new Bar("test"); var bar = new Bar("test");
assert(bar.foo === undefined); expect(bar.foo).toBeUndefined();
assert(bar.bar === "test"); expect(bar.bar).toBe("test");
assert(bar.baz === undefined); expect(bar.baz).toBeUndefined();
var foobar = new FooBar("test"); var foobar = new FooBar("test");
assert(foobar.foo === "test"); expect(foobar.foo).toBe("test");
assert(foobar.bar === "test"); expect(foobar.bar).toBe("test");
assert(foobar.baz === undefined); expect(foobar.baz).toBeUndefined();
var foobarbaz = new FooBarBaz("test"); var foobarbaz = new FooBarBaz("test");
assert(foobarbaz.foo === "test"); expect(foobarbaz.foo).toBe("test");
assert(foobarbaz.bar === "test"); expect(foobarbaz.bar).toBe("test");
assert(foobarbaz.baz === "test"); expect(foobarbaz.baz).toBe("test");
assert(Math.abs.call(null, -1) === 1); expect(Math.abs.call(null, -1)).toBe(1);
var add = (x, y) => x + y; var add = (x, y) => x + y;
assert(add.call(null, 1, 2) === 3); expect(add.call(null, 1, 2)).toBe(3);
var multiply = function (x, y) { return x * y; }; var multiply = function (x, y) { return x * y; };
assert(multiply.call(null, 3, 4) === 12); expect(multiply.call(null, 3, 4)).toBe(12);
assert((() => this).call("foo") === globalThis); expect((() => this).call("foo")).toBe(globalThis);
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,21 +1,15 @@
load("test-common.js"); test("basic functionality", () => {
expect((function() {}).toString()).toBe("function () {\n ???\n}");
try { expect((function(foo) {}).toString()).toBe("function (foo) {\n ???\n}");
assert((function() {}).toString() === "function () {\n ???\n}"); expect((function(foo, bar, baz) {}).toString()).toBe("function (foo, bar, baz) {\n ???\n}");
assert((function(foo) {}).toString() === "function (foo) {\n ???\n}"); expect((function(foo, bar, baz) {
assert((function(foo, bar, baz) {}).toString() === "function (foo, bar, baz) {\n ???\n}");
assert((function(foo, bar, baz) {
if (foo) { if (foo) {
return baz; return baz;
} else if (bar) { } else if (bar) {
return foo; return foo;
} }
return bar + 42; return bar + 42;
}).toString() === "function (foo, bar, baz) {\n ???\n}"); }).toString()).toBe("function (foo, bar, baz) {\n ???\n}");
assert(console.log.toString() === "function log() {\n [NativeFunction]\n}"); expect(console.debug.toString()).toBe("function debug() {\n [NativeFunction]\n}");
assert(Function.toString() === "function Function() {\n [FunctionConstructor]\n}"); expect(Function.toString()).toBe("function Function() {\n [FunctionConstructor]\n}");
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,27 +0,0 @@
load("test-common.js");
try {
assert(Infinity + "" === "Infinity");
assert(-Infinity + "" === "-Infinity");
assert(Infinity === Infinity);
assert(Infinity - 1 === Infinity);
assert(Infinity + 1 === Infinity);
assert(-Infinity === -Infinity);
assert(-Infinity - 1 === -Infinity);
assert(-Infinity + 1 === -Infinity);
assert(1 / Infinity === 0);
assert(1 / -Infinity === 0);
assert(1 / 0 === Infinity);
assert(-1 / 0 === -Infinity);
assert(-100 < Infinity);
assert(0 < Infinity);
assert(100 < Infinity);
assert(-Infinity < Infinity);
assert(-100 > -Infinity);
assert(0 > -Infinity);
assert(100 > -Infinity);
assert(Infinity > -Infinity);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -0,0 +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);
});

View file

@ -1,15 +1,9 @@
load("test-common.js"); test("basic functionality", () => {
try {
let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`; let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`;
let object = JSON.parse(string, (key, value) => typeof value === "number" ? value * 2 : value); let object = JSON.parse(string, (key, value) => typeof value === "number" ? value * 2 : value);
assertDeepEquals(object, { var1: 20, var2: "hello", var3: { nested: 10 } }); expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } });
object = JSON.parse(string, (key, value) => typeof value === "number" ? undefined : value); object = JSON.parse(string, (key, value) => typeof value === "number" ? undefined : value);
assertDeepEquals(object, { var2: "hello", var3: {} }); expect(object).toEqual({ var2: "hello", var3: {} });
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,7 +1,5 @@
load("test-common.js"); test("basic functionality", () => {
expect(JSON.parse).toHaveLength(2);
try {
assert(JSON.parse.length === 2);
const properties = [ const properties = [
["5", 5], ["5", 5],
@ -14,10 +12,12 @@ try {
]; ];
properties.forEach(testCase => { properties.forEach(testCase => {
assertDeepEquals(JSON.parse(testCase[0]), testCase[1]); expect(JSON.parse(testCase[0])).toEqual(testCase[1]);
}); });
});
let syntaxErrors = [ test("syntax errors", () => {
[
undefined, undefined,
NaN, NaN,
-NaN, -NaN,
@ -29,15 +29,9 @@ try {
"[1,2,3, ]", "[1,2,3, ]",
'{ "foo": "bar",}', '{ "foo": "bar",}',
'{ "foo": "bar", }', '{ "foo": "bar", }',
]; ].forEach(test => {
expect(() => {
syntaxErrors.forEach(error => assertThrowsError(() => { JSON.parse(test);
JSON.parse(error); }).toThrow(SyntaxError);
}, { });
error: SyntaxError, });
}));
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,8 +1,4 @@
load("test-common.js"); test("basic functionality", () => {
try {
assert(JSON.stringify.length === 3);
let o = { let o = {
key1: "key1", key1: "key1",
key2: "key2", key2: "key2",
@ -28,9 +24,5 @@ try {
o.key1 = "key1"; o.key1 = "key1";
assert(JSON.stringify(o) === '{"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"}');
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,6 +1,4 @@
load("test-common.js"); test("basic functionality", () => {
try {
let p = new Proxy([], { let p = new Proxy([], {
get(_, key) { get(_, key) {
if (key === "length") if (key === "length")
@ -9,10 +7,6 @@ try {
}, },
}); });
assert(JSON.stringify(p) === "[0,1,2]"); expect(JSON.stringify(p)).toBe("[0,1,2]");
assert(JSON.stringify([[new Proxy(p, {})]]) === "[[[0,1,2]]]"); expect(JSON.stringify([[new Proxy(p, {})]])).toBe("[[[0,1,2]]]");
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,6 +1,4 @@
load("test-common.js"); test("basic functionality", () => {
try {
let o = { let o = {
var1: "foo", var1: "foo",
var2: 42, var2: 42,
@ -25,15 +23,11 @@ try {
return value; return value;
}); });
assert(string === '{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}'); expect(string).toBe('{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}');
string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]); string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]);
assert(string == '{"var1":"foo","var2":42,"obj":{}}'); expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}');
string = JSON.stringify(o, ["var1", "var1", "var2", "obj", "subarr"]); string = JSON.stringify(o, ["var1", "var1", "var2", "obj", "subarr"]);
assert(string == '{"var1":"foo","var2":42,"obj":{"subarr":[3]}}'); expect(string).toBe('{"var1":"foo","var2":42,"obj":{"subarr":[3]}}');
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,6 +1,4 @@
load("test-common.js"); test("basic functionality", () => {
try {
let o = { let o = {
foo: 1, foo: 1,
bar: "baz", bar: "baz",
@ -26,7 +24,7 @@ try {
} }
}`; }`;
assert(string === expected); expect(string).toBe(expected);
string = JSON.stringify(o, null, "abcd"); string = JSON.stringify(o, null, "abcd");
expected = expected =
@ -43,9 +41,5 @@ abcdabcd]
abcd} abcd}
}`; }`;
assert(string === expected); expect(string).toBe(expected);
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,71 +1,71 @@
load("test-common.js"); describe("correct behavior", () => {
test("length", () => {
try { expect(JSON.stringify).toHaveLength(3);
assert(JSON.stringify.length === 3);
assertThrowsError(() => {
JSON.stringify(5n);
}, {
error: TypeError,
message: "Cannot serialize BigInt value to JSON",
}); });
const properties = [ 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"}'],
[ [
{ [5, "5"],
var1: 1, [undefined, undefined],
var2: 2, [null, "null"],
toJSON(key) { [NaN, "null"],
let o = this; [-NaN, "null"],
o.var2 = 10; [Infinity, "null"],
return o; [-Infinity, "null"],
} [true, "true"],
}, [false, "false"],
'{"var1":1,"var2":10}', ["test", '"test"'],
], [new Number(5), "5"],
]; [new Boolean(false), "false"],
[new String("test"), '"test"'],
properties.forEach(testCase => { [() => {}, undefined],
assert(JSON.stringify(testCase[0]) === testCase[1]); [[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]);
});
}); });
let bad1 = {}; test("ignores non-enumerable properties", () => {
bad1.foo = bad1; let o = { foo: "bar" };
let bad2 = []; Object.defineProperty(o, "baz", { value: "qux", enumerable: false });
bad2[5] = [[[bad2]]]; expect(JSON.stringify(o)).toBe('{"foo":"bar"}');
});
});
let bad3a = { foo: "bar" }; describe("errors", () => {
let bad3b = [1, 2, bad3a]; test("cannot serialize BigInt", () => {
bad3a.bad = bad3b; expect(() => {
JSON.stringify(5n);
}).toThrow(TypeError, "Cannot serialize BigInt value to JSON");
});
[bad1, bad2, bad3a].forEach(bad => assertThrowsError(() => { test("cannot serialize circular structures", () => {
JSON.stringify(bad); let bad1 = {};
}, { bad1.foo = bad1;
error: TypeError, let bad2 = [];
message: "Cannot stringify circular object", bad2[5] = [[[bad2]]];
}));
let o = { foo: "bar" }; let bad3a = { foo: "bar" };
Object.defineProperty(o, "baz", { value: "qux", enumerable: false }); let bad3b = [1, 2, bad3a];
assert(JSON.stringify(o) === '{"foo":"bar"}'); bad3a.bad = bad3b;
console.log("PASS"); [bad1, bad2, bad3a].forEach(bad => {
} catch (e) { expect(() => {
console.log("FAIL: " + e); JSON.stringify(bad);
} }).toThrow(TypeError, "Cannot stringify circular object");
});
});
});

View file

@ -1,16 +1,10 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.E).toBeCloseTo(2.718281);
try { expect(Math.LN2).toBeCloseTo(0.693147);
assert(isClose(Math.E, 2.718281)); expect(Math.LN10).toBeCloseTo(2.302585);
assert(isClose(Math.LN2, 0.693147)); expect(Math.LOG2E).toBeCloseTo(1.442695);
assert(isClose(Math.LN10, 2.302585)); expect(Math.LOG10E).toBeCloseTo(0.434294);
assert(isClose(Math.LOG2E, 1.442695)); expect(Math.PI).toBeCloseTo(3.1415926);
assert(isClose(Math.LOG10E, 0.434294)); expect(Math.SQRT1_2).toBeCloseTo(0.707106);
assert(isClose(Math.PI, 3.1415926)); expect(Math.SQRT2).toBeCloseTo(1.414213);
assert(isClose(Math.SQRT1_2, 0.707106)); });
assert(isClose(Math.SQRT2, 1.414213));
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,16 +1,14 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.abs).toHaveLength(1);
try { expect(Math.abs('-1')).toBe(1);
assert(Math.abs('-1') === 1); expect(Math.abs(-2)).toBe(2);
assert(Math.abs(-2) === 2); expect(Math.abs(null)).toBe(0);
assert(Math.abs(null) === 0); expect(Math.abs('')).toBe(0);
assert(Math.abs('') === 0); expect(Math.abs([])).toBe(0);
assert(Math.abs([]) === 0); expect(Math.abs([2])).toBe(2);
assert(Math.abs([2]) === 2); expect(Math.abs([1, 2])).toBeNaN();
assert(isNaN(Math.abs([1, 2]))); expect(Math.abs({})).toBeNaN();
assert(isNaN(Math.abs({}))); expect(Math.abs('string')).toBeNaN();
assert(isNaN(Math.abs('string'))); expect(Math.abs()).toBeNaN();
assert(isNaN(Math.abs())); });
console.log("PASS");
} catch {
}

View file

@ -1,13 +1,9 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.acosh).toHaveLength(1);
try { expect(Math.acosh(-1)).toBeNaN();
assert(isNaN(Math.acosh(-1))); expect(Math.acosh(0)).toBeNaN();
assert(isNaN(Math.acosh(0))); expect(Math.acosh(0.5)).toBeNaN();
assert(isNaN(Math.acosh(0.5))); expect(Math.acosh(1)).toBeCloseTo(0);
assert(isClose(Math.acosh(1), 0)); // FIXME: expect(Math.acosh(2)).toBeCloseTo(1.316957);
// FIXME: assert(isClose(Math.acosh(2), 1.316957)); });
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,6 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.asinh).toHaveLength(1);
try { expect(Math.asinh(0)).toBeCloseTo(0);
assert(isClose(Math.asinh(0), 0)); // FIXME: expect(Math.asinh(1)).toBeCloseTo(0.881373);
});
// FIXME: assert(isClose(Math.asinh(1), 0.881373));
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,14 +1,10 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.atanh).toHaveLength(1);
try { expect(Math.atanh(-2)).toBeNaN();
assert(isNaN(Math.atanh(-2))); expect(Math.atanh(2)).toBeNaN();
assert(Math.atanh(-1) === -Infinity); expect(Math.atanh(-1)).toBe(-Infinity);
// FIXME: assert(Math.atanh(0) === 0); // FIXME: expect(Math.atanh(0)).toBe(0);
assert(isClose(Math.atanh(0.5), 0.549306)); expect(Math.atanh(0.5)).toBeCloseTo(0.549306);
// FIXME: assert(Math.atanh(1) === Infinity); // FIXME: expect(Math.atanh(1)).toBe(Infinity);
assert(isNaN(Math.atanh(2))); });
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,16 +1,12 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.cbrt).toHaveLength(1);
try { expect(Math.cbrt(NaN)).toBeNaN();
assert(isNaN(Math.cbrt(NaN))); // FIXME: expect(Math.cbrt(-1)).toBe(-1);
// FIXME: assert(Math.cbrt(-1) === -1); expect(Math.cbrt(-0)).toBe(-0);
assert(Math.cbrt(-0) === -0); // FIXME: expect(Math.cbrt(-Infinity)).toBe(-Infinity);
// FIXME: assert(Math.cbrt(-Infinity) === -Infinity); // FIXME: expect(Math.cbrt(1)).toBe(1);
// FIXME: assert(Math.cbrt(1) === 1); // FIXME: expect(Math.cbrt(Infinity)).toBe(Infinity);
// FIXME: assert(Math.cbrt(Infinity) === Infinity); expect(Math.cbrt(null)).toBe(0);
assert(Math.cbrt(null) === 0); // FIXME: expect(Math.cbrt(2)).toBeCloseTo(1.259921));
// FIXME: assert(isClose(Math.cbrt(2), 1.259921)); });
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,19 +1,13 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.ceil).toHaveLength(1);
try { expect(Math.ceil(0.95)).toBe(1);
assert(Math.ceil(0.95) === 1); expect(Math.ceil(4)).toBe(4);
assert(Math.ceil(4) === 4); expect(Math.ceil(7.004)).toBe(8);
assert(Math.ceil(7.004) == 8); expect(Math.ceil(-0.95)).toBe(-0);
assert(Math.ceil(-0.95) === -0); expect(Math.ceil(-4) ).toBe(-4);
assert(Math.ceil(-4) === -4); expect(Math.ceil(-7.004)).toBe(-7);
assert(Math.ceil(-7.004) === -7);
assert(isNaN(Math.ceil())); expect(Math.ceil()).toBeNaN();
assert(isNaN(Math.ceil(NaN))); expect(Math.ceil(NaN)).toBeNaN();
});
assert(Math.ceil.length === 1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

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

View file

@ -1,18 +1,14 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.cos).toHaveLength(1);
try { expect(Math.cos(0)).toBe(1);
assert(Math.cos(0) === 1); expect(Math.cos(null)).toBe(1);
assert(Math.cos(null) === 1); expect(Math.cos('')).toBe(1);
assert(Math.cos('') === 1); expect(Math.cos([])).toBe(1);
assert(Math.cos([]) === 1); expect(Math.cos(Math.PI)).toBe(-1);
assert(Math.cos(Math.PI) === -1); expect(Math.cos()).toBeNaN();
assert(isNaN(Math.cos())); expect(Math.cos(undefined)).toBeNaN();
assert(isNaN(Math.cos(undefined))); expect(Math.cos([1, 2, 3])).toBeNaN();
assert(isNaN(Math.cos([1, 2, 3]))); expect(Math.cos({})).toBeNaN();
assert(isNaN(Math.cos({}))); expect(Math.cos("foo")).toBeNaN();
assert(isNaN(Math.cos("foo"))); });
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,19 +1,13 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.exp).toHaveLength(1);
try { expect(Math.exp(0)).toBe(1);
assert(Math.exp.length === 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);
assert(Math.exp(0) === 1); expect(Math.exp()).toBeNaN();
assert(isClose(Math.exp(-2), 0.135335)); expect(Math.exp(undefined)).toBeNaN();
assert(isClose(Math.exp(-1), 0.367879)); expect(Math.exp("foo")).toBeNaN();
assert(isClose(Math.exp(1), 2.718281)); });
assert(isClose(Math.exp(2), 7.389056));
assert(isNaN(Math.exp()));
assert(isNaN(Math.exp(undefined)));
assert(isNaN(Math.exp("foo")));
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,19 +1,13 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.expm1).toHaveLength(1);
try { expect(Math.expm1(0)).toBe(0);
assert(Math.expm1.length === 1); expect(Math.expm1(-2)).toBeCloseTo(-0.864664);
expect(Math.expm1(-1)).toBeCloseTo(-0.632120);
expect(Math.expm1(1)).toBeCloseTo(1.718281);
expect(Math.expm1(2)).toBeCloseTo(6.389056);
assert(Math.expm1(0) === 0); expect(Math.expm1()).toBeNaN();
assert(isClose(Math.expm1(-2), -0.864664)); expect(Math.expm1(undefined)).toBeNaN();
assert(isClose(Math.expm1(-1), -0.632120)); expect(Math.expm1("foo")).toBeNaN();
assert(isClose(Math.expm1(1), 1.718281)); });
assert(isClose(Math.expm1(2), 6.389056));
assert(isNaN(Math.expm1()));
assert(isNaN(Math.expm1(undefined)));
assert(isNaN(Math.expm1("foo")));
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,19 +1,13 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.floor).toHaveLength(1);
try { expect(Math.floor(0.95)).toBe(0);
assert(Math.floor(0.95) === 0); expect(Math.floor(4)).toBe(4);
assert(Math.floor(4) === 4); expect(Math.floor(7.004)).toBe(7);
assert(Math.floor(7.004) == 7); expect(Math.floor(-0.95)).toBe(-1);
assert(Math.floor(-0.95) === -1); expect(Math.floor(-4)).toBe(-4);
assert(Math.floor(-4) === -4); expect(Math.floor(-7.004)).toBe(-8);
assert(Math.floor(-7.004) === -8);
assert(isNaN(Math.floor())); expect(Math.floor()).toBeNaN();
assert(isNaN(Math.floor(NaN))); expect(Math.floor(NaN)).toBeNaN();
});
assert(Math.floor.length === 1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,13 +1,8 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.log1p).toHaveLength(1);
try { expect(Math.log1p(-2)).toBeNaN();
assert(isNaN(Math.log1p(-2))); expect(Math.log1p(-1)).toBe(-Infinity);
assert(Math.log1p(-1) === -Infinity); // FIXME: expect(Math.log1p(0)).toBe(0);
// FIXME: assert(Math.log1p(0) === 0); // FIXME: expect(Math.log1p(1)).toBeCloseTo(0.693147);
// FIXME: assert(isClose(Math.log1p(1), 0.693147)); });
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,15 +1,10 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.max).toHaveLength(2);
try { expect(Math.max()).toBe(-Infinity);
assert(Math.max.length === 2); expect(Math.max(1)).toBe(1);
assert(Math.max() === -Infinity); expect(Math.max(2, 1)).toBe(2);
assert(Math.max(1) === 1); expect(Math.max(1, 2, 3)).toBe(3);
assert(Math.max(2, 1) === 2); expect(Math.max(NaN)).toBeNaN();
assert(Math.max(1, 2, 3) === 3); expect(Math.max("String", 1)).toBeNaN();
assert(isNaN(Math.max(NaN))); });
assert(isNaN(Math.max("String", 1)));
console.log("PASS");
} catch {
console.log("FAIL");
}

View file

@ -1,14 +1,9 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.min).toHaveLength(2);
try { expect(Math.min(1)).toBe(1);
assert(Math.min.length === 2); expect(Math.min(2, 1)).toBe(1);
assert(Math.min(1) === 1); expect(Math.min(1, 2, 3)).toBe(1);
assert(Math.min(2, 1) === 1); expect(Math.min(NaN)).toBeNaN();
assert(Math.min(1, 2, 3) === 1); expect(Math.min("String", 1)).toBeNaN();
assert(isNaN(Math.min(NaN))); });
assert(isNaN(Math.min("String", 1)));
console.log("PASS");
} catch {
console.log("FAIL");
}

View file

@ -1,29 +1,25 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.pow).toHaveLength(2);
try { expect(Math.pow(2, 0)).toBe(1);
assert(Math.pow(2, 0) === 1); expect(Math.pow(2, 1)).toBe(2);
assert(Math.pow(2, 1) === 2); expect(Math.pow(2, 2)).toBe(4);
assert(Math.pow(2, 2) === 4); expect(Math.pow(2, 3)).toBe(8);
assert(Math.pow(2, 3) === 8); expect(Math.pow(2, -3)).toBe(0.125);
assert(Math.pow(2, -3) === 0.125); expect(Math.pow(3, 2)).toBe(9);
assert(Math.pow(3, 2) === 9); expect(Math.pow(0, 0)).toBe(1);
assert(Math.pow(0, 0) === 1); expect(Math.pow(2, Math.pow(3, 2))).toBe(512);
assert(Math.pow(2, Math.pow(3, 2)) === 512); expect(Math.pow(Math.pow(2, 3), 2)).toBe(64);
assert(Math.pow(Math.pow(2, 3), 2) === 64); expect(Math.pow("2", "3")).toBe(8);
assert(Math.pow("2", "3") === 8); expect(Math.pow("", [])).toBe(1);
assert(Math.pow("", []) === 1); expect(Math.pow([], null)).toBe(1);
assert(Math.pow([], null) === 1); expect(Math.pow(null, null)).toBe(1);
assert(Math.pow(null, null) === 1); expect(Math.pow(undefined, null)).toBe(1);
assert(Math.pow(undefined, null) === 1); expect(Math.pow(NaN, 2)).toBeNaN();
assert(isNaN(Math.pow(NaN, 2))); expect(Math.pow(2, NaN)).toBeNaN();
assert(isNaN(Math.pow(2, NaN))); expect(Math.pow(undefined, 2)).toBeNaN();
assert(isNaN(Math.pow(undefined, 2))); expect(Math.pow(2, undefined)).toBeNaN();
assert(isNaN(Math.pow(2, undefined))); expect(Math.pow(null, undefined)).toBeNaN();
assert(isNaN(Math.pow(null, undefined))); expect(Math.pow(2, "foo")).toBeNaN();
assert(isNaN(Math.pow(2, "foo"))); expect(Math.pow("foo", 2)).toBeNaN();
assert(isNaN(Math.pow("foo", 2))); });
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,5 +1,3 @@
load("test-common.js");
function isPositiveZero(value) { function isPositiveZero(value) {
return value === 0 && 1 / value === Infinity; return value === 0 && 1 / value === Infinity;
} }
@ -8,35 +6,33 @@ function isNegativeZero(value) {
return value === 0 && 1 / value === -Infinity; return value === 0 && 1 / value === -Infinity;
} }
try { test("basic functionality", () => {
assert(Math.sign.length === 1); expect(Math.sign).toHaveLength(1);
assert(Math.sign(0.0001) === 1); expect(Math.sign.length).toBe(1);
assert(Math.sign(1) === 1);
assert(Math.sign(42) === 1);
assert(Math.sign(Infinity) === 1);
assert(isPositiveZero(Math.sign(0)));
assert(isPositiveZero(Math.sign(null)));
assert(isPositiveZero(Math.sign('')));
assert(isPositiveZero(Math.sign([])));
assert(Math.sign(-0.0001) === -1); expect(Math.sign(0.0001)).toBe(1);
assert(Math.sign(-1) === -1); expect(Math.sign(1)).toBe(1);
assert(Math.sign(-42) === -1); expect(Math.sign(42)).toBe(1);
assert(Math.sign(-Infinity) === -1); expect(Math.sign(Infinity)).toBe(1);
assert(isNegativeZero(Math.sign(-0))); expect(isPositiveZero(Math.sign(0))).toBeTrue();
assert(isNegativeZero(Math.sign(-null))); expect(isPositiveZero(Math.sign(null))).toBeTrue();
assert(isNegativeZero(Math.sign(-''))); expect(isPositiveZero(Math.sign(''))).toBeTrue();
assert(isNegativeZero(Math.sign(-[]))); expect(isPositiveZero(Math.sign([]))).toBeTrue();
assert(isNaN(Math.sign())); expect(Math.sign(-0.0001)).toBe(-1);
assert(isNaN(Math.sign(undefined))); expect(Math.sign(-1)).toBe(-1);
assert(isNaN(Math.sign([1, 2, 3]))); expect(Math.sign(-42)).toBe(-1);
assert(isNaN(Math.sign({}))); expect(Math.sign(-Infinity)).toBe(-1);
assert(isNaN(Math.sign(NaN))); expect(isNegativeZero(Math.sign(-0))).toBeTrue();
assert(isNaN(Math.sign("foo"))); expect(isNegativeZero(Math.sign(-null))).toBeTrue();
expect(isNegativeZero(Math.sign(-''))).toBeTrue();
expect(isNegativeZero(Math.sign(-[]))).toBeTrue();
console.log("PASS"); expect(Math.sign()).toBeNaN();
} catch (e) { expect(Math.sign(undefined)).toBeNaN();
console.log("FAIL: " + e); expect(Math.sign([1, 2, 3])).toBeNaN();
} expect(Math.sign({})).toBeNaN();
expect(Math.sign(NaN)).toBeNaN();
expect(Math.sign("foo")).toBeNaN();
});

View file

@ -1,19 +1,15 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.sin).toHaveLength(1);
try { expect(Math.sin(0)).toBe(0);
assert(Math.sin(0) === 0); expect(Math.sin(null)).toBe(0);
assert(Math.sin(null) === 0); expect(Math.sin('')).toBe(0);
assert(Math.sin('') === 0); expect(Math.sin([])).toBe(0);
assert(Math.sin([]) === 0); expect(Math.sin(Math.PI * 3 / 2)).toBe(-1);
assert(Math.sin(Math.PI * 3 / 2) === -1); expect(Math.sin(Math.PI / 2)).toBe(1);
assert(Math.sin(Math.PI / 2) === 1); expect(Math.sin()).toBeNaN();
assert(isNaN(Math.sin())); expect(Math.sin(undefined)).toBeNaN();
assert(isNaN(Math.sin(undefined))); expect(Math.sin([1, 2, 3])).toBeNaN();
assert(isNaN(Math.sin([1, 2, 3]))); expect(Math.sin({})).toBeNaN();
assert(isNaN(Math.sin({}))); expect(Math.sin("foo")).toBeNaN();
assert(isNaN(Math.sin("foo"))); });
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,7 +1,4 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.sqrt).toHaveLength(1);
try { expect(Math.sqrt(9)).toBe(3);
assert(Math.sqrt(9) === 3); });
console.log("PASS");
} catch {
}

View file

@ -1,18 +1,14 @@
load("test-common.js"); test("basic functionality", () => {
expect(Math.tan).toHaveLength(1);
try { expect(Math.tan(0)).toBe(0);
assert(Math.tan(0) === 0); expect(Math.tan(null)).toBe(0);
assert(Math.tan(null) === 0); expect(Math.tan('')).toBe(0);
assert(Math.tan('') === 0); expect(Math.tan([])).toBe(0);
assert(Math.tan([]) === 0); expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1);
assert(Math.ceil(Math.tan(Math.PI / 4)) === 1); expect(Math.tan()).toBeNaN();
assert(isNaN(Math.tan())); expect(Math.tan(undefined)).toBeNaN();
assert(isNaN(Math.tan(undefined))); expect(Math.tan([1, 2, 3])).toBeNaN();
assert(isNaN(Math.tan([1, 2, 3]))); expect(Math.tan({})).toBeNaN();
assert(isNaN(Math.tan({}))); expect(Math.tan("foo")).toBeNaN();
assert(isNaN(Math.tan("foo"))); });
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,18 +1,12 @@
load("test-common.js") test("basic functionality", () => {
expect(Math.trunc).toHaveLength(1);
try { expect(Math.trunc(13.37)).toBe(13);
assert(Math.trunc(13.37) === 13); expect(Math.trunc(42.84)).toBe(42);
assert(Math.trunc(42.84) === 42); expect(Math.trunc(0.123)).toBe( 0);
assert(Math.trunc(0.123) === 0); expect(Math.trunc(-0.123)).toBe(-0);
assert(Math.trunc(-0.123) === -0);
assert(isNaN(Math.trunc(NaN))); expect(Math.trunc(NaN)).toBeNaN();
assert(isNaN(Math.trunc('foo'))); expect(Math.trunc('foo')).toBeNaN();
assert(isNaN(Math.trunc())); expect(Math.trunc()).toBeNaN();
});
assert(Math.trunc.length === 1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,21 +0,0 @@
load("test-common.js");
try {
var nan = undefined + 1;
assert(nan + "" == "NaN");
assert(NaN + "" == "NaN");
assert(nan !== nan);
assert(NaN !== NaN);
assert(isNaN(nan) === true);
assert(isNaN(NaN) === true);
assert(isNaN(0) === false);
assert(isNaN(undefined) === true);
assert(isNaN(null) === false);
assert(isNaN(Infinity) === false);
assert(!!NaN === false);
assert(!!nan === false);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

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

View file

@ -1,17 +1,11 @@
load("test-common.js"); test("basic functionality", () => {
expect(Number.EPSILON).toBe(2 ** -52);
try { expect(Number.EPSILON).toBeGreaterThan(0);
assert(Number.EPSILON === 2 ** -52); expect(Number.MAX_SAFE_INTEGER).toBe(2 ** 53 - 1);
assert(Number.EPSILON > 0); expect(Number.MAX_SAFE_INTEGER + 1).toBe(Number.MAX_SAFE_INTEGER + 2);
assert(Number.MAX_SAFE_INTEGER === 2 ** 53 - 1); expect(Number.MIN_SAFE_INTEGER).toBe(-(2 ** 53 - 1));
assert(Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2); expect(Number.MIN_SAFE_INTEGER - 1).toBe(Number.MIN_SAFE_INTEGER - 2);
assert(Number.MIN_SAFE_INTEGER === -(2 ** 53 - 1)); expect(Number.POSITIVE_INFINITY).toBe(Infinity);
assert(Number.MIN_SAFE_INTEGER - 1 === Number.MIN_SAFE_INTEGER - 2); expect(Number.NEGATIVE_INFINITY).toBe(-Infinity);
assert(Number.POSITIVE_INFINITY === Infinity); expect(Number.NaN).toBeNaN();
assert(Number.NEGATIVE_INFINITY === -Infinity); });
assert(isNaN(Number.NaN));
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,30 +1,24 @@
load("test-common.js"); test("basic functionality", () => {
expect(Number.isFinite).toHaveLength(1);
expect(Number.isFinite).not.toBe(isFinite);
try { expect(Number.isFinite(0)).toBeTrue();
assert(Number.isFinite !== isFinite); expect(Number.isFinite(1.23)).toBeTrue();
assert(Number.isFinite.length === 1); expect(Number.isFinite(42)).toBeTrue();
assert(Number.isFinite(0) === true); expect(Number.isFinite("")).toBeFalse();
assert(Number.isFinite(1.23) === true); expect(Number.isFinite("0")).toBeFalse();
assert(Number.isFinite(42) === true); expect(Number.isFinite("42")).toBeFalse();
expect(Number.isFinite(true)).toBeFalse();
assert(Number.isFinite("") === false); expect(Number.isFinite(false)).toBeFalse();
assert(Number.isFinite("0") === false); expect(Number.isFinite(null)).toBeFalse();
assert(Number.isFinite("42") === false); expect(Number.isFinite([])).toBeFalse();
assert(Number.isFinite(true) === false); expect(Number.isFinite()).toBeFalse();
assert(Number.isFinite(false) === false); expect(Number.isFinite(NaN)).toBeFalse();
assert(Number.isFinite(null) === false); expect(Number.isFinite(undefined)).toBeFalse();
assert(Number.isFinite([]) === false); expect(Number.isFinite(Infinity)).toBeFalse();
assert(Number.isFinite() === false); expect(Number.isFinite(-Infinity)).toBeFalse();
assert(Number.isFinite(NaN) === false); expect(Number.isFinite("foo")).toBeFalse();
assert(Number.isFinite(undefined) === false); expect(Number.isFinite({})).toBeFalse();
assert(Number.isFinite(Infinity) === false); expect(Number.isFinite([1, 2, 3])).toBeFalse();
assert(Number.isFinite(-Infinity) === false); });
assert(Number.isFinite("foo") === false);
assert(Number.isFinite({}) === false);
assert(Number.isFinite([1, 2, 3]) === false);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e.message);
}

View file

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

View file

@ -1,31 +1,25 @@
load("test-common.js"); test("basic functionality", () => {
expect(Number.isNaN).toHaveLength(1);
expect(Number.isNaN).not.toBe(isNaN);
try { expect(Number.isNaN(0)).toBeFalse();
assert(Number.isNaN !== isNaN); expect(Number.isNaN(42)).toBeFalse();
assert(Number.isNaN.length === 1); 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();
assert(Number.isNaN(0) === false); expect(Number.isNaN(NaN)).toBeTrue();
assert(Number.isNaN(42) === false); expect(Number.isNaN(Number.NaN)).toBeTrue();
assert(Number.isNaN("") === false); expect(Number.isNaN(0 / 0)).toBeTrue();
assert(Number.isNaN("0") === false); });
assert(Number.isNaN("42") === false);
assert(Number.isNaN(true) === false);
assert(Number.isNaN(false) === false);
assert(Number.isNaN(null) === false);
assert(Number.isNaN([]) === false);
assert(Number.isNaN(Infinity) === false);
assert(Number.isNaN(-Infinity) === false);
assert(Number.isNaN() === false);
assert(Number.isNaN(undefined) === false);
assert(Number.isNaN("foo") === false);
assert(Number.isNaN({}) === false);
assert(Number.isNaN([1, 2, 3]) === false);
assert(Number.isNaN(NaN) === true);
assert(Number.isNaN(Number.NaN) === true);
assert(Number.isNaN(0 / 0) === true);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e.message);
}

View file

@ -1,30 +1,24 @@
load("test-common.js"); test("basic functionality", () => {
expect(Number.isSafeInteger).toHaveLength(1);
try { expect(Number.isSafeInteger(0)).toBeTrue();
assert(Number.isSafeInteger.length === 1); 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();
assert(Number.isSafeInteger(0) === true); expect(Number.isSafeInteger()).toBeFalse();
assert(Number.isSafeInteger(1) === true); expect(Number.isSafeInteger("1")).toBeFalse();
assert(Number.isSafeInteger(2.0) === true); expect(Number.isSafeInteger(2.1)).toBeFalse();
assert(Number.isSafeInteger(42) === true); expect(Number.isSafeInteger(42.42)).toBeFalse();
assert(Number.isSafeInteger(Number.MAX_SAFE_INTEGER) === true); expect(Number.isSafeInteger("")).toBeFalse();
assert(Number.isSafeInteger(Number.MIN_SAFE_INTEGER) === true); expect(Number.isSafeInteger([])).toBeFalse();
expect(Number.isSafeInteger(null)).toBeFalse();
assert(Number.isSafeInteger() === false); expect(Number.isSafeInteger(undefined)).toBeFalse();
assert(Number.isSafeInteger("1") === false); expect(Number.isSafeInteger(NaN)).toBeFalse();
assert(Number.isSafeInteger(2.1) === false); expect(Number.isSafeInteger(Infinity)).toBeFalse();
assert(Number.isSafeInteger(42.42) === false); expect(Number.isSafeInteger(-Infinity)).toBeFalse();
assert(Number.isSafeInteger("") === false); expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1)).toBeFalse();
assert(Number.isSafeInteger([]) === false); expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1)).toBeFalse();
assert(Number.isSafeInteger(null) === false); });
assert(Number.isSafeInteger(undefined) === false);
assert(Number.isSafeInteger(NaN) === false);
assert(Number.isSafeInteger(Infinity) === false);
assert(Number.isSafeInteger(-Infinity) === false);
assert(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1) === false);
assert(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1) === false);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e.message);
}

View file

@ -1,39 +1,33 @@
load("test-common.js"); test("basic functionality", () => {
expect(Number).toHaveLength(1);
expect(Number.name).toBe("Number");
expect(Number.prototype).not.toHaveProperty("length");
try { expect(typeof Number()).toBe("number");
assert(Number.length === 1); expect(typeof new Number()).toBe("object");
assert(Number.name === "Number");
assert(Number.prototype.length === undefined);
assert(typeof Number() === "number"); expect(Number()).toBe(0);
assert(typeof new Number() === "object"); expect(new Number().valueOf()).toBe(0);
expect(Number("42")).toBe(42);
assert(Number() === 0); expect(new Number("42").valueOf()).toBe(42);
assert(new Number().valueOf() === 0); expect(Number(null)).toBe(0);
assert(Number("42") === 42); expect(new Number(null).valueOf()).toBe(0);
assert(new Number("42").valueOf() === 42); expect(Number(true)).toBe(1);
assert(Number(null) === 0); expect(new Number(true).valueOf()).toBe(1);
assert(new Number(null).valueOf() === 0); expect(Number("Infinity")).toBe(Infinity);
assert(Number(true) === 1); expect(new Number("Infinity").valueOf()).toBe(Infinity);
assert(new Number(true).valueOf() === 1); expect(Number("+Infinity")).toBe(Infinity);
assert(Number("Infinity") === Infinity); expect(new Number("+Infinity").valueOf()).toBe(Infinity);
assert(new Number("Infinity").valueOf() === Infinity); expect(Number("-Infinity")).toBe(-Infinity);
assert(Number("+Infinity") === Infinity); expect(new Number("-Infinity").valueOf()).toBe(-Infinity);
assert(new Number("+Infinity").valueOf() === Infinity); expect(Number(undefined)).toBeNaN();
assert(Number("-Infinity") === -Infinity); expect(new Number(undefined).valueOf()).toBeNaN();
assert(new Number("-Infinity").valueOf() === -Infinity); expect(Number({})).toBeNaN();
assert(isNaN(Number(undefined))); expect(new Number({}).valueOf()).toBeNaN();
assert(isNaN(new Number(undefined).valueOf())); expect(Number({a: 1})).toBeNaN();
assert(isNaN(Number({}))); expect(new Number({a: 1}).valueOf()).toBeNaN();
assert(isNaN(new Number({}).valueOf())); expect(Number([1, 2, 3])).toBeNaN();
assert(isNaN(Number({a: 1}))); expect(new Number([1, 2, 3]).valueOf()).toBeNaN();
assert(isNaN(new Number({a: 1}).valueOf())); expect(Number("foo")).toBeNaN();
assert(isNaN(Number([1, 2, 3]))); expect(new Number("foo").valueOf()).toBeNaN();
assert(isNaN(new Number([1, 2, 3]).valueOf())); });
assert(isNaN(Number("foo")));
assert(isNaN(new Number("foo").valueOf()));
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e.message);
}

View file

@ -1,11 +1,5 @@
load("test-common.js"); test("basic functionality", () => {
try {
// Ensuring it's the same function as the global // Ensuring it's the same function as the global
// parseFloat() is enough as that already has tests :^) // parseFloat() is enough as that already has tests :^)
assert(Number.parseFloat === parseFloat); expect(Number.parseFloat).toBe(parseFloat);
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,10 +1,4 @@
load("test-common.js"); test("basic functionality", () => {
expect(typeof Number.prototype).toBe("object");
try { expect(Number.prototype.valueOf()).toBe(0);
assert(typeof Number.prototype === "object"); });
assert(Number.prototype.valueOf() === 0);
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,123 +1,127 @@
load("test-common.js"); describe("normal functionality", () => {
test("non-configurable property", () => {
let o = {};
Object.defineProperty(o, "foo", { value: 1, writable: false, enumerable: false });
try { expect(o.foo).toBe(1);
var o = {}; o.foo = 2;
Object.defineProperty(o, "foo", { value: 1, writable: false, enumerable: false }); expect(o.foo).toBe(1);
assert(o.foo === 1); expect(o).not.toHaveConfigurableProperty("foo");
o.foo = 2; expect(o).not.toHaveEnumerableProperty("foo");
assert(o.foo === 1); expect(o).not.toHaveWritableProperty("foo");
Object.defineProperty(o, 2, { get() { return 10; } }); expect(o).toHaveValueProperty("foo", 1);
assert(o[2] === 10);
var d = Object.getOwnPropertyDescriptor(o, "foo");
assert(d.configurable === false);
assert(d.enumerable === false);
assert(d.writable === false);
assert(d.value === 1);
Object.defineProperty(o, "bar", { value: "hi", writable: true, enumerable: true });
assert(o.bar === "hi");
o.bar = "ho";
assert(o.bar === "ho");
d = Object.getOwnPropertyDescriptor(o, "bar");
assert(d.configurable === false);
assert(d.enumerable === true);
assert(d.writable === true);
assert(d.value === "ho");
assertThrowsError(() => {
Object.defineProperty(o, "bar", { value: "xx", enumerable: false });
}, {
error: TypeError
}); });
Object.defineProperty(o, "baz", { value: 9, configurable: true, writable: false }); test("array index getter", () => {
Object.defineProperty(o, "baz", { configurable: true, writable: true }); let o = {};
Object.defineProperty(o, 2, { get() { return 10; } });
d = Object.getOwnPropertyDescriptor(o, "baz"); expect(o[2]).toBe(10);
assert(d.configurable === true);
assert(d.writable === true);
assert(d.value === 9);
Object.defineProperty(o, "qux", {
configurable: true,
get() {
return o.secret_qux + 1;
},
set(value) {
this.secret_qux = value + 1;
},
}); });
o.qux = 10; test("configurable property", () => {
assert(o.qux === 12); let o = {};
o.qux = 20; Object.defineProperty(o, "foo", { value: "hi", writable: true, enumerable: true });
assert(o.qux = 22);
Object.defineProperty(o, "qux", { configurable: true, value: 4 }); expect(o.foo).toBe("hi");
o.foo = "ho";
expect(o.foo).toBe("ho");
assert(o.qux === 4); expect(o).not.toHaveConfigurableProperty("foo");
o.qux = 5; expect(o).toHaveEnumerableProperty("foo");
assert(o.qux = 4); expect(o).toHaveWritableProperty("foo");
expect(o).toHaveValueProperty("foo", "ho");
Object.defineProperty(o, "qux", {
configurable: false,
get() {
return this.secret_qux + 2;
},
set(value) {
o.secret_qux = value + 2;
},
}); });
o.qux = 10; test("reconfigure configurable property", () => {
assert(o.qux === 14); let o = {};
o.qux = 20; Object.defineProperty(o, "foo", { value: 9, configurable: true, writable: false });
assert(o.qux = 24); Object.defineProperty(o, "foo", { configurable: true, writable: true });
assertThrowsError(() => { expect(o).toHaveConfigurableProperty("foo");
Object.defineProperty(o, "qux", { expect(o).toHaveWritableProperty("foo");
configurable: false, expect(o).not.toHaveEnumerableProperty("foo");
expect(o).toHaveValueProperty("foo", 9);
});
test("define accessor", () => {
let o = {};
Object.defineProperty(o, "foo", {
configurable: true,
get() { get() {
return this.secret_qux + 2; return o.secret_foo + 1;
},
set(value) {
this.secret_foo = value + 1;
}, },
}); });
}, {
error: TypeError, o.foo = 10;
message: "Cannot change attributes of non-configurable property 'qux'", expect(o.foo).toBe(12);
o.foo = 20;
expect(o.foo).toBe(22);
Object.defineProperty(o, "foo", { configurable: true, value: 4 });
expect(o.foo).toBe(4);
expect(o.foo = 5).toBe(5);
expect(o.foo = 4).toBe(4);
});
});
describe("errors", () => {
test("redefine non-configurable property", () => {
let o = {};
Object.defineProperty(o, "foo", { value: 1, writable: true, enumerable: true });
expect(() => {
Object.defineProperty(o, "foo", { value: 2, writable: false, enumerable: true });
}).toThrowWithMessage(TypeError, "Cannot change attributes of non-configurable property 'foo'");
}); });
assertThrowsError(() => { test("cannot define 'value' and 'get' in the same descriptor", () => {
Object.defineProperty(o, "qux", { value: 2 }); let o = {};
}, {
error: TypeError, expect(() => {
message: "Cannot change attributes of non-configurable property 'qux'", Object.defineProperty(o, "a", {
get() {},
value: 9,
});
}).toThrowWithMessage(TypeError, "Accessor property descriptor cannot specify a value or writable key");
}); });
assertThrowsError(() => { test("cannot define 'value' and 'set' in the same descriptor", () => {
Object.defineProperty(o, "a", { let o = {};
get() {},
value: 9, expect(() => {
Object.defineProperty(o, "a", {
set() {},
writable: true,
});
}).toThrowWithMessage(TypeError, "Accessor property descriptor cannot specify a value or writable key");
});
test("redefine non-configurable accessor", () => {
let o = {};
Object.defineProperty(o, "foo", {
configurable: false,
get() {
return this.secret_foo + 2;
},
set(value) {
o.secret_foo = value + 2;
},
}); });
}, {
error: TypeError,
message: "Accessor property descriptor cannot specify a value or writable key",
});
assertThrowsError(() => { expect(() => {
Object.defineProperty(o, "a", { Object.defineProperty(o, "foo", {
set() {}, configurable: false,
writable: true, get() {
}); return this.secret_foo + 2;
}, { },
error: TypeError, });
message: "Accessor property descriptor cannot specify a value or writable key", }).toThrowWithMessage(TypeError, "Cannot change attributes of non-configurable property 'foo'");
}); });
});
console.log("PASS");
} catch (e) {
console.log(e)
}

View file

@ -1,54 +1,45 @@
load("test-common.js"); describe("basic functionality", () => {
test("length", () => {
try { expect(Object.entries).toHaveLength(1);
assert(Object.entries.length === 1); expect(Object.entries(true)).toHaveLength(0);
assert(Object.entries(true).length === 0); expect(Object.entries(45)).toHaveLength(0);
assert(Object.entries(45).length === 0); expect(Object.entries(-998)).toHaveLength(0);
assert(Object.entries(-998).length === 0); expect(Object.entries("abcd")).toHaveLength(4);
assert(Object.entries("abcd").length === 4); expect(Object.entries([1, 2, 3])).toHaveLength(3);
assert(Object.entries([1, 2, 3]).length === 3); expect(Object.entries({ a: 1, b: 2, c: 3 })).toHaveLength(3);
assert(Object.entries({ a: 1, b: 2, c: 3 }).length === 3);
assertThrowsError(() => {
Object.entries(null);
}, {
error: TypeError,
message: "ToObject on null or undefined",
}); });
assertThrowsError(() => { test("entries with object", () => {
Object.entries(undefined); let entries = Object.entries({ foo: 1, bar: 2, baz: 3 });
}, {
error: TypeError, expect(entries).toEqual([["foo", 1], ["bar", 2], ["baz", 3]]);
message: "ToObject on null or undefined",
}); });
let entries = Object.entries({ foo: 1, bar: 2, baz: 3 }); test("entries with array", () => {
assert( entries = Object.entries(["a", "b", "c"]);
entries.length === 3 && entries[0].length === 2 && expect(entries).toEqual([["0", "a"], ["1", "b"], ["2", "c"]]);
entries[1].length === 2 && entries[2].length === 2 &&
entries[0][0] === "foo" && entries[0][1] === 1 &&
entries[1][0] === "bar" && entries[1][1] === 2 &&
entries[2][0] === "baz" && entries[2][1] === 3
);
entries = Object.entries(["a", "b", "c"]);
assert(
entries.length === 3 && entries[0].length === 2 &&
entries[1].length === 2 && entries[2].length === 2 &&
entries[0][0] === "0" && entries[0][1] === "a" &&
entries[1][0] === "1" && entries[1][1] === "b" &&
entries[2][0] === "2" && entries[2][1] === "c"
);
let obj = { foo: 1 };
Object.defineProperty(obj, "getFoo", {
value: function() { return this.foo; },
}); });
let entries = Object.entries(obj);
assert(entries.length === 1 && entries[0][0] === "foo" && entries[0][1] === 1);
console.log("PASS"); test("ignores non-enumerable properties", () => {
} catch (e) { let obj = { foo: 1 };
console.log("FAIL: " + e); Object.defineProperty(obj, "getFoo", {
} value: function() { return this.foo; },
});
let entries = Object.entries(obj);
expect(entries).toEqual([["foo", 1]]);
});
});
describe("errors", () => {
test("null argument", () => {
expect(() => {
Object.entries(null);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
test("undefined argument", () => {
expect(() => {
Object.entries(undefined);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
})
});

View file

@ -1,51 +1,49 @@
load("test-common.js"); test("plain property", () => {
let o = { foo: "bar" };
try { expect(o).toHaveConfigurableProperty("foo");
let o = { expect(o).toHaveEnumerableProperty("foo");
foo: "bar", expect(o).toHaveWritableProperty("foo");
get x() { }, expect(o).toHaveValueProperty("foo", "bar");
set ["hi" + 1](_) { }, expect(o).not.toHaveGetterProperty("foo");
}; expect(o).not.toHaveSetterProperty("foo");
});
Object.defineProperty(o, "baz", { test("getter property", () => {
let o = { get foo() {} };
expect(o).toHaveConfigurableProperty("foo");
expect(o).toHaveEnumerableProperty("foo");
expect(o).not.toHaveWritableProperty("foo");
expect(o).not.toHaveValueProperty("foo");
expect(o).toHaveGetterProperty("foo");
expect(o).not.toHaveSetterProperty("foo");
});
test("setter property", () => {
let o = { set foo(_) {} };
expect(o).toHaveConfigurableProperty("foo");
expect(o).toHaveEnumerableProperty("foo");
expect(o).not.toHaveWritableProperty("foo");
expect(o).not.toHaveValueProperty("foo");
expect(o).not.toHaveGetterProperty("foo");
expect(o).toHaveSetterProperty("foo");
});
test("defined property", () => {
let o = {};
Object.defineProperty(o, "foo", {
enumerable: false, enumerable: false,
writable: true, writable: true,
value: 10, value: 10,
}); });
let d = Object.getOwnPropertyDescriptor(o, "foo"); expect(o).not.toHaveConfigurableProperty("foo");
assert(d.enumerable === true); expect(o).not.toHaveEnumerableProperty("foo");
assert(d.configurable === true); expect(o).toHaveWritableProperty("foo");
assert(d.writable === true); expect(o).toHaveValueProperty("foo", 10);
assert(d.value === "bar"); expect(o).not.toHaveGetterProperty("foo");
assert(d.get === undefined); expect(o).not.toHaveSetterProperty("foo");
assert(d.set === undefined); });
let d = Object.getOwnPropertyDescriptor(o, "x");
assert(d.enumerable === true);
assert(d.configurable === true);
assert(d.writable === undefined);
assert(d.value === undefined);
assert(typeof d.get === "function");
assert(d.set === undefined);
let d = Object.getOwnPropertyDescriptor(o, "hi1");
assert(d.enumerable === true);
assert(d.configurable === true);
assert(d.writable === undefined);
assert(d.value === undefined);
assert(d.get === undefined);
assert(typeof d.set === "function");
let d = Object.getOwnPropertyDescriptor(o, "baz");
assert(d.enumerable === false);
assert(d.configurable === false);
assert(d.writable === true);
assert(d.value === 10);
assert(d.get === undefined);
assert(d.set === undefined);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,21 +1,9 @@
load("test-common.js"); test("use with array", () => {
try {
let names = Object.getOwnPropertyNames([1, 2, 3]); let names = Object.getOwnPropertyNames([1, 2, 3]);
expect(names).toEqual(["0", "1", "2", "length"]);
});
assert(names.length === 4); test("use with object", () => {
assert(names[0] === "0"); let names = Object.getOwnPropertyNames({ foo: 1, bar: 2, baz: 3 });
assert(names[1] === "1"); expect(names).toEqual(["foo", "bar", "baz"]);
assert(names[2] === "2"); });
assert(names[3] === "length");
names = Object.getOwnPropertyNames({ foo: 1, bar: 2, baz: 3 });
assert(names.length === 3);
assert(names[0] === "foo");
assert(names[1] === "bar");
assert(names[2] === "baz");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,10 @@
load("test-common.js"); test("basic functionality", () => {
let o1 = new Object();
let o2 = {};
try { expect(Object.getPrototypeOf(o1)).toBe(Object.getPrototypeOf(o2));
var o1 = new Object(); expect(Object.getPrototypeOf(Object.getPrototypeOf(o1))).toBe(null);
var o2 = {};
assert(Object.getPrototypeOf(o1) === Object.getPrototypeOf(o2)); Object.setPrototypeOf(o1, o2);
assert(Object.getPrototypeOf(Object.getPrototypeOf(o1)) === null); expect(Object.getPrototypeOf(o1)).toBe(o2);
console.log("PASS"); });
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,53 +1,54 @@
load("test-common.js"); test("length", () => {
expect(Object.is).toHaveLength(2);
});
try { test("arguments that evaluate to true", () => {
assert(Object.is.length === 2); let a = [1, 2, 3];
let o = { foo: "bar" };
var a = [1, 2, 3]; expect(Object.is("", "")).toBeTrue();
var o = {foo: "bar"}; expect(Object.is("foo", "foo")).toBeTrue();
expect(Object.is(0, 0)).toBeTrue();
expect(Object.is(+0, +0)).toBeTrue();
expect(Object.is(-0, -0)).toBeTrue();
expect(Object.is(1.23, 1.23)).toBeTrue();
expect(Object.is(42, 42)).toBeTrue();
expect(Object.is(NaN, NaN)).toBeTrue();
expect(Object.is(Infinity, Infinity)).toBeTrue();
expect(Object.is(+Infinity, +Infinity)).toBeTrue();
expect(Object.is(-Infinity, -Infinity)).toBeTrue();
expect(Object.is(true, true)).toBeTrue();
expect(Object.is(false, false)).toBeTrue();
expect(Object.is(null, null)).toBeTrue();
expect(Object.is(undefined, undefined)).toBeTrue();
expect(Object.is(undefined)).toBeTrue();
expect(Object.is()).toBeTrue();
expect(Object.is(a, a)).toBeTrue();
expect(Object.is(o, o)).toBeTrue();
});
assert(Object.is("", "") === true); test("arguments that evaluate to false", () => {
assert(Object.is("foo", "foo") === true); let a = [1, 2, 3];
assert(Object.is(0, 0) === true); let o = { foo: "bar" };
assert(Object.is(+0, +0) === true);
assert(Object.is(-0, -0) === true);
assert(Object.is(1.23, 1.23) === true);
assert(Object.is(42, 42) === true);
assert(Object.is(NaN, NaN) === true);
assert(Object.is(Infinity, Infinity) === true);
assert(Object.is(+Infinity, +Infinity) === true);
assert(Object.is(-Infinity, -Infinity) === true);
assert(Object.is(true, true) === true);
assert(Object.is(false, false) === true);
assert(Object.is(null, null) === true);
assert(Object.is(undefined, undefined) === true);
assert(Object.is(undefined) === true);
assert(Object.is() === true);
assert(Object.is(a, a) === true);
assert(Object.is(o, o) === true);
assert(Object.is("test") === false); expect(Object.is("test")).toBeFalse();
assert(Object.is("foo", "bar") === false); expect(Object.is("foo", "bar")).toBeFalse();
assert(Object.is(1, "1") === false); expect(Object.is(1, "1")).toBeFalse();
assert(Object.is(+0, -0) === false); expect(Object.is(+0, -0)).toBeFalse();
assert(Object.is(-0, +0) === false); expect(Object.is(-0, +0)).toBeFalse();
assert(Object.is(42, 24) === false); expect(Object.is(42, 24)).toBeFalse();
assert(Object.is(Infinity, -Infinity) === false); expect(Object.is(Infinity, -Infinity)).toBeFalse();
assert(Object.is(-Infinity, +Infinity) === false); expect(Object.is(-Infinity, +Infinity)).toBeFalse();
assert(Object.is(true, false) === false); expect(Object.is(true, false)).toBeFalse();
assert(Object.is(false, true) === false); expect(Object.is(false, true)).toBeFalse();
assert(Object.is(undefined, null) === false); expect(Object.is(undefined, null)).toBeFalse();
assert(Object.is(null, undefined) === false); expect(Object.is(null, undefined)).toBeFalse();
assert(Object.is([], []) === false); expect(Object.is([], [])).toBeFalse();
assert(Object.is(a, [1, 2, 3]) === false); expect(Object.is(a, [1, 2, 3])).toBeFalse();
assert(Object.is([1, 2, 3], a) === false); expect(Object.is([1, 2, 3], a)).toBeFalse();
assert(Object.is({}, {}) === false); expect(Object.is({}, {})).toBeFalse();
assert(Object.is(o, {foo: "bar"}) === false); expect(Object.is(o, {foo: "bar"})).toBeFalse();
assert(Object.is({foo: "bar"}, o) === false); expect(Object.is({foo: "bar"}, o)).toBeFalse();
assert(Object.is(a, o) === false); expect(Object.is(a, o)).toBeFalse();
assert(Object.is(o, a) === false); expect(Object.is(o, a)).toBeFalse();
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,22 +1,18 @@
load("test-common.js"); test("basic functionality", () => {
expect(Object.isExtensible).toHaveLength(1);
try { expect(Object.isExtensible()).toBeFalse();
assert(Object.isExtensible() === false); expect(Object.isExtensible(undefined)).toBeFalse();
assert(Object.isExtensible(undefined) === false); expect(Object.isExtensible(null)).toBeFalse();
assert(Object.isExtensible(null) === false); expect(Object.isExtensible(true)).toBeFalse();
assert(Object.isExtensible(true) === false); expect(Object.isExtensible(6)).toBeFalse();
assert(Object.isExtensible(6) === false); expect(Object.isExtensible("test")).toBeFalse();
assert(Object.isExtensible("test") === false);
let s = Symbol(); let s = Symbol();
assert(Object.isExtensible(s) === false); expect(Object.isExtensible(s)).toBeFalse();
let o = { foo: "foo" }; let o = { foo: "foo" };
assert(Object.isExtensible(o) === true); expect(Object.isExtensible(o)).toBeTrue();
Object.preventExtensions(o); Object.preventExtensions(o);
assert(Object.isExtensible(o) === false); expect(Object.isExtensible(o)).toBeFalse();
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,14 +1,8 @@
load("test-common.js"); test("basic functionality", () => {
expect(Object).toHaveLength(1);
expect(Object.name).toBe("Object");
expect(Object.prototype.length).toBe(undefined);
try { expect(typeof Object()).toBe("object");
assert(Object.length === 1); expect(typeof new Object()).toBe("object");
assert(Object.name === "Object"); });
assert(Object.prototype.length === undefined);
assert(typeof Object() === "object");
assert(typeof new Object() === "object");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,42 +1,44 @@
load("test-common.js"); describe("correct behavior", () => {
test("length", () => {
try { expect(Object.keys).toHaveLength(1);
assert(Object.keys.length === 1); expect(Object.keys(true)).toHaveLength(0);
assert(Object.keys(true).length === 0); expect(Object.keys(45)).toHaveLength(0);
assert(Object.keys(45).length === 0); expect(Object.keys(-998)).toHaveLength(0);
assert(Object.keys(-998).length === 0); expect(Object.keys("abcd")).toHaveLength(4);
assert(Object.keys("abcd").length === 4); expect(Object.keys([1, 2, 3])).toHaveLength(3);
assert(Object.keys([1, 2, 3]).length === 3); expect(Object.keys({ a: 1, b: 2, c: 3 })).toHaveLength(3);
assert(Object.keys({ a: 1, b: 2, c: 3 }).length === 3);
assertThrowsError(() => {
Object.keys(null);
}, {
error: TypeError,
message: "ToObject on null or undefined",
}); });
assertThrowsError(() => { test("object argument", () => {
Object.keys(undefined); let keys = Object.keys({ foo: 1, bar: 2, baz: 3 });
}, { expect(keys).toEqual(["foo", "bar", "baz"]);
error: TypeError,
message: "ToObject on null or undefined",
}); });
let keys = Object.keys({ foo: 1, bar: 2, baz: 3 }); test("array argument", () => {
assert(keys[0] === "foo" && keys[1] === "bar" && keys[2] === "baz"); let keys = Object.keys(["a", "b", "c"]);
expect(keys).toEqual(["0", "1", "2"]);
keys = Object.keys(["a", "b", "c"]);
assert(keys[0] === "0" && keys[1] === "1" && keys[2] === "2");
let obj = { foo: 1 };
Object.defineProperty(obj, 'getFoo', {
value: function() { return this.foo; },
}); });
keys = Object.keys(obj);
assert(keys.length === 1 && keys[0] === 'foo');
console.log("PASS"); test("ignores non-enumerable properties", () => {
} catch (e) { let obj = { foo: 1 };
console.log("FAIL: " + e); Object.defineProperty(obj, "getFoo", {
} value: function() { return this.foo; },
});
keys = Object.keys(obj);
expect(keys).toEqual(["foo"]);
});
});
describe("errors", () => {
test("null argument value", () => {
expect(() => {
Object.keys(null);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
test("undefined argument value", () => {
expect(() => {
Object.keys(undefined);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
});

View file

@ -1,54 +1,53 @@
load("test-common.js"); describe("correct behavior", () => {
test("non-object arguments", () => {
expect(Object.preventExtensions()).toBeUndefined();
expect(Object.preventExtensions(undefined)).toBeUndefined();
expect(Object.preventExtensions(null)).toBeNull();
expect(Object.preventExtensions(true)).toBeTrue();
expect(Object.preventExtensions(6)).toBe(6);
expect(Object.preventExtensions("test")).toBe("test");
try { let s = Symbol();
assert(Object.preventExtensions() === undefined); expect(Object.preventExtensions(s)).toBe(s);
assert(Object.preventExtensions(undefined) === undefined);
assert(Object.preventExtensions(null) === null);
assert(Object.preventExtensions(true) === true);
assert(Object.preventExtensions(6) === 6);
assert(Object.preventExtensions("test") === "test");
let s = Symbol();
assert(Object.preventExtensions(s) === s);
let o = { foo: "foo" };
assert(o.foo === "foo");
o.bar = "bar";
assert(o.bar === "bar");
assert(Object.preventExtensions(o) === o);
assert(o.foo === "foo");
assert(o.bar === "bar");
o.baz = "baz";
assert(o.baz === undefined);
assertThrowsError(() => {
Object.defineProperty(o, "baz", { value: "baz" });
}, {
error: TypeError,
message: "Cannot define property baz on non-extensible object",
}); });
assert(o.baz === undefined); test("basic functionality", () => {
let o = { foo: "foo" };
expect(o.foo).toBe("foo");
o.bar = "bar";
expect(o.bar).toBe("bar");
expect(Object.preventExtensions(o)).toBe(o);
expect(o.foo).toBe("foo");
expect(o.bar).toBe("bar");
assertThrowsError(() => {
"use strict";
o.baz = "baz"; o.baz = "baz";
}, { expect(o.baz).toBeUndefined();
error: TypeError, });
message: "Cannot define property baz on non-extensible object", });
describe("errors", () => {
test("defining a property on a non-extensible object", () => {
let o = {};
Object.preventExtensions(o);
expect(() => {
Object.defineProperty(o, "baz", { value: "baz" });
}).toThrowWithMessage(TypeError, "Cannot define property baz on non-extensible object");
expect(o.baz).toBeUndefined();
}); });
assertThrowsError(() => { test("putting property on a non-extensible object", () => {
"use strict"; let o = {};
Object.defineProperty(o, "baz", { value: "baz" }); Object.preventExtensions(o);
}, {
error: TypeError,
message: "Cannot define property baz on non-extensible object",
});
console.log("PASS"); expect(() => {
} catch (e) { "use strict";
console.log("FAIL: " + e); o.foo = "foo";
} }).toThrowWithMessage(TypeError, "Cannot define property foo on non-extensible object");
expect(o.foo = "foo").toBe("foo");
expect(o.foo).toBeUndefined();
});
});

View file

@ -1,36 +1,18 @@
load("test-common.js"); test("basic functionality", () => {
[Array, BigInt, Boolean, Date, Error, Function, Number, Object, String].forEach(constructor => {
expect(constructor.prototype.constructor).toBe(constructor);
if (constructor !== BigInt)
expect(Reflect.construct(constructor, []).constructor).toBe(constructor);
});
try { let o = {};
assert(Array.prototype.constructor === Array); expect(o.constructor).toBe(Object);
assert(Boolean.prototype.constructor === Boolean);
assert(Date.prototype.constructor === Date);
assert(Error.prototype.constructor === Error);
assert(Function.prototype.constructor === Function);
assert(Number.prototype.constructor === Number);
assert(Object.prototype.constructor === Object);
o = {};
assert(o.constructor === Object);
o = new Object();
assert(o.constructor === Object);
a = []; a = [];
assert(a.constructor === Array); expect(a.constructor).toBe(Array);
a = new Array(); expect(Object.prototype).toHaveConfigurableProperty("constructor");
assert(a.constructor === Array); expect(Object.prototype).not.toHaveEnumerableProperty("constructor");
expect(Object.prototype).toHaveWritableProperty("constructor");
n = new Number(3); expect(Object.prototype).toHaveValueProperty("constructor", Object);
assert(n.constructor === Number); });
d = Object.getOwnPropertyDescriptor(Object.prototype, "constructor");
assert(d.configurable === true);
assert(d.enumerable === false);
assert(d.writable === true);
assert(d.value === Object);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,17 +1,13 @@
load("test-common.js"); test("basic functionality", () => {
try {
var o = {}; var o = {};
o.foo = 1;
assert(o.hasOwnProperty("foo") === true);
assert(o.hasOwnProperty("bar") === false);
assert(o.hasOwnProperty() === false);
assert(o.hasOwnProperty(undefined) === false);
o.undefined = 2;
assert(o.hasOwnProperty() === true);
assert(o.hasOwnProperty(undefined) === true);
console.log("PASS"); o.foo = 1;
} catch (e) { expect(o.hasOwnProperty("foo")).toBeTrue();
console.log("FAIL: " + e); expect(o.hasOwnProperty("bar")).toBeFalse();
} expect(o.hasOwnProperty()).toBeFalse();
expect(o.hasOwnProperty(undefined)).toBeFalse();
o.undefined = 2;
expect(o.hasOwnProperty()).toBeTrue();
expect(o.hasOwnProperty(undefined)).toBeTrue();
});

View file

@ -1,10 +1,5 @@
load("test-common.js"); test("basic functionality", () => {
try {
var o = new Object(); var o = new Object();
Object.prototype.foo = 123; Object.prototype.foo = 123;
assert(o.foo === 123); expect(o.foo).toBe(123);
console.log("PASS"); });
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,32 +1,31 @@
load("test-common.js"); describe("correct behavior", () => {
test("length", () => {
expect(Object.prototype.toLocaleString).toHaveLength(0);
})
try { test("basic functionality", () => {
assert(Object.prototype.toLocaleString.length === 0); let o;
var o; o = {};
expect(o.toString()).toBe(o.toLocaleString());
o = {}; o = { toString: () => 42 };
assert(o.toString() === o.toLocaleString()); expect(o.toString()).toBe(42);
});
});
o = { toString: () => 42 }; describe("errors", () => {
assert(o.toString() === 42); test("toString that throws error", () => {
let o = { toString: () => { throw new Error(); } };
o = { toString: () => { throw Error(); } }; expect(() => {
assertThrowsError(() => { o.toLocaleString();
o.toLocaleString(); }).toThrow(Error);
}, {
error: Error
}); });
o = { toString: "foo" }; test("toString that is not a function", () => {
assertThrowsError(() => { let o = { toString: "foo" };
o.toLocaleString(); expect(() => {
}, { o.toLocaleString();
error: TypeError, }).toThrowWithMessage(TypeError, "foo is not a function");
message: "foo is not a function"
}); });
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,8 +1,8 @@
load("test-common.js"); test("basic functionality", () => {
expect(Object.prototype.toString).toHaveLength(0);
try { // FIXME: The tag is ObjectPrototype, but should be Object
assert(typeof Object.prototype.toString() === "string"); // expect(Object.prototype.toString()).toBe("[object Object]");
console.log("PASS"); expect({ foo: 1 }.toString()).toBe("[object Object]");
} catch (e) { expect([].toString()).toBe("");
console.log("FAIL: " + e); expect(Object.prototype.toString.call([])).toBe("[object Array]");
} });

View file

@ -1,36 +1,43 @@
load("test-common.js"); describe("correct behavior", () => {
test("length", () => {
try { expect(Object.setPrototypeOf).toHaveLength(2);
assert(Object.setPrototypeOf.length === 2);
assertThrowsError(() => {
Object.setPrototypeOf();
}, {
error: TypeError,
message: "Object.setPrototypeOf requires at least two arguments",
}); });
assertThrowsError(() => { test("basic functionality", () => {
Object.setPrototypeOf({}, "foo"); let o = {};
}, { let p = {};
error: TypeError, expect(Object.setPrototypeOf(o, p)).toBe(o);
message: "Prototype must be an object or null" expect(Object.getPrototypeOf(o)).toBe(p);
});
});
describe("errors", () => {
test("requires two arguments", () => {
expect(() => {
Object.setPrototypeOf();
}).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments");
expect(() => {
Object.setPrototypeOf({});
}).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments");
}); });
o = {}; test("prototype must be an object", () => {
p = {}; expect(() => {
assert(Object.setPrototypeOf(o, p) === o); Object.setPrototypeOf({}, "foo");
}).toThrowWithMessage(TypeError, "Prototype must be an object or null");
Object.preventExtensions(o);
assertThrowsError(() => {
Object.setPrototypeOf(o, {});
}, {
error: TypeError,
message: "Object's [[SetPrototypeOf]] method returned false"
}); });
assert(Object.setPrototypeOf(o, p) === o);
console.log("PASS"); test("non-extensible target", () => {
} catch (e) { let o = {};
console.log("FAIL: " + e); let p = {};
} Object.setPrototypeOf(o, p);
Object.preventExtensions(o);
expect(() => {
Object.setPrototypeOf(o, {});
}).toThrowWithMessage(TypeError, "Object's [[SetPrototypeOf]] method returned false");
expect(Object.setPrototypeOf(o, p)).toBe(o);
});
});

View file

@ -1,42 +1,44 @@
load("test-common.js"); describe("correct behavior", () => {
test("lengths", () => {
try { expect(Object.values).toHaveLength(1);
assert(Object.values.length === 1); expect(Object.values(true)).toHaveLength(0);
assert(Object.values(true).length === 0); expect(Object.values(45)).toHaveLength(0);
assert(Object.values(45).length === 0); expect(Object.values(-998)).toHaveLength(0);
assert(Object.values(-998).length === 0); expect(Object.values("abcd")).toHaveLength(4);
assert(Object.values("abcd").length === 4); expect(Object.values([1, 2, 3])).toHaveLength(3);
assert(Object.values([1, 2, 3]).length === 3); expect(Object.values({ a: 1, b: 2, c: 3 })).toHaveLength(3);
assert(Object.values({ a: 1, b: 2, c: 3 }).length === 3);
assertThrowsError(() => {
Object.values(null);
}, {
error: TypeError,
message: "ToObject on null or undefined",
}); });
assertThrowsError(() => { test("object argument", () => {
Object.values(undefined); let values = Object.values({ foo: 1, bar: 2, baz: 3 });
}, { expect(values).toEqual([1, 2, 3]);
error: TypeError,
message: "ToObject on null or undefined",
}); });
let values = Object.values({ foo: 1, bar: 2, baz: 3 }); test("array argument", () => {
assert(values[0] === 1 && values[1] === 2 && values[2] === 3); let values = Object.values(["a", "b", "c"]);
expect(values).toEqual(["a", "b", "c"]);
values = Object.values(["a", "b", "c"]);
assert(values[0] === "a" && values[1] === "b" && values[2] === "c");
let obj = { foo: 1 };
Object.defineProperty(obj, 'getFoo', {
value: function() { return this.foo; },
}); });
let values = Object.values(obj);
assert(values.length === 1 && values[0] === 1);
console.log("PASS"); test("ignores non-enumerable properties", () => {
} catch (e) { let obj = { foo: 1 };
console.log("FAIL: " + e); Object.defineProperty(obj, 'getFoo', {
} value: function() { return this.foo; },
});
let values = Object.values(obj);
expect(values).toEqual([1]);
});
});
describe("errors", () => {
test("null argument", () => {
expect(() => {
Object.values(null);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
test("undefined argument", () => {
expect(() => {
Object.values(undefined);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
});

View file

@ -1,23 +1,17 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.fromCharCode).toHaveLength(1);
try { expect(String.fromCharCode()).toBe("");
assert(String.fromCharCode.length === 1); expect(String.fromCharCode(0)).toBe("\u0000");
expect(String.fromCharCode(false)).toBe("\u0000");
assert(String.fromCharCode() === ""); expect(String.fromCharCode(null)).toBe("\u0000");
assert(String.fromCharCode(0) === "\u0000"); expect(String.fromCharCode(undefined)).toBe("\u0000");
assert(String.fromCharCode(false) === "\u0000"); expect(String.fromCharCode(1)).toBe("\u0001");
assert(String.fromCharCode(null) === "\u0000"); expect(String.fromCharCode(true)).toBe("\u0001");
assert(String.fromCharCode(undefined) === "\u0000"); expect(String.fromCharCode(-1)).toBe("\uffff");
assert(String.fromCharCode(1) === "\u0001"); expect(String.fromCharCode(0xffff)).toBe("\uffff");
assert(String.fromCharCode(true) === "\u0001"); expect(String.fromCharCode(0x123ffff)).toBe("\uffff");
assert(String.fromCharCode(-1) === "\uffff"); expect(String.fromCharCode(65)).toBe("A");
assert(String.fromCharCode(0xffff) === "\uffff"); expect(String.fromCharCode(65, 66, 67)).toBe("ABC");
assert(String.fromCharCode(0x123ffff) === "\uffff"); expect(String.fromCharCode(228, 246, 252)).toBe("äöü");
assert(String.fromCharCode(65) === "A"); });
assert(String.fromCharCode(65, 66, 67) === "ABC");
assert(String.fromCharCode(228, 246, 252) === "äöü");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,23 +1,9 @@
load("test-common.js"); test("constructor properties", () => {
expect(String).toHaveLength(1);
expect(String.name).toBe("String");
});
try { test("typeof", () => {
assert(String.length === 1); expect(typeof String()).toBe("string");
assert(String.name === "String"); expect(typeof new String()).toBe("object");
assert(String.prototype.length === 0); });
assert(typeof String() === "string");
assert(typeof new String() === "object");
assert(String() === "");
assert(new String().valueOf() === "");
assert(String("foo") === "foo");
assert(new String("foo").valueOf() === "foo");
assert(String(123) === "123");
assert(new String(123).valueOf() === "123");
assert(String(123) === "123");
assert(new String(123).valueOf() === "123");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,6 +1,4 @@
load("test-common.js"); test("basic functionality", () => {
try {
const genericStringPrototypeFunctions = [ const genericStringPrototypeFunctions = [
"charAt", "charAt",
"repeat", "repeat",
@ -24,29 +22,16 @@ try {
String.prototype[name].call({ toString: () => 123 }); String.prototype[name].call({ toString: () => 123 });
String.prototype[name].call({ toString: () => undefined }); String.prototype[name].call({ toString: () => undefined });
assertThrowsError(() => { expect(() => {
String.prototype[name].call({ toString: () => new String() }); String.prototype[name].call({ toString: () => new String() });
}, { }).toThrowWithMessage(TypeError, "Cannot convert object to string");
error: TypeError,
message: "Cannot convert object to string"
});
assertThrowsError(() => { expect(() => {
String.prototype[name].call({ toString: () => [] }); String.prototype[name].call({ toString: () => [] });
}, { }).toThrowWithMessage(TypeError, "Cannot convert object to string");
error: TypeError,
message: "Cannot convert object to string"
});
assertThrowsError(() => { expect(() => {
String.prototype[name].call({ toString: () => ({}) }); String.prototype[name].call({ toString: () => ({}) });
}, { }).toThrowWithMessage(TypeError, "Cannot convert object to string");
error: TypeError,
message: "Cannot convert object to string"
});
}); });
});
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,24 +1,20 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.charAt).toHaveLength(1);
try {
var s = "foobar" var s = "foobar"
assert(typeof s === "string"); expect(typeof s).toBe("string");
assert(s.length === 6); expect(s).toHaveLength(6);
assert(s.charAt(0) === 'f'); expect(s.charAt(0)).toBe("f");
assert(s.charAt(1) === 'o'); expect(s.charAt(1)).toBe("o");
assert(s.charAt(2) === 'o'); expect(s.charAt(2)).toBe("o");
assert(s.charAt(3) === 'b'); expect(s.charAt(3)).toBe("b");
assert(s.charAt(4) === 'a'); expect(s.charAt(4)).toBe("a");
assert(s.charAt(5) === 'r'); expect(s.charAt(5)).toBe("r");
assert(s.charAt(6) === ''); expect(s.charAt(6)).toBe("");
assert(s.charAt() === 'f'); expect(s.charAt()).toBe("f");
assert(s.charAt(NaN) === 'f'); expect(s.charAt(NaN)).toBe("f");
assert(s.charAt("foo") === 'f'); expect(s.charAt("foo")).toBe("f");
assert(s.charAt(undefined) === 'f'); expect(s.charAt(undefined)).toBe("f");
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,22 +1,17 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.concat).toHaveLength(1);
try { expect("".concat(1)).toBe("1");
assert(String.prototype.concat.length === 1); expect("".concat(3,2,1)).toBe("321");
assert("".concat(1) === "1"); expect("hello".concat(" ", "friends")).toBe("hello friends");
assert("".concat(3,2,1) === "321"); expect("".concat(null)).toBe("null");
assert("hello".concat(" ", "friends") === "hello friends"); expect("".concat(false)).toBe("false");
assert("".concat(null) === "null"); expect("".concat(true)).toBe("true");
assert("".concat(false) === "false"); expect("".concat([])).toBe("");
assert("".concat(true) === "true"); expect("".concat([1, 2, 3, 'hello'])).toBe("1,2,3,hello");
assert("".concat([]) === ""); expect("".concat(true, [])).toBe("true");
assert("".concat([1, 2, 3, 'hello']) === "1,2,3,hello"); expect("".concat(true, false)).toBe("truefalse");
assert("".concat(true, []) === "true"); expect("".concat({})).toBe("[object Object]");
assert("".concat(true, false) === "truefalse"); expect("".concat(1, {})).toBe("1[object Object]");
assert("".concat({}) === "[object Object]"); expect("".concat(1, {}, false)).toBe("1[object Object]false");
assert("".concat(1, {}) === "1[object Object]"); });
assert("".concat(1, {}, false) === "1[object Object]false");
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,18 +1,12 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.includes).toHaveLength(1);
try { expect("hello friends".includes("hello")).toBe(true);
assert(String.prototype.includes.length === 1); expect("hello friends".includes("hello", 100)).toBe(false);
expect("hello friends".includes("hello", -10)).toBe(true);
assert("hello friends".includes("hello") === true); expect("hello friends".includes("friends", 6)).toBe(true);
assert("hello friends".includes("hello", 100) === false); expect("hello friends".includes("hello", 6)).toBe(false);
assert("hello friends".includes("hello", -10) === true); expect("hello friends false".includes(false)).toBe(true);
assert("hello friends".includes("friends", 6) === true); expect("hello 10 friends".includes(10)).toBe(true);
assert("hello friends".includes("hello", 6) === false); expect("hello friends undefined".includes()).toBe(true);
assert("hello friends false".includes(false) === true); });
assert("hello 10 friends".includes(10) === true);
assert("hello friends undefined".includes() === true);
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,12 +1,8 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.indexOf).toHaveLength(1);
try {
var s = "hello friends" var s = "hello friends"
assert(s.indexOf("friends") === 6); expect(s.indexOf("friends")).toBe(6);
assert(s.indexOf("enemies") === -1); expect(s.indexOf("enemies")).toBe(-1);
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,13 +1,9 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype).toHaveLength(0);
expect(typeof Object.getPrototypeOf("")).toBe("object");
expect(Object.getPrototypeOf("").valueOf()).toBe("");
try { expect(typeof String.prototype).toBe("object");
assert(typeof Object.getPrototypeOf("") === "object"); expect(String.prototype.valueOf()).toBe("");
assert(Object.getPrototypeOf("").valueOf() === ''); });
assert(typeof String.prototype === "object");
assert(String.prototype.valueOf() === '');
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,27 +1,22 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.lastIndexOf).toHaveLength(1);
try { expect("hello friends".lastIndexOf()).toBe(-1);
assert(String.prototype.lastIndexOf.length === 1); expect("hello friends".lastIndexOf("e")).toBe(9);
assert("hello friends".lastIndexOf() === -1); expect("hello friends".lastIndexOf("e", -7)).toBe(-1);
assert("hello friends".lastIndexOf("e") === 9); expect("hello friends".lastIndexOf("e", 100)).toBe(9);
assert("hello friends".lastIndexOf("e", -7) === -1); expect("hello friends".lastIndexOf("")).toBe(13);
assert("hello friends".lastIndexOf("e", 100) === 9); expect("hello friends".lastIndexOf("Z")).toBe(-1);
assert("hello friends".lastIndexOf("") === 13); expect("hello friends".lastIndexOf("serenity")).toBe(-1);
assert("hello friends".lastIndexOf("Z") === -1); expect("hello friends".lastIndexOf("", 4)).toBe(4);
assert("hello friends".lastIndexOf("serenity") === -1); expect("hello serenity friends".lastIndexOf("serenity")).toBe(6);
assert("hello friends".lastIndexOf("", 4) === 4); expect("hello serenity friends serenity".lastIndexOf("serenity")).toBe(23);
assert("hello serenity friends".lastIndexOf("serenity") === 6); expect("hello serenity friends serenity".lastIndexOf("serenity", 14)).toBe(6);
assert("hello serenity friends serenity".lastIndexOf("serenity") === 23); expect("".lastIndexOf("")).toBe(0);
assert("hello serenity friends serenity".lastIndexOf("serenity", 14) === 6); expect("".lastIndexOf("", 1)).toBe(0);
assert("".lastIndexOf("") === 0); expect("".lastIndexOf("", -1)).toBe(0);
assert("".lastIndexOf("", 1) === 0); expect("hello friends serenity".lastIndexOf("h", 10)).toBe(0);
assert("".lastIndexOf("", -1) === 0); expect("hello friends serenity".lastIndexOf("l", 4)).toBe(3);
assert("hello friends serenity".lastIndexOf("h", 10) === 0); expect("hello friends serenity".lastIndexOf("s", 13)).toBe(12);
assert("hello friends serenity".lastIndexOf("l", 4) === 3); expect("hello".lastIndexOf("serenity")).toBe(-1);
assert("hello friends serenity".lastIndexOf("s", 13) === 12); });
assert("hello".lastIndexOf("serenity") === -1);
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,24 +1,18 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.padEnd).toHaveLength(1);
try {
assert(String.prototype.padEnd.length === 1);
var s = "foo"; var s = "foo";
assert(s.padEnd(-1) === "foo"); expect(s.padEnd(-1)).toBe("foo");
assert(s.padEnd(0) === "foo"); expect(s.padEnd(0)).toBe("foo");
assert(s.padEnd(3) === "foo"); expect(s.padEnd(3)).toBe("foo");
assert(s.padEnd(5) === "foo "); expect(s.padEnd(5)).toBe("foo ");
assert(s.padEnd(10) === "foo "); expect(s.padEnd(10)).toBe("foo ");
assert(s.padEnd("5") === "foo "); expect(s.padEnd("5")).toBe("foo ");
assert(s.padEnd([[["5"]]]) === "foo "); expect(s.padEnd([[["5"]]])).toBe("foo ");
assert(s.padEnd(2, "+") === "foo"); expect(s.padEnd(2, "+")).toBe("foo");
assert(s.padEnd(5, "+") === "foo++"); expect(s.padEnd(5, "+")).toBe("foo++");
assert(s.padEnd(5, 1) === "foo11"); expect(s.padEnd(5, 1)).toBe("foo11");
assert(s.padEnd(10, null) === "foonullnul"); expect(s.padEnd(10, null)).toBe("foonullnul");
assert(s.padEnd(10, "bar") === "foobarbarb"); expect(s.padEnd(10, "bar")).toBe("foobarbarb");
assert(s.padEnd(10, "123456789") === "foo1234567"); expect(s.padEnd(10, "123456789")).toBe("foo1234567");
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,24 +1,18 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.padStart).toHaveLength(1);
try {
assert(String.prototype.padStart.length === 1);
var s = "foo"; var s = "foo";
assert(s.padStart(-1) === "foo"); expect(s.padStart(-1)).toBe("foo");
assert(s.padStart(0) === "foo"); expect(s.padStart(0)).toBe("foo");
assert(s.padStart(3) === "foo"); expect(s.padStart(3)).toBe("foo");
assert(s.padStart(5) === " foo"); expect(s.padStart(5)).toBe(" foo");
assert(s.padStart(10) === " foo"); expect(s.padStart(10)).toBe(" foo");
assert(s.padStart("5") === " foo"); expect(s.padStart("5")).toBe(" foo");
assert(s.padStart([[["5"]]]) === " foo"); expect(s.padStart([[["5"]]])).toBe(" foo");
assert(s.padStart(2, "+") === "foo"); expect(s.padStart(2, "+")).toBe("foo");
assert(s.padStart(5, "+") === "++foo"); expect(s.padStart(5, "+")).toBe("++foo");
assert(s.padStart(5, 1) === "11foo"); expect(s.padStart(5, 1)).toBe("11foo");
assert(s.padStart(10, null) === "nullnulfoo"); expect(s.padStart(10, null)).toBe("nullnulfoo");
assert(s.padStart(10, "bar") === "barbarbfoo"); expect(s.padStart(10, "bar")).toBe("barbarbfoo");
assert(s.padStart(10, "123456789") === "1234567foo"); expect(s.padStart(10, "123456789")).toBe("1234567foo");
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,37 +1,25 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.repeat).toHaveLength(1);
try { expect("foo".repeat(0)).toBe("");
assert(String.prototype.repeat.length === 1); expect("foo".repeat(1)).toBe("foo");
expect("foo".repeat(2)).toBe("foofoo");
expect("foo".repeat(3)).toBe("foofoofoo");
expect("foo".repeat(3.1)).toBe("foofoofoo");
expect("foo".repeat(3.5)).toBe("foofoofoo");
expect("foo".repeat(3.9)).toBe("foofoofoo");
expect("foo".repeat(null)).toBe("");
expect("foo".repeat(undefined)).toBe("");
expect("foo".repeat([])).toBe("");
expect("foo".repeat("")).toBe("");
});
try { test("throws correct range errors", () => {
expect(() => {
"foo".repeat(-1); "foo".repeat(-1);
assertNotReached(); }).toThrowWithMessage(RangeError, "repeat count must be a positive number");
} catch (e) {
assert(e.name === "RangeError");
assert(e.message === "repeat count must be a positive number");
}
try { expect(() => {
"foo".repeat(Infinity); "foo".repeat(Infinity);
assertNotReached(); }).toThrowWithMessage(RangeError, "repeat count must be a finite number");
} catch (e) { });
assert(e.name === "RangeError");
assert(e.message === "repeat count must be a finite number");
}
assert("foo".repeat(0) === "");
assert("foo".repeat(1) === "foo");
assert("foo".repeat(2) === "foofoo");
assert("foo".repeat(3) === "foofoofoo");
assert("foo".repeat(3.1) === "foofoofoo");
assert("foo".repeat(3.5) === "foofoofoo");
assert("foo".repeat(3.9) === "foofoofoo");
assert("foo".repeat(null) === "");
assert("foo".repeat(undefined) === "");
assert("foo".repeat([]) === "");
assert("foo".repeat("") === "");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,22 +1,18 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.slice).toHaveLength(2);
try { expect("hello friends".slice()).toBe("hello friends");
assert(String.prototype.slice.length === 2); expect("hello friends".slice(1)).toBe("ello friends");
assert("hello friends".slice() === "hello friends"); expect("hello friends".slice(0, 5)).toBe("hello");
assert("hello friends".slice(1) === "ello friends"); expect("hello friends".slice(13, 6)).toBe("");
assert("hello friends".slice(0, 5) === "hello"); expect("hello friends".slice("", 5)).toBe("hello");
assert("hello friends".slice(13, 6) === ""); expect("hello friends".slice(3, 3)).toBe("");
assert("hello friends".slice('', 5) === "hello"); expect("hello friends".slice(-1, 13)).toBe("s");
assert("hello friends".slice(3, 3) === ""); expect("hello friends".slice(0, 50)).toBe("hello friends");
assert("hello friends".slice(-1, 13) === "s"); expect("hello friends".slice(0, "5")).toBe("hello");
assert("hello friends".slice(0, 50) === "hello friends"); expect("hello friends".slice("6", "13")).toBe("friends");
assert("hello friends".slice(0, "5") === "hello"); expect("hello friends".slice(-7)).toBe("friends");
assert("hello friends".slice("6", "13") === "friends"); expect("hello friends".slice(1000)).toBe("");
assert("hello friends".slice(-7) === "friends"); expect("hello friends".slice(-1000)).toBe("hello friends");
assert("hello friends".slice(1000) === ""); });
assert("hello friends".slice(-1000) === "hello friends");
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,40 +1,36 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.startsWith).toHaveLength(1);
try {
var s = "foobar"; var s = "foobar";
assert(s.startsWith("f") === true); expect(s.startsWith("f")).toBeTrue();
assert(s.startsWith("fo") === true); expect(s.startsWith("fo")).toBeTrue();
assert(s.startsWith("foo") === true); expect(s.startsWith("foo")).toBeTrue();
assert(s.startsWith("foob") === true); expect(s.startsWith("foob")).toBeTrue();
assert(s.startsWith("fooba") === true); expect(s.startsWith("fooba")).toBeTrue();
assert(s.startsWith("foobar") === true); expect(s.startsWith("foobar")).toBeTrue();
assert(s.startsWith("foobar1") === false); expect(s.startsWith("foobar1")).toBeFalse();
assert(s.startsWith("f", 0) === true); expect(s.startsWith("f", 0)).toBeTrue();
assert(s.startsWith("fo", 0) === true); expect(s.startsWith("fo", 0)).toBeTrue();
assert(s.startsWith("foo", 0) === true); expect(s.startsWith("foo", 0)).toBeTrue();
assert(s.startsWith("foob", 0) === true); expect(s.startsWith("foob", 0)).toBeTrue();
assert(s.startsWith("fooba", 0) === true); expect(s.startsWith("fooba", 0)).toBeTrue();
assert(s.startsWith("foobar", 0) === true); expect(s.startsWith("foobar", 0)).toBeTrue();
assert(s.startsWith("foobar1", 0) === false); expect(s.startsWith("foobar1", 0)).toBeFalse();
assert(s.startsWith("foo", []) === true); expect(s.startsWith("foo", [])).toBeTrue();
assert(s.startsWith("foo", null) === true); expect(s.startsWith("foo", null)).toBeTrue();
assert(s.startsWith("foo", undefined) === true); expect(s.startsWith("foo", undefined)).toBeTrue();
assert(s.startsWith("foo", false) === true); expect(s.startsWith("foo", false)).toBeTrue();
assert(s.startsWith("foo", true) === false); expect(s.startsWith("foo", true)).toBeFalse();
assert(s.startsWith("foo", "foo") === true); expect(s.startsWith("foo", "foo")).toBeTrue();
assert(s.startsWith("foo", -1) === true); expect(s.startsWith("foo", -1)).toBeTrue();
assert(s.startsWith("foo", 42) === false); expect(s.startsWith("foo", 42)).toBeFalse();
assert(s.startsWith("bar", 3) === true); expect(s.startsWith("bar", 3)).toBeTrue();
assert(s.startsWith("bar", "3") === true); expect(s.startsWith("bar", "3")).toBeTrue();
assert(s.startsWith("bar1", 3) === false); expect(s.startsWith("bar1", 3)).toBeFalse();
assert(s.startsWith() === false); expect(s.startsWith()).toBeFalse();
assert(s.startsWith("") === true); expect(s.startsWith("")).toBeTrue();
assert(s.startsWith("", 0) === true); expect(s.startsWith("", 0)).toBeTrue();
assert(s.startsWith("", 1) === true); expect(s.startsWith("", 1)).toBeTrue();
assert(s.startsWith("", -1) === true); expect(s.startsWith("", -1)).toBeTrue();
assert(s.startsWith("", 42) === true); expect(s.startsWith("", 42)).toBeTrue();
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,19 +1,14 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.substring).toHaveLength(2);
try { expect("hello friends".substring()).toBe("hello friends");
assert(String.prototype.substring.length === 2); expect("hello friends".substring(1)).toBe("ello friends");
assert("hello friends".substring() === "hello friends"); expect("hello friends".substring(0, 5)).toBe("hello");
assert("hello friends".substring(1) === "ello friends"); expect("hello friends".substring(13, 6)).toBe("friends");
assert("hello friends".substring(0, 5) === "hello"); expect("hello friends".substring('', 5)).toBe("hello");
assert("hello friends".substring(13, 6) === "friends"); expect("hello friends".substring(3, 3)).toBe("");
assert("hello friends".substring('', 5) === "hello"); expect("hello friends".substring(-1, 13)).toBe("hello friends");
assert("hello friends".substring(3, 3) === ""); expect("hello friends".substring(0, 50)).toBe("hello friends");
assert("hello friends".substring(-1, 13) === "hello friends"); expect("hello friends".substring(0, "5")).toBe("hello");
assert("hello friends".substring(0, 50) === "hello friends"); expect("hello friends".substring("6", "13")).toBe("friends");
assert("hello friends".substring(0, "5") === "hello"); });
assert("hello friends".substring("6", "13") === "friends");
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -1,15 +1,9 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.toLowerCase).toHaveLength(0);
try { expect("foo".toLowerCase()).toBe("foo");
assert(String.prototype.toLowerCase.length === 0); expect("Foo".toLowerCase()).toBe("foo");
expect("FOO".toLowerCase()).toBe("foo");
assert("foo".toLowerCase() === "foo"); expect(('b' + 'a' + + 'a' + 'a').toLowerCase()).toBe("banana");
assert("Foo".toLowerCase() === "foo"); });
assert("FOO".toLowerCase() === "foo");
assert(('b' + 'a' + + 'a' + 'a').toLowerCase() === "banana");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,11 +1,6 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.toString).toHaveLength(0)
try { expect("".toString()).toBe("");
assert(String.prototype.toString.length === 0) expect("hello friends".toString()).toBe("hello friends");
assert("".toString() === ""); });
assert("hello friends".toString() === "hello friends");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,15 +1,9 @@
load("test-common.js"); test("basic functionality", () => {
expect(String.prototype.toUpperCase).toHaveLength(0);
try { expect("foo".toUpperCase()).toBe("FOO");
assert(String.prototype.toUpperCase.length === 0); expect("Foo".toUpperCase()).toBe("FOO");
expect("FOO".toUpperCase()).toBe("FOO");
assert("foo".toUpperCase() === "FOO"); expect(('b' + 'a' + + 'n' + 'a').toUpperCase()).toBe("BANANA");
assert("Foo".toUpperCase() === "FOO"); });
assert("FOO".toUpperCase() === "FOO");
assert(('b' + 'a' + + 'n' + 'a').toUpperCase() === "BANANA");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,56 +1,58 @@
load("test-common.js"); test("trim", () => {
expect(String.prototype.trim).toHaveLength(0);
try { expect(" hello friends ".trim()).toBe("hello friends");
assert(String.prototype.trim.length === 0); expect("hello friends ".trim()).toBe("hello friends");
assert(String.prototype.trimStart.length === 0); expect(" hello friends".trim()).toBe("hello friends");
assert(String.prototype.trimEnd.length === 0);
assert(" hello friends ".trim() === "hello friends");
assert("hello friends ".trim() === "hello friends");
assert(" hello friends".trim() === "hello friends");
assert(" hello friends".trimStart() === "hello friends");
assert("hello friends ".trimEnd() === "hello friends");
assert(" hello friends".trimEnd() === " hello friends");
assert("hello friends ".trimStart() === "hello friends ");
assert(" hello friends ".trimEnd() === " hello friends");
assert(" hello friends ".trimStart() === "hello friends ");
assert("\thello friends".trimStart() === "hello friends"); expect("\thello friends\t".trim()).toBe("hello friends");
assert("hello friends\t".trimStart() === "hello friends\t"); expect("\thello friends".trim()).toBe("hello friends");
assert("\thello friends\t".trimStart() === "hello friends\t"); expect("hello friends\t".trim()).toBe("hello friends");
assert("\rhello friends".trimStart() === "hello friends");
assert("hello friends\r".trimStart() === "hello friends\r");
assert("\rhello friends\r".trimStart() === "hello friends\r");
assert("hello friends\t".trimEnd() === "hello friends"); expect("\rhello friends\r".trim()).toBe("hello friends");
assert("\thello friends".trimEnd() === "\thello friends"); expect("\rhello friends".trim()).toBe("hello friends");
assert("\thello friends\t".trimEnd() === "\thello friends"); expect("hello friends\r".trim()).toBe("hello friends");
assert("hello friends\r".trimEnd() === "hello friends");
assert("\rhello friends".trimEnd() === "\rhello friends");
assert("\rhello friends\r".trimEnd() === "\rhello friends");
assert("hello friends\n".trimEnd() === "hello friends");
assert("\r\nhello friends".trimEnd() === "\r\nhello friends");
assert("\rhello friends\r\n".trimEnd() === "\rhello friends");
assert("\thello friends\t".trim() === "hello friends"); expect("\rhello friends\n".trim()).toBe("hello friends");
assert("\thello friends".trim() === "hello friends"); expect("\r\thello friends".trim()).toBe("hello friends");
assert("hello friends\t".trim() === "hello friends"); expect("hello friends\r\n".trim()).toBe("hello friends");
expect(" \thello friends\r\n".trim()).toBe("hello friends");
assert("\rhello friends\r".trim() === "hello friends"); expect("\n\t\thello friends\r\n".trim()).toBe("hello friends");
assert("\rhello friends".trim() === "hello friends"); expect("\n\t\thello friends\t\t".trim()).toBe("hello friends");
assert("hello friends\r".trim() === "hello friends"); });
assert("\rhello friends\n".trim() === "hello friends");
assert("\r\thello friends".trim() === "hello friends");
assert("hello friends\r\n".trim() === "hello friends");
assert(" \thello friends\r\n".trim() === "hello friends");
assert("\n\t\thello friends\r\n".trim() === "hello friends");
assert("\n\t\thello friends\t\t".trim() === "hello friends");
test("trimStart", () => {
expect(String.prototype.trimStart).toHaveLength(0);
console.log("PASS"); expect(" hello friends".trimStart()).toBe("hello friends");
} catch (e) { expect("hello friends ".trimStart()).toBe("hello friends ");
console.log("FAIL: " + e); expect(" hello friends ".trimStart()).toBe("hello friends ");
}
expect("\thello friends".trimStart()).toBe("hello friends");
expect("hello friends\t".trimStart()).toBe("hello friends\t");
expect("\thello friends\t".trimStart()).toBe("hello friends\t");
expect("\rhello friends".trimStart()).toBe("hello friends");
expect("hello friends\r".trimStart()).toBe("hello friends\r");
expect("\rhello friends\r".trimStart()).toBe("hello friends\r");
});
test("trimEnd", () => {
expect(String.prototype.trimEnd).toHaveLength(0);
expect("hello friends ".trimEnd()).toBe("hello friends");
expect(" hello friends".trimEnd()).toBe(" hello friends");
expect(" hello friends ".trimEnd()).toBe(" hello friends");
expect("hello friends\t".trimEnd()).toBe("hello friends");
expect("\thello friends".trimEnd()).toBe("\thello friends");
expect("\thello friends\t".trimEnd()).toBe("\thello friends");
expect("hello friends\r".trimEnd()).toBe("hello friends");
expect("\rhello friends".trimEnd()).toBe("\rhello friends");
expect("\rhello friends\r".trimEnd()).toBe("\rhello friends");
expect("hello friends\n".trimEnd()).toBe("hello friends");
expect("\r\nhello friends".trimEnd()).toBe("\r\nhello friends");
expect("\rhello friends\r\n".trimEnd()).toBe("\rhello friends");
});

View file

@ -0,0 +1,12 @@
test("basic functionality", () => {
expect(String.prototype.valueOf).toHaveLength(0);
expect(String()).toBe("");
expect(new String().valueOf()).toBe("");
expect(String("foo")).toBe("foo");
expect(new String("foo").valueOf()).toBe("foo");
expect(String(123)).toBe("123");
expect(new String(123).valueOf()).toBe("123");
expect(String(123)).toBe("123");
expect(new String(123).valueOf()).toBe("123");
});

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