diff options
author | Linus Groh <mail@linusgroh.de> | 2020-04-19 22:35:32 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-20 11:41:25 +0200 |
commit | d3e3f5b42195f61ea3a8ca136c73d3d86098d87b (patch) | |
tree | 23423462bb5ec1f3d2359afc3ad46d81e6c82154 /Libraries | |
parent | a893c6ff0d1380a3315266d5af45342ad5297526 (diff) | |
download | serenity-d3e3f5b42195f61ea3a8ca136c73d3d86098d87b.zip |
LibJS: Add tests for String.prototype.repeat()
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/Tests/String.prototype.repeat.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Libraries/LibJS/Tests/String.prototype.repeat.js b/Libraries/LibJS/Tests/String.prototype.repeat.js new file mode 100644 index 0000000000..3b711a0f7b --- /dev/null +++ b/Libraries/LibJS/Tests/String.prototype.repeat.js @@ -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); +} |