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

LibJS: Add tests for String.prototype.repeat()

This commit is contained in:
Linus Groh 2020-04-19 22:35:32 +01:00 committed by Andreas Kling
parent a893c6ff0d
commit d3e3f5b421

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