1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:47:44 +00:00

LibJS: Reorganize tests into subfolders

This commit is contained in:
Matthew Olsson 2020-07-02 16:09:21 -07:00 committed by Andreas Kling
parent 21064a1883
commit 4c48c9d69d
213 changed files with 10 additions and 2 deletions

View file

@ -0,0 +1,23 @@
load("test-common.js");
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);
}

View file

@ -0,0 +1,23 @@
load("test-common.js");
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);
}

View file

@ -0,0 +1,52 @@
load("test-common.js");
try {
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 });
assertThrowsError(() => {
String.prototype[name].call({ toString: () => new String() });
}, {
error: TypeError,
message: "Cannot convert object to string"
});
assertThrowsError(() => {
String.prototype[name].call({ toString: () => [] });
}, {
error: TypeError,
message: "Cannot convert object to string"
});
assertThrowsError(() => {
String.prototype[name].call({ toString: () => ({}) });
}, {
error: TypeError,
message: "Cannot convert object to string"
});
});
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -0,0 +1,24 @@
load("test-common.js");
try {
var s = "foobar"
assert(typeof s === "string");
assert(s.length === 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) === '');
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);
}

View file

@ -0,0 +1,22 @@
load("test-common.js");
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);
}

View file

@ -0,0 +1,18 @@
load("test-common.js");
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);
}

View file

@ -0,0 +1,12 @@
load("test-common.js");
try {
var s = "hello friends"
assert(s.indexOf("friends") === 6);
assert(s.indexOf("enemies") === -1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -0,0 +1,13 @@
load("test-common.js");
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);
}

View file

@ -0,0 +1,27 @@
load("test-common.js");
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);
}

View file

@ -0,0 +1,24 @@
load("test-common.js");
try {
assert(String.prototype.padEnd.length === 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);
}

View file

@ -0,0 +1,24 @@
load("test-common.js");
try {
assert(String.prototype.padStart.length === 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);
}

View file

@ -0,0 +1,37 @@
load("test-common.js");
try {
assert(String.prototype.repeat.length === 1);
try {
"foo".repeat(-1);
assertNotReached();
} catch (e) {
assert(e.name === "RangeError");
assert(e.message === "repeat count must be a positive number");
}
try {
"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);
}

View file

@ -0,0 +1,22 @@
load("test-common.js");
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");
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -0,0 +1,40 @@
load("test-common.js");
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);
}

View file

@ -0,0 +1,19 @@
load("test-common.js");
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);
}

View file

@ -0,0 +1,15 @@
load("test-common.js");
try {
assert(String.prototype.toLowerCase.length === 0);
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);
}

View file

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

View file

@ -0,0 +1,15 @@
load("test-common.js");
try {
assert(String.prototype.toUpperCase.length === 0);
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);
}

View file

@ -0,0 +1,56 @@
load("test-common.js");
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 ");
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");
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");
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");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

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