mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibJS: Add tests for String.prototype.repeat()
This commit is contained in:
parent
a893c6ff0d
commit
d3e3f5b421
1 changed files with 37 additions and 0 deletions
37
Libraries/LibJS/Tests/String.prototype.repeat.js
Normal file
37
Libraries/LibJS/Tests/String.prototype.repeat.js
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue