mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
test-js: Use prettier and format all files
This commit is contained in:
parent
e532888242
commit
6d58c48c2f
248 changed files with 8291 additions and 7725 deletions
|
@ -1,17 +1,17 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.fromCharCode).toHaveLength(1);
|
||||
expect(String.fromCharCode).toHaveLength(1);
|
||||
|
||||
expect(String.fromCharCode()).toBe("");
|
||||
expect(String.fromCharCode(0)).toBe("\u0000");
|
||||
expect(String.fromCharCode(false)).toBe("\u0000");
|
||||
expect(String.fromCharCode(null)).toBe("\u0000");
|
||||
expect(String.fromCharCode(undefined)).toBe("\u0000");
|
||||
expect(String.fromCharCode(1)).toBe("\u0001");
|
||||
expect(String.fromCharCode(true)).toBe("\u0001");
|
||||
expect(String.fromCharCode(-1)).toBe("\uffff");
|
||||
expect(String.fromCharCode(0xffff)).toBe("\uffff");
|
||||
expect(String.fromCharCode(0x123ffff)).toBe("\uffff");
|
||||
expect(String.fromCharCode(65)).toBe("A");
|
||||
expect(String.fromCharCode(65, 66, 67)).toBe("ABC");
|
||||
expect(String.fromCharCode(228, 246, 252)).toBe("äöü");
|
||||
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("äöü");
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
test("constructor properties", () => {
|
||||
expect(String).toHaveLength(1);
|
||||
expect(String.name).toBe("String");
|
||||
expect(String).toHaveLength(1);
|
||||
expect(String.name).toBe("String");
|
||||
});
|
||||
|
||||
test("typeof", () => {
|
||||
expect(typeof String()).toBe("string");
|
||||
expect(typeof new String()).toBe("object");
|
||||
expect(typeof String()).toBe("string");
|
||||
expect(typeof new String()).toBe("object");
|
||||
});
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
test("basic functionality", () => {
|
||||
const genericStringPrototypeFunctions = [
|
||||
"charAt",
|
||||
"repeat",
|
||||
"startsWith",
|
||||
"indexOf",
|
||||
"toLowerCase",
|
||||
"toUpperCase",
|
||||
"padStart",
|
||||
"padEnd",
|
||||
"trim",
|
||||
"trimStart",
|
||||
"trimEnd",
|
||||
"concat",
|
||||
"substring",
|
||||
"includes",
|
||||
"slice",
|
||||
];
|
||||
const genericStringPrototypeFunctions = [
|
||||
"charAt",
|
||||
"repeat",
|
||||
"startsWith",
|
||||
"indexOf",
|
||||
"toLowerCase",
|
||||
"toUpperCase",
|
||||
"padStart",
|
||||
"padEnd",
|
||||
"trim",
|
||||
"trimStart",
|
||||
"trimEnd",
|
||||
"concat",
|
||||
"substring",
|
||||
"includes",
|
||||
"slice",
|
||||
];
|
||||
|
||||
genericStringPrototypeFunctions.forEach(name => {
|
||||
String.prototype[name].call({ toString: () => "hello friends" });
|
||||
String.prototype[name].call({ toString: () => 123 });
|
||||
String.prototype[name].call({ toString: () => undefined });
|
||||
genericStringPrototypeFunctions.forEach(name => {
|
||||
String.prototype[name].call({ toString: () => "hello friends" });
|
||||
String.prototype[name].call({ toString: () => 123 });
|
||||
String.prototype[name].call({ toString: () => undefined });
|
||||
|
||||
expect(() => {
|
||||
String.prototype[name].call({ toString: () => new String() });
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert object to string");
|
||||
expect(() => {
|
||||
String.prototype[name].call({ toString: () => new String() });
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert object to string");
|
||||
|
||||
expect(() => {
|
||||
String.prototype[name].call({ toString: () => [] });
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert object to string");
|
||||
expect(() => {
|
||||
String.prototype[name].call({ toString: () => [] });
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert object to string");
|
||||
|
||||
expect(() => {
|
||||
String.prototype[name].call({ toString: () => ({}) });
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert object to string");
|
||||
});
|
||||
expect(() => {
|
||||
String.prototype[name].call({ toString: () => ({}) });
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert object to string");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.charAt).toHaveLength(1);
|
||||
expect(String.prototype.charAt).toHaveLength(1);
|
||||
|
||||
var s = "foobar"
|
||||
expect(typeof s).toBe("string");
|
||||
expect(s).toHaveLength(6);
|
||||
var s = "foobar";
|
||||
expect(typeof s).toBe("string");
|
||||
expect(s).toHaveLength(6);
|
||||
|
||||
expect(s.charAt(0)).toBe("f");
|
||||
expect(s.charAt(1)).toBe("o");
|
||||
expect(s.charAt(2)).toBe("o");
|
||||
expect(s.charAt(3)).toBe("b");
|
||||
expect(s.charAt(4)).toBe("a");
|
||||
expect(s.charAt(5)).toBe("r");
|
||||
expect(s.charAt(6)).toBe("");
|
||||
expect(s.charAt(0)).toBe("f");
|
||||
expect(s.charAt(1)).toBe("o");
|
||||
expect(s.charAt(2)).toBe("o");
|
||||
expect(s.charAt(3)).toBe("b");
|
||||
expect(s.charAt(4)).toBe("a");
|
||||
expect(s.charAt(5)).toBe("r");
|
||||
expect(s.charAt(6)).toBe("");
|
||||
|
||||
expect(s.charAt()).toBe("f");
|
||||
expect(s.charAt(NaN)).toBe("f");
|
||||
expect(s.charAt("foo")).toBe("f");
|
||||
expect(s.charAt(undefined)).toBe("f");
|
||||
expect(s.charAt()).toBe("f");
|
||||
expect(s.charAt(NaN)).toBe("f");
|
||||
expect(s.charAt("foo")).toBe("f");
|
||||
expect(s.charAt(undefined)).toBe("f");
|
||||
});
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.concat).toHaveLength(1);
|
||||
expect(String.prototype.concat).toHaveLength(1);
|
||||
|
||||
expect("".concat(1)).toBe("1");
|
||||
expect("".concat(3,2,1)).toBe("321");
|
||||
expect("hello".concat(" ", "friends")).toBe("hello friends");
|
||||
expect("".concat(null)).toBe("null");
|
||||
expect("".concat(false)).toBe("false");
|
||||
expect("".concat(true)).toBe("true");
|
||||
expect("".concat([])).toBe("");
|
||||
expect("".concat([1, 2, 3, 'hello'])).toBe("1,2,3,hello");
|
||||
expect("".concat(true, [])).toBe("true");
|
||||
expect("".concat(true, false)).toBe("truefalse");
|
||||
expect("".concat({})).toBe("[object Object]");
|
||||
expect("".concat(1, {})).toBe("1[object Object]");
|
||||
expect("".concat(1, {}, false)).toBe("1[object Object]false");
|
||||
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");
|
||||
});
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.includes).toHaveLength(1);
|
||||
expect(String.prototype.includes).toHaveLength(1);
|
||||
|
||||
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);
|
||||
expect("hello friends".includes("hello")).toBeTrue();
|
||||
expect("hello friends".includes("hello", 100)).toBeFalse();
|
||||
expect("hello friends".includes("hello", -10)).toBeTrue();
|
||||
expect("hello friends".includes("friends", 6)).toBeTrue();
|
||||
expect("hello friends".includes("hello", 6)).toBeFalse();
|
||||
expect("hello friends false".includes(false)).toBeTrue();
|
||||
expect("hello 10 friends".includes(10)).toBeTrue();
|
||||
expect("hello friends undefined".includes()).toBeTrue();
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.indexOf).toHaveLength(1);
|
||||
expect(String.prototype.indexOf).toHaveLength(1);
|
||||
|
||||
var s = "hello friends"
|
||||
var s = "hello friends";
|
||||
|
||||
expect(s.indexOf("friends")).toBe(6);
|
||||
expect(s.indexOf("enemies")).toBe(-1);
|
||||
expect(s.indexOf("friends")).toBe(6);
|
||||
expect(s.indexOf("enemies")).toBe(-1);
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype).toHaveLength(0);
|
||||
|
||||
expect(typeof Object.getPrototypeOf("")).toBe("object");
|
||||
expect(Object.getPrototypeOf("").valueOf()).toBe("");
|
||||
expect(String.prototype).toHaveLength(0);
|
||||
|
||||
expect(typeof String.prototype).toBe("object");
|
||||
expect(String.prototype.valueOf()).toBe("");
|
||||
expect(typeof Object.getPrototypeOf("")).toBe("object");
|
||||
expect(Object.getPrototypeOf("").valueOf()).toBe("");
|
||||
|
||||
expect(typeof String.prototype).toBe("object");
|
||||
expect(String.prototype.valueOf()).toBe("");
|
||||
});
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.lastIndexOf).toHaveLength(1);
|
||||
expect(String.prototype.lastIndexOf).toHaveLength(1);
|
||||
|
||||
expect("hello friends".lastIndexOf()).toBe(-1);
|
||||
expect("hello friends".lastIndexOf("e")).toBe(9);
|
||||
expect("hello friends".lastIndexOf("e", -7)).toBe(-1);
|
||||
expect("hello friends".lastIndexOf("e", 100)).toBe(9);
|
||||
expect("hello friends".lastIndexOf("")).toBe(13);
|
||||
expect("hello friends".lastIndexOf("Z")).toBe(-1);
|
||||
expect("hello friends".lastIndexOf("serenity")).toBe(-1);
|
||||
expect("hello friends".lastIndexOf("", 4)).toBe(4);
|
||||
expect("hello serenity friends".lastIndexOf("serenity")).toBe(6);
|
||||
expect("hello serenity friends serenity".lastIndexOf("serenity")).toBe(23);
|
||||
expect("hello serenity friends serenity".lastIndexOf("serenity", 14)).toBe(6);
|
||||
expect("".lastIndexOf("")).toBe(0);
|
||||
expect("".lastIndexOf("", 1)).toBe(0);
|
||||
expect("".lastIndexOf("", -1)).toBe(0);
|
||||
expect("hello friends serenity".lastIndexOf("h", 10)).toBe(0);
|
||||
expect("hello friends serenity".lastIndexOf("l", 4)).toBe(3);
|
||||
expect("hello friends serenity".lastIndexOf("s", 13)).toBe(12);
|
||||
expect("hello".lastIndexOf("serenity")).toBe(-1);
|
||||
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);
|
||||
});
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.padEnd).toHaveLength(1);
|
||||
expect(String.prototype.padEnd).toHaveLength(1);
|
||||
|
||||
var s = "foo";
|
||||
expect(s.padEnd(-1)).toBe("foo");
|
||||
expect(s.padEnd(0)).toBe("foo");
|
||||
expect(s.padEnd(3)).toBe("foo");
|
||||
expect(s.padEnd(5)).toBe("foo ");
|
||||
expect(s.padEnd(10)).toBe("foo ");
|
||||
expect(s.padEnd("5")).toBe("foo ");
|
||||
expect(s.padEnd([[["5"]]])).toBe("foo ");
|
||||
expect(s.padEnd(2, "+")).toBe("foo");
|
||||
expect(s.padEnd(5, "+")).toBe("foo++");
|
||||
expect(s.padEnd(5, 1)).toBe("foo11");
|
||||
expect(s.padEnd(10, null)).toBe("foonullnul");
|
||||
expect(s.padEnd(10, "bar")).toBe("foobarbarb");
|
||||
expect(s.padEnd(10, "123456789")).toBe("foo1234567");
|
||||
var s = "foo";
|
||||
expect(s.padEnd(-1)).toBe("foo");
|
||||
expect(s.padEnd(0)).toBe("foo");
|
||||
expect(s.padEnd(3)).toBe("foo");
|
||||
expect(s.padEnd(5)).toBe("foo ");
|
||||
expect(s.padEnd(10)).toBe("foo ");
|
||||
expect(s.padEnd("5")).toBe("foo ");
|
||||
expect(s.padEnd([[["5"]]])).toBe("foo ");
|
||||
expect(s.padEnd(2, "+")).toBe("foo");
|
||||
expect(s.padEnd(5, "+")).toBe("foo++");
|
||||
expect(s.padEnd(5, 1)).toBe("foo11");
|
||||
expect(s.padEnd(10, null)).toBe("foonullnul");
|
||||
expect(s.padEnd(10, "bar")).toBe("foobarbarb");
|
||||
expect(s.padEnd(10, "123456789")).toBe("foo1234567");
|
||||
});
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.padStart).toHaveLength(1);
|
||||
expect(String.prototype.padStart).toHaveLength(1);
|
||||
|
||||
var s = "foo";
|
||||
expect(s.padStart(-1)).toBe("foo");
|
||||
expect(s.padStart(0)).toBe("foo");
|
||||
expect(s.padStart(3)).toBe("foo");
|
||||
expect(s.padStart(5)).toBe(" foo");
|
||||
expect(s.padStart(10)).toBe(" foo");
|
||||
expect(s.padStart("5")).toBe(" foo");
|
||||
expect(s.padStart([[["5"]]])).toBe(" foo");
|
||||
expect(s.padStart(2, "+")).toBe("foo");
|
||||
expect(s.padStart(5, "+")).toBe("++foo");
|
||||
expect(s.padStart(5, 1)).toBe("11foo");
|
||||
expect(s.padStart(10, null)).toBe("nullnulfoo");
|
||||
expect(s.padStart(10, "bar")).toBe("barbarbfoo");
|
||||
expect(s.padStart(10, "123456789")).toBe("1234567foo");
|
||||
var s = "foo";
|
||||
expect(s.padStart(-1)).toBe("foo");
|
||||
expect(s.padStart(0)).toBe("foo");
|
||||
expect(s.padStart(3)).toBe("foo");
|
||||
expect(s.padStart(5)).toBe(" foo");
|
||||
expect(s.padStart(10)).toBe(" foo");
|
||||
expect(s.padStart("5")).toBe(" foo");
|
||||
expect(s.padStart([[["5"]]])).toBe(" foo");
|
||||
expect(s.padStart(2, "+")).toBe("foo");
|
||||
expect(s.padStart(5, "+")).toBe("++foo");
|
||||
expect(s.padStart(5, 1)).toBe("11foo");
|
||||
expect(s.padStart(10, null)).toBe("nullnulfoo");
|
||||
expect(s.padStart(10, "bar")).toBe("barbarbfoo");
|
||||
expect(s.padStart(10, "123456789")).toBe("1234567foo");
|
||||
});
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.repeat).toHaveLength(1);
|
||||
expect(String.prototype.repeat).toHaveLength(1);
|
||||
|
||||
expect("foo".repeat(0)).toBe("");
|
||||
expect("foo".repeat(1)).toBe("foo");
|
||||
expect("foo".repeat(2)).toBe("foofoo");
|
||||
expect("foo".repeat(3)).toBe("foofoofoo");
|
||||
expect("foo".repeat(3.1)).toBe("foofoofoo");
|
||||
expect("foo".repeat(3.5)).toBe("foofoofoo");
|
||||
expect("foo".repeat(3.9)).toBe("foofoofoo");
|
||||
expect("foo".repeat(null)).toBe("");
|
||||
expect("foo".repeat(undefined)).toBe("");
|
||||
expect("foo".repeat([])).toBe("");
|
||||
expect("foo".repeat("")).toBe("");
|
||||
expect("foo".repeat(0)).toBe("");
|
||||
expect("foo".repeat(1)).toBe("foo");
|
||||
expect("foo".repeat(2)).toBe("foofoo");
|
||||
expect("foo".repeat(3)).toBe("foofoofoo");
|
||||
expect("foo".repeat(3.1)).toBe("foofoofoo");
|
||||
expect("foo".repeat(3.5)).toBe("foofoofoo");
|
||||
expect("foo".repeat(3.9)).toBe("foofoofoo");
|
||||
expect("foo".repeat(null)).toBe("");
|
||||
expect("foo".repeat(undefined)).toBe("");
|
||||
expect("foo".repeat([])).toBe("");
|
||||
expect("foo".repeat("")).toBe("");
|
||||
});
|
||||
|
||||
test("throws correct range errors", () => {
|
||||
expect(() => {
|
||||
"foo".repeat(-1);
|
||||
}).toThrowWithMessage(RangeError, "repeat count must be a positive number");
|
||||
expect(() => {
|
||||
"foo".repeat(-1);
|
||||
}).toThrowWithMessage(RangeError, "repeat count must be a positive number");
|
||||
|
||||
expect(() => {
|
||||
"foo".repeat(Infinity);
|
||||
}).toThrowWithMessage(RangeError, "repeat count must be a finite number");
|
||||
expect(() => {
|
||||
"foo".repeat(Infinity);
|
||||
}).toThrowWithMessage(RangeError, "repeat count must be a finite number");
|
||||
});
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.slice).toHaveLength(2);
|
||||
expect(String.prototype.slice).toHaveLength(2);
|
||||
|
||||
expect("hello friends".slice()).toBe("hello friends");
|
||||
expect("hello friends".slice(1)).toBe("ello friends");
|
||||
expect("hello friends".slice(0, 5)).toBe("hello");
|
||||
expect("hello friends".slice(13, 6)).toBe("");
|
||||
expect("hello friends".slice("", 5)).toBe("hello");
|
||||
expect("hello friends".slice(3, 3)).toBe("");
|
||||
expect("hello friends".slice(-1, 13)).toBe("s");
|
||||
expect("hello friends".slice(0, 50)).toBe("hello friends");
|
||||
expect("hello friends".slice(0, "5")).toBe("hello");
|
||||
expect("hello friends".slice("6", "13")).toBe("friends");
|
||||
expect("hello friends".slice(-7)).toBe("friends");
|
||||
expect("hello friends".slice(1000)).toBe("");
|
||||
expect("hello friends".slice(-1000)).toBe("hello friends");
|
||||
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");
|
||||
});
|
||||
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.startsWith).toHaveLength(1);
|
||||
expect(String.prototype.startsWith).toHaveLength(1);
|
||||
|
||||
var s = "foobar";
|
||||
expect(s.startsWith("f")).toBeTrue();
|
||||
expect(s.startsWith("fo")).toBeTrue();
|
||||
expect(s.startsWith("foo")).toBeTrue();
|
||||
expect(s.startsWith("foob")).toBeTrue();
|
||||
expect(s.startsWith("fooba")).toBeTrue();
|
||||
expect(s.startsWith("foobar")).toBeTrue();
|
||||
expect(s.startsWith("foobar1")).toBeFalse();
|
||||
expect(s.startsWith("f", 0)).toBeTrue();
|
||||
expect(s.startsWith("fo", 0)).toBeTrue();
|
||||
expect(s.startsWith("foo", 0)).toBeTrue();
|
||||
expect(s.startsWith("foob", 0)).toBeTrue();
|
||||
expect(s.startsWith("fooba", 0)).toBeTrue();
|
||||
expect(s.startsWith("foobar", 0)).toBeTrue();
|
||||
expect(s.startsWith("foobar1", 0)).toBeFalse();
|
||||
expect(s.startsWith("foo", [])).toBeTrue();
|
||||
expect(s.startsWith("foo", null)).toBeTrue();
|
||||
expect(s.startsWith("foo", undefined)).toBeTrue();
|
||||
expect(s.startsWith("foo", false)).toBeTrue();
|
||||
expect(s.startsWith("foo", true)).toBeFalse();
|
||||
expect(s.startsWith("foo", "foo")).toBeTrue();
|
||||
expect(s.startsWith("foo", -1)).toBeTrue();
|
||||
expect(s.startsWith("foo", 42)).toBeFalse();
|
||||
expect(s.startsWith("bar", 3)).toBeTrue();
|
||||
expect(s.startsWith("bar", "3")).toBeTrue();
|
||||
expect(s.startsWith("bar1", 3)).toBeFalse();
|
||||
expect(s.startsWith()).toBeFalse();
|
||||
expect(s.startsWith("")).toBeTrue();
|
||||
expect(s.startsWith("", 0)).toBeTrue();
|
||||
expect(s.startsWith("", 1)).toBeTrue();
|
||||
expect(s.startsWith("", -1)).toBeTrue();
|
||||
expect(s.startsWith("", 42)).toBeTrue();
|
||||
var s = "foobar";
|
||||
expect(s.startsWith("f")).toBeTrue();
|
||||
expect(s.startsWith("fo")).toBeTrue();
|
||||
expect(s.startsWith("foo")).toBeTrue();
|
||||
expect(s.startsWith("foob")).toBeTrue();
|
||||
expect(s.startsWith("fooba")).toBeTrue();
|
||||
expect(s.startsWith("foobar")).toBeTrue();
|
||||
expect(s.startsWith("foobar1")).toBeFalse();
|
||||
expect(s.startsWith("f", 0)).toBeTrue();
|
||||
expect(s.startsWith("fo", 0)).toBeTrue();
|
||||
expect(s.startsWith("foo", 0)).toBeTrue();
|
||||
expect(s.startsWith("foob", 0)).toBeTrue();
|
||||
expect(s.startsWith("fooba", 0)).toBeTrue();
|
||||
expect(s.startsWith("foobar", 0)).toBeTrue();
|
||||
expect(s.startsWith("foobar1", 0)).toBeFalse();
|
||||
expect(s.startsWith("foo", [])).toBeTrue();
|
||||
expect(s.startsWith("foo", null)).toBeTrue();
|
||||
expect(s.startsWith("foo", undefined)).toBeTrue();
|
||||
expect(s.startsWith("foo", false)).toBeTrue();
|
||||
expect(s.startsWith("foo", true)).toBeFalse();
|
||||
expect(s.startsWith("foo", "foo")).toBeTrue();
|
||||
expect(s.startsWith("foo", -1)).toBeTrue();
|
||||
expect(s.startsWith("foo", 42)).toBeFalse();
|
||||
expect(s.startsWith("bar", 3)).toBeTrue();
|
||||
expect(s.startsWith("bar", "3")).toBeTrue();
|
||||
expect(s.startsWith("bar1", 3)).toBeFalse();
|
||||
expect(s.startsWith()).toBeFalse();
|
||||
expect(s.startsWith("")).toBeTrue();
|
||||
expect(s.startsWith("", 0)).toBeTrue();
|
||||
expect(s.startsWith("", 1)).toBeTrue();
|
||||
expect(s.startsWith("", -1)).toBeTrue();
|
||||
expect(s.startsWith("", 42)).toBeTrue();
|
||||
});
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.substring).toHaveLength(2);
|
||||
expect(String.prototype.substring).toHaveLength(2);
|
||||
|
||||
expect("hello friends".substring()).toBe("hello friends");
|
||||
expect("hello friends".substring(1)).toBe("ello friends");
|
||||
expect("hello friends".substring(0, 5)).toBe("hello");
|
||||
expect("hello friends".substring(13, 6)).toBe("friends");
|
||||
expect("hello friends".substring('', 5)).toBe("hello");
|
||||
expect("hello friends".substring(3, 3)).toBe("");
|
||||
expect("hello friends".substring(-1, 13)).toBe("hello friends");
|
||||
expect("hello friends".substring(0, 50)).toBe("hello friends");
|
||||
expect("hello friends".substring(0, "5")).toBe("hello");
|
||||
expect("hello friends".substring("6", "13")).toBe("friends");
|
||||
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");
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.toLowerCase).toHaveLength(0);
|
||||
expect(String.prototype.toLowerCase).toHaveLength(0);
|
||||
|
||||
expect("foo".toLowerCase()).toBe("foo");
|
||||
expect("Foo".toLowerCase()).toBe("foo");
|
||||
expect("FOO".toLowerCase()).toBe("foo");
|
||||
expect("foo".toLowerCase()).toBe("foo");
|
||||
expect("Foo".toLowerCase()).toBe("foo");
|
||||
expect("FOO".toLowerCase()).toBe("foo");
|
||||
|
||||
expect(('b' + 'a' + + 'a' + 'a').toLowerCase()).toBe("banana");
|
||||
expect(("b" + "a" + +"a" + "a").toLowerCase()).toBe("banana");
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.toString).toHaveLength(0)
|
||||
expect(String.prototype.toString).toHaveLength(0);
|
||||
|
||||
expect("".toString()).toBe("");
|
||||
expect("hello friends".toString()).toBe("hello friends");
|
||||
expect("".toString()).toBe("");
|
||||
expect("hello friends".toString()).toBe("hello friends");
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.toUpperCase).toHaveLength(0);
|
||||
expect(String.prototype.toUpperCase).toHaveLength(0);
|
||||
|
||||
expect("foo".toUpperCase()).toBe("FOO");
|
||||
expect("Foo".toUpperCase()).toBe("FOO");
|
||||
expect("FOO".toUpperCase()).toBe("FOO");
|
||||
expect("foo".toUpperCase()).toBe("FOO");
|
||||
expect("Foo".toUpperCase()).toBe("FOO");
|
||||
expect("FOO".toUpperCase()).toBe("FOO");
|
||||
|
||||
expect(('b' + 'a' + + 'n' + 'a').toUpperCase()).toBe("BANANA");
|
||||
expect(("b" + "a" + +"n" + "a").toUpperCase()).toBe("BANANA");
|
||||
});
|
||||
|
|
|
@ -1,58 +1,58 @@
|
|||
test("trim", () => {
|
||||
expect(String.prototype.trim).toHaveLength(0);
|
||||
expect(String.prototype.trim).toHaveLength(0);
|
||||
|
||||
expect(" hello friends ".trim()).toBe("hello friends");
|
||||
expect("hello friends ".trim()).toBe("hello friends");
|
||||
expect(" hello friends".trim()).toBe("hello friends");
|
||||
expect(" hello friends ".trim()).toBe("hello friends");
|
||||
expect("hello friends ".trim()).toBe("hello friends");
|
||||
expect(" hello friends".trim()).toBe("hello friends");
|
||||
|
||||
expect("\thello friends\t".trim()).toBe("hello friends");
|
||||
expect("\thello friends".trim()).toBe("hello friends");
|
||||
expect("hello friends\t".trim()).toBe("hello friends");
|
||||
expect("\thello friends\t".trim()).toBe("hello friends");
|
||||
expect("\thello friends".trim()).toBe("hello friends");
|
||||
expect("hello friends\t".trim()).toBe("hello friends");
|
||||
|
||||
expect("\rhello friends\r".trim()).toBe("hello friends");
|
||||
expect("\rhello friends".trim()).toBe("hello friends");
|
||||
expect("hello friends\r".trim()).toBe("hello friends");
|
||||
expect("\rhello friends\r".trim()).toBe("hello friends");
|
||||
expect("\rhello friends".trim()).toBe("hello friends");
|
||||
expect("hello friends\r".trim()).toBe("hello friends");
|
||||
|
||||
expect("\rhello friends\n".trim()).toBe("hello friends");
|
||||
expect("\r\thello friends".trim()).toBe("hello friends");
|
||||
expect("hello friends\r\n".trim()).toBe("hello friends");
|
||||
expect(" \thello friends\r\n".trim()).toBe("hello friends");
|
||||
expect("\n\t\thello friends\r\n".trim()).toBe("hello friends");
|
||||
expect("\n\t\thello friends\t\t".trim()).toBe("hello friends");
|
||||
expect("\rhello friends\n".trim()).toBe("hello friends");
|
||||
expect("\r\thello friends".trim()).toBe("hello friends");
|
||||
expect("hello friends\r\n".trim()).toBe("hello friends");
|
||||
expect(" \thello friends\r\n".trim()).toBe("hello friends");
|
||||
expect("\n\t\thello friends\r\n".trim()).toBe("hello friends");
|
||||
expect("\n\t\thello friends\t\t".trim()).toBe("hello friends");
|
||||
});
|
||||
|
||||
test("trimStart", () => {
|
||||
expect(String.prototype.trimStart).toHaveLength(0);
|
||||
expect(String.prototype.trimStart).toHaveLength(0);
|
||||
|
||||
expect(" hello friends".trimStart()).toBe("hello friends");
|
||||
expect("hello friends ".trimStart()).toBe("hello friends ");
|
||||
expect(" hello friends ".trimStart()).toBe("hello friends ");
|
||||
expect(" 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("\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");
|
||||
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(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 ".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\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\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");
|
||||
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");
|
||||
});
|
||||
|
|
|
@ -1,12 +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");
|
||||
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");
|
||||
});
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.raw).toHaveLength(1);
|
||||
expect(String.raw).toHaveLength(1);
|
||||
|
||||
let str = String.raw`foo\nbar`;
|
||||
expect(str).toHaveLength(8);
|
||||
expect(str).toBe("foo\\nbar");
|
||||
let str = String.raw`foo\nbar`;
|
||||
expect(str).toHaveLength(8);
|
||||
expect(str).toBe("foo\\nbar");
|
||||
|
||||
str = String.raw`foo ${1 + 9}\nbar${"hf!"}`;
|
||||
expect(str).toBe("foo 10\\nbarhf!");
|
||||
str = String.raw`foo ${1 + 9}\nbar${"hf!"}`;
|
||||
expect(str).toBe("foo 10\\nbarhf!");
|
||||
|
||||
str = String.raw`${10}${20}${30}`;
|
||||
expect(str).toBe("102030");
|
||||
str = String.raw`${10}${20}${30}`;
|
||||
expect(str).toBe("102030");
|
||||
|
||||
str = String.raw({ raw: ["foo ", "\\nbar"] }, 10, "hf!");
|
||||
expect(str).toBe("foo 10\\nbar");
|
||||
str = String.raw({ raw: ["foo ", "\\nbar"] }, 10, "hf!");
|
||||
expect(str).toBe("foo 10\\nbar");
|
||||
|
||||
str = String.raw({ raw: ["foo ", "\\nbar"] });
|
||||
expect(str).toBe("foo \\nbar");
|
||||
str = String.raw({ raw: ["foo ", "\\nbar"] });
|
||||
expect(str).toBe("foo \\nbar");
|
||||
|
||||
str = String.raw({ raw: [] }, 10, "hf!");
|
||||
expect(str).toBe("");
|
||||
str = String.raw({ raw: [] }, 10, "hf!");
|
||||
expect(str).toBe("");
|
||||
|
||||
str = String.raw({ raw: 1 });
|
||||
expect(str).toBe("");
|
||||
str = String.raw({ raw: 1 });
|
||||
expect(str).toBe("");
|
||||
});
|
||||
|
||||
test("passing object with no 'raw' property", () => {
|
||||
expect(() => {
|
||||
String.raw({});
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert property 'raw' to object from undefined");
|
||||
expect(() => {
|
||||
String.raw({});
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert property 'raw' to object from undefined");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue