michael@0: /* Test String.prototype.repeat */ michael@0: michael@0: load(libdir + 'asserts.js'); michael@0: michael@0: assertEq("abc".repeat(1), "abc"); michael@0: assertEq("abc".repeat(2), "abcabc"); michael@0: assertEq("abc".repeat(3), "abcabcabc"); michael@0: assertEq("a".repeat(10), "aaaaaaaaaa"); michael@0: assertEq("abc".repeat(0), ""); michael@0: assertEq("abc".repeat(2.9), "abcabc"); michael@0: michael@0: var myobj = {toString : (function () "abc"), repeat : String.prototype.repeat}; michael@0: assertEq(myobj.repeat(1), "abc"); michael@0: assertEq(myobj.repeat(2), "abcabc"); michael@0: michael@0: assertThrowsInstanceOf(function() { michael@0: "abc".repeat(-1); michael@0: }, RangeError, michael@0: "String.prototype.repeat should raise RangeError on negative arguments"); michael@0: assertThrowsInstanceOf(function() { michael@0: "abc".repeat(Number.POSITIVE_INFINITY); michael@0: }, RangeError, michael@0: "String.prototype.repeat should raise RangeError on excedding maximum string length"); michael@0: assertThrowsInstanceOf(function() { michael@0: "abc".repeat(1 << 29); michael@0: }, RangeError, michael@0: "String.prototype.repeat should raise RangeError on excedding maximum string length"); michael@0: michael@0: assertEq("".repeat(5), ""); michael@0: assertEq("".repeat(1 << 29), "");