1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +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,23 +1,17 @@
load("test-common.js");
test("basic functionality", () => {
expect(String.fromCharCode).toHaveLength(1);
try {
assert(String.fromCharCode.length === 1);
assert(String.fromCharCode() === "");
assert(String.fromCharCode(0) === "\u0000");
assert(String.fromCharCode(false) === "\u0000");
assert(String.fromCharCode(null) === "\u0000");
assert(String.fromCharCode(undefined) === "\u0000");
assert(String.fromCharCode(1) === "\u0001");
assert(String.fromCharCode(true) === "\u0001");
assert(String.fromCharCode(-1) === "\uffff");
assert(String.fromCharCode(0xffff) === "\uffff");
assert(String.fromCharCode(0x123ffff) === "\uffff");
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);
}
expect(String.fromCharCode()).toBe("");
expect(String.fromCharCode(0)).toBe("\u0000");
expect(String.fromCharCode(false)).toBe("\u0000");
expect(String.fromCharCode(null)).toBe("\u0000");
expect(String.fromCharCode(undefined)).toBe("\u0000");
expect(String.fromCharCode(1)).toBe("\u0001");
expect(String.fromCharCode(true)).toBe("\u0001");
expect(String.fromCharCode(-1)).toBe("\uffff");
expect(String.fromCharCode(0xffff)).toBe("\uffff");
expect(String.fromCharCode(0x123ffff)).toBe("\uffff");
expect(String.fromCharCode(65)).toBe("A");
expect(String.fromCharCode(65, 66, 67)).toBe("ABC");
expect(String.fromCharCode(228, 246, 252)).toBe("äöü");
});

View file

@ -1,23 +1,9 @@
load("test-common.js");
test("constructor properties", () => {
expect(String).toHaveLength(1);
expect(String.name).toBe("String");
});
try {
assert(String.length === 1);
assert(String.name === "String");
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);
}
test("typeof", () => {
expect(typeof String()).toBe("string");
expect(typeof new String()).toBe("object");
});

View file

@ -1,6 +1,4 @@
load("test-common.js");
try {
test("basic functionality", () => {
const genericStringPrototypeFunctions = [
"charAt",
"repeat",
@ -24,29 +22,16 @@ try {
String.prototype[name].call({ toString: () => 123 });
String.prototype[name].call({ toString: () => undefined });
assertThrowsError(() => {
expect(() => {
String.prototype[name].call({ toString: () => new String() });
}, {
error: TypeError,
message: "Cannot convert object to string"
});
}).toThrowWithMessage(TypeError, "Cannot convert object to string");
assertThrowsError(() => {
expect(() => {
String.prototype[name].call({ toString: () => [] });
}, {
error: TypeError,
message: "Cannot convert object to string"
});
}).toThrowWithMessage(TypeError, "Cannot convert object to string");
assertThrowsError(() => {
expect(() => {
String.prototype[name].call({ toString: () => ({}) });
}, {
error: TypeError,
message: "Cannot convert object to string"
});
}).toThrowWithMessage(TypeError, "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"
assert(typeof s === "string");
assert(s.length === 6);
expect(typeof s).toBe("string");
expect(s).toHaveLength(6);
assert(s.charAt(0) === 'f');
assert(s.charAt(1) === 'o');
assert(s.charAt(2) === 'o');
assert(s.charAt(3) === 'b');
assert(s.charAt(4) === 'a');
assert(s.charAt(5) === 'r');
assert(s.charAt(6) === '');
expect(s.charAt(0)).toBe("f");
expect(s.charAt(1)).toBe("o");
expect(s.charAt(2)).toBe("o");
expect(s.charAt(3)).toBe("b");
expect(s.charAt(4)).toBe("a");
expect(s.charAt(5)).toBe("r");
expect(s.charAt(6)).toBe("");
assert(s.charAt() === 'f');
assert(s.charAt(NaN) === 'f');
assert(s.charAt("foo") === 'f');
assert(s.charAt(undefined) === 'f');
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
expect(s.charAt()).toBe("f");
expect(s.charAt(NaN)).toBe("f");
expect(s.charAt("foo")).toBe("f");
expect(s.charAt(undefined)).toBe("f");
});

View file

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

View file

@ -1,18 +1,12 @@
load("test-common.js");
test("basic functionality", () => {
expect(String.prototype.includes).toHaveLength(1);
try {
assert(String.prototype.includes.length === 1);
assert("hello friends".includes("hello") === true);
assert("hello friends".includes("hello", 100) === false);
assert("hello friends".includes("hello", -10) === true);
assert("hello friends".includes("friends", 6) === true);
assert("hello friends".includes("hello", 6) === false);
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);
}
expect("hello friends".includes("hello")).toBe(true);
expect("hello friends".includes("hello", 100)).toBe(false);
expect("hello friends".includes("hello", -10)).toBe(true);
expect("hello friends".includes("friends", 6)).toBe(true);
expect("hello friends".includes("hello", 6)).toBe(false);
expect("hello friends false".includes(false)).toBe(true);
expect("hello 10 friends".includes(10)).toBe(true);
expect("hello friends undefined".includes()).toBe(true);
});

View file

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

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 {
assert(typeof Object.getPrototypeOf("") === "object");
assert(Object.getPrototypeOf("").valueOf() === '');
assert(typeof String.prototype === "object");
assert(String.prototype.valueOf() === '');
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}
expect(typeof String.prototype).toBe("object");
expect(String.prototype.valueOf()).toBe("");
});

View file

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

View file

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

View file

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

View file

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

View file

@ -1,22 +1,18 @@
load("test-common.js");
test("basic functionality", () => {
expect(String.prototype.slice).toHaveLength(2);
try {
assert(String.prototype.slice.length === 2);
assert("hello friends".slice() === "hello friends");
assert("hello friends".slice(1) === "ello friends");
assert("hello friends".slice(0, 5) === "hello");
assert("hello friends".slice(13, 6) === "");
assert("hello friends".slice('', 5) === "hello");
assert("hello friends".slice(3, 3) === "");
assert("hello friends".slice(-1, 13) === "s");
assert("hello friends".slice(0, 50) === "hello friends");
assert("hello friends".slice(0, "5") === "hello");
assert("hello friends".slice("6", "13") === "friends");
assert("hello friends".slice(-7) === "friends");
assert("hello friends".slice(1000) === "");
assert("hello friends".slice(-1000) === "hello friends");
expect("hello friends".slice()).toBe("hello friends");
expect("hello friends".slice(1)).toBe("ello friends");
expect("hello friends".slice(0, 5)).toBe("hello");
expect("hello friends".slice(13, 6)).toBe("");
expect("hello friends".slice("", 5)).toBe("hello");
expect("hello friends".slice(3, 3)).toBe("");
expect("hello friends".slice(-1, 13)).toBe("s");
expect("hello friends".slice(0, 50)).toBe("hello friends");
expect("hello friends".slice(0, "5")).toBe("hello");
expect("hello friends".slice("6", "13")).toBe("friends");
expect("hello friends".slice(-7)).toBe("friends");
expect("hello friends".slice(1000)).toBe("");
expect("hello friends".slice(-1000)).toBe("hello friends");
});
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";
assert(s.startsWith("f") === true);
assert(s.startsWith("fo") === true);
assert(s.startsWith("foo") === true);
assert(s.startsWith("foob") === true);
assert(s.startsWith("fooba") === true);
assert(s.startsWith("foobar") === true);
assert(s.startsWith("foobar1") === false);
assert(s.startsWith("f", 0) === true);
assert(s.startsWith("fo", 0) === true);
assert(s.startsWith("foo", 0) === true);
assert(s.startsWith("foob", 0) === true);
assert(s.startsWith("fooba", 0) === true);
assert(s.startsWith("foobar", 0) === true);
assert(s.startsWith("foobar1", 0) === false);
assert(s.startsWith("foo", []) === true);
assert(s.startsWith("foo", null) === true);
assert(s.startsWith("foo", undefined) === true);
assert(s.startsWith("foo", false) === true);
assert(s.startsWith("foo", true) === false);
assert(s.startsWith("foo", "foo") === true);
assert(s.startsWith("foo", -1) === true);
assert(s.startsWith("foo", 42) === false);
assert(s.startsWith("bar", 3) === true);
assert(s.startsWith("bar", "3") === true);
assert(s.startsWith("bar1", 3) === false);
assert(s.startsWith() === false);
assert(s.startsWith("") === true);
assert(s.startsWith("", 0) === true);
assert(s.startsWith("", 1) === true);
assert(s.startsWith("", -1) === true);
assert(s.startsWith("", 42) === true);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
expect(s.startsWith("f")).toBeTrue();
expect(s.startsWith("fo")).toBeTrue();
expect(s.startsWith("foo")).toBeTrue();
expect(s.startsWith("foob")).toBeTrue();
expect(s.startsWith("fooba")).toBeTrue();
expect(s.startsWith("foobar")).toBeTrue();
expect(s.startsWith("foobar1")).toBeFalse();
expect(s.startsWith("f", 0)).toBeTrue();
expect(s.startsWith("fo", 0)).toBeTrue();
expect(s.startsWith("foo", 0)).toBeTrue();
expect(s.startsWith("foob", 0)).toBeTrue();
expect(s.startsWith("fooba", 0)).toBeTrue();
expect(s.startsWith("foobar", 0)).toBeTrue();
expect(s.startsWith("foobar1", 0)).toBeFalse();
expect(s.startsWith("foo", [])).toBeTrue();
expect(s.startsWith("foo", null)).toBeTrue();
expect(s.startsWith("foo", undefined)).toBeTrue();
expect(s.startsWith("foo", false)).toBeTrue();
expect(s.startsWith("foo", true)).toBeFalse();
expect(s.startsWith("foo", "foo")).toBeTrue();
expect(s.startsWith("foo", -1)).toBeTrue();
expect(s.startsWith("foo", 42)).toBeFalse();
expect(s.startsWith("bar", 3)).toBeTrue();
expect(s.startsWith("bar", "3")).toBeTrue();
expect(s.startsWith("bar1", 3)).toBeFalse();
expect(s.startsWith()).toBeFalse();
expect(s.startsWith("")).toBeTrue();
expect(s.startsWith("", 0)).toBeTrue();
expect(s.startsWith("", 1)).toBeTrue();
expect(s.startsWith("", -1)).toBeTrue();
expect(s.startsWith("", 42)).toBeTrue();
});

View file

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

View file

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

View file

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

View file

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

View file

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

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");
});

View file

@ -1,35 +1,31 @@
load("test-common.js")
test("basic functionality", () => {
expect(String.raw).toHaveLength(1);
try {
let str = String.raw`foo\nbar`;
assert(str.length === 8 && str === "foo\\nbar");
expect(str).toHaveLength(8);
expect(str).toBe("foo\\nbar");
str = String.raw`foo ${1 + 9}\nbar${"hf!"}`;
assert(str === "foo 10\\nbarhf!");
expect(str).toBe("foo 10\\nbarhf!");
str = String.raw`${10}${20}${30}`;
assert(str === "102030");
expect(str).toBe("102030");
str = String.raw({ raw: ["foo ", "\\nbar"] }, 10, "hf!");
assert(str === "foo 10\\nbar");
expect(str).toBe("foo 10\\nbar");
str = String.raw({ raw: ["foo ", "\\nbar"] });
assert(str === "foo \\nbar");
expect(str).toBe("foo \\nbar");
str = String.raw({ raw: [] }, 10, "hf!");
assert(str === "");
expect(str).toBe("");
str = String.raw({ raw: 1 });
assert(str === "");
expect(str).toBe("");
});
assertThrowsError(() => {
test("passing object with no 'raw' property", () => {
expect(() => {
String.raw({});
}, {
error: TypeError,
message: "Cannot convert property 'raw' to object from undefined",
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
}).toThrowWithMessage(TypeError, "Cannot convert property 'raw' to object from undefined");
});